OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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)
 
bool anyOf (std::vector< Analyzer::Expr * > const &target_exprs, SQLAgg const agg_kind)
 

Function Documentation

bool anonymous_namespace{QueryMemoryDescriptor.cpp}::anyOf ( std::vector< Analyzer::Expr * > const target_exprs,
SQLAgg const  agg_kind 
)

Definition at line 422 of file QueryMemoryDescriptor.cpp.

References const.

Referenced by QueryMemoryDescriptor::QueryMemoryDescriptor().

422  {
423  return boost::algorithm::any_of(target_exprs, [agg_kind](Analyzer::Expr const* expr) {
424  auto const* const agg = dynamic_cast<Analyzer::AggExpr const*>(expr);
425  return agg && agg->get_aggtype() == agg_kind;
426  });
427 }
#define const

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

References CHECK, CHECK_EQ, g_bigint_count, get_bit_width(), get_compact_type(), get_target_info(), i, kAVG, and kENCODING_NONE.

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

185  {
186  std::vector<int8_t> col_widths;
187  size_t col_expr_idx = 0;
188  for (const auto col_expr : col_expr_list) {
189  if (!col_expr) {
190  // row index
191  col_widths.push_back(sizeof(int64_t));
192  } else {
193  const auto agg_info = get_target_info(col_expr, g_bigint_count);
194  const auto chosen_type = get_compact_type(agg_info);
195  if ((chosen_type.is_string() && chosen_type.get_compression() == kENCODING_NONE) ||
196  chosen_type.is_array()) {
197  col_widths.push_back(sizeof(int64_t));
198  col_widths.push_back(sizeof(int64_t));
199  ++col_expr_idx;
200  continue;
201  }
202  if (chosen_type.is_geometry()) {
203  for (auto i = 0; i < chosen_type.get_physical_coord_cols(); ++i) {
204  col_widths.push_back(sizeof(int64_t));
205  col_widths.push_back(sizeof(int64_t));
206  }
207  ++col_expr_idx;
208  continue;
209  }
210  const auto col_expr_bitwidth = get_bit_width(chosen_type);
211  CHECK_EQ(size_t(0), col_expr_bitwidth % 8);
212  col_widths.push_back(static_cast<int8_t>(col_expr_bitwidth >> 3));
213  // for average, we'll need to keep the count as well
214  if (agg_info.agg_kind == kAVG) {
215  CHECK(agg_info.is_agg);
216  col_widths.push_back(sizeof(int64_t));
217  }
218  }
219  ++col_expr_idx;
220  }
221  return col_widths;
222 }
#define CHECK_EQ(x, y)
Definition: Logger.h:211
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:79
const SQLTypeInfo get_compact_type(const TargetInfo &target)
size_t get_bit_width(const SQLTypeInfo &ti)
bool g_bigint_count
#define CHECK(condition)
Definition: Logger.h:203
Definition: sqldefs.h:72

+ 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 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 }
size_t get_bit_width(const SQLTypeInfo &ti)
bool is_integer() const
Definition: sqltypes.h:491

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

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

Referenced by pick_baseline_key_component_width().

40  {
41  return range.getIntMin() > INT32_MIN && range.getIntMax() < EMPTY_KEY_32 - 1;
42 }
int64_t getIntMin() const
#define INT32_MIN
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 115 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().

116  {
117  if (range.getType() == ExpressionRangeType::Invalid) {
118  return sizeof(int64_t);
119  }
120  switch (range.getType()) {
122  if (group_col_width == sizeof(int64_t) && range.hasNulls()) {
123  return sizeof(int64_t);
124  }
125  return is_valid_int32_range(range) ? sizeof(int32_t) : sizeof(int64_t);
128  return sizeof(int64_t); // No compaction for floating point yet.
129  default:
130  UNREACHABLE();
131  }
132  return sizeof(int64_t);
133 }
#define UNREACHABLE()
Definition: Logger.h:247
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 136 of file QueryMemoryDescriptor.cpp.

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

138  {
139  int8_t compact_width{4};
140  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
141  const auto expr_range = getExpressionRange(groupby_expr.get(), query_infos, executor);
142  compact_width = std::max(compact_width,
144  expr_range, groupby_expr->get_type_info().get_size()));
145  }
146  return compact_width;
147 }
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 44 of file QueryMemoryDescriptor.cpp.

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

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

+ 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 62 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().

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

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