OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{QueryMemoryDescriptor.cpp} Namespace Reference

Functions

bool is_int_and_no_bigger_than (const SQLTypeInfo &ti, const size_t byte_width)
 
bool is_valid_int32_range (const ExpressionRange &range)
 
std::vector< int64_t > target_expr_group_by_indices (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const std::vector< Analyzer::Expr * > &target_exprs)
 
std::vector< int64_t > target_expr_proj_indices (const RelAlgExecutionUnit &ra_exe_unit, const Catalog_Namespace::Catalog &cat)
 
int8_t pick_baseline_key_component_width (const ExpressionRange &range, const size_t group_col_width)
 
int8_t pick_baseline_key_width (const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos, const Executor *executor)
 
bool use_streaming_top_n (const RelAlgExecutionUnit &ra_exe_unit, const bool output_columnar)
 
template<class T >
std::vector< int8_t > get_col_byte_widths (const T &col_expr_list)
 
template<SQLAgg... agg_types>
bool any_of (std::vector< Analyzer::Expr * > const &target_exprs)
 

Function Documentation

template<SQLAgg... agg_types>
bool anonymous_namespace{QueryMemoryDescriptor.cpp}::any_of ( std::vector< Analyzer::Expr * > const &  target_exprs)

Definition at line 441 of file QueryMemoryDescriptor.cpp.

Referenced by import_export::TypedImportBuffer::add_values(), ResultSet::areAnyColumnsLazyFetched(), Executor::codegenJoinLoops(), RelAlgExecutor::executeUnion(), QueryPlanDagExtractor::handleLeftDeepJoinTree(), Analyzer::WindowFunction::hasAggregateTreeRequiredWindowFunc(), HashingSchemeRecycler::hasItemInCache(), QueryMemoryInitializer::initRowGroups(), anonymous_namespace{DdlCommandExecutor.cpp}::is_default_server(), OverlapsJoinSupportedFunction::is_many_to_many_func(), OverlapsJoinSupportedFunction::is_overlaps_supported_func(), OverlapsJoinSupportedFunction::is_point_poly_rewrite_target_func(), OverlapsJoinSupportedFunction::is_poly_mpoly_rewrite_target_func(), OverlapsJoinSupportedFunction::is_poly_point_rewrite_target_func(), OverlapsJoinSupportedFunction::is_range_join_rewrite_target_func(), anonymous_namespace{RelAlgExecutor.cpp}::is_window_execution_unit(), RegisteredQueryHint::isAnyQueryHintDelivered(), Analyzer::WindowFunction::isFrameNavigateWindowFunction(), Analyzer::WindowFunction::isFramingAvailableWindowFunc(), and HashtableRecycler::isInvalidHashTableCacheKey().

441  {
442  return boost::algorithm::any_of(target_exprs, [=](Analyzer::Expr const* expr) {
443  auto const* const agg = dynamic_cast<Analyzer::AggExpr const*>(expr);
444  return agg && (... || (agg_types == agg->get_aggtype()));
445  });
446 }
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)

+ Here is the caller graph for this function:

template<class T >
std::vector<int8_t> anonymous_namespace{QueryMemoryDescriptor.cpp}::get_col_byte_widths ( const T &  col_expr_list)
inline

Definition at line 186 of file QueryMemoryDescriptor.cpp.

References CHECK, CHECK_EQ, g_bigint_count, get_bit_width(), get_compact_type(), get_target_info(), anonymous_namespace{TargetExprBuilder.cpp}::is_varlen_projection(), kAVG, kENCODING_NONE, and heavydb.dtypes::T.

Referenced by QueryMemoryDescriptor::init(), and QueryMemoryDescriptor::pick_target_compact_width().

186  {
187  std::vector<int8_t> col_widths;
188  size_t col_expr_idx = 0;
189  for (const auto& col_expr : col_expr_list) {
190  if (!col_expr) {
191  // row index
192  col_widths.push_back(sizeof(int64_t));
193  } else {
194  bool is_varlen_projection{false};
195  if constexpr (std::is_same<T, std::list<std::shared_ptr<Analyzer::Expr>>>::value) {
197  !(std::dynamic_pointer_cast<const Analyzer::GeoExpr>(col_expr) == nullptr);
198  } else {
200  !(dynamic_cast<const Analyzer::GeoExpr*>(col_expr) == nullptr);
201  }
202 
203  if (is_varlen_projection) {
204  col_widths.push_back(sizeof(int64_t));
205  ++col_expr_idx;
206  continue;
207  }
208  const auto agg_info = get_target_info(col_expr, g_bigint_count);
209  const auto chosen_type = get_compact_type(agg_info);
210  if ((chosen_type.is_string() && chosen_type.get_compression() == kENCODING_NONE) ||
211  chosen_type.is_array()) {
212  col_widths.push_back(sizeof(int64_t));
213  col_widths.push_back(sizeof(int64_t));
214  ++col_expr_idx;
215  continue;
216  }
217  if (chosen_type.is_geometry()) {
218  for (auto i = 0; i < chosen_type.get_physical_coord_cols(); ++i) {
219  col_widths.push_back(sizeof(int64_t));
220  col_widths.push_back(sizeof(int64_t));
221  }
222  ++col_expr_idx;
223  continue;
224  }
225  const auto col_expr_bitwidth = get_bit_width(chosen_type);
226  CHECK_EQ(size_t(0), col_expr_bitwidth % 8);
227  col_widths.push_back(static_cast<int8_t>(col_expr_bitwidth >> 3));
228  // for average, we'll need to keep the count as well
229  if (agg_info.agg_kind == kAVG) {
230  CHECK(agg_info.is_agg);
231  col_widths.push_back(sizeof(int64_t));
232  }
233  }
234  ++col_expr_idx;
235  }
236  return col_widths;
237 }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:88
const SQLTypeInfo get_compact_type(const TargetInfo &target)
bool is_varlen_projection(const Analyzer::Expr *target_expr, const SQLTypeInfo &ti)
size_t get_bit_width(const SQLTypeInfo &ti)
bool g_bigint_count
#define CHECK(condition)
Definition: Logger.h:289
Definition: sqldefs.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{QueryMemoryDescriptor.cpp}::is_int_and_no_bigger_than ( const SQLTypeInfo ti,
const size_t  byte_width 
)

Definition at line 34 of file QueryMemoryDescriptor.cpp.

References get_bit_width(), and SQLTypeInfo::is_integer().

Referenced by QueryMemoryDescriptor::pick_target_compact_width().

34  {
35  if (!ti.is_integer()) {
36  return false;
37  }
38  return get_bit_width(ti) <= (byte_width * 8);
39 }
size_t get_bit_width(const SQLTypeInfo &ti)
bool is_integer() const
Definition: sqltypes.h:578

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{QueryMemoryDescriptor.cpp}::is_valid_int32_range ( const ExpressionRange range)

Definition at line 41 of file QueryMemoryDescriptor.cpp.

References EMPTY_KEY_32, ExpressionRange::getIntMax(), and ExpressionRange::getIntMin().

Referenced by pick_baseline_key_component_width().

41  {
42  return range.getIntMin() > INT32_MIN && range.getIntMax() < EMPTY_KEY_32 - 1;
43 }
int64_t getIntMin() const
int64_t getIntMax() const
#define EMPTY_KEY_32

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t anonymous_namespace{QueryMemoryDescriptor.cpp}::pick_baseline_key_component_width ( const ExpressionRange range,
const size_t  group_col_width 
)

Definition at line 116 of file QueryMemoryDescriptor.cpp.

References Double, Float, ExpressionRange::getType(), ExpressionRange::hasNulls(), Integer, Invalid, is_valid_int32_range(), and UNREACHABLE.

Referenced by pick_baseline_key_width().

117  {
118  if (range.getType() == ExpressionRangeType::Invalid) {
119  return sizeof(int64_t);
120  }
121  switch (range.getType()) {
123  if (group_col_width == sizeof(int64_t) && range.hasNulls()) {
124  return sizeof(int64_t);
125  }
126  return is_valid_int32_range(range) ? sizeof(int32_t) : sizeof(int64_t);
129  return sizeof(int64_t); // No compaction for floating point yet.
130  default:
131  UNREACHABLE();
132  }
133  return sizeof(int64_t);
134 }
#define UNREACHABLE()
Definition: Logger.h:333
bool is_valid_int32_range(const ExpressionRange &range)
bool hasNulls() const
ExpressionRangeType getType() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t anonymous_namespace{QueryMemoryDescriptor.cpp}::pick_baseline_key_width ( const RelAlgExecutionUnit ra_exe_unit,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor 
)

Definition at line 137 of file QueryMemoryDescriptor.cpp.

References getExpressionRange(), RelAlgExecutionUnit::groupby_exprs, and pick_baseline_key_component_width().

139  {
140  int8_t compact_width{4};
141  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
142  const auto expr_range = getExpressionRange(groupby_expr.get(), query_infos, executor);
143  compact_width = std::max(compact_width,
145  expr_range, groupby_expr->get_type_info().get_size()));
146  }
147  return compact_width;
148 }
int8_t pick_baseline_key_component_width(const ExpressionRange &range, const size_t group_col_width)
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)

+ Here is the call graph for this function:

std::vector<int64_t> anonymous_namespace{QueryMemoryDescriptor.cpp}::target_expr_group_by_indices ( const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby_exprs,
const std::vector< Analyzer::Expr * > &  target_exprs 
)

Definition at line 45 of file QueryMemoryDescriptor.cpp.

References Analyzer::Var::get_varno(), and Analyzer::Var::kGROUPBY.

47  {
48  std::vector<int64_t> indices(target_exprs.size(), -1);
49  for (size_t target_idx = 0; target_idx < target_exprs.size(); ++target_idx) {
50  const auto target_expr = target_exprs[target_idx];
51  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
52  continue;
53  }
54  const auto var_expr = dynamic_cast<const Analyzer::Var*>(target_expr);
55  if (var_expr && var_expr->get_which_row() == Analyzer::Var::kGROUPBY) {
56  indices[target_idx] = var_expr->get_varno() - 1;
57  continue;
58  }
59  }
60  return indices;
61 }
int get_varno() const
Definition: Analyzer.h:284

+ Here is the call graph for this function:

std::vector<int64_t> anonymous_namespace{QueryMemoryDescriptor.cpp}::target_expr_proj_indices ( const RelAlgExecutionUnit ra_exe_unit,
const Catalog_Namespace::Catalog cat 
)

Definition at line 63 of file QueryMemoryDescriptor.cpp.

References cat(), CHECK, get_column_descriptor_maybe(), RelAlgExecutionUnit::input_descs, SortInfo::order_entries, RelAlgExecutionUnit::quals, RelAlgExecutionUnit::simple_quals, RelAlgExecutionUnit::sort_info, RelAlgExecutionUnit::target_exprs, and ScalarExprVisitor< T >::visit().

64  {
65  if (ra_exe_unit.input_descs.size() > 1 ||
66  !ra_exe_unit.sort_info.order_entries.empty()) {
67  return {};
68  }
69  std::vector<int64_t> target_indices(ra_exe_unit.target_exprs.size(), -1);
70  UsedColumnsVisitor columns_visitor;
71  std::unordered_set<int> used_columns;
72  for (const auto& simple_qual : ra_exe_unit.simple_quals) {
73  const auto crt_used_columns = columns_visitor.visit(simple_qual.get());
74  used_columns.insert(crt_used_columns.begin(), crt_used_columns.end());
75  }
76  for (const auto& qual : ra_exe_unit.quals) {
77  const auto crt_used_columns = columns_visitor.visit(qual.get());
78  used_columns.insert(crt_used_columns.begin(), crt_used_columns.end());
79  }
80  for (const auto& target : ra_exe_unit.target_exprs) {
81  const auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(target);
82  if (col_var) {
83  const auto cd = get_column_descriptor_maybe(
84  col_var->get_column_id(), col_var->get_table_id(), cat);
85  if (!cd || !cd->isVirtualCol) {
86  continue;
87  }
88  }
89  const auto crt_used_columns = columns_visitor.visit(target);
90  used_columns.insert(crt_used_columns.begin(), crt_used_columns.end());
91  }
92  for (size_t target_idx = 0; target_idx < ra_exe_unit.target_exprs.size();
93  ++target_idx) {
94  const auto target_expr = ra_exe_unit.target_exprs[target_idx];
95  CHECK(target_expr);
96  const auto& ti = target_expr->get_type_info();
97  // TODO: add proper lazy fetch for varlen types in result set
98  if (ti.is_varlen()) {
99  continue;
100  }
101  const auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(target_expr);
102  if (!col_var) {
103  continue;
104  }
105  if (!ti.is_varlen() &&
106  used_columns.find(col_var->get_column_id()) == used_columns.end()) {
107  // setting target index to be zero so that later it can be decoded properly (in lazy
108  // fetch, the zeroth target index indicates the corresponding rowid column for the
109  // projected entry)
110  target_indices[target_idx] = 0;
111  }
112  }
113  return target_indices;
114 }
std::vector< Analyzer::Expr * > target_exprs
std::string cat(Ts &&...args)
const std::list< Analyzer::OrderEntry > order_entries
std::vector< InputDescriptor > input_descs
T visit(const Analyzer::Expr *expr) const
const ColumnDescriptor * get_column_descriptor_maybe(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:220
std::list< std::shared_ptr< Analyzer::Expr > > quals
#define CHECK(condition)
Definition: Logger.h:289
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals

+ Here is the call graph for this function:

bool anonymous_namespace{QueryMemoryDescriptor.cpp}::use_streaming_top_n ( const RelAlgExecutionUnit ra_exe_unit,
const bool  output_columnar 
)

Definition at line 150 of file QueryMemoryDescriptor.cpp.

References SortInfo::algorithm, CHECK_GT, CHECK_LE, g_cluster, g_streaming_topn_max, SortInfo::limit, anonymous_namespace{Utm.h}::n, SortInfo::offset, SortInfo::order_entries, RelAlgExecutionUnit::sort_info, StreamingTopN, and RelAlgExecutionUnit::target_exprs.

151  {
152  if (g_cluster) {
153  return false; // TODO(miyu)
154  }
155 
156  for (const auto target_expr : ra_exe_unit.target_exprs) {
157  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
158  return false;
159  }
160  if (dynamic_cast<const Analyzer::WindowFunction*>(target_expr)) {
161  return false;
162  }
163  }
164 
165  // TODO: Allow streaming top n for columnar output
166  if (!output_columnar && ra_exe_unit.sort_info.order_entries.size() == 1 &&
167  ra_exe_unit.sort_info.limit &&
169  const auto only_order_entry = ra_exe_unit.sort_info.order_entries.front();
170  CHECK_GT(only_order_entry.tle_no, int(0));
171  CHECK_LE(static_cast<size_t>(only_order_entry.tle_no),
172  ra_exe_unit.target_exprs.size());
173  const auto order_entry_expr = ra_exe_unit.target_exprs[only_order_entry.tle_no - 1];
174  const auto n = ra_exe_unit.sort_info.offset + ra_exe_unit.sort_info.limit;
175  if ((order_entry_expr->get_type_info().is_number() ||
176  order_entry_expr->get_type_info().is_time()) &&
177  n <= g_streaming_topn_max) {
178  return true;
179  }
180  }
181 
182  return false;
183 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< Analyzer::OrderEntry > order_entries
const SortAlgorithm algorithm
size_t g_streaming_topn_max
Definition: ResultSet.cpp:51
#define CHECK_GT(x, y)
Definition: Logger.h:301
const size_t limit
#define CHECK_LE(x, y)
Definition: Logger.h:300
bool g_cluster
constexpr double n
Definition: Utm.h:38
const size_t offset