OmniSciDB  340b00dbf6
 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)
 
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)
 

Function Documentation

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

Definition at line 31 of file QueryMemoryDescriptor.cpp.

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

Referenced by QueryMemoryDescriptor::pick_target_compact_width().

31  {
32  if (!ti.is_integer()) {
33  return false;
34  }
35  return get_bit_width(ti) <= (byte_width * 8);
36 }
size_t get_bit_width(const SQLTypeInfo &ti)
bool is_integer() const
Definition: sqltypes.h:489

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

110  {
111  if (range.getType() == ExpressionRangeType::Invalid) {
112  return sizeof(int64_t);
113  }
114  switch (range.getType()) {
116  if (group_col_width == sizeof(int64_t) && range.hasNulls()) {
117  return sizeof(int64_t);
118  }
119  return range.getIntMax() < EMPTY_KEY_32 - 1 ? sizeof(int32_t) : sizeof(int64_t);
122  return sizeof(int64_t); // No compaction for floating point yet.
123  default:
124  UNREACHABLE();
125  }
126  return sizeof(int64_t);
127 }
#define UNREACHABLE()
Definition: Logger.h:241
bool hasNulls() const
ExpressionRangeType getType() 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_width ( const RelAlgExecutionUnit ra_exe_unit,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor 
)

Definition at line 130 of file QueryMemoryDescriptor.cpp.

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

132  {
133  int8_t compact_width{4};
134  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
135  const auto expr_range = getExpressionRange(groupby_expr.get(), query_infos, executor);
136  compact_width = std::max(compact_width,
138  expr_range, groupby_expr->get_type_info().get_size()));
139  }
140  return compact_width;
141 }
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 38 of file QueryMemoryDescriptor.cpp.

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

40  {
41  std::vector<int64_t> indices(target_exprs.size(), -1);
42  for (size_t target_idx = 0; target_idx < target_exprs.size(); ++target_idx) {
43  const auto target_expr = target_exprs[target_idx];
44  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
45  continue;
46  }
47  const auto var_expr = dynamic_cast<const Analyzer::Var*>(target_expr);
48  if (var_expr && var_expr->get_which_row() == Analyzer::Var::kGROUPBY) {
49  indices[target_idx] = var_expr->get_varno() - 1;
50  continue;
51  }
52  }
53  return indices;
54 }
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 56 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().

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

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

Definition at line 143 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.

144  {
145  if (g_cluster) {
146  return false; // TODO(miyu)
147  }
148 
149  for (const auto target_expr : ra_exe_unit.target_exprs) {
150  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
151  return false;
152  }
153  if (dynamic_cast<const Analyzer::WindowFunction*>(target_expr)) {
154  return false;
155  }
156  }
157 
158  // TODO: Allow streaming top n for columnar output
159  if (!output_columnar && ra_exe_unit.sort_info.order_entries.size() == 1 &&
160  ra_exe_unit.sort_info.limit &&
162  const auto only_order_entry = ra_exe_unit.sort_info.order_entries.front();
163  CHECK_GT(only_order_entry.tle_no, int(0));
164  CHECK_LE(static_cast<size_t>(only_order_entry.tle_no),
165  ra_exe_unit.target_exprs.size());
166  const auto order_entry_expr = ra_exe_unit.target_exprs[only_order_entry.tle_no - 1];
167  const auto n = ra_exe_unit.sort_info.offset + ra_exe_unit.sort_info.limit;
168  if ((order_entry_expr->get_type_info().is_number() ||
169  order_entry_expr->get_type_info().is_time()) &&
170  n <= 100000) { // TODO(miyu): relax?
171  return true;
172  }
173  }
174 
175  return false;
176 }
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