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

Namespaces

 anonymous_namespace{RelAlgExecutor.cpp}
 

Classes

class  RelLeftDeepTreeIdsCollector
 
struct  TextEncodingCastCounts
 
class  TextEncodingCastCountVisitor
 
class  RexUsedInputsVisitor
 
struct  ErrorInfo
 

Functions

bool node_is_aggregate (const RelAlgNode *ra)
 
std::unordered_set< PhysicalInputget_physical_inputs (const Catalog_Namespace::Catalog &cat, const RelAlgNode *ra)
 
void set_parallelism_hints (const RelAlgNode &ra_node, const Catalog_Namespace::Catalog &catalog)
 
void prepare_string_dictionaries (const RelAlgNode &ra_node, const Catalog_Namespace::Catalog &catalog)
 
void prepare_foreign_table_for_execution (const RelAlgNode &ra_node, const Catalog_Namespace::Catalog &catalog)
 
void prepare_for_system_table_execution (const RelAlgNode &ra_node, const Catalog_Namespace::Catalog &catalog, const CompilationOptions &co)
 
bool has_valid_query_plan_dag (const RelAlgNode *node)
 
std::list< Analyzer::OrderEntryget_order_entries (const RelSort *sort)
 
void build_render_targets (RenderInfo &render_info, const std::vector< Analyzer::Expr * > &work_unit_target_exprs, const std::vector< TargetMetaInfo > &targets_meta)
 
bool is_validate_or_explain_query (const ExecutionOptions &eo)
 
TextEncodingCastCounts get_text_cast_counts (const RelAlgExecutionUnit &ra_exe_unit)
 
void check_none_encoded_string_cast_tuple_limit (const std::vector< InputTableInfo > &query_infos, const RelAlgExecutionUnit &ra_exe_unit)
 
void check_sort_node_source_constraint (const RelSort *sort)
 
const RelAlgNodeget_data_sink (const RelAlgNode *ra_node)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelCompound *compound, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelAggregate *aggregate, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelProject *project, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelTableFunction *table_func, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelFilter *filter, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelLogicalUnion *logical_union, const Catalog_Namespace::Catalog &)
 
int table_id_from_ra (const RelAlgNode *ra_node)
 
std::unordered_map< const
RelAlgNode *, int > 
get_input_nest_levels (const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_join_source_used_inputs (const RelAlgNode *ra_node, const Catalog_Namespace::Catalog &cat)
 
void collect_used_input_desc (std::vector< InputDescriptor > &input_descs, const Catalog_Namespace::Catalog &cat, std::unordered_set< std::shared_ptr< const InputColDescriptor >> &input_col_descs_unique, const RelAlgNode *ra_node, const std::unordered_set< const RexInput * > &source_used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
 
template<class RA >
std::pair< std::vector
< InputDescriptor >, std::list
< std::shared_ptr< const
InputColDescriptor > > > 
get_input_desc_impl (const RA *ra_node, const std::unordered_set< const RexInput * > &used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< size_t > &input_permutation, const Catalog_Namespace::Catalog &cat)
 
template<class RA >
std::tuple< std::vector
< InputDescriptor >, std::list
< std::shared_ptr< const
InputColDescriptor >
>, std::vector
< std::shared_ptr< RexInput > > > 
get_input_desc (const RA *ra_node, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< size_t > &input_permutation, const Catalog_Namespace::Catalog &cat)
 
size_t get_scalar_sources_size (const RelCompound *compound)
 
size_t get_scalar_sources_size (const RelProject *project)
 
size_t get_scalar_sources_size (const RelTableFunction *table_func)
 
const RexScalarscalar_at (const size_t i, const RelCompound *compound)
 
const RexScalarscalar_at (const size_t i, const RelProject *project)
 
const RexScalarscalar_at (const size_t i, const RelTableFunction *table_func)
 
std::shared_ptr< Analyzer::Exprset_transient_dict (const std::shared_ptr< Analyzer::Expr > expr)
 
void set_transient_dict_maybe (std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::shared_ptr< Analyzer::Expr > &expr)
 
std::shared_ptr< Analyzer::Exprcast_dict_to_none (const std::shared_ptr< Analyzer::Expr > &input)
 
template<class RA >
std::vector< std::shared_ptr
< Analyzer::Expr > > 
translate_scalar_sources (const RA *ra_node, const RelAlgTranslator &translator, const ::ExecutorType executor_type)
 
template<class RA >
std::vector< std::shared_ptr
< Analyzer::Expr > > 
translate_scalar_sources_for_update (const RA *ra_node, const RelAlgTranslator &translator, int32_t tableId, const Catalog_Namespace::Catalog &cat, const ColumnNameList &colNames, size_t starting_projection_column_idx)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
translate_groupby_exprs (const RelCompound *compound, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
translate_groupby_exprs (const RelAggregate *aggregate, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
 
QualsConjunctiveForm translate_quals (const RelCompound *compound, const RelAlgTranslator &translator)
 
std::vector< Analyzer::Expr * > translate_targets (std::vector< std::shared_ptr< Analyzer::Expr >> &target_exprs_owned, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const RelCompound *compound, const RelAlgTranslator &translator, const ExecutorType executor_type)
 
std::vector< Analyzer::Expr * > translate_targets (std::vector< std::shared_ptr< Analyzer::Expr >> &target_exprs_owned, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const RelAggregate *aggregate, const RelAlgTranslator &translator)
 
bool is_count_distinct (const Analyzer::Expr *expr)
 
bool is_agg (const Analyzer::Expr *expr)
 
SQLTypeInfo get_logical_type_for_expr (const Analyzer::Expr &expr)
 
template<class RA >
std::vector< TargetMetaInfoget_targets_meta (const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
 
template<>
std::vector< TargetMetaInfoget_targets_meta (const RelFilter *filter, const std::vector< Analyzer::Expr * > &target_exprs)
 
bool is_window_execution_unit (const RelAlgExecutionUnit &ra_exe_unit)
 
std::shared_ptr< Analyzer::Exprtransform_to_inner (const Analyzer::Expr *expr)
 
template<class T >
int64_t insert_one_dict_str (T *col_data, const std::string &columnName, const SQLTypeInfo &columnType, const Analyzer::Constant *col_cv, const Catalog_Namespace::Catalog &catalog)
 
template<class T >
int64_t insert_one_dict_str (T *col_data, const ColumnDescriptor *cd, const Analyzer::Constant *col_cv, const Catalog_Namespace::Catalog &catalog)
 
size_t get_scan_limit (const RelAlgNode *ra, const size_t limit)
 
bool first_oe_is_desc (const std::list< Analyzer::OrderEntry > &order_entries)
 
size_t groups_approx_upper_bound (const std::vector< InputTableInfo > &table_infos)
 
bool is_projection (const RelAlgExecutionUnit &ra_exe_unit)
 
bool can_output_columnar (const RelAlgExecutionUnit &ra_exe_unit, const RenderInfo *render_info, const RelAlgNode *body)
 
bool should_output_columnar (const RelAlgExecutionUnit &ra_exe_unit)
 
bool compute_output_buffer_size (const RelAlgExecutionUnit &ra_exe_unit)
 
bool exe_unit_has_quals (const RelAlgExecutionUnit ra_exe_unit)
 
RelAlgExecutionUnit decide_approx_count_distinct_implementation (const RelAlgExecutionUnit &ra_exe_unit_in, const std::vector< InputTableInfo > &table_infos, const Executor *executor, const ExecutorDeviceType device_type_in, std::vector< std::shared_ptr< Analyzer::Expr >> &target_exprs_owned)
 
bool can_use_bump_allocator (const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const ExecutionOptions &eo)
 
ErrorInfo getErrorDescription (const int32_t error_code)
 
JoinType get_join_type (const RelAlgNode *ra)
 
std::unique_ptr< const
RexOperator
get_bitwise_equals (const RexScalar *scalar)
 
std::unique_ptr< const
RexOperator
get_bitwise_equals_conjunction (const RexScalar *scalar)
 
std::vector< JoinTypeleft_deep_join_types (const RelLeftDeepInnerJoin *left_deep_join)
 
template<class RA >
std::vector< size_t > do_table_reordering (std::vector< InputDescriptor > &input_descs, std::list< std::shared_ptr< const InputColDescriptor >> &input_col_descs, const JoinQualsPerNestingLevel &left_deep_join_quals, std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const RA *node, const std::vector< InputTableInfo > &query_infos, const Executor *executor)
 
std::vector< size_t > get_left_deep_join_input_sizes (const RelLeftDeepInnerJoin *left_deep_join)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
rewrite_quals (const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
 
std::vector< const RexScalar * > rex_to_conjunctive_form (const RexScalar *qual_expr)
 
std::shared_ptr< Analyzer::Exprbuild_logical_expression (const std::vector< std::shared_ptr< Analyzer::Expr >> &factors, const SQLOps sql_op)
 
template<class QualsList >
bool list_contains_expression (const QualsList &haystack, const std::shared_ptr< Analyzer::Expr > &needle)
 
std::shared_ptr< Analyzer::Exprreverse_logical_distribution (const std::shared_ptr< Analyzer::Expr > &expr)
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
synthesize_inputs (const RelAlgNode *ra_node, const size_t nest_level, const std::vector< TargetMetaInfo > &in_metainfo, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
 
std::vector< Analyzer::Expr * > get_raw_pointers (std::vector< std::shared_ptr< Analyzer::Expr >> const &input)
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
target_exprs_for_union (RelAlgNode const *input_node)
 
std::pair< std::vector
< TargetMetaInfo >
, std::vector< std::shared_ptr
< Analyzer::Expr > > > 
get_inputs_meta (const RelFilter *filter, const RelAlgTranslator &translator, const std::vector< std::shared_ptr< RexInput >> &inputs_owned, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
 

Function Documentation

std::shared_ptr<Analyzer::Expr> anonymous_namespace{RelAlgExecutor.cpp}::build_logical_expression ( const std::vector< std::shared_ptr< Analyzer::Expr >> &  factors,
const SQLOps  sql_op 
)

Definition at line 4443 of file RelAlgExecutor.cpp.

References CHECK, kONE, and Parser::OperExpr::normalize().

Referenced by reverse_logical_distribution().

4445  {
4446  CHECK(!factors.empty());
4447  auto acc = factors.front();
4448  for (size_t i = 1; i < factors.size(); ++i) {
4449  acc = Parser::OperExpr::normalize(sql_op, kONE, acc, factors[i]);
4450  }
4451  return acc;
4452 }
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr, const Executor *executor=nullptr)
Definition: ParserNode.cpp:370
Definition: sqldefs.h:70
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::build_render_targets ( RenderInfo render_info,
const std::vector< Analyzer::Expr * > &  work_unit_target_exprs,
const std::vector< TargetMetaInfo > &  targets_meta 
)

Definition at line 216 of file RelAlgExecutor.cpp.

References CHECK_EQ, and RenderInfo::targets.

Referenced by RelAlgExecutor::executeRelAlgStep(), RelAlgExecutor::executeSort(), and RelAlgExecutor::executeWorkUnit().

218  {
219  CHECK_EQ(work_unit_target_exprs.size(), targets_meta.size());
220  render_info.targets.clear();
221  for (size_t i = 0; i < targets_meta.size(); ++i) {
222  render_info.targets.emplace_back(std::make_shared<Analyzer::TargetEntry>(
223  targets_meta[i].get_resname(),
224  work_unit_target_exprs[i]->get_shared_ptr(),
225  false));
226  }
227 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::vector< std::shared_ptr< Analyzer::TargetEntry > > targets
Definition: RenderInfo.h:36

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::can_output_columnar ( const RelAlgExecutionUnit ra_exe_unit,
const RenderInfo render_info,
const RelAlgNode body 
)

Definition at line 3407 of file RelAlgExecutor.cpp.

References is_projection(), RenderInfo::isPotentialInSituRender(), SortInfo::order_entries, RelAlgExecutionUnit::sort_info, and RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

3409  {
3410  if (!is_projection(ra_exe_unit)) {
3411  return false;
3412  }
3413  if (render_info && render_info->isPotentialInSituRender()) {
3414  return false;
3415  }
3416  if (!ra_exe_unit.sort_info.order_entries.empty()) {
3417  // disable output columnar when we have top-sort node query
3418  return false;
3419  }
3420  for (const auto& target_expr : ra_exe_unit.target_exprs) {
3421  // We don't currently support varlen columnar projections, so
3422  // return false if we find one
3423  if (target_expr->get_type_info().is_varlen()) {
3424  return false;
3425  }
3426  }
3427  if (auto top_project = dynamic_cast<const RelProject*>(body)) {
3428  if (top_project->isRowwiseOutputForced()) {
3429  return false;
3430  }
3431  }
3432  return true;
3433 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< Analyzer::OrderEntry > order_entries
bool is_projection(const RelAlgExecutionUnit &ra_exe_unit)
bool isPotentialInSituRender() const
Definition: RenderInfo.cpp:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::can_use_bump_allocator ( const RelAlgExecutionUnit ra_exe_unit,
const CompilationOptions co,
const ExecutionOptions eo 
)
inline

Definition at line 3533 of file RelAlgExecutor.cpp.

References CompilationOptions::device_type, g_enable_bump_allocator, GPU, SortInfo::order_entries, ExecutionOptions::output_columnar_hint, and RelAlgExecutionUnit::sort_info.

Referenced by RelAlgExecutor::executeWorkUnit().

3535  {
3537  !eo.output_columnar_hint && ra_exe_unit.sort_info.order_entries.empty();
3538 }
const std::list< Analyzer::OrderEntry > order_entries
ExecutorDeviceType device_type
bool g_enable_bump_allocator
Definition: Execute.cpp:120

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::Expr> anonymous_namespace{RelAlgExecutor.cpp}::cast_dict_to_none ( const std::shared_ptr< Analyzer::Expr > &  input)

Definition at line 1705 of file RelAlgExecutor.cpp.

References kENCODING_DICT, and kTEXT.

Referenced by translate_scalar_sources(), and translate_targets().

1706  {
1707  const auto& input_ti = input->get_type_info();
1708  if (input_ti.is_string() && input_ti.get_compression() == kENCODING_DICT) {
1709  return input->add_cast(SQLTypeInfo(kTEXT, input_ti.get_notnull()));
1710  }
1711  return input;
1712 }
Definition: sqltypes.h:52

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::check_none_encoded_string_cast_tuple_limit ( const std::vector< InputTableInfo > &  query_infos,
const RelAlgExecutionUnit ra_exe_unit 
)

Definition at line 421 of file RelAlgExecutor.cpp.

References gpu_enabled::accumulate(), g_enable_watchdog, g_watchdog_none_encoded_string_translation_limit, and get_text_cast_counts().

Referenced by RelAlgExecutor::executeWorkUnit().

423  {
424  if (!g_enable_watchdog) {
425  return;
426  }
427  auto const tuples_upper_bound =
428  std::accumulate(query_infos.cbegin(),
429  query_infos.cend(),
430  size_t(0),
431  [](auto max, auto const& query_info) {
432  return std::max(max, query_info.info.getNumTuples());
433  });
434  if (tuples_upper_bound <= g_watchdog_none_encoded_string_translation_limit) {
435  return;
436  }
437 
438  const auto& text_cast_counts = get_text_cast_counts(ra_exe_unit);
439  const bool has_text_casts =
440  text_cast_counts.text_decoding_casts + text_cast_counts.text_encoding_casts > 0UL;
441 
442  if (!has_text_casts) {
443  return;
444  }
445  std::ostringstream oss;
446  oss << "Query requires one or more casts between none-encoded and dictionary-encoded "
447  << "strings, and the estimated table size (" << tuples_upper_bound << " rows) "
448  << "exceeds the configured watchdog none-encoded string translation limit of "
450  throw std::runtime_error(oss.str());
451 }
TextEncodingCastCounts get_text_cast_counts(const RelAlgExecutionUnit &ra_exe_unit)
size_t g_watchdog_none_encoded_string_translation_limit
Definition: Execute.cpp:81
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
bool g_enable_watchdog

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::check_sort_node_source_constraint ( const RelSort sort)
inline

Definition at line 786 of file RelAlgExecutor.cpp.

References CHECK_EQ, RelAlgNode::getInput(), and RelAlgNode::inputCount().

Referenced by RelAlgExecutor::executeRelAlgQuerySingleStep(), and RelAlgExecutor::executeSort().

786  {
787  CHECK_EQ(size_t(1), sort->inputCount());
788  const auto source = sort->getInput(0);
789  if (dynamic_cast<const RelSort*>(source)) {
790  throw std::runtime_error("Sort node not supported as input to another sort");
791  }
792 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
const size_t inputCount() const
Definition: RelAlgDag.h:824

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::collect_used_input_desc ( std::vector< InputDescriptor > &  input_descs,
const Catalog_Namespace::Catalog cat,
std::unordered_set< std::shared_ptr< const InputColDescriptor >> &  input_col_descs_unique,
const RelAlgNode ra_node,
const std::unordered_set< const RexInput * > &  source_used_inputs,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level 
)

Definition at line 1558 of file RelAlgExecutor.cpp.

References RelRexToStringConfig::defaults(), Catalog_Namespace::Catalog::getColumnIdBySpi(), table_id_from_ra(), RelAlgNode::toString(), and VLOG.

Referenced by get_input_desc_impl().

1564  {
1565  VLOG(3) << "ra_node=" << ra_node->toString(RelRexToStringConfig::defaults())
1566  << " input_col_descs_unique.size()=" << input_col_descs_unique.size()
1567  << " source_used_inputs.size()=" << source_used_inputs.size();
1568  for (const auto used_input : source_used_inputs) {
1569  const auto input_ra = used_input->getSourceNode();
1570  const int table_id = table_id_from_ra(input_ra);
1571  const auto col_id = used_input->getIndex();
1572  auto it = input_to_nest_level.find(input_ra);
1573  if (it != input_to_nest_level.end()) {
1574  const int input_desc = it->second;
1575  input_col_descs_unique.insert(std::make_shared<const InputColDescriptor>(
1576  dynamic_cast<const RelScan*>(input_ra)
1577  ? cat.getColumnIdBySpi(table_id, col_id + 1)
1578  : col_id,
1579  table_id,
1580  input_desc));
1581  } else if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1582  throw std::runtime_error("Bushy joins not supported");
1583  }
1584  }
1585 }
virtual std::string toString(RelRexToStringConfig config) const =0
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:49
int table_id_from_ra(const RelAlgNode *ra_node)
#define VLOG(n)
Definition: Logger.h:316
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:2052

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::compute_output_buffer_size ( const RelAlgExecutionUnit ra_exe_unit)

Determines whether a query needs to compute the size of its output buffer. Returns true for projection queries with no LIMIT or a LIMIT that exceeds the high scan limit threshold (meaning it would be cheaper to compute the number of rows passing or use the bump allocator than allocate the current scan limit per GPU)

Definition at line 3446 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::groupby_exprs, Executor::high_scan_limit, RelAlgExecutionUnit::scan_limit, and RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

3446  {
3447  for (const auto target_expr : ra_exe_unit.target_exprs) {
3448  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
3449  return false;
3450  }
3451  }
3452  if (ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front() &&
3453  (!ra_exe_unit.scan_limit || ra_exe_unit.scan_limit > Executor::high_scan_limit)) {
3454  return true;
3455  }
3456  return false;
3457 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
static const size_t high_scan_limit
Definition: Execute.h:602

+ Here is the caller graph for this function:

RelAlgExecutionUnit anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation ( const RelAlgExecutionUnit ra_exe_unit_in,
const std::vector< InputTableInfo > &  table_infos,
const Executor executor,
const ExecutorDeviceType  device_type_in,
std::vector< std::shared_ptr< Analyzer::Expr >> &  target_exprs_owned 
)

Definition at line 3464 of file RelAlgExecutor.cpp.

References Bitmap, CHECK, CHECK_GE, g_bigint_count, g_cluster, g_hll_precision_bits, get_agg_type(), get_count_distinct_sub_bitmap_count(), get_target_info(), getExpressionRange(), GPU, hll_size_for_rate(), Integer, kAPPROX_COUNT_DISTINCT, kCOUNT, kENCODING_DICT, kINT, and RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit(), and RelAlgExecutor::handleOutOfMemoryRetry().

3469  {
3470  RelAlgExecutionUnit ra_exe_unit = ra_exe_unit_in;
3471  for (size_t i = 0; i < ra_exe_unit.target_exprs.size(); ++i) {
3472  const auto target_expr = ra_exe_unit.target_exprs[i];
3473  const auto agg_info = get_target_info(target_expr, g_bigint_count);
3474  if (agg_info.agg_kind != kAPPROX_COUNT_DISTINCT) {
3475  continue;
3476  }
3477  CHECK(dynamic_cast<const Analyzer::AggExpr*>(target_expr));
3478  const auto arg = static_cast<Analyzer::AggExpr*>(target_expr)->get_own_arg();
3479  CHECK(arg);
3480  const auto& arg_ti = arg->get_type_info();
3481  // Avoid calling getExpressionRange for variable length types (string and array),
3482  // it'd trigger an assertion since that API expects to be called only for types
3483  // for which the notion of range is well-defined. A bit of a kludge, but the
3484  // logic to reject these types anyway is at lower levels in the stack and not
3485  // really worth pulling into a separate function for now.
3486  if (!(arg_ti.is_number() || arg_ti.is_boolean() || arg_ti.is_time() ||
3487  (arg_ti.is_string() && arg_ti.get_compression() == kENCODING_DICT))) {
3488  continue;
3489  }
3490  const auto arg_range = getExpressionRange(arg.get(), table_infos, executor);
3491  if (arg_range.getType() != ExpressionRangeType::Integer) {
3492  continue;
3493  }
3494  // When running distributed, the threshold for using the precise implementation
3495  // must be consistent across all leaves, otherwise we could have a mix of precise
3496  // and approximate bitmaps and we cannot aggregate them.
3497  const auto device_type = g_cluster ? ExecutorDeviceType::GPU : device_type_in;
3498  const auto bitmap_sz_bits = arg_range.getIntMax() - arg_range.getIntMin() + 1;
3499  const auto sub_bitmap_count =
3500  get_count_distinct_sub_bitmap_count(bitmap_sz_bits, ra_exe_unit, device_type);
3501  int64_t approx_bitmap_sz_bits{0};
3502  const auto error_rate = static_cast<Analyzer::AggExpr*>(target_expr)->get_arg1();
3503  if (error_rate) {
3504  CHECK(error_rate->get_type_info().get_type() == kINT);
3505  CHECK_GE(error_rate->get_constval().intval, 1);
3506  approx_bitmap_sz_bits = hll_size_for_rate(error_rate->get_constval().intval);
3507  } else {
3508  approx_bitmap_sz_bits = g_hll_precision_bits;
3509  }
3510  CountDistinctDescriptor approx_count_distinct_desc{CountDistinctImplType::Bitmap,
3511  arg_range.getIntMin(),
3512  approx_bitmap_sz_bits,
3513  true,
3514  device_type,
3515  sub_bitmap_count};
3516  CountDistinctDescriptor precise_count_distinct_desc{CountDistinctImplType::Bitmap,
3517  arg_range.getIntMin(),
3518  bitmap_sz_bits,
3519  false,
3520  device_type,
3521  sub_bitmap_count};
3522  if (approx_count_distinct_desc.bitmapPaddedSizeBytes() >=
3523  precise_count_distinct_desc.bitmapPaddedSizeBytes()) {
3524  auto precise_count_distinct = makeExpr<Analyzer::AggExpr>(
3525  get_agg_type(kCOUNT, arg.get()), kCOUNT, arg, true, nullptr);
3526  target_exprs_owned.push_back(precise_count_distinct);
3527  ra_exe_unit.target_exprs[i] = precise_count_distinct.get();
3528  }
3529  }
3530  return ra_exe_unit;
3531 }
std::vector< Analyzer::Expr * > target_exprs
int hll_size_for_rate(const int err_percent)
Definition: HyperLogLog.h:113
#define CHECK_GE(x, y)
Definition: Logger.h:235
SQLTypeInfo get_agg_type(const SQLAgg agg_kind, const Analyzer::Expr *arg_expr)
int g_hll_precision_bits
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:97
size_t get_count_distinct_sub_bitmap_count(const size_t bitmap_sz_bits, const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType device_type)
bool g_bigint_count
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)
Definition: sqldefs.h:77
#define CHECK(condition)
Definition: Logger.h:222
bool g_cluster
Definition: sqltypes.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class RA >
std::vector<size_t> anonymous_namespace{RelAlgExecutor.cpp}::do_table_reordering ( std::vector< InputDescriptor > &  input_descs,
std::list< std::shared_ptr< const InputColDescriptor >> &  input_col_descs,
const JoinQualsPerNestingLevel left_deep_join_quals,
std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level,
const RA *  node,
const std::vector< InputTableInfo > &  query_infos,
const Executor executor 
)

Definition at line 4253 of file RelAlgExecutor.cpp.

References cat(), CHECK, g_cluster, get_input_desc(), get_input_nest_levels(), get_node_input_permutation(), and table_is_replicated().

Referenced by RelAlgExecutor::createCompoundWorkUnit(), and RelAlgExecutor::createProjectWorkUnit().

4260  {
4261  if (g_cluster) {
4262  // Disable table reordering in distributed mode. The aggregator does not have enough
4263  // information to break ties
4264  return {};
4265  }
4266  const auto& cat = *executor->getCatalog();
4267  for (const auto& table_info : query_infos) {
4268  if (table_info.table_id < 0) {
4269  continue;
4270  }
4271  const auto td = cat.getMetadataForTable(table_info.table_id);
4272  CHECK(td);
4273  if (table_is_replicated(td)) {
4274  return {};
4275  }
4276  }
4277  const auto input_permutation =
4278  get_node_input_permutation(left_deep_join_quals, query_infos, executor);
4279  input_to_nest_level = get_input_nest_levels(node, input_permutation);
4280  std::tie(input_descs, input_col_descs, std::ignore) =
4281  get_input_desc(node, input_to_nest_level, input_permutation, cat);
4282  return input_permutation;
4283 }
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
std::string cat(Ts &&...args)
std::vector< node_t > get_node_input_permutation(const JoinQualsPerNestingLevel &left_deep_join_quals, const std::vector< InputTableInfo > &table_infos, const Executor *executor)
bool table_is_replicated(const TableDescriptor *td)
#define CHECK(condition)
Definition: Logger.h:222
bool g_cluster
std::tuple< std::vector< InputDescriptor >, std::list< std::shared_ptr< const InputColDescriptor > >, std::vector< std::shared_ptr< RexInput > > > get_input_desc(const RA *ra_node, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< size_t > &input_permutation, const Catalog_Namespace::Catalog &cat)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::exe_unit_has_quals ( const RelAlgExecutionUnit  ra_exe_unit)
inline

Definition at line 3459 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::join_quals, RelAlgExecutionUnit::quals, and RelAlgExecutionUnit::simple_quals.

Referenced by RelAlgExecutor::executeWorkUnit().

3459  {
3460  return !(ra_exe_unit.quals.empty() && ra_exe_unit.join_quals.empty() &&
3461  ra_exe_unit.simple_quals.empty());
3462 }
const JoinQualsPerNestingLevel join_quals
std::list< std::shared_ptr< Analyzer::Expr > > quals
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::first_oe_is_desc ( const std::list< Analyzer::OrderEntry > &  order_entries)

Definition at line 3138 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::createSortInputWorkUnit(), and RelAlgExecutor::executeSort().

3138  {
3139  return !order_entries.empty() && order_entries.front().is_desc;
3140 }

+ Here is the caller graph for this function:

std::unique_ptr<const RexOperator> anonymous_namespace{RelAlgExecutor.cpp}::get_bitwise_equals ( const RexScalar scalar)

Definition at line 4168 of file RelAlgExecutor.cpp.

References CHECK_EQ, kAND, kBW_EQ, kEQ, kISNULL, kOR, and RexVisitorBase< T >::visit().

Referenced by get_bitwise_equals_conjunction().

4168  {
4169  const auto condition = dynamic_cast<const RexOperator*>(scalar);
4170  if (!condition || condition->getOperator() != kOR || condition->size() != 2) {
4171  return nullptr;
4172  }
4173  const auto equi_join_condition =
4174  dynamic_cast<const RexOperator*>(condition->getOperand(0));
4175  if (!equi_join_condition || equi_join_condition->getOperator() != kEQ) {
4176  return nullptr;
4177  }
4178  const auto both_are_null_condition =
4179  dynamic_cast<const RexOperator*>(condition->getOperand(1));
4180  if (!both_are_null_condition || both_are_null_condition->getOperator() != kAND ||
4181  both_are_null_condition->size() != 2) {
4182  return nullptr;
4183  }
4184  const auto lhs_is_null =
4185  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(0));
4186  const auto rhs_is_null =
4187  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(1));
4188  if (!lhs_is_null || !rhs_is_null || lhs_is_null->getOperator() != kISNULL ||
4189  rhs_is_null->getOperator() != kISNULL) {
4190  return nullptr;
4191  }
4192  CHECK_EQ(size_t(1), lhs_is_null->size());
4193  CHECK_EQ(size_t(1), rhs_is_null->size());
4194  CHECK_EQ(size_t(2), equi_join_condition->size());
4195  const auto eq_lhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(0));
4196  const auto eq_rhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(1));
4197  const auto is_null_lhs = dynamic_cast<const RexInput*>(lhs_is_null->getOperand(0));
4198  const auto is_null_rhs = dynamic_cast<const RexInput*>(rhs_is_null->getOperand(0));
4199  if (!eq_lhs || !eq_rhs || !is_null_lhs || !is_null_rhs) {
4200  return nullptr;
4201  }
4202  std::vector<std::unique_ptr<const RexScalar>> eq_operands;
4203  if (*eq_lhs == *is_null_lhs && *eq_rhs == *is_null_rhs) {
4204  RexDeepCopyVisitor deep_copy_visitor;
4205  auto lhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(0));
4206  auto rhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(1));
4207  eq_operands.emplace_back(lhs_op_copy.release());
4208  eq_operands.emplace_back(rhs_op_copy.release());
4209  return boost::make_unique<const RexOperator>(
4210  kBW_EQ, eq_operands, equi_join_condition->getType());
4211  }
4212  return nullptr;
4213 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
Definition: sqldefs.h:37
Definition: sqldefs.h:29
virtual T visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
Definition: sqldefs.h:36
Definition: sqldefs.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr<const RexOperator> anonymous_namespace{RelAlgExecutor.cpp}::get_bitwise_equals_conjunction ( const RexScalar scalar)

Definition at line 4215 of file RelAlgExecutor.cpp.

References CHECK_GE, get_bitwise_equals(), and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

4216  {
4217  const auto condition = dynamic_cast<const RexOperator*>(scalar);
4218  if (condition && condition->getOperator() == kAND) {
4219  CHECK_GE(condition->size(), size_t(2));
4220  auto acc = get_bitwise_equals(condition->getOperand(0));
4221  if (!acc) {
4222  return nullptr;
4223  }
4224  for (size_t i = 1; i < condition->size(); ++i) {
4225  std::vector<std::unique_ptr<const RexScalar>> and_operands;
4226  and_operands.emplace_back(std::move(acc));
4227  and_operands.emplace_back(get_bitwise_equals_conjunction(condition->getOperand(i)));
4228  acc =
4229  boost::make_unique<const RexOperator>(kAND, and_operands, condition->getType());
4230  }
4231  return acc;
4232  }
4233  return get_bitwise_equals(scalar);
4234 }
std::unique_ptr< const RexOperator > get_bitwise_equals_conjunction(const RexScalar *scalar)
#define CHECK_GE(x, y)
Definition: Logger.h:235
Definition: sqldefs.h:36
std::unique_ptr< const RexOperator > get_bitwise_equals(const RexScalar *scalar)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const RelAlgNode* anonymous_namespace{RelAlgExecutor.cpp}::get_data_sink ( const RelAlgNode ra_node)

Definition at line 1353 of file RelAlgExecutor.cpp.

References CHECK_EQ, RelAlgNode::getInput(), RelAlgNode::inputCount(), and join().

Referenced by get_input_desc_impl(), get_input_nest_levels(), get_inputs_meta(), get_join_source_used_inputs(), get_join_type(), and get_used_inputs().

1353  {
1354  if (auto table_func = dynamic_cast<const RelTableFunction*>(ra_node)) {
1355  return table_func;
1356  }
1357  if (auto join = dynamic_cast<const RelJoin*>(ra_node)) {
1358  CHECK_EQ(size_t(2), join->inputCount());
1359  return join;
1360  }
1361  if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1362  CHECK_EQ(size_t(1), ra_node->inputCount());
1363  }
1364  auto only_src = ra_node->getInput(0);
1365  const bool is_join = dynamic_cast<const RelJoin*>(only_src) ||
1366  dynamic_cast<const RelLeftDeepInnerJoin*>(only_src);
1367  return is_join ? only_src : ra_node;
1368 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::string join(T const &container, std::string const &delim)
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
const size_t inputCount() const
Definition: RelAlgDag.h:824

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class RA >
std::tuple<std::vector<InputDescriptor>, std::list<std::shared_ptr<const InputColDescriptor> >, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc ( const RA *  ra_node,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level,
const std::vector< size_t > &  input_permutation,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1644 of file RelAlgExecutor.cpp.

References get_input_desc_impl(), get_used_inputs(), and VLOG.

Referenced by RelAlgExecutor::createAggregateWorkUnit(), RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createFilterWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::createTableFunctionWorkUnit(), RelAlgExecutor::createUnionWorkUnit(), and do_table_reordering().

1647  {
1648  std::unordered_set<const RexInput*> used_inputs;
1649  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1650  std::tie(used_inputs, used_inputs_owned) = get_used_inputs(ra_node, cat);
1651  VLOG(3) << "used_inputs.size() = " << used_inputs.size();
1652  auto input_desc_pair = get_input_desc_impl(
1653  ra_node, used_inputs, input_to_nest_level, input_permutation, cat);
1654  return std::make_tuple(
1655  input_desc_pair.first, input_desc_pair.second, used_inputs_owned);
1656 }
std::pair< std::vector< InputDescriptor >, std::list< std::shared_ptr< const InputColDescriptor > > > get_input_desc_impl(const RA *ra_node, const std::unordered_set< const RexInput * > &used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< size_t > &input_permutation, const Catalog_Namespace::Catalog &cat)
std::pair< std::unordered_set< const RexInput * >, std::vector< std::shared_ptr< RexInput > > > get_used_inputs(const RelCompound *compound, const Catalog_Namespace::Catalog &cat)
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class RA >
std::pair<std::vector<InputDescriptor>, std::list<std::shared_ptr<const InputColDescriptor> > > anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc_impl ( const RA *  ra_node,
const std::unordered_set< const RexInput * > &  used_inputs,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level,
const std::vector< size_t > &  input_permutation,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1590 of file RelAlgExecutor.cpp.

References collect_used_input_desc(), get_data_sink(), get_join_source_used_inputs(), gpu_enabled::sort(), and table_id_from_ra().

Referenced by get_input_desc().

1594  {
1595  std::vector<InputDescriptor> input_descs;
1596  const auto data_sink_node = get_data_sink(ra_node);
1597  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1598  const auto input_node_idx =
1599  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1600  auto input_ra = data_sink_node->getInput(input_node_idx);
1601  const int table_id = table_id_from_ra(input_ra);
1602  input_descs.emplace_back(table_id, input_idx);
1603  }
1604  std::unordered_set<std::shared_ptr<const InputColDescriptor>> input_col_descs_unique;
1605  collect_used_input_desc(input_descs,
1606  cat,
1607  input_col_descs_unique, // modified
1608  ra_node,
1609  used_inputs,
1610  input_to_nest_level);
1611  std::unordered_set<const RexInput*> join_source_used_inputs;
1612  std::vector<std::shared_ptr<RexInput>> join_source_used_inputs_owned;
1613  std::tie(join_source_used_inputs, join_source_used_inputs_owned) =
1614  get_join_source_used_inputs(ra_node, cat);
1615  collect_used_input_desc(input_descs,
1616  cat,
1617  input_col_descs_unique, // modified
1618  ra_node,
1619  join_source_used_inputs,
1620  input_to_nest_level);
1621  std::vector<std::shared_ptr<const InputColDescriptor>> input_col_descs(
1622  input_col_descs_unique.begin(), input_col_descs_unique.end());
1623 
1624  std::sort(input_col_descs.begin(),
1625  input_col_descs.end(),
1626  [](std::shared_ptr<const InputColDescriptor> const& lhs,
1627  std::shared_ptr<const InputColDescriptor> const& rhs) {
1628  return std::make_tuple(lhs->getScanDesc().getNestLevel(),
1629  lhs->getColId(),
1630  lhs->getScanDesc().getTableId()) <
1631  std::make_tuple(rhs->getScanDesc().getNestLevel(),
1632  rhs->getColId(),
1633  rhs->getScanDesc().getTableId());
1634  });
1635  return {input_descs,
1636  std::list<std::shared_ptr<const InputColDescriptor>>(input_col_descs.begin(),
1637  input_col_descs.end())};
1638 }
void collect_used_input_desc(std::vector< InputDescriptor > &input_descs, const Catalog_Namespace::Catalog &cat, std::unordered_set< std::shared_ptr< const InputColDescriptor >> &input_col_descs_unique, const RelAlgNode *ra_node, const std::unordered_set< const RexInput * > &source_used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
std::pair< std::unordered_set< const RexInput * >, std::vector< std::shared_ptr< RexInput > > > get_join_source_used_inputs(const RelAlgNode *ra_node, const Catalog_Namespace::Catalog &cat)
int table_id_from_ra(const RelAlgNode *ra_node)
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unordered_map<const RelAlgNode*, int> anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels ( const RelAlgNode ra_node,
const std::vector< size_t > &  input_permutation 
)

Definition at line 1490 of file RelAlgExecutor.cpp.

References CHECK, RelRexToStringConfig::defaults(), get_data_sink(), logger::INFO, and LOG_IF.

Referenced by RelAlgExecutor::createAggregateWorkUnit(), RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createFilterWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::createTableFunctionWorkUnit(), RelAlgExecutor::createUnionWorkUnit(), do_table_reordering(), and RelAlgExecutor::getRelAlgTranslator().

1492  {
1493  const auto data_sink_node = get_data_sink(ra_node);
1494  std::unordered_map<const RelAlgNode*, int> input_to_nest_level;
1495  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1496  const auto input_node_idx =
1497  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1498  const auto input_ra = data_sink_node->getInput(input_node_idx);
1499  // Having a non-zero mapped value (input_idx) results in the query being interpretted
1500  // as a JOIN within CodeGenerator::codegenColVar() due to rte_idx being set to the
1501  // mapped value (input_idx) which originates here. This would be incorrect for UNION.
1502  size_t const idx = dynamic_cast<const RelLogicalUnion*>(ra_node) ? 0 : input_idx;
1503  const auto it_ok = input_to_nest_level.emplace(input_ra, idx);
1504  CHECK(it_ok.second);
1505  LOG_IF(INFO, !input_permutation.empty())
1506  << "Assigned input " << input_ra->toString(RelRexToStringConfig::defaults())
1507  << " to nest level " << input_idx;
1508  }
1509  return input_to_nest_level;
1510 }
#define LOG_IF(severity, condition)
Definition: Logger.h:312
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:49
#define CHECK(condition)
Definition: Logger.h:222
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<std::vector<TargetMetaInfo>, std::vector<std::shared_ptr<Analyzer::Expr> > > anonymous_namespace{RelAlgExecutor.cpp}::get_inputs_meta ( const RelFilter filter,
const RelAlgTranslator translator,
const std::vector< std::shared_ptr< RexInput >> &  inputs_owned,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level 
)

Definition at line 5092 of file RelAlgExecutor.cpp.

References CHECK, get_data_sink(), get_raw_pointers(), get_targets_meta(), synthesize_inputs(), and RelAlgTranslator::translateScalarRex().

Referenced by RelAlgExecutor::createFilterWorkUnit().

5095  {
5096  std::vector<TargetMetaInfo> in_metainfo;
5097  std::vector<std::shared_ptr<Analyzer::Expr>> exprs_owned;
5098  const auto data_sink_node = get_data_sink(filter);
5099  auto input_it = inputs_owned.begin();
5100  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
5101  const auto source = data_sink_node->getInput(nest_level);
5102  const auto scan_source = dynamic_cast<const RelScan*>(source);
5103  if (scan_source) {
5104  CHECK(source->getOutputMetainfo().empty());
5105  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources_owned;
5106  for (size_t i = 0; i < scan_source->size(); ++i, ++input_it) {
5107  scalar_sources_owned.push_back(translator.translateScalarRex(input_it->get()));
5108  }
5109  const auto source_metadata =
5110  get_targets_meta(scan_source, get_raw_pointers(scalar_sources_owned));
5111  in_metainfo.insert(
5112  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
5113  exprs_owned.insert(
5114  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
5115  } else {
5116  const auto& source_metadata = source->getOutputMetainfo();
5117  input_it += source_metadata.size();
5118  in_metainfo.insert(
5119  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
5120  const auto scalar_sources_owned = synthesize_inputs(
5121  data_sink_node, nest_level, source_metadata, input_to_nest_level);
5122  exprs_owned.insert(
5123  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
5124  }
5125  }
5126  return std::make_pair(in_metainfo, exprs_owned);
5127 }
std::vector< Analyzer::Expr * > get_raw_pointers(std::vector< std::shared_ptr< Analyzer::Expr >> const &input)
std::vector< std::shared_ptr< Analyzer::Expr > > synthesize_inputs(const RelAlgNode *ra_node, const size_t nest_level, const std::vector< TargetMetaInfo > &in_metainfo, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
#define CHECK(condition)
Definition: Logger.h:222
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_join_source_used_inputs ( const RelAlgNode ra_node,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1513 of file RelAlgExecutor.cpp.

References CHECK_EQ, CHECK_GE, CHECK_GT, RelRexToStringConfig::defaults(), get_data_sink(), anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelAlgNode::inputCount(), join(), run_benchmark_import::result, RelAlgNode::toString(), and RexVisitorBase< T >::visit().

Referenced by get_input_desc_impl().

1514  {
1515  const auto data_sink_node = get_data_sink(ra_node);
1516  if (auto join = dynamic_cast<const RelJoin*>(data_sink_node)) {
1517  CHECK_EQ(join->inputCount(), 2u);
1518  const auto condition = join->getCondition();
1519  RexUsedInputsVisitor visitor(cat);
1520  auto condition_inputs = visitor.visit(condition);
1521  std::vector<std::shared_ptr<RexInput>> condition_inputs_owned(
1522  visitor.get_inputs_owned());
1523  return std::make_pair(condition_inputs, condition_inputs_owned);
1524  }
1525 
1526  if (auto left_deep_join = dynamic_cast<const RelLeftDeepInnerJoin*>(data_sink_node)) {
1527  CHECK_GE(left_deep_join->inputCount(), 2u);
1528  const auto condition = left_deep_join->getInnerCondition();
1529  RexUsedInputsVisitor visitor(cat);
1530  auto result = visitor.visit(condition);
1531  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
1532  ++nesting_level) {
1533  const auto outer_condition = left_deep_join->getOuterCondition(nesting_level);
1534  if (outer_condition) {
1535  const auto outer_result = visitor.visit(outer_condition);
1536  result.insert(outer_result.begin(), outer_result.end());
1537  }
1538  }
1539  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1540  return std::make_pair(result, used_inputs_owned);
1541  }
1542 
1543  if (dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1544  CHECK_GT(ra_node->inputCount(), 1u)
1546  } else if (dynamic_cast<const RelTableFunction*>(ra_node)) {
1547  // no-op
1548  CHECK_GE(ra_node->inputCount(), 0u)
1550  } else {
1551  CHECK_EQ(ra_node->inputCount(), 1u)
1553  }
1554  return std::make_pair(std::unordered_set<const RexInput*>{},
1555  std::vector<std::shared_ptr<RexInput>>{});
1556 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::string join(T const &container, std::string const &delim)
#define CHECK_GE(x, y)
Definition: Logger.h:235
#define CHECK_GT(x, y)
Definition: Logger.h:234
virtual std::string toString(RelRexToStringConfig config) const =0
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:49
const size_t inputCount() const
Definition: RelAlgDag.h:824
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

JoinType anonymous_namespace{RelAlgExecutor.cpp}::get_join_type ( const RelAlgNode ra)

Definition at line 4156 of file RelAlgExecutor.cpp.

References get_data_sink(), INNER, INVALID, and join().

Referenced by RelAlgExecutor::createAggregateWorkUnit(), RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createFilterWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), and RelAlgExecutor::getRelAlgTranslator().

4156  {
4157  auto sink = get_data_sink(ra);
4158  if (auto join = dynamic_cast<const RelJoin*>(sink)) {
4159  return join->getJoinType();
4160  }
4161  if (dynamic_cast<const RelLeftDeepInnerJoin*>(sink)) {
4162  return JoinType::INNER;
4163  }
4164 
4165  return JoinType::INVALID;
4166 }
std::string join(T const &container, std::string const &delim)
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<size_t> anonymous_namespace{RelAlgExecutor.cpp}::get_left_deep_join_input_sizes ( const RelLeftDeepInnerJoin left_deep_join)

Definition at line 4285 of file RelAlgExecutor.cpp.

References get_node_output(), RelAlgNode::getInput(), and RelAlgNode::inputCount().

Referenced by RelAlgExecutor::createCompoundWorkUnit(), and RelAlgExecutor::createProjectWorkUnit().

4286  {
4287  std::vector<size_t> input_sizes;
4288  for (size_t i = 0; i < left_deep_join->inputCount(); ++i) {
4289  const auto inputs = get_node_output(left_deep_join->getInput(i));
4290  input_sizes.push_back(inputs.size());
4291  }
4292  return input_sizes;
4293 }
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
const size_t inputCount() const
Definition: RelAlgDag.h:824
RANodeOutput get_node_output(const RelAlgNode *ra_node)
Definition: RelAlgDag.cpp:370

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypeInfo anonymous_namespace{RelAlgExecutor.cpp}::get_logical_type_for_expr ( const Analyzer::Expr expr)
inline

Definition at line 1920 of file RelAlgExecutor.cpp.

References get_logical_type_info(), get_nullable_logical_type_info(), Analyzer::Expr::get_type_info(), is_agg(), is_count_distinct(), and kBIGINT.

Referenced by get_targets_meta().

1920  {
1921  if (is_count_distinct(&expr)) {
1922  return SQLTypeInfo(kBIGINT, false);
1923  } else if (is_agg(&expr)) {
1925  }
1926  return get_logical_type_info(expr.get_type_info());
1927 }
bool is_agg(const Analyzer::Expr *expr)
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1108
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1087
bool is_count_distinct(const Analyzer::Expr *expr)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<Analyzer::OrderEntry> anonymous_namespace{RelAlgExecutor.cpp}::get_order_entries ( const RelSort sort)

Definition at line 205 of file RelAlgExecutor.cpp.

References RelSort::collationCount(), Descending, First, RelSort::getCollation(), and run_benchmark_import::result.

Referenced by RelAlgExecutor::executeRelAlgQuerySingleStep(), and RelAlgExecutor::executeSort().

205  {
206  std::list<Analyzer::OrderEntry> result;
207  for (size_t i = 0; i < sort->collationCount(); ++i) {
208  const auto sort_field = sort->getCollation(i);
209  result.emplace_back(sort_field.getField() + 1,
210  sort_field.getSortDir() == SortDirection::Descending,
211  sort_field.getNullsPosition() == NullSortedPosition::First);
212  }
213  return result;
214 }
SortField getCollation(const size_t i) const
Definition: RelAlgDag.h:1776
size_t collationCount() const
Definition: RelAlgDag.h:1774

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unordered_set<PhysicalInput> anonymous_namespace{RelAlgExecutor.cpp}::get_physical_inputs ( const Catalog_Namespace::Catalog cat,
const RelAlgNode ra 
)

Definition at line 74 of file RelAlgExecutor.cpp.

References get_physical_inputs(), and Catalog_Namespace::Catalog::getColumnIdBySpi().

76  {
77  auto phys_inputs = get_physical_inputs(ra);
78  std::unordered_set<PhysicalInput> phys_inputs2;
79  for (auto& phi : phys_inputs) {
80  phys_inputs2.insert(
81  PhysicalInput{cat.getColumnIdBySpi(phi.table_id, phi.col_id), phi.table_id});
82  }
83  return phys_inputs2;
84 }
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:2052

+ Here is the call graph for this function:

std::vector<Analyzer::Expr*> anonymous_namespace{RelAlgExecutor.cpp}::get_raw_pointers ( std::vector< std::shared_ptr< Analyzer::Expr >> const &  input)

Definition at line 4620 of file RelAlgExecutor.cpp.

References shared::transform().

Referenced by RelAlgExecutor::createFilterWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::createTableFunctionWorkUnit(), RelAlgExecutor::createUnionWorkUnit(), and get_inputs_meta().

4621  {
4622  std::vector<Analyzer::Expr*> output(input.size());
4623  auto const raw_ptr = [](auto& shared_ptr) { return shared_ptr.get(); };
4624  std::transform(input.cbegin(), input.cend(), output.begin(), raw_ptr);
4625  return output;
4626 }
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t anonymous_namespace{RelAlgExecutor.cpp}::get_scalar_sources_size ( const RelCompound compound)

Definition at line 1658 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSourcesSize().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1658  {
1659  return compound->getScalarSourcesSize();
1660 }
const size_t getScalarSourcesSize() const
Definition: RelAlgDag.h:1687

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t anonymous_namespace{RelAlgExecutor.cpp}::get_scalar_sources_size ( const RelProject project)

Definition at line 1662 of file RelAlgExecutor.cpp.

References RelProject::size().

1662  {
1663  return project->size();
1664 }
size_t size() const override
Definition: RelAlgDag.h:1068

+ Here is the call graph for this function:

size_t anonymous_namespace{RelAlgExecutor.cpp}::get_scalar_sources_size ( const RelTableFunction table_func)

Definition at line 1666 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputsSize().

1666  {
1667  return table_func->getTableFuncInputsSize();
1668 }
size_t getTableFuncInputsSize() const
Definition: RelAlgDag.h:2079

+ Here is the call graph for this function:

size_t anonymous_namespace{RelAlgExecutor.cpp}::get_scan_limit ( const RelAlgNode ra,
const size_t  limit 
)

Definition at line 3129 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::createSortInputWorkUnit().

3129  {
3130  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
3131  if (aggregate) {
3132  return 0;
3133  }
3134  const auto compound = dynamic_cast<const RelCompound*>(ra);
3135  return (compound && compound->isAggregate()) ? 0 : limit;
3136 }

+ Here is the caller graph for this function:

template<class RA >
std::vector<TargetMetaInfo> anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta ( const RA *  ra_node,
const std::vector< Analyzer::Expr * > &  target_exprs 
)

Definition at line 1930 of file RelAlgExecutor.cpp.

References CHECK, CHECK_EQ, and get_logical_type_for_expr().

Referenced by RelAlgExecutor::createAggregateWorkUnit(), RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::createTableFunctionWorkUnit(), RelAlgExecutor::createUnionWorkUnit(), get_inputs_meta(), and get_targets_meta().

1932  {
1933  std::vector<TargetMetaInfo> targets_meta;
1934  CHECK_EQ(ra_node->size(), target_exprs.size());
1935  for (size_t i = 0; i < ra_node->size(); ++i) {
1936  CHECK(target_exprs[i]);
1937  // TODO(alex): remove the count distinct type fixup.
1938  targets_meta.emplace_back(ra_node->getFieldName(i),
1939  get_logical_type_for_expr(*target_exprs[i]),
1940  target_exprs[i]->get_type_info());
1941  }
1942  return targets_meta;
1943 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
SQLTypeInfo get_logical_type_for_expr(const Analyzer::Expr &expr)
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
std::vector<TargetMetaInfo> anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta ( const RelFilter filter,
const std::vector< Analyzer::Expr * > &  target_exprs 
)

Definition at line 1946 of file RelAlgExecutor.cpp.

References RelRexToStringConfig::defaults(), get_targets_meta(), RelAlgNode::getInput(), RelAlgNode::toString(), and UNREACHABLE.

1948  {
1949  RelAlgNode const* input0 = filter->getInput(0);
1950  if (auto const* input = dynamic_cast<RelCompound const*>(input0)) {
1951  return get_targets_meta(input, target_exprs);
1952  } else if (auto const* input = dynamic_cast<RelProject const*>(input0)) {
1953  return get_targets_meta(input, target_exprs);
1954  } else if (auto const* input = dynamic_cast<RelLogicalUnion const*>(input0)) {
1955  return get_targets_meta(input, target_exprs);
1956  } else if (auto const* input = dynamic_cast<RelAggregate const*>(input0)) {
1957  return get_targets_meta(input, target_exprs);
1958  } else if (auto const* input = dynamic_cast<RelScan const*>(input0)) {
1959  return get_targets_meta(input, target_exprs);
1960  }
1961  UNREACHABLE() << "Unhandled node type: "
1963  return {};
1964 }
#define UNREACHABLE()
Definition: Logger.h:266
virtual std::string toString(RelRexToStringConfig config) const =0
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:49

+ Here is the call graph for this function:

TextEncodingCastCounts anonymous_namespace{RelAlgExecutor.cpp}::get_text_cast_counts ( const RelAlgExecutionUnit ra_exe_unit)

Definition at line 380 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::groupby_exprs, RelAlgExecutionUnit::join_quals, RelAlgExecutionUnit::quals, RelAlgExecutionUnit::simple_quals, RelAlgExecutionUnit::target_exprs, anonymous_namespace{RelAlgExecutor.cpp}::TextEncodingCastCounts::text_decoding_casts, anonymous_namespace{RelAlgExecutor.cpp}::TextEncodingCastCounts::text_encoding_casts, and ScalarExprVisitor< T >::visit().

Referenced by check_none_encoded_string_cast_tuple_limit().

380  {
381  TextEncodingCastCounts cast_counts;
382 
383  auto check_node_for_text_casts = [&cast_counts](
384  const Analyzer::Expr* expr,
385  const bool disregard_casts_to_none_encoding) {
386  if (!expr) {
387  return;
388  }
389  TextEncodingCastCountVisitor visitor(disregard_casts_to_none_encoding);
390  const auto this_node_cast_counts = visitor.visit(expr);
391  cast_counts.text_encoding_casts += this_node_cast_counts.text_encoding_casts;
392  cast_counts.text_decoding_casts += this_node_cast_counts.text_decoding_casts;
393  };
394 
395  for (const auto& qual : ra_exe_unit.quals) {
396  check_node_for_text_casts(qual.get(), false);
397  }
398  for (const auto& simple_qual : ra_exe_unit.simple_quals) {
399  check_node_for_text_casts(simple_qual.get(), false);
400  }
401  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
402  check_node_for_text_casts(groupby_expr.get(), false);
403  }
404  for (const auto& target_expr : ra_exe_unit.target_exprs) {
405  check_node_for_text_casts(target_expr, false);
406  }
407  for (const auto& join_condition : ra_exe_unit.join_quals) {
408  for (const auto& join_qual : join_condition.quals) {
409  // We currently need to not count casts to none-encoded strings for join quals,
410  // as analyzer will generate these but our join framework disregards them.
411  // Some investigation was done on having analyzer issue the correct inter-string
412  // dictionary casts, but this actually causes them to get executed and so the same
413  // work gets done twice.
414  check_node_for_text_casts(join_qual.get(),
415  true /* disregard_casts_to_none_encoding */);
416  }
417  }
418  return cast_counts;
419 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
const JoinQualsPerNestingLevel join_quals
std::list< std::shared_ptr< Analyzer::Expr > > quals
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:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs ( const RelCompound compound,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1371 of file RelAlgExecutor.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelCompound::getFilterExpr(), RelCompound::getScalarSource(), RelCompound::getScalarSourcesSize(), and RexVisitorBase< T >::visit().

Referenced by get_input_desc().

1371  {
1372  RexUsedInputsVisitor visitor(cat);
1373  const auto filter_expr = compound->getFilterExpr();
1374  std::unordered_set<const RexInput*> used_inputs =
1375  filter_expr ? visitor.visit(filter_expr) : std::unordered_set<const RexInput*>{};
1376  const auto sources_size = compound->getScalarSourcesSize();
1377  for (size_t i = 0; i < sources_size; ++i) {
1378  const auto source_inputs = visitor.visit(compound->getScalarSource(i));
1379  used_inputs.insert(source_inputs.begin(), source_inputs.end());
1380  }
1381  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1382  return std::make_pair(used_inputs, used_inputs_owned);
1383 }
const RexScalar * getFilterExpr() const
Definition: RelAlgDag.h:1673
const size_t getScalarSourcesSize() const
Definition: RelAlgDag.h:1687
const RexScalar * getScalarSource(const size_t i) const
Definition: RelAlgDag.h:1689

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs ( const RelAggregate aggregate,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1386 of file RelAlgExecutor.cpp.

References CHECK_EQ, CHECK_GE, RelAggregate::getAggExprs(), RelAggregate::getGroupByCount(), RelAlgNode::getInput(), RelAlgNode::getOutputMetainfo(), and RelAlgNode::inputCount().

1386  {
1387  CHECK_EQ(size_t(1), aggregate->inputCount());
1388  std::unordered_set<const RexInput*> used_inputs;
1389  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1390  const auto source = aggregate->getInput(0);
1391  const auto& in_metainfo = source->getOutputMetainfo();
1392  const auto group_count = aggregate->getGroupByCount();
1393  CHECK_GE(in_metainfo.size(), group_count);
1394  for (size_t i = 0; i < group_count; ++i) {
1395  auto synthesized_used_input = new RexInput(source, i);
1396  used_inputs_owned.emplace_back(synthesized_used_input);
1397  used_inputs.insert(synthesized_used_input);
1398  }
1399  for (const auto& agg_expr : aggregate->getAggExprs()) {
1400  for (size_t i = 0; i < agg_expr->size(); ++i) {
1401  const auto operand_idx = agg_expr->getOperand(i);
1402  CHECK_GE(in_metainfo.size(), static_cast<size_t>(operand_idx));
1403  auto synthesized_used_input = new RexInput(source, operand_idx);
1404  used_inputs_owned.emplace_back(synthesized_used_input);
1405  used_inputs.insert(synthesized_used_input);
1406  }
1407  }
1408  return std::make_pair(used_inputs, used_inputs_owned);
1409 }
const size_t getGroupByCount() const
Definition: RelAlgDag.h:1195
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define CHECK_GE(x, y)
Definition: Logger.h:235
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
Definition: RelAlgDag.h:1218
const size_t inputCount() const
Definition: RelAlgDag.h:824
const std::vector< TargetMetaInfo > & getOutputMetainfo() const
Definition: RelAlgDag.h:810

+ Here is the call graph for this function:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs ( const RelProject project,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1412 of file RelAlgExecutor.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelProject::getProjectAt(), RelProject::size(), and RexVisitorBase< T >::visit().

1412  {
1413  RexUsedInputsVisitor visitor(cat);
1414  std::unordered_set<const RexInput*> used_inputs;
1415  for (size_t i = 0; i < project->size(); ++i) {
1416  const auto proj_inputs = visitor.visit(project->getProjectAt(i));
1417  used_inputs.insert(proj_inputs.begin(), proj_inputs.end());
1418  }
1419  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1420  return std::make_pair(used_inputs, used_inputs_owned);
1421 }
size_t size() const override
Definition: RelAlgDag.h:1068
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1070

+ Here is the call graph for this function:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs ( const RelTableFunction table_func,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1424 of file RelAlgExecutor.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelTableFunction::getTableFuncInputAt(), RelTableFunction::getTableFuncInputsSize(), and RexVisitorBase< T >::visit().

1425  {
1426  RexUsedInputsVisitor visitor(cat);
1427  std::unordered_set<const RexInput*> used_inputs;
1428  for (size_t i = 0; i < table_func->getTableFuncInputsSize(); ++i) {
1429  const auto table_func_inputs = visitor.visit(table_func->getTableFuncInputAt(i));
1430  used_inputs.insert(table_func_inputs.begin(), table_func_inputs.end());
1431  }
1432  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1433  return std::make_pair(used_inputs, used_inputs_owned);
1434 }
size_t getTableFuncInputsSize() const
Definition: RelAlgDag.h:2079
const RexScalar * getTableFuncInputAt(const size_t idx) const
Definition: RelAlgDag.h:2085

+ Here is the call graph for this function:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs ( const RelFilter filter,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1437 of file RelAlgExecutor.cpp.

References CHECK, and get_data_sink().

1437  {
1438  std::unordered_set<const RexInput*> used_inputs;
1439  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1440  const auto data_sink_node = get_data_sink(filter);
1441  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
1442  const auto source = data_sink_node->getInput(nest_level);
1443  const auto scan_source = dynamic_cast<const RelScan*>(source);
1444  if (scan_source) {
1445  CHECK(source->getOutputMetainfo().empty());
1446  for (size_t i = 0; i < scan_source->size(); ++i) {
1447  auto synthesized_used_input = new RexInput(scan_source, i);
1448  used_inputs_owned.emplace_back(synthesized_used_input);
1449  used_inputs.insert(synthesized_used_input);
1450  }
1451  } else {
1452  const auto& partial_in_metadata = source->getOutputMetainfo();
1453  for (size_t i = 0; i < partial_in_metadata.size(); ++i) {
1454  auto synthesized_used_input = new RexInput(source, i);
1455  used_inputs_owned.emplace_back(synthesized_used_input);
1456  used_inputs.insert(synthesized_used_input);
1457  }
1458  }
1459  }
1460  return std::make_pair(used_inputs, used_inputs_owned);
1461 }
#define CHECK(condition)
Definition: Logger.h:222
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

std::pair<std::unordered_set<const RexInput*>, std::vector<std::shared_ptr<RexInput> > > anonymous_namespace{RelAlgExecutor.cpp}::get_used_inputs ( const RelLogicalUnion logical_union,
const Catalog_Namespace::Catalog  
)

Definition at line 1464 of file RelAlgExecutor.cpp.

References RelAlgNode::getInput(), RelAlgNode::inputCount(), and VLOG.

1464  {
1465  std::unordered_set<const RexInput*> used_inputs(logical_union->inputCount());
1466  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1467  used_inputs_owned.reserve(logical_union->inputCount());
1468  VLOG(3) << "logical_union->inputCount()=" << logical_union->inputCount();
1469  auto const n_inputs = logical_union->inputCount();
1470  for (size_t nest_level = 0; nest_level < n_inputs; ++nest_level) {
1471  auto input = logical_union->getInput(nest_level);
1472  for (size_t i = 0; i < input->size(); ++i) {
1473  used_inputs_owned.emplace_back(std::make_shared<RexInput>(input, i));
1474  used_inputs.insert(used_inputs_owned.back().get());
1475  }
1476  }
1477  return std::make_pair(std::move(used_inputs), std::move(used_inputs_owned));
1478 }
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
const size_t inputCount() const
Definition: RelAlgDag.h:824
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

ErrorInfo anonymous_namespace{RelAlgExecutor.cpp}::getErrorDescription ( const int32_t  error_code)

Definition at line 4057 of file RelAlgExecutor.cpp.

References Executor::ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED, Executor::ERR_DIV_BY_ZERO, Executor::ERR_GEOS, Executor::ERR_INTERRUPTED, Executor::ERR_OUT_OF_CPU_MEM, Executor::ERR_OUT_OF_GPU_MEM, Executor::ERR_OUT_OF_RENDER_MEM, Executor::ERR_OUT_OF_TIME, Executor::ERR_OVERFLOW_OR_UNDERFLOW, Executor::ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES, Executor::ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY, Executor::ERR_STRING_CONST_IN_RESULTSET, Executor::ERR_TOO_MANY_LITERALS, Executor::ERR_UNSUPPORTED_SELF_JOIN, and Executor::ERR_WIDTH_BUCKET_INVALID_ARGUMENT.

Referenced by RelAlgExecutor::getErrorMessageFromCode().

4057  {
4058  // 'designated initializers' don't compile on Windows for std 17
4059  // They require /std:c++20. They been removed for the windows port.
4060  switch (error_code) {
4062  return {"ERR_DIV_BY_ZERO", "Division by zero"};
4064  return {"ERR_OUT_OF_GPU_MEM",
4065 
4066  "Query couldn't keep the entire working set of columns in GPU memory"};
4068  return {"ERR_UNSUPPORTED_SELF_JOIN", "Self joins not supported yet"};
4070  return {"ERR_OUT_OF_CPU_MEM", "Not enough host memory to execute the query"};
4072  return {"ERR_OVERFLOW_OR_UNDERFLOW", "Overflow or underflow"};
4074  return {"ERR_OUT_OF_TIME", "Query execution has exceeded the time limit"};
4076  return {"ERR_INTERRUPTED", "Query execution has been interrupted"};
4078  return {"ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED",
4079  "Columnar conversion not supported for variable length types"};
4081  return {"ERR_TOO_MANY_LITERALS", "Too many literals in the query"};
4083  return {"ERR_STRING_CONST_IN_RESULTSET",
4084 
4085  "NONE ENCODED String types are not supported as input result set."};
4087  return {"ERR_OUT_OF_RENDER_MEM",
4088 
4089  "Insufficient GPU memory for query results in render output buffer "
4090  "sized by render-mem-bytes"};
4092  return {"ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY",
4093  "Streaming-Top-N not supported in Render Query"};
4095  return {"ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES",
4096  "Multiple distinct values encountered"};
4097  case Executor::ERR_GEOS:
4098  return {"ERR_GEOS", "ERR_GEOS"};
4100  return {"ERR_WIDTH_BUCKET_INVALID_ARGUMENT",
4101 
4102  "Arguments of WIDTH_BUCKET function does not satisfy the condition"};
4103  default:
4104  return {nullptr, nullptr};
4105  }
4106 }
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1346
static const int32_t ERR_GEOS
Definition: Execute.h:1352
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1348
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1349
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1350
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1347
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1338
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1342
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1344
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1345
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1341
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1351
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1339
static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT
Definition: Execute.h:1353
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1343

+ Here is the caller graph for this function:

size_t anonymous_namespace{RelAlgExecutor.cpp}::groups_approx_upper_bound ( const std::vector< InputTableInfo > &  table_infos)

Upper bound estimation for the number of groups. Not strictly correct and not tight, but if the tables involved are really small we shouldn't waste time doing the NDV estimation. We don't account for cross-joins and / or group by unnested array, which is the reason this estimation isn't entirely reliable.

Definition at line 3391 of file RelAlgExecutor.cpp.

References CHECK.

Referenced by RelAlgExecutor::executeWorkUnit().

3391  {
3392  CHECK(!table_infos.empty());
3393  const auto& first_table = table_infos.front();
3394  size_t max_num_groups = first_table.info.getNumTuplesUpperBound();
3395  for (const auto& table_info : table_infos) {
3396  if (table_info.info.getNumTuplesUpperBound() > max_num_groups) {
3397  max_num_groups = table_info.info.getNumTuplesUpperBound();
3398  }
3399  }
3400  return std::max(max_num_groups, size_t(1));
3401 }
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::has_valid_query_plan_dag ( const RelAlgNode node)

Definition at line 199 of file RelAlgExecutor.cpp.

References EMPTY_HASHED_PLAN_DAG_KEY, and RelAlgNode::getQueryPlanDagHash().

Referenced by RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::executeRelAlgStep(), RelAlgExecutor::executeSort(), and RelAlgExecutor::executeTableFunction().

199  {
201 }
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
size_t getQueryPlanDagHash() const
Definition: RelAlgDag.h:808

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
int64_t anonymous_namespace{RelAlgExecutor.cpp}::insert_one_dict_str ( T *  col_data,
const std::string &  columnName,
const SQLTypeInfo columnType,
const Analyzer::Constant col_cv,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 2728 of file RelAlgExecutor.cpp.

References CHECK, logger::ERROR, SQLTypeInfo::get_comp_param(), Analyzer::Constant::get_constval(), Analyzer::Constant::get_is_null(), Catalog_Namespace::Catalog::getMetadataForDict(), inline_fixed_encoding_null_val(), LOG, Datum::stringval, and heavydb.dtypes::T.

Referenced by RelAlgExecutor::executeSimpleInsert(), and insert_one_dict_str().

2732  {
2733  if (col_cv->get_is_null()) {
2734  *col_data = inline_fixed_encoding_null_val(columnType);
2735  } else {
2736  const int dict_id = columnType.get_comp_param();
2737  const auto col_datum = col_cv->get_constval();
2738  const auto& str = *col_datum.stringval;
2739  const auto dd = catalog.getMetadataForDict(dict_id);
2740  CHECK(dd && dd->stringDict);
2741  int32_t str_id = dd->stringDict->getOrAdd(str);
2742  if (!dd->dictIsTemp) {
2743  const auto checkpoint_ok = dd->stringDict->checkpoint();
2744  if (!checkpoint_ok) {
2745  throw std::runtime_error("Failed to checkpoint dictionary for column " +
2746  columnName);
2747  }
2748  }
2749  const bool invalid = str_id > max_valid_int_value<T>();
2750  if (invalid || str_id == inline_int_null_value<int32_t>()) {
2751  if (invalid) {
2752  LOG(ERROR) << "Could not encode string: " << str
2753  << ", the encoded value doesn't fit in " << sizeof(T) * 8
2754  << " bits. Will store NULL instead.";
2755  }
2756  str_id = inline_fixed_encoding_null_val(columnType);
2757  }
2758  *col_data = str_id;
2759  }
2760  return *col_data;
2761 }
#define LOG(tag)
Definition: Logger.h:216
bool get_is_null() const
Definition: Analyzer.h:341
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1960
std::string * stringval
Definition: sqltypes.h:220
Datum get_constval() const
Definition: Analyzer.h:342
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
int64_t anonymous_namespace{RelAlgExecutor.cpp}::insert_one_dict_str ( T *  col_data,
const ColumnDescriptor cd,
const Analyzer::Constant col_cv,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 2764 of file RelAlgExecutor.cpp.

References ColumnDescriptor::columnName, ColumnDescriptor::columnType, and insert_one_dict_str().

2767  {
2768  return insert_one_dict_str(col_data, cd->columnName, cd->columnType, col_cv, catalog);
2769 }
int64_t insert_one_dict_str(T *col_data, const std::string &columnName, const SQLTypeInfo &columnType, const Analyzer::Constant *col_cv, const Catalog_Namespace::Catalog &catalog)
SQLTypeInfo columnType
std::string columnName

+ Here is the call graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::is_agg ( const Analyzer::Expr expr)

Definition at line 1908 of file RelAlgExecutor.cpp.

References Analyzer::AggExpr::get_aggtype(), kAVG, kMAX, kMIN, and kSUM.

Referenced by anonymous_namespace{RelAlgDag.cpp}::create_compound(), RelAlgExecutor::executeWorkUnit(), get_logical_type_for_expr(), and ResultSet::getSingleSlotTargetBitmap().

1908  {
1909  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1910  if (agg_expr && agg_expr->get_contains_agg()) {
1911  auto agg_type = agg_expr->get_aggtype();
1912  if (agg_type == SQLAgg::kMIN || agg_type == SQLAgg::kMAX ||
1913  agg_type == SQLAgg::kSUM || agg_type == SQLAgg::kAVG) {
1914  return true;
1915  }
1916  }
1917  return false;
1918 }
Definition: sqldefs.h:74
Definition: sqldefs.h:76
SQLAgg get_aggtype() const
Definition: Analyzer.h:1201
Definition: sqldefs.h:75
Definition: sqldefs.h:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::is_count_distinct ( const Analyzer::Expr expr)

Definition at line 1903 of file RelAlgExecutor.cpp.

References Analyzer::AggExpr::get_is_distinct().

Referenced by get_logical_type_for_expr().

1903  {
1904  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1905  return agg_expr && agg_expr->get_is_distinct();
1906 }
bool get_is_distinct() const
Definition: Analyzer.h:1204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::is_projection ( const RelAlgExecutionUnit ra_exe_unit)

Definition at line 3403 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::groupby_exprs.

Referenced by can_output_columnar(), and RelAlgTranslator::translateGeoFunctionArg().

3403  {
3404  return ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front();
3405 }
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::is_validate_or_explain_query ( const ExecutionOptions eo)

Definition at line 229 of file RelAlgExecutor.cpp.

References ExecutionOptions::just_calcite_explain, ExecutionOptions::just_explain, and ExecutionOptions::just_validate.

Referenced by RelAlgExecutor::canUseResultsetCache(), RelAlgExecutor::executeTableFunction(), and RelAlgExecutor::executeWorkUnit().

229  {
230  return eo.just_validate || eo.just_explain || eo.just_calcite_explain;
231 }

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::is_window_execution_unit ( const RelAlgExecutionUnit ra_exe_unit)

Definition at line 2240 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

2240  {
2241  return std::any_of(ra_exe_unit.target_exprs.begin(),
2242  ra_exe_unit.target_exprs.end(),
2243  [](const Analyzer::Expr* expr) {
2244  return dynamic_cast<const Analyzer::WindowFunction*>(expr);
2245  });
2246 }
std::vector< Analyzer::Expr * > target_exprs

+ Here is the caller graph for this function:

std::vector<JoinType> anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types ( const RelLeftDeepInnerJoin left_deep_join)

Definition at line 4236 of file RelAlgExecutor.cpp.

References ANTI, CHECK_GE, RelLeftDeepInnerJoin::getJoinType(), RelLeftDeepInnerJoin::getOuterCondition(), INNER, RelAlgNode::inputCount(), LEFT, and SEMI.

Referenced by RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), RelAlgExecutor::getRelAlgTranslator(), and RelAlgExecutor::translateLeftDeepJoinFilter().

4236  {
4237  CHECK_GE(left_deep_join->inputCount(), size_t(2));
4238  std::vector<JoinType> join_types(left_deep_join->inputCount() - 1, JoinType::INNER);
4239  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
4240  ++nesting_level) {
4241  if (left_deep_join->getOuterCondition(nesting_level)) {
4242  join_types[nesting_level - 1] = JoinType::LEFT;
4243  }
4244  auto cur_level_join_type = left_deep_join->getJoinType(nesting_level);
4245  if (cur_level_join_type == JoinType::SEMI || cur_level_join_type == JoinType::ANTI) {
4246  join_types[nesting_level - 1] = cur_level_join_type;
4247  }
4248  }
4249  return join_types;
4250 }
const RexScalar * getOuterCondition(const size_t nesting_level) const
#define CHECK_GE(x, y)
Definition: Logger.h:235
const JoinType getJoinType(const size_t nesting_level) const
const size_t inputCount() const
Definition: RelAlgDag.h:824

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class QualsList >
bool anonymous_namespace{RelAlgExecutor.cpp}::list_contains_expression ( const QualsList &  haystack,
const std::shared_ptr< Analyzer::Expr > &  needle 
)

Definition at line 4455 of file RelAlgExecutor.cpp.

Referenced by reverse_logical_distribution().

4456  {
4457  for (const auto& qual : haystack) {
4458  if (*qual == *needle) {
4459  return true;
4460  }
4461  }
4462  return false;
4463 }

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::node_is_aggregate ( const RelAlgNode ra)

Definition at line 68 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::executeRelAlgQuerySingleStep(), and RelAlgExecutor::executeSort().

68  {
69  const auto compound = dynamic_cast<const RelCompound*>(ra);
70  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
71  return ((compound && compound->isAggregate()) || aggregate);
72 }

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::prepare_for_system_table_execution ( const RelAlgNode ra_node,
const Catalog_Namespace::Catalog catalog,
const CompilationOptions co 
)

Definition at line 148 of file RelAlgExecutor.cpp.

References CHECK, CHECK_LE, CPU, Data_Namespace::CPU_LEVEL, Data_Namespace::DataMgr::deleteChunksWithPrefix(), CompilationOptions::device_type, g_enable_system_tables, get_physical_inputs(), Chunk_NS::Chunk::getChunk(), Catalog_Namespace::Catalog::getColumnIdBySpi(), Catalog_Namespace::Catalog::getDatabaseId(), Catalog_Namespace::Catalog::getDataMgr(), Catalog_Namespace::Catalog::getMetadataForColumn(), and Catalog_Namespace::Catalog::getMetadataForTable().

Referenced by RelAlgExecutor::executeRelAlgQueryNoRetry(), and RelAlgExecutor::prepareForSystemTableExecution().

150  {
152  std::map<int32_t, std::vector<int32_t>> system_table_columns_by_table_id;
153  for (const auto& physical_input : get_physical_inputs(&ra_node)) {
154  int table_id = physical_input.table_id;
155  auto table = catalog.getMetadataForTable(table_id, false);
156  if (table && table->is_in_memory_system_table) {
157  auto column_id = catalog.getColumnIdBySpi(table_id, physical_input.col_id);
158  system_table_columns_by_table_id[table_id].emplace_back(column_id);
159  }
160  }
161  // Execute on CPU for queries involving system tables
162  if (!system_table_columns_by_table_id.empty() &&
164  throw QueryMustRunOnCpu();
165  }
166 
167  for (const auto& [table_id, column_ids] : system_table_columns_by_table_id) {
168  // Clear any previously cached data, since system tables depend on point in
169  // time data snapshots.
171  ChunkKey{catalog.getDatabaseId(), table_id}, Data_Namespace::CPU_LEVEL);
172 
173  // TODO(Misiu): This prefetching can be removed if we can add support for
174  // ExpressionRanges to reduce invalid with valid ranges (right now prefetching
175  // causes us to fetch the chunks twice). Right now if we do not prefetch (i.e. if
176  // we remove the code below) some nodes will return valid ranges and others will
177  // return unknown because they only use placeholder metadata and the LeafAggregator
178  // has no idea how to reduce the two.
179  auto td = catalog.getMetadataForTable(table_id);
180  CHECK(td);
181  CHECK(td->fragmenter);
182  auto fragment_count = td->fragmenter->getFragmentsForQuery().fragments.size();
183  CHECK_LE(fragment_count, static_cast<size_t>(1))
184  << "In-memory system tables are expected to have a single fragment.";
185  if (fragment_count > 0) {
186  for (auto column_id : column_ids) {
187  // Prefetch system table chunks in order to force chunk statistics metadata
188  // computation.
189  auto cd = catalog.getMetadataForColumn(table_id, column_id);
190  ChunkKey chunk_key{catalog.getDatabaseId(), table_id, column_id, 0};
192  cd, &(catalog.getDataMgr()), chunk_key, Data_Namespace::CPU_LEVEL, 0, 0, 0);
193  }
194  }
195  }
196  }
197 }
std::vector< int > ChunkKey
Definition: types.h:36
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:243
bool g_enable_system_tables
Definition: SysCatalog.cpp:64
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
int getDatabaseId() const
Definition: Catalog.h:298
ExecutorDeviceType device_type
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:495
#define CHECK_LE(x, y)
Definition: Logger.h:233
#define CHECK(condition)
Definition: Logger.h:222
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
static std::shared_ptr< Chunk > getChunk(const ColumnDescriptor *cd, DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int deviceId, const size_t num_bytes, const size_t num_elems, const bool pinnable=true)
Definition: Chunk.cpp:31
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:2052

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::prepare_foreign_table_for_execution ( const RelAlgNode ra_node,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 139 of file RelAlgExecutor.cpp.

References anonymous_namespace{Execute.cpp}::prepare_string_dictionaries(), and set_parallelism_hints().

Referenced by RelAlgExecutor::executeRelAlgQueryNoRetry(), and RelAlgExecutor::prepareForeignTables().

140  {
141  // Iterate through ra_node inputs for types that need to be loaded pre-execution
142  // If they do not have valid metadata, load them into CPU memory to generate
143  // the metadata and leave them ready to be used by the query
144  set_parallelism_hints(ra_node, catalog);
145  prepare_string_dictionaries(ra_node, catalog);
146 }
void prepare_string_dictionaries(const std::unordered_set< PhysicalInput > &phys_inputs, const Catalog_Namespace::Catalog &catalog)
Definition: Execute.cpp:188
void set_parallelism_hints(const RelAlgNode &ra_node, const Catalog_Namespace::Catalog &catalog)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::prepare_string_dictionaries ( const RelAlgNode ra_node,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 128 of file RelAlgExecutor.cpp.

References StorageType::FOREIGN_TABLE, get_physical_inputs(), Catalog_Namespace::Catalog::getColumnIdBySpi(), Catalog_Namespace::Catalog::getMetadataForTable(), and foreign_storage::populate_string_dictionary().

129  {
130  for (const auto [col_id, table_id] : get_physical_inputs(&ra_node)) {
131  auto table = catalog.getMetadataForTable(table_id, false);
132  if (table && table->storageType == StorageType::FOREIGN_TABLE) {
133  auto spi_col_id = catalog.getColumnIdBySpi(table_id, col_id);
134  foreign_storage::populate_string_dictionary(table_id, spi_col_id, catalog);
135  }
136  }
137 }
void populate_string_dictionary(const int32_t table_id, const int32_t col_id, const Catalog_Namespace::Catalog &catalog)
Definition: Execute.cpp:205
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
static constexpr char const * FOREIGN_TABLE
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:2052

+ Here is the call graph for this function:

std::shared_ptr<Analyzer::Expr> anonymous_namespace{RelAlgExecutor.cpp}::reverse_logical_distribution ( const std::shared_ptr< Analyzer::Expr > &  expr)

Definition at line 4468 of file RelAlgExecutor.cpp.

References build_logical_expression(), CHECK_GE, kAND, kONE, kOR, list_contains_expression(), Parser::OperExpr::normalize(), qual_to_conjunctive_form(), and qual_to_disjunctive_form().

Referenced by RelAlgExecutor::makeJoinQuals().

4469  {
4470  const auto expr_terms = qual_to_disjunctive_form(expr);
4471  CHECK_GE(expr_terms.size(), size_t(1));
4472  const auto& first_term = expr_terms.front();
4473  const auto first_term_factors = qual_to_conjunctive_form(first_term);
4474  std::vector<std::shared_ptr<Analyzer::Expr>> common_factors;
4475  // First, collect the conjunctive components common to all the disjunctive components.
4476  // Don't do it for simple qualifiers, we only care about expensive or join qualifiers.
4477  for (const auto& first_term_factor : first_term_factors.quals) {
4478  bool is_common =
4479  expr_terms.size() > 1; // Only report common factors for disjunction.
4480  for (size_t i = 1; i < expr_terms.size(); ++i) {
4481  const auto crt_term_factors = qual_to_conjunctive_form(expr_terms[i]);
4482  if (!list_contains_expression(crt_term_factors.quals, first_term_factor)) {
4483  is_common = false;
4484  break;
4485  }
4486  }
4487  if (is_common) {
4488  common_factors.push_back(first_term_factor);
4489  }
4490  }
4491  if (common_factors.empty()) {
4492  return expr;
4493  }
4494  // Now that the common expressions are known, collect the remaining expressions.
4495  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_terms;
4496  for (const auto& term : expr_terms) {
4497  const auto term_cf = qual_to_conjunctive_form(term);
4498  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_quals(
4499  term_cf.simple_quals.begin(), term_cf.simple_quals.end());
4500  for (const auto& qual : term_cf.quals) {
4501  if (!list_contains_expression(common_factors, qual)) {
4502  remaining_quals.push_back(qual);
4503  }
4504  }
4505  if (!remaining_quals.empty()) {
4506  remaining_terms.push_back(build_logical_expression(remaining_quals, kAND));
4507  }
4508  }
4509  // Reconstruct the expression with the transformation applied.
4510  const auto common_expr = build_logical_expression(common_factors, kAND);
4511  if (remaining_terms.empty()) {
4512  return common_expr;
4513  }
4514  const auto remaining_expr = build_logical_expression(remaining_terms, kOR);
4515  return Parser::OperExpr::normalize(kAND, kONE, common_expr, remaining_expr);
4516 }
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr, const Executor *executor=nullptr)
Definition: ParserNode.cpp:370
Definition: sqldefs.h:37
#define CHECK_GE(x, y)
Definition: Logger.h:235
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
bool list_contains_expression(const QualsList &haystack, const std::shared_ptr< Analyzer::Expr > &needle)
Definition: sqldefs.h:36
std::shared_ptr< Analyzer::Expr > build_logical_expression(const std::vector< std::shared_ptr< Analyzer::Expr >> &factors, const SQLOps sql_op)
Definition: sqldefs.h:70
std::vector< std::shared_ptr< Analyzer::Expr > > qual_to_disjunctive_form(const std::shared_ptr< Analyzer::Expr > &qual_expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::rewrite_quals ( const std::list< std::shared_ptr< Analyzer::Expr >> &  quals)

Definition at line 4295 of file RelAlgExecutor.cpp.

References rewrite_expr().

Referenced by RelAlgExecutor::createCompoundWorkUnit().

4296  {
4297  std::list<std::shared_ptr<Analyzer::Expr>> rewritten_quals;
4298  for (const auto& qual : quals) {
4299  const auto rewritten_qual = rewrite_expr(qual.get());
4300  rewritten_quals.push_back(rewritten_qual ? rewritten_qual : qual);
4301  }
4302  return rewritten_quals;
4303 }
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<const RexScalar*> anonymous_namespace{RelAlgExecutor.cpp}::rex_to_conjunctive_form ( const RexScalar qual_expr)

Definition at line 4428 of file RelAlgExecutor.cpp.

References CHECK, CHECK_GE, and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

4428  {
4429  CHECK(qual_expr);
4430  const auto bin_oper = dynamic_cast<const RexOperator*>(qual_expr);
4431  if (!bin_oper || bin_oper->getOperator() != kAND) {
4432  return {qual_expr};
4433  }
4434  CHECK_GE(bin_oper->size(), size_t(2));
4435  auto lhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(0));
4436  for (size_t i = 1; i < bin_oper->size(); ++i) {
4437  const auto rhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(i));
4438  lhs_cf.insert(lhs_cf.end(), rhs_cf.begin(), rhs_cf.end());
4439  }
4440  return lhs_cf;
4441 }
#define CHECK_GE(x, y)
Definition: Logger.h:235
std::vector< const RexScalar * > rex_to_conjunctive_form(const RexScalar *qual_expr)
Definition: sqldefs.h:36
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

const RexScalar* anonymous_namespace{RelAlgExecutor.cpp}::scalar_at ( const size_t  i,
const RelCompound compound 
)

Definition at line 1670 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSource().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1670  {
1671  return compound->getScalarSource(i);
1672 }
const RexScalar * getScalarSource(const size_t i) const
Definition: RelAlgDag.h:1689

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const RexScalar* anonymous_namespace{RelAlgExecutor.cpp}::scalar_at ( const size_t  i,
const RelProject project 
)

Definition at line 1674 of file RelAlgExecutor.cpp.

References RelProject::getProjectAt().

1674  {
1675  return project->getProjectAt(i);
1676 }
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1070

+ Here is the call graph for this function:

const RexScalar* anonymous_namespace{RelAlgExecutor.cpp}::scalar_at ( const size_t  i,
const RelTableFunction table_func 
)

Definition at line 1678 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputAt().

1678  {
1679  return table_func->getTableFuncInputAt(i);
1680 }
const RexScalar * getTableFuncInputAt(const size_t idx) const
Definition: RelAlgDag.h:2085

+ Here is the call graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::set_parallelism_hints ( const RelAlgNode ra_node,
const Catalog_Namespace::Catalog catalog 
)

Definition at line 86 of file RelAlgExecutor.cpp.

References CHECK, Data_Namespace::CPU_LEVEL, StorageType::FOREIGN_TABLE, get_physical_inputs(), Catalog_Namespace::Catalog::getColumnIdBySpi(), Catalog_Namespace::Catalog::getDatabaseId(), Catalog_Namespace::Catalog::getDataMgr(), PersistentStorageMgr::getForeignStorageMgr(), Catalog_Namespace::Catalog::getForeignTable(), Catalog_Namespace::Catalog::getMetadataForColumn(), Catalog_Namespace::Catalog::getMetadataForTable(), Data_Namespace::DataMgr::getPersistentStorageMgr(), and foreign_storage::key_does_not_shard_to_leaf().

Referenced by prepare_foreign_table_for_execution().

87  {
88  std::map<ChunkKey, std::set<foreign_storage::ForeignStorageMgr::ParallelismHint>>
89  parallelism_hints_per_table;
90  for (const auto& physical_input : get_physical_inputs(&ra_node)) {
91  int table_id = physical_input.table_id;
92  auto table = catalog.getMetadataForTable(table_id, false);
93  if (table && table->storageType == StorageType::FOREIGN_TABLE &&
94  !table->is_in_memory_system_table) {
95  int col_id = catalog.getColumnIdBySpi(table_id, physical_input.col_id);
96  const auto col_desc = catalog.getMetadataForColumn(table_id, col_id);
97  auto foreign_table = catalog.getForeignTable(table_id);
98  for (const auto& fragment :
99  foreign_table->fragmenter->getFragmentsForQuery().fragments) {
100  Chunk_NS::Chunk chunk{col_desc};
101  ChunkKey chunk_key = {
102  catalog.getDatabaseId(), table_id, col_id, fragment.fragmentId};
103 
104  // Parallelism hints should not include fragments that are not mapped to the
105  // current node, otherwise we will try to prefetch them and run into trouble.
107  continue;
108  }
109 
110  // do not include chunk hints that are in CPU memory
111  if (!chunk.isChunkOnDevice(
112  &catalog.getDataMgr(), chunk_key, Data_Namespace::CPU_LEVEL, 0)) {
113  parallelism_hints_per_table[{catalog.getDatabaseId(), table_id}].insert(
115  fragment.fragmentId});
116  }
117  }
118  }
119  }
120  if (!parallelism_hints_per_table.empty()) {
121  auto foreign_storage_mgr =
123  CHECK(foreign_storage_mgr);
124  foreign_storage_mgr->setParallelismHints(parallelism_hints_per_table);
125  }
126 }
const foreign_storage::ForeignTable * getForeignTable(const std::string &tableName) const
Definition: Catalog.cpp:1883
std::vector< int > ChunkKey
Definition: types.h:36
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:243
PersistentStorageMgr * getPersistentStorageMgr() const
Definition: DataMgr.cpp:637
foreign_storage::ForeignStorageMgr * getForeignStorageMgr() const
bool key_does_not_shard_to_leaf(const ChunkKey &key)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
int getDatabaseId() const
Definition: Catalog.h:298
#define CHECK(condition)
Definition: Logger.h:222
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
static constexpr char const * FOREIGN_TABLE
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:2052

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::Expr> anonymous_namespace{RelAlgExecutor.cpp}::set_transient_dict ( const std::shared_ptr< Analyzer::Expr expr)

Definition at line 1682 of file RelAlgExecutor.cpp.

References kENCODING_DICT, kENCODING_NONE, and TRANSIENT_DICT_ID.

Referenced by set_transient_dict_maybe(), translate_groupby_exprs(), and translate_targets().

1683  {
1684  const auto& ti = expr->get_type_info();
1685  if (!ti.is_string() || ti.get_compression() != kENCODING_NONE) {
1686  return expr;
1687  }
1688  auto transient_dict_ti = ti;
1689  transient_dict_ti.set_compression(kENCODING_DICT);
1690  transient_dict_ti.set_comp_param(TRANSIENT_DICT_ID);
1691  transient_dict_ti.set_fixed_size();
1692  return expr->add_cast(transient_dict_ti);
1693 }
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:259

+ Here is the caller graph for this function:

void anonymous_namespace{RelAlgExecutor.cpp}::set_transient_dict_maybe ( std::vector< std::shared_ptr< Analyzer::Expr >> &  scalar_sources,
const std::shared_ptr< Analyzer::Expr > &  expr 
)

Definition at line 1695 of file RelAlgExecutor.cpp.

References fold_expr(), and set_transient_dict().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1697  {
1698  try {
1699  scalar_sources.push_back(set_transient_dict(fold_expr(expr.get())));
1700  } catch (...) {
1701  scalar_sources.push_back(fold_expr(expr.get()));
1702  }
1703 }
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::should_output_columnar ( const RelAlgExecutionUnit ra_exe_unit)

Definition at line 3435 of file RelAlgExecutor.cpp.

References g_columnar_large_projections, g_columnar_large_projections_threshold, and RelAlgExecutionUnit::scan_limit.

Referenced by RelAlgExecutor::executeWorkUnit().

3435  {
3438 }
bool g_columnar_large_projections
size_t g_columnar_large_projections_threshold

+ Here is the caller graph for this function:

std::vector<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::synthesize_inputs ( const RelAlgNode ra_node,
const size_t  nest_level,
const std::vector< TargetMetaInfo > &  in_metainfo,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level 
)

Definition at line 4594 of file RelAlgExecutor.cpp.

References CHECK, CHECK_GE, CHECK_LE, RelAlgNode::getInput(), RelAlgNode::inputCount(), and table_id_from_ra().

Referenced by RelAlgExecutor::createAggregateWorkUnit(), and get_inputs_meta().

4598  {
4599  CHECK_LE(size_t(1), ra_node->inputCount());
4600  CHECK_GE(size_t(2), ra_node->inputCount());
4601  const auto input = ra_node->getInput(nest_level);
4602  const auto it_rte_idx = input_to_nest_level.find(input);
4603  CHECK(it_rte_idx != input_to_nest_level.end());
4604  const int rte_idx = it_rte_idx->second;
4605  const int table_id = table_id_from_ra(input);
4606  std::vector<std::shared_ptr<Analyzer::Expr>> inputs;
4607  const auto scan_ra = dynamic_cast<const RelScan*>(input);
4608  int input_idx = 0;
4609  for (const auto& input_meta : in_metainfo) {
4610  inputs.push_back(
4611  std::make_shared<Analyzer::ColumnVar>(input_meta.get_type_info(),
4612  table_id,
4613  scan_ra ? input_idx + 1 : input_idx,
4614  rte_idx));
4615  ++input_idx;
4616  }
4617  return inputs;
4618 }
#define CHECK_GE(x, y)
Definition: Logger.h:235
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
#define CHECK_LE(x, y)
Definition: Logger.h:233
int table_id_from_ra(const RelAlgNode *ra_node)
#define CHECK(condition)
Definition: Logger.h:222
const size_t inputCount() const
Definition: RelAlgDag.h:824

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int anonymous_namespace{RelAlgExecutor.cpp}::table_id_from_ra ( const RelAlgNode ra_node)

Definition at line 1480 of file RelAlgExecutor.cpp.

References CHECK, RelAlgNode::getId(), and RelScan::getTableDescriptor().

Referenced by collect_used_input_desc(), get_input_desc_impl(), and synthesize_inputs().

1480  {
1481  const auto scan_ra = dynamic_cast<const RelScan*>(ra_node);
1482  if (scan_ra) {
1483  const auto td = scan_ra->getTableDescriptor();
1484  CHECK(td);
1485  return td->tableId;
1486  }
1487  return -ra_node->getId();
1488 }
unsigned getId() const
Definition: RelAlgDag.h:814
#define CHECK(condition)
Definition: Logger.h:222
const TableDescriptor * getTableDescriptor() const
Definition: RelAlgDag.h:911

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::target_exprs_for_union ( RelAlgNode const *  input_node)

Definition at line 4796 of file RelAlgExecutor.cpp.

References RelAlgNode::getId(), RelAlgNode::getOutputMetainfo(), shared::printContainer(), and VLOG.

Referenced by RelAlgExecutor::createUnionWorkUnit().

4797  {
4798  std::vector<TargetMetaInfo> const& tmis = input_node->getOutputMetainfo();
4799  VLOG(3) << "input_node->getOutputMetainfo()=" << shared::printContainer(tmis);
4800  const int negative_node_id = -input_node->getId();
4801  std::vector<std::shared_ptr<Analyzer::Expr>> target_exprs;
4802  target_exprs.reserve(tmis.size());
4803  for (size_t i = 0; i < tmis.size(); ++i) {
4804  target_exprs.push_back(std::make_shared<Analyzer::ColumnVar>(
4805  tmis[i].get_type_info(), negative_node_id, i, 0));
4806  }
4807  return target_exprs;
4808 }
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:107
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::Expr> anonymous_namespace{RelAlgExecutor.cpp}::transform_to_inner ( const Analyzer::Expr expr)

Definition at line 2391 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::computeWindow().

2391  {
2392  const auto tuple = dynamic_cast<const Analyzer::ExpressionTuple*>(expr);
2393  if (tuple) {
2394  std::vector<std::shared_ptr<Analyzer::Expr>> transformed_tuple;
2395  for (const auto& element : tuple->getTuple()) {
2396  transformed_tuple.push_back(transform_to_inner(element.get()));
2397  }
2398  return makeExpr<Analyzer::ExpressionTuple>(transformed_tuple);
2399  }
2400  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
2401  if (!col) {
2402  throw std::runtime_error("Only columns supported in the window partition for now");
2403  }
2404  return makeExpr<Analyzer::ColumnVar>(
2405  col->get_type_info(), col->get_table_id(), col->get_column_id(), 1);
2406 }
std::shared_ptr< Analyzer::Expr > transform_to_inner(const Analyzer::Expr *expr)

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::translate_groupby_exprs ( const RelCompound compound,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  scalar_sources 
)

Definition at line 1781 of file RelAlgExecutor.cpp.

References RelCompound::getGroupByCount(), RelCompound::isAggregate(), and set_transient_dict().

Referenced by RelAlgExecutor::createAggregateWorkUnit(), and RelAlgExecutor::createCompoundWorkUnit().

1783  {
1784  if (!compound->isAggregate()) {
1785  return {nullptr};
1786  }
1787  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1788  for (size_t group_idx = 0; group_idx < compound->getGroupByCount(); ++group_idx) {
1789  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1790  }
1791  return groupby_exprs;
1792 }
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
const size_t getGroupByCount() const
Definition: RelAlgDag.h:1698
bool isAggregate() const
Definition: RelAlgDag.h:1700

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::translate_groupby_exprs ( const RelAggregate aggregate,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  scalar_sources 
)

Definition at line 1794 of file RelAlgExecutor.cpp.

References RelAggregate::getGroupByCount(), and set_transient_dict().

1796  {
1797  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1798  for (size_t group_idx = 0; group_idx < aggregate->getGroupByCount(); ++group_idx) {
1799  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1800  }
1801  return groupby_exprs;
1802 }
const size_t getGroupByCount() const
Definition: RelAlgDag.h:1195
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)

+ Here is the call graph for this function:

QualsConjunctiveForm anonymous_namespace{RelAlgExecutor.cpp}::translate_quals ( const RelCompound compound,
const RelAlgTranslator translator 
)

Definition at line 1804 of file RelAlgExecutor.cpp.

References fold_expr(), RelCompound::getFilterExpr(), qual_to_conjunctive_form(), and RelAlgTranslator::translateScalarRex().

Referenced by RelAlgExecutor::createCompoundWorkUnit().

1805  {
1806  const auto filter_rex = compound->getFilterExpr();
1807  const auto filter_expr =
1808  filter_rex ? translator.translateScalarRex(filter_rex) : nullptr;
1809  return filter_expr ? qual_to_conjunctive_form(fold_expr(filter_expr.get()))
1811 }
const RexScalar * getFilterExpr() const
Definition: RelAlgDag.h:1673
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class RA >
std::vector<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources ( const RA *  ra_node,
const RelAlgTranslator translator,
const ::ExecutorType  executor_type 
)

Definition at line 1715 of file RelAlgExecutor.cpp.

References cast_dict_to_none(), RelRexToStringConfig::defaults(), fold_expr(), get_scalar_sources_size(), Native, rewrite_array_elements(), rewrite_expr(), scalar_at(), set_transient_dict_maybe(), TableFunctions, RelAlgTranslator::translateScalarRex(), and VLOG.

Referenced by RelAlgExecutor::createCompoundWorkUnit(), RelAlgExecutor::createProjectWorkUnit(), and RelAlgExecutor::createTableFunctionWorkUnit().

1718  {
1719  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1720  const size_t scalar_sources_size = get_scalar_sources_size(ra_node);
1721  VLOG(3) << "get_scalar_sources_size("
1722  << ra_node->toString(RelRexToStringConfig::defaults())
1723  << ") = " << scalar_sources_size;
1724  for (size_t i = 0; i < scalar_sources_size; ++i) {
1725  const auto scalar_rex = scalar_at(i, ra_node);
1726  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1727  // RexRef are synthetic scalars we append at the end of the real ones
1728  // for the sake of taking memory ownership, no real work needed here.
1729  continue;
1730  }
1731 
1732  const auto scalar_expr =
1733  rewrite_array_elements(translator.translateScalarRex(scalar_rex).get());
1734  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1735  if (executor_type == ExecutorType::Native) {
1736  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1737  } else if (executor_type == ExecutorType::TableFunctions) {
1738  scalar_sources.push_back(fold_expr(rewritten_expr.get()));
1739  } else {
1740  scalar_sources.push_back(cast_dict_to_none(fold_expr(rewritten_expr.get())));
1741  }
1742  }
1743 
1744  return scalar_sources;
1745 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t get_scalar_sources_size(const RelCompound *compound)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::Expr > cast_dict_to_none(const std::shared_ptr< Analyzer::Expr > &input)
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:49
const RexScalar * scalar_at(const size_t i, const RelCompound *compound)
#define VLOG(n)
Definition: Logger.h:316
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)
void set_transient_dict_maybe(std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::shared_ptr< Analyzer::Expr > &expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class RA >
std::vector<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources_for_update ( const RA *  ra_node,
const RelAlgTranslator translator,
int32_t  tableId,
const Catalog_Namespace::Catalog cat,
const ColumnNameList colNames,
size_t  starting_projection_column_idx 
)

Definition at line 1748 of file RelAlgExecutor.cpp.

References cat(), get_scalar_sources_size(), rewrite_array_elements(), rewrite_expr(), scalar_at(), set_transient_dict_maybe(), and RelAlgTranslator::translateScalarRex().

1754  {
1755  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1756  for (size_t i = 0; i < get_scalar_sources_size(ra_node); ++i) {
1757  const auto scalar_rex = scalar_at(i, ra_node);
1758  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1759  // RexRef are synthetic scalars we append at the end of the real ones
1760  // for the sake of taking memory ownership, no real work needed here.
1761  continue;
1762  }
1763 
1764  std::shared_ptr<Analyzer::Expr> translated_expr;
1765  if (i >= starting_projection_column_idx && i < get_scalar_sources_size(ra_node) - 1) {
1766  translated_expr = cast_to_column_type(translator.translateScalarRex(scalar_rex),
1767  tableId,
1768  cat,
1769  colNames[i - starting_projection_column_idx]);
1770  } else {
1771  translated_expr = translator.translateScalarRex(scalar_rex);
1772  }
1773  const auto scalar_expr = rewrite_array_elements(translated_expr.get());
1774  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1775  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1776  }
1777 
1778  return scalar_sources;
1779 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
std::string cat(Ts &&...args)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t get_scalar_sources_size(const RelCompound *compound)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
const RexScalar * scalar_at(const size_t i, const RelCompound *compound)
void set_transient_dict_maybe(std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::shared_ptr< Analyzer::Expr > &expr)

+ Here is the call graph for this function:

std::vector<Analyzer::Expr*> anonymous_namespace{RelAlgExecutor.cpp}::translate_targets ( std::vector< std::shared_ptr< Analyzer::Expr >> &  target_exprs_owned,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  scalar_sources,
const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby_exprs,
const RelCompound compound,
const RelAlgTranslator translator,
const ExecutorType  executor_type 
)

Definition at line 1830 of file RelAlgExecutor.cpp.

References cast_dict_to_none(), CHECK, CHECK_GE, CHECK_LE, anonymous_namespace{RelAlgExecutor.cpp}::anonymous_namespace{RelAlgExecutor.cpp}::conditionally_change_arg_to_int_type(), fold_expr(), RexRef::getIndex(), RelCompound::getTargetExpr(), Analyzer::Var::kGROUPBY, Native, rewrite_expr(), set_transient_dict(), RelCompound::size(), RelAlgTranslator::translateAggregateRex(), RelAlgTranslator::translateScalarRex(), and var_ref().

Referenced by RelAlgExecutor::createAggregateWorkUnit(), and RelAlgExecutor::createCompoundWorkUnit().

1836  {
1837  std::vector<Analyzer::Expr*> target_exprs;
1838  for (size_t i = 0; i < compound->size(); ++i) {
1839  const auto target_rex = compound->getTargetExpr(i);
1840  const auto target_rex_agg = dynamic_cast<const RexAgg*>(target_rex);
1841  std::shared_ptr<Analyzer::Expr> target_expr;
1842  if (target_rex_agg) {
1843  target_expr =
1844  RelAlgTranslator::translateAggregateRex(target_rex_agg, scalar_sources);
1846  } else {
1847  const auto target_rex_scalar = dynamic_cast<const RexScalar*>(target_rex);
1848  const auto target_rex_ref = dynamic_cast<const RexRef*>(target_rex_scalar);
1849  if (target_rex_ref) {
1850  const auto ref_idx = target_rex_ref->getIndex();
1851  CHECK_GE(ref_idx, size_t(1));
1852  CHECK_LE(ref_idx, groupby_exprs.size());
1853  const auto groupby_expr = *std::next(groupby_exprs.begin(), ref_idx - 1);
1854  target_expr = var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, ref_idx);
1855  } else {
1856  target_expr = translator.translateScalarRex(target_rex_scalar);
1857  auto rewritten_expr = rewrite_expr(target_expr.get());
1858  target_expr = fold_expr(rewritten_expr.get());
1859  if (executor_type == ExecutorType::Native) {
1860  try {
1861  target_expr = set_transient_dict(target_expr);
1862  } catch (...) {
1863  // noop
1864  }
1865  } else {
1866  target_expr = cast_dict_to_none(target_expr);
1867  }
1868  }
1869  }
1870  CHECK(target_expr);
1871  target_exprs_owned.push_back(target_expr);
1872  target_exprs.push_back(target_expr.get());
1873  }
1874  return target_exprs;
1875 }
const Rex * getTargetExpr(const size_t i) const
Definition: RelAlgDag.h:1679
size_t getIndex() const
Definition: RelAlgDag.h:693
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t size() const override
Definition: RelAlgDag.h:1671
void conditionally_change_arg_to_int_type(std::shared_ptr< Analyzer::Expr > &target_expr)
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2700
#define CHECK_GE(x, y)
Definition: Logger.h:235
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::Expr > cast_dict_to_none(const std::shared_ptr< Analyzer::Expr > &input)
#define CHECK_LE(x, y)
Definition: Logger.h:233
#define CHECK(condition)
Definition: Logger.h:222
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)
static std::shared_ptr< Analyzer::Expr > translateAggregateRex(const RexAgg *rex, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<Analyzer::Expr*> anonymous_namespace{RelAlgExecutor.cpp}::translate_targets ( std::vector< std::shared_ptr< Analyzer::Expr >> &  target_exprs_owned,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  scalar_sources,
const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby_exprs,
const RelAggregate aggregate,
const RelAlgTranslator translator 
)

Definition at line 1877 of file RelAlgExecutor.cpp.

References CHECK, fold_expr(), RelAggregate::getAggExprs(), Analyzer::Var::kGROUPBY, RelAlgTranslator::translateAggregateRex(), and var_ref().

1882  {
1883  std::vector<Analyzer::Expr*> target_exprs;
1884  size_t group_key_idx = 1;
1885  for (const auto& groupby_expr : groupby_exprs) {
1886  auto target_expr =
1887  var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, group_key_idx++);
1888  target_exprs_owned.push_back(target_expr);
1889  target_exprs.push_back(target_expr.get());
1890  }
1891 
1892  for (const auto& target_rex_agg : aggregate->getAggExprs()) {
1893  auto target_expr =
1894  RelAlgTranslator::translateAggregateRex(target_rex_agg.get(), scalar_sources);
1895  CHECK(target_expr);
1896  target_expr = fold_expr(target_expr.get());
1897  target_exprs_owned.push_back(target_expr);
1898  target_exprs.push_back(target_expr.get());
1899  }
1900  return target_exprs;
1901 }
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2700
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
Definition: RelAlgDag.h:1218
#define CHECK(condition)
Definition: Logger.h:222
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)
static std::shared_ptr< Analyzer::Expr > translateAggregateRex(const RexAgg *rex, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)

+ Here is the call graph for this function: