OmniSciDB  8a228a1076
anonymous_namespace{QueryMemoryDescriptor.cpp} Namespace Reference

Functions

bool is_int_and_no_bigger_than (const SQLTypeInfo &ti, const size_t byte_width)
 
std::vector< ssize_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< ssize_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)
 

Function Documentation

◆ is_int_and_no_bigger_than()

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

Definition at line 33 of file QueryMemoryDescriptor.cpp.

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

Referenced by QueryMemoryDescriptor::pick_target_compact_width().

33  {
34  if (!ti.is_integer()) {
35  return false;
36  }
37  return get_bit_width(ti) <= (byte_width * 8);
38 }
bool is_integer() const
Definition: sqltypes.h:418
size_t get_bit_width(const SQLTypeInfo &ti)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pick_baseline_key_component_width()

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

Definition at line 111 of file QueryMemoryDescriptor.cpp.

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

Referenced by pick_baseline_key_width().

112  {
113  if (range.getType() == ExpressionRangeType::Invalid) {
114  return sizeof(int64_t);
115  }
116  switch (range.getType()) {
118  if (group_col_width == sizeof(int64_t) && range.hasNulls()) {
119  return sizeof(int64_t);
120  }
121  return range.getIntMax() < EMPTY_KEY_32 - 1 ? sizeof(int32_t) : sizeof(int64_t);
124  return sizeof(int64_t); // No compaction for floating point yet.
125  default:
126  UNREACHABLE();
127  }
128  return sizeof(int64_t);
129 }
#define UNREACHABLE()
Definition: Logger.h:241
int64_t getIntMax() const
ExpressionRangeType getType() const
bool hasNulls() const
#define EMPTY_KEY_32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pick_baseline_key_width()

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 132 of file QueryMemoryDescriptor.cpp.

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

Referenced by QueryMemoryDescriptor::init().

134  {
135  int8_t compact_width{4};
136  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
137  const auto expr_range = getExpressionRange(groupby_expr.get(), query_infos, executor);
138  compact_width = std::max(compact_width,
140  expr_range, groupby_expr->get_type_info().get_size()));
141  }
142  return compact_width;
143 }
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:
+ Here is the caller graph for this function:

◆ target_expr_group_by_indices()

std::vector<ssize_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 40 of file QueryMemoryDescriptor.cpp.

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

Referenced by QueryMemoryDescriptor::init().

42  {
43  std::vector<ssize_t> indices(target_exprs.size(), -1);
44  for (size_t target_idx = 0; target_idx < target_exprs.size(); ++target_idx) {
45  const auto target_expr = target_exprs[target_idx];
46  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
47  continue;
48  }
49  const auto var_expr = dynamic_cast<const Analyzer::Var*>(target_expr);
50  if (var_expr && var_expr->get_which_row() == Analyzer::Var::kGROUPBY) {
51  indices[target_idx] = var_expr->get_varno() - 1;
52  continue;
53  }
54  }
55  return indices;
56 }
int get_varno() const
Definition: Analyzer.h:276
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ target_expr_proj_indices()

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

Definition at line 58 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().

Referenced by QueryMemoryDescriptor::init().

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

◆ use_streaming_top_n()

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

Definition at line 145 of file QueryMemoryDescriptor.cpp.

References SortInfo::algorithm, CHECK_GT, CHECK_LE, g_cluster, SortInfo::limit, SortInfo::offset, SortInfo::order_entries, RelAlgExecutionUnit::sort_info, StreamingTopN, and RelAlgExecutionUnit::target_exprs.

Referenced by QueryMemoryDescriptor::init().

146  {
147  if (g_cluster) {
148  return false; // TODO(miyu)
149  }
150 
151  for (const auto target_expr : ra_exe_unit.target_exprs) {
152  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
153  return false;
154  }
155  if (dynamic_cast<const Analyzer::WindowFunction*>(target_expr)) {
156  return false;
157  }
158  }
159 
160  // TODO: Allow streaming top n for columnar output
161  if (!output_columnar && ra_exe_unit.sort_info.order_entries.size() == 1 &&
162  ra_exe_unit.sort_info.limit &&
164  const auto only_order_entry = ra_exe_unit.sort_info.order_entries.front();
165  CHECK_GT(only_order_entry.tle_no, int(0));
166  CHECK_LE(static_cast<size_t>(only_order_entry.tle_no),
167  ra_exe_unit.target_exprs.size());
168  const auto order_entry_expr = ra_exe_unit.target_exprs[only_order_entry.tle_no - 1];
169  const auto n = ra_exe_unit.sort_info.offset + ra_exe_unit.sort_info.limit;
170  if ((order_entry_expr->get_type_info().is_number() ||
171  order_entry_expr->get_type_info().is_time()) &&
172  n <= 100000) { // TODO(miyu): relax?
173  return true;
174  }
175  }
176 
177  return false;
178 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< Analyzer::OrderEntry > order_entries
const SortAlgorithm algorithm
#define CHECK_GT(x, y)
Definition: Logger.h:209
const size_t limit
const SortInfo sort_info
#define CHECK_LE(x, y)
Definition: Logger.h:208
bool g_cluster
const size_t offset
+ Here is the caller graph for this function: