OmniSciDB  b28c0d5765
 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, std::unordered_map< size_t, SQLTypeInfo > &target_exprs_type_infos, 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, std::unordered_map< size_t, SQLTypeInfo > &target_exprs_type_infos, 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 4582 of file RelAlgExecutor.cpp.

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

Referenced by reverse_logical_distribution().

4584  {
4585  CHECK(!factors.empty());
4586  auto acc = factors.front();
4587  for (size_t i = 1; i < factors.size(); ++i) {
4588  acc = Parser::OperExpr::normalize(sql_op, kONE, acc, factors[i]);
4589  }
4590  return acc;
4591 }
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:71
#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:37

+ 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 3496 of file RelAlgExecutor.cpp.

References is_projection(), heavyai::InSituFlagsOwnerInterface::isInSitu(), SortInfo::order_entries, RelAlgExecutionUnit::sort_info, and RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

3498  {
3499  if (!is_projection(ra_exe_unit)) {
3500  return false;
3501  }
3502  if (render_info && render_info->isInSitu()) {
3503  return false;
3504  }
3505  if (!ra_exe_unit.sort_info.order_entries.empty()) {
3506  // disable output columnar when we have top-sort node query
3507  return false;
3508  }
3509  for (const auto& target_expr : ra_exe_unit.target_exprs) {
3510  // We don't currently support varlen columnar projections, so
3511  // return false if we find one
3512  if (target_expr->get_type_info().is_varlen()) {
3513  return false;
3514  }
3515  }
3516  if (auto top_project = dynamic_cast<const RelProject*>(body)) {
3517  if (top_project->isRowwiseOutputForced()) {
3518  return false;
3519  }
3520  }
3521  return true;
3522 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< Analyzer::OrderEntry > order_entries
bool is_projection(const RelAlgExecutionUnit &ra_exe_unit)

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

3624  {
3626  !eo.output_columnar_hint && ra_exe_unit.sort_info.order_entries.empty();
3627 }
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 1761 of file RelAlgExecutor.cpp.

References kENCODING_DICT, and kTEXT.

Referenced by translate_scalar_sources(), and translate_targets().

1762  {
1763  const auto& input_ti = input->get_type_info();
1764  if (input_ti.is_string() && input_ti.get_compression() == kENCODING_DICT) {
1765  return input->add_cast(SQLTypeInfo(kTEXT, input_ti.get_notnull()));
1766  }
1767  return input;
1768 }
Definition: sqltypes.h:67

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

439  {
440  if (!g_enable_watchdog) {
441  return;
442  }
443  auto const tuples_upper_bound =
444  std::accumulate(query_infos.cbegin(),
445  query_infos.cend(),
446  size_t(0),
447  [](auto max, auto const& query_info) {
448  return std::max(max, query_info.info.getNumTuples());
449  });
450  if (tuples_upper_bound <= g_watchdog_none_encoded_string_translation_limit) {
451  return;
452  }
453 
454  const auto& text_cast_counts = get_text_cast_counts(ra_exe_unit);
455  const bool has_text_casts =
456  text_cast_counts.text_decoding_casts + text_cast_counts.text_encoding_casts > 0UL;
457 
458  if (!has_text_casts) {
459  return;
460  }
461  std::ostringstream oss;
462  oss << "Query requires one or more casts between none-encoded and dictionary-encoded "
463  << "strings, and the estimated table size (" << tuples_upper_bound << " rows) "
464  << "exceeds the configured watchdog none-encoded string translation limit of "
466  throw std::runtime_error(oss.str());
467 }
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 814 of file RelAlgExecutor.cpp.

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

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

814  {
815  CHECK_EQ(size_t(1), sort->inputCount());
816  const auto source = sort->getInput(0);
817  if (dynamic_cast<const RelSort*>(source)) {
818  throw std::runtime_error("Sort node not supported as input to another sort");
819  }
820 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:892
const size_t inputCount() const
Definition: RelAlgDag.h:890

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

1620  {
1621  VLOG(3) << "ra_node=" << ra_node->toString(RelRexToStringConfig::defaults())
1622  << " input_col_descs_unique.size()=" << input_col_descs_unique.size()
1623  << " source_used_inputs.size()=" << source_used_inputs.size();
1624  for (const auto used_input : source_used_inputs) {
1625  const auto input_ra = used_input->getSourceNode();
1626  const int table_id = table_id_from_ra(input_ra);
1627  const auto col_id = used_input->getIndex();
1628  auto it = input_to_nest_level.find(input_ra);
1629  if (it != input_to_nest_level.end()) {
1630  const int input_desc = it->second;
1631  input_col_descs_unique.insert(std::make_shared<const InputColDescriptor>(
1632  dynamic_cast<const RelScan*>(input_ra)
1633  ? cat.getColumnIdBySpi(table_id, col_id + 1)
1634  : col_id,
1635  table_id,
1636  input_desc));
1637  } else if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1638  throw std::runtime_error("Bushy joins not supported");
1639  }
1640  }
1641 }
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:2068

+ 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 3535 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

3535  {
3536  for (const auto target_expr : ra_exe_unit.target_exprs) {
3537  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
3538  return false;
3539  }
3540  }
3541  if (ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front() &&
3542  (!ra_exe_unit.scan_limit || ra_exe_unit.scan_limit > Executor::high_scan_limit)) {
3543  return true;
3544  }
3545  return false;
3546 }
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:608

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

3558  {
3559  RelAlgExecutionUnit ra_exe_unit = ra_exe_unit_in;
3560  for (size_t i = 0; i < ra_exe_unit.target_exprs.size(); ++i) {
3561  const auto target_expr = ra_exe_unit.target_exprs[i];
3562  const auto agg_info = get_target_info(target_expr, g_bigint_count);
3563  if (agg_info.agg_kind != kAPPROX_COUNT_DISTINCT) {
3564  continue;
3565  }
3566  CHECK(dynamic_cast<const Analyzer::AggExpr*>(target_expr));
3567  const auto arg = static_cast<Analyzer::AggExpr*>(target_expr)->get_own_arg();
3568  CHECK(arg);
3569  const auto& arg_ti = arg->get_type_info();
3570  // Avoid calling getExpressionRange for variable length types (string and array),
3571  // it'd trigger an assertion since that API expects to be called only for types
3572  // for which the notion of range is well-defined. A bit of a kludge, but the
3573  // logic to reject these types anyway is at lower levels in the stack and not
3574  // really worth pulling into a separate function for now.
3575  if (!(arg_ti.is_number() || arg_ti.is_boolean() || arg_ti.is_time() ||
3576  (arg_ti.is_string() && arg_ti.get_compression() == kENCODING_DICT))) {
3577  continue;
3578  }
3579  const auto arg_range = getExpressionRange(arg.get(), table_infos, executor);
3580  if (arg_range.getType() != ExpressionRangeType::Integer) {
3581  continue;
3582  }
3583  // When running distributed, the threshold for using the precise implementation
3584  // must be consistent across all leaves, otherwise we could have a mix of precise
3585  // and approximate bitmaps and we cannot aggregate them.
3586  const auto device_type = g_cluster ? ExecutorDeviceType::GPU : device_type_in;
3587  const auto bitmap_sz_bits = arg_range.getIntMax() - arg_range.getIntMin() + 1;
3588  const auto sub_bitmap_count =
3589  get_count_distinct_sub_bitmap_count(bitmap_sz_bits, ra_exe_unit, device_type);
3590  int64_t approx_bitmap_sz_bits{0};
3591  const auto error_rate = static_cast<Analyzer::AggExpr*>(target_expr)->get_arg1();
3592  if (error_rate) {
3593  CHECK(error_rate->get_type_info().get_type() == kINT);
3594  CHECK_GE(error_rate->get_constval().intval, 1);
3595  approx_bitmap_sz_bits = hll_size_for_rate(error_rate->get_constval().intval);
3596  } else {
3597  approx_bitmap_sz_bits = g_hll_precision_bits;
3598  }
3599  CountDistinctDescriptor approx_count_distinct_desc{CountDistinctImplType::Bitmap,
3600  arg_range.getIntMin(),
3601  approx_bitmap_sz_bits,
3602  true,
3603  device_type,
3604  sub_bitmap_count};
3605  CountDistinctDescriptor precise_count_distinct_desc{CountDistinctImplType::Bitmap,
3606  arg_range.getIntMin(),
3607  bitmap_sz_bits,
3608  false,
3609  device_type,
3610  sub_bitmap_count};
3611  if (approx_count_distinct_desc.bitmapPaddedSizeBytes() >=
3612  precise_count_distinct_desc.bitmapPaddedSizeBytes()) {
3613  auto precise_count_distinct = makeExpr<Analyzer::AggExpr>(
3614  get_agg_type(kCOUNT, arg.get()), kCOUNT, arg, true, nullptr);
3615  target_exprs_owned.push_back(precise_count_distinct);
3616  ra_exe_unit.target_exprs[i] = precise_count_distinct.get();
3617  }
3618  }
3619  return ra_exe_unit;
3620 }
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:88
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:78
#define CHECK(condition)
Definition: Logger.h:222
bool g_cluster
Definition: sqltypes.h:60

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

4396  {
4397  if (g_cluster) {
4398  // Disable table reordering in distributed mode. The aggregator does not have enough
4399  // information to break ties
4400  return {};
4401  }
4402  const auto& cat = *executor->getCatalog();
4403  for (const auto& table_info : query_infos) {
4404  if (table_info.table_id < 0) {
4405  continue;
4406  }
4407  const auto td = cat.getMetadataForTable(table_info.table_id);
4408  CHECK(td);
4409  if (table_is_replicated(td)) {
4410  return {};
4411  }
4412  }
4413  const auto input_permutation =
4414  get_node_input_permutation(left_deep_join_quals, query_infos, executor);
4415  input_to_nest_level = get_input_nest_levels(node, input_permutation);
4416  std::tie(input_descs, input_col_descs, std::ignore) =
4417  get_input_desc(node, input_to_nest_level, input_permutation, cat);
4418  return input_permutation;
4419 }
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 3548 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

3548  {
3549  return !(ra_exe_unit.quals.empty() && ra_exe_unit.join_quals.empty() &&
3550  ra_exe_unit.simple_quals.empty());
3551 }
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 3224 of file RelAlgExecutor.cpp.

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

3224  {
3225  return !order_entries.empty() && order_entries.front().is_desc;
3226 }

+ 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 4304 of file RelAlgExecutor.cpp.

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

Referenced by get_bitwise_equals_conjunction().

4304  {
4305  const auto condition = dynamic_cast<const RexOperator*>(scalar);
4306  if (!condition || condition->getOperator() != kOR || condition->size() != 2) {
4307  return nullptr;
4308  }
4309  const auto equi_join_condition =
4310  dynamic_cast<const RexOperator*>(condition->getOperand(0));
4311  if (!equi_join_condition || equi_join_condition->getOperator() != kEQ) {
4312  return nullptr;
4313  }
4314  const auto both_are_null_condition =
4315  dynamic_cast<const RexOperator*>(condition->getOperand(1));
4316  if (!both_are_null_condition || both_are_null_condition->getOperator() != kAND ||
4317  both_are_null_condition->size() != 2) {
4318  return nullptr;
4319  }
4320  const auto lhs_is_null =
4321  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(0));
4322  const auto rhs_is_null =
4323  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(1));
4324  if (!lhs_is_null || !rhs_is_null || lhs_is_null->getOperator() != kISNULL ||
4325  rhs_is_null->getOperator() != kISNULL) {
4326  return nullptr;
4327  }
4328  CHECK_EQ(size_t(1), lhs_is_null->size());
4329  CHECK_EQ(size_t(1), rhs_is_null->size());
4330  CHECK_EQ(size_t(2), equi_join_condition->size());
4331  const auto eq_lhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(0));
4332  const auto eq_rhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(1));
4333  const auto is_null_lhs = dynamic_cast<const RexInput*>(lhs_is_null->getOperand(0));
4334  const auto is_null_rhs = dynamic_cast<const RexInput*>(rhs_is_null->getOperand(0));
4335  if (!eq_lhs || !eq_rhs || !is_null_lhs || !is_null_rhs) {
4336  return nullptr;
4337  }
4338  std::vector<std::unique_ptr<const RexScalar>> eq_operands;
4339  if (*eq_lhs == *is_null_lhs && *eq_rhs == *is_null_rhs) {
4340  RexDeepCopyVisitor deep_copy_visitor;
4341  auto lhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(0));
4342  auto rhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(1));
4343  eq_operands.emplace_back(lhs_op_copy.release());
4344  eq_operands.emplace_back(rhs_op_copy.release());
4345  return boost::make_unique<const RexOperator>(
4346  kBW_EQ, eq_operands, equi_join_condition->getType());
4347  }
4348  return nullptr;
4349 }
#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 4351 of file RelAlgExecutor.cpp.

References CHECK_GE, get_bitwise_equals(), and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

4352  {
4353  const auto condition = dynamic_cast<const RexOperator*>(scalar);
4354  if (condition && condition->getOperator() == kAND) {
4355  CHECK_GE(condition->size(), size_t(2));
4356  auto acc = get_bitwise_equals(condition->getOperand(0));
4357  if (!acc) {
4358  return nullptr;
4359  }
4360  for (size_t i = 1; i < condition->size(); ++i) {
4361  std::vector<std::unique_ptr<const RexScalar>> and_operands;
4362  and_operands.emplace_back(std::move(acc));
4363  and_operands.emplace_back(get_bitwise_equals_conjunction(condition->getOperand(i)));
4364  acc =
4365  boost::make_unique<const RexOperator>(kAND, and_operands, condition->getType());
4366  }
4367  return acc;
4368  }
4369  return get_bitwise_equals(scalar);
4370 }
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 1409 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().

1409  {
1410  if (auto table_func = dynamic_cast<const RelTableFunction*>(ra_node)) {
1411  return table_func;
1412  }
1413  if (auto join = dynamic_cast<const RelJoin*>(ra_node)) {
1414  CHECK_EQ(size_t(2), join->inputCount());
1415  return join;
1416  }
1417  if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1418  CHECK_EQ(size_t(1), ra_node->inputCount());
1419  }
1420  auto only_src = ra_node->getInput(0);
1421  const bool is_join = dynamic_cast<const RelJoin*>(only_src) ||
1422  dynamic_cast<const RelLeftDeepInnerJoin*>(only_src);
1423  return is_join ? only_src : ra_node;
1424 }
#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:892
const size_t inputCount() const
Definition: RelAlgDag.h:890

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

1703  {
1704  std::unordered_set<const RexInput*> used_inputs;
1705  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1706  std::tie(used_inputs, used_inputs_owned) = get_used_inputs(ra_node, cat);
1707  VLOG(3) << "used_inputs.size() = " << used_inputs.size();
1708  auto input_desc_pair = get_input_desc_impl(
1709  ra_node, used_inputs, input_to_nest_level, input_permutation, cat);
1710  return std::make_tuple(
1711  input_desc_pair.first, input_desc_pair.second, used_inputs_owned);
1712 }
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 1646 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().

1650  {
1651  std::vector<InputDescriptor> input_descs;
1652  const auto data_sink_node = get_data_sink(ra_node);
1653  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1654  const auto input_node_idx =
1655  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1656  auto input_ra = data_sink_node->getInput(input_node_idx);
1657  const int table_id = table_id_from_ra(input_ra);
1658  input_descs.emplace_back(table_id, input_idx);
1659  }
1660  std::unordered_set<std::shared_ptr<const InputColDescriptor>> input_col_descs_unique;
1661  collect_used_input_desc(input_descs,
1662  cat,
1663  input_col_descs_unique, // modified
1664  ra_node,
1665  used_inputs,
1666  input_to_nest_level);
1667  std::unordered_set<const RexInput*> join_source_used_inputs;
1668  std::vector<std::shared_ptr<RexInput>> join_source_used_inputs_owned;
1669  std::tie(join_source_used_inputs, join_source_used_inputs_owned) =
1670  get_join_source_used_inputs(ra_node, cat);
1671  collect_used_input_desc(input_descs,
1672  cat,
1673  input_col_descs_unique, // modified
1674  ra_node,
1675  join_source_used_inputs,
1676  input_to_nest_level);
1677  std::vector<std::shared_ptr<const InputColDescriptor>> input_col_descs(
1678  input_col_descs_unique.begin(), input_col_descs_unique.end());
1679 
1680  std::sort(input_col_descs.begin(),
1681  input_col_descs.end(),
1682  [](std::shared_ptr<const InputColDescriptor> const& lhs,
1683  std::shared_ptr<const InputColDescriptor> const& rhs) {
1684  return std::make_tuple(lhs->getScanDesc().getNestLevel(),
1685  lhs->getColId(),
1686  lhs->getScanDesc().getTableId()) <
1687  std::make_tuple(rhs->getScanDesc().getNestLevel(),
1688  rhs->getColId(),
1689  rhs->getScanDesc().getTableId());
1690  });
1691  return {input_descs,
1692  std::list<std::shared_ptr<const InputColDescriptor>>(input_col_descs.begin(),
1693  input_col_descs.end())};
1694 }
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 1546 of file RelAlgExecutor.cpp.

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

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

1548  {
1549  const auto data_sink_node = get_data_sink(ra_node);
1550  std::unordered_map<const RelAlgNode*, int> input_to_nest_level;
1551  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1552  const auto input_node_idx =
1553  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1554  const auto input_ra = data_sink_node->getInput(input_node_idx);
1555  // Having a non-zero mapped value (input_idx) results in the query being interpretted
1556  // as a JOIN within CodeGenerator::codegenColVar() due to rte_idx being set to the
1557  // mapped value (input_idx) which originates here. This would be incorrect for UNION.
1558  size_t const idx = dynamic_cast<const RelLogicalUnion*>(ra_node) ? 0 : input_idx;
1559  const auto it_ok = input_to_nest_level.emplace(input_ra, idx);
1560  CHECK(it_ok.second);
1561  LOG_IF(DEBUG1, !input_permutation.empty())
1562  << "Assigned input " << input_ra->toString(RelRexToStringConfig::defaults())
1563  << " to nest level " << input_idx;
1564  }
1565  return input_to_nest_level;
1566 }
#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 5242 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createFilterWorkUnit().

5245  {
5246  std::vector<TargetMetaInfo> in_metainfo;
5247  std::vector<std::shared_ptr<Analyzer::Expr>> exprs_owned;
5248  const auto data_sink_node = get_data_sink(filter);
5249  auto input_it = inputs_owned.begin();
5250  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
5251  const auto source = data_sink_node->getInput(nest_level);
5252  const auto scan_source = dynamic_cast<const RelScan*>(source);
5253  if (scan_source) {
5254  CHECK(source->getOutputMetainfo().empty());
5255  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources_owned;
5256  for (size_t i = 0; i < scan_source->size(); ++i, ++input_it) {
5257  scalar_sources_owned.push_back(translator.translate(input_it->get()));
5258  }
5259  const auto source_metadata =
5260  get_targets_meta(scan_source, get_raw_pointers(scalar_sources_owned));
5261  in_metainfo.insert(
5262  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
5263  exprs_owned.insert(
5264  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
5265  } else {
5266  const auto& source_metadata = source->getOutputMetainfo();
5267  input_it += source_metadata.size();
5268  in_metainfo.insert(
5269  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
5270  const auto scalar_sources_owned = synthesize_inputs(
5271  data_sink_node, nest_level, source_metadata, input_to_nest_level);
5272  exprs_owned.insert(
5273  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
5274  }
5275  }
5276  return std::make_pair(in_metainfo, exprs_owned);
5277 }
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 > translate(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 1569 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, and RelAlgNode::toString().

Referenced by get_input_desc_impl().

1570  {
1571  const auto data_sink_node = get_data_sink(ra_node);
1572  if (auto join = dynamic_cast<const RelJoin*>(data_sink_node)) {
1573  CHECK_EQ(join->inputCount(), 2u);
1574  const auto condition = join->getCondition();
1575  RexUsedInputsVisitor visitor(cat);
1576  auto condition_inputs = visitor.visit(condition);
1577  std::vector<std::shared_ptr<RexInput>> condition_inputs_owned(
1578  visitor.get_inputs_owned());
1579  return std::make_pair(condition_inputs, condition_inputs_owned);
1580  }
1581 
1582  if (auto left_deep_join = dynamic_cast<const RelLeftDeepInnerJoin*>(data_sink_node)) {
1583  CHECK_GE(left_deep_join->inputCount(), 2u);
1584  const auto condition = left_deep_join->getInnerCondition();
1585  RexUsedInputsVisitor visitor(cat);
1586  auto result = visitor.visit(condition);
1587  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
1588  ++nesting_level) {
1589  const auto outer_condition = left_deep_join->getOuterCondition(nesting_level);
1590  if (outer_condition) {
1591  const auto outer_result = visitor.visit(outer_condition);
1592  result.insert(outer_result.begin(), outer_result.end());
1593  }
1594  }
1595  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1596  return std::make_pair(result, used_inputs_owned);
1597  }
1598 
1599  if (dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1600  CHECK_GT(ra_node->inputCount(), 1u)
1602  } else if (dynamic_cast<const RelTableFunction*>(ra_node)) {
1603  // no-op
1604  CHECK_GE(ra_node->inputCount(), 0u)
1606  } else {
1607  CHECK_EQ(ra_node->inputCount(), 1u)
1609  }
1610  return std::make_pair(std::unordered_set<const RexInput*>{},
1611  std::vector<std::shared_ptr<RexInput>>{});
1612 }
#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:890
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 4292 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().

4292  {
4293  auto sink = get_data_sink(ra);
4294  if (auto join = dynamic_cast<const RelJoin*>(sink)) {
4295  return join->getJoinType();
4296  }
4297  if (dynamic_cast<const RelLeftDeepInnerJoin*>(sink)) {
4298  return JoinType::INNER;
4299  }
4300 
4301  return JoinType::INVALID;
4302 }
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 4421 of file RelAlgExecutor.cpp.

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

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

4422  {
4423  std::vector<size_t> input_sizes;
4424  for (size_t i = 0; i < left_deep_join->inputCount(); ++i) {
4425  const auto inputs = get_node_output(left_deep_join->getInput(i));
4426  input_sizes.push_back(inputs.size());
4427  }
4428  return input_sizes;
4429 }
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:892
const size_t inputCount() const
Definition: RelAlgDag.h:890
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 1984 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().

1984  {
1985  if (is_count_distinct(&expr)) {
1986  return SQLTypeInfo(kBIGINT, false);
1987  } else if (is_agg(&expr)) {
1989  }
1990  return get_logical_type_info(expr.get_type_info());
1991 }
bool is_agg(const Analyzer::Expr *expr)
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1223
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1202
bool is_count_distinct(const Analyzer::Expr *expr)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82

+ 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:1934
size_t collationCount() const
Definition: RelAlgDag.h:1932

+ 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:2068

+ 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 4758 of file RelAlgExecutor.cpp.

References shared::transform().

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

4759  {
4760  std::vector<Analyzer::Expr*> output(input.size());
4761  auto const raw_ptr = [](auto& shared_ptr) { return shared_ptr.get(); };
4762  std::transform(input.cbegin(), input.cend(), output.begin(), raw_ptr);
4763  return output;
4764 }
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:320

+ 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 1714 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSourcesSize().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1714  {
1715  return compound->getScalarSourcesSize();
1716 }
const size_t getScalarSourcesSize() const
Definition: RelAlgDag.h:1840

+ 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 1718 of file RelAlgExecutor.cpp.

References RelProject::size().

1718  {
1719  return project->size();
1720 }
size_t size() const override
Definition: RelAlgDag.h:1156

+ 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 1722 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputsSize().

1722  {
1723  return table_func->getTableFuncInputsSize();
1724 }
size_t getTableFuncInputsSize() const
Definition: RelAlgDag.h:2259

+ 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 3215 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::createSortInputWorkUnit().

3215  {
3216  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
3217  if (aggregate) {
3218  return 0;
3219  }
3220  const auto compound = dynamic_cast<const RelCompound*>(ra);
3221  return (compound && compound->isAggregate()) ? 0 : limit;
3222 }

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

1996  {
1997  std::vector<TargetMetaInfo> targets_meta;
1998  CHECK_EQ(ra_node->size(), target_exprs.size());
1999  for (size_t i = 0; i < ra_node->size(); ++i) {
2000  CHECK(target_exprs[i]);
2001  // TODO(alex): remove the count distinct type fixup.
2002  targets_meta.emplace_back(ra_node->getFieldName(i),
2003  get_logical_type_for_expr(*target_exprs[i]),
2004  target_exprs[i]->get_type_info());
2005  }
2006  return targets_meta;
2007 }
#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 2010 of file RelAlgExecutor.cpp.

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

2012  {
2013  RelAlgNode const* input0 = filter->getInput(0);
2014  if (auto const* input = dynamic_cast<RelCompound const*>(input0)) {
2015  return get_targets_meta(input, target_exprs);
2016  } else if (auto const* input = dynamic_cast<RelProject const*>(input0)) {
2017  return get_targets_meta(input, target_exprs);
2018  } else if (auto const* input = dynamic_cast<RelLogicalUnion const*>(input0)) {
2019  return get_targets_meta(input, target_exprs);
2020  } else if (auto const* input = dynamic_cast<RelAggregate const*>(input0)) {
2021  return get_targets_meta(input, target_exprs);
2022  } else if (auto const* input = dynamic_cast<RelScan const*>(input0)) {
2023  return get_targets_meta(input, target_exprs);
2024  }
2025  UNREACHABLE() << "Unhandled node type: "
2027  return {};
2028 }
#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:892
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 396 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().

396  {
397  TextEncodingCastCounts cast_counts;
398 
399  auto check_node_for_text_casts = [&cast_counts](
400  const Analyzer::Expr* expr,
401  const bool disregard_casts_to_none_encoding) {
402  if (!expr) {
403  return;
404  }
405  TextEncodingCastCountVisitor visitor(disregard_casts_to_none_encoding);
406  const auto this_node_cast_counts = visitor.visit(expr);
407  cast_counts.text_encoding_casts += this_node_cast_counts.text_encoding_casts;
408  cast_counts.text_decoding_casts += this_node_cast_counts.text_decoding_casts;
409  };
410 
411  for (const auto& qual : ra_exe_unit.quals) {
412  check_node_for_text_casts(qual.get(), false);
413  }
414  for (const auto& simple_qual : ra_exe_unit.simple_quals) {
415  check_node_for_text_casts(simple_qual.get(), false);
416  }
417  for (const auto& groupby_expr : ra_exe_unit.groupby_exprs) {
418  check_node_for_text_casts(groupby_expr.get(), false);
419  }
420  for (const auto& target_expr : ra_exe_unit.target_exprs) {
421  check_node_for_text_casts(target_expr, false);
422  }
423  for (const auto& join_condition : ra_exe_unit.join_quals) {
424  for (const auto& join_qual : join_condition.quals) {
425  // We currently need to not count casts to none-encoded strings for join quals,
426  // as analyzer will generate these but our join framework disregards them.
427  // Some investigation was done on having analyzer issue the correct inter-string
428  // dictionary casts, but this actually causes them to get executed and so the same
429  // work gets done twice.
430  check_node_for_text_casts(join_qual.get(),
431  true /* disregard_casts_to_none_encoding */);
432  }
433  }
434  return cast_counts;
435 }
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 1427 of file RelAlgExecutor.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelCompound::getFilterExpr(), RelCompound::getScalarSource(), and RelCompound::getScalarSourcesSize().

Referenced by get_input_desc().

1427  {
1428  RexUsedInputsVisitor visitor(cat);
1429  const auto filter_expr = compound->getFilterExpr();
1430  std::unordered_set<const RexInput*> used_inputs =
1431  filter_expr ? visitor.visit(filter_expr) : std::unordered_set<const RexInput*>{};
1432  const auto sources_size = compound->getScalarSourcesSize();
1433  for (size_t i = 0; i < sources_size; ++i) {
1434  const auto source_inputs = visitor.visit(compound->getScalarSource(i));
1435  used_inputs.insert(source_inputs.begin(), source_inputs.end());
1436  }
1437  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1438  return std::make_pair(used_inputs, used_inputs_owned);
1439 }
const RexScalar * getFilterExpr() const
Definition: RelAlgDag.h:1826
const size_t getScalarSourcesSize() const
Definition: RelAlgDag.h:1840
const RexScalar * getScalarSource(const size_t i) const
Definition: RelAlgDag.h:1842

+ 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 1442 of file RelAlgExecutor.cpp.

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

1442  {
1443  CHECK_EQ(size_t(1), aggregate->inputCount());
1444  std::unordered_set<const RexInput*> used_inputs;
1445  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1446  const auto source = aggregate->getInput(0);
1447  const auto& in_metainfo = source->getOutputMetainfo();
1448  const auto group_count = aggregate->getGroupByCount();
1449  CHECK_GE(in_metainfo.size(), group_count);
1450  for (size_t i = 0; i < group_count; ++i) {
1451  auto synthesized_used_input = new RexInput(source, i);
1452  used_inputs_owned.emplace_back(synthesized_used_input);
1453  used_inputs.insert(synthesized_used_input);
1454  }
1455  for (const auto& agg_expr : aggregate->getAggExprs()) {
1456  for (size_t i = 0; i < agg_expr->size(); ++i) {
1457  const auto operand_idx = agg_expr->getOperand(i);
1458  CHECK_GE(in_metainfo.size(), static_cast<size_t>(operand_idx));
1459  auto synthesized_used_input = new RexInput(source, operand_idx);
1460  used_inputs_owned.emplace_back(synthesized_used_input);
1461  used_inputs.insert(synthesized_used_input);
1462  }
1463  }
1464  return std::make_pair(used_inputs, used_inputs_owned);
1465 }
const size_t getGroupByCount() const
Definition: RelAlgDag.h:1324
#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:892
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
Definition: RelAlgDag.h:1347
const size_t inputCount() const
Definition: RelAlgDag.h:890
const std::vector< TargetMetaInfo > & getOutputMetainfo() const
Definition: RelAlgDag.h:876

+ 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 1468 of file RelAlgExecutor.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelProject::getProjectAt(), and RelProject::size().

1468  {
1469  RexUsedInputsVisitor visitor(cat);
1470  std::unordered_set<const RexInput*> used_inputs;
1471  for (size_t i = 0; i < project->size(); ++i) {
1472  const auto proj_inputs = visitor.visit(project->getProjectAt(i));
1473  used_inputs.insert(proj_inputs.begin(), proj_inputs.end());
1474  }
1475  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1476  return std::make_pair(used_inputs, used_inputs_owned);
1477 }
size_t size() const override
Definition: RelAlgDag.h:1156
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1186

+ 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 1480 of file RelAlgExecutor.cpp.

References anonymous_namespace{RelAlgExecutor.cpp}::RexUsedInputsVisitor::get_inputs_owned(), RelTableFunction::getTableFuncInputAt(), and RelTableFunction::getTableFuncInputsSize().

1481  {
1482  RexUsedInputsVisitor visitor(cat);
1483  std::unordered_set<const RexInput*> used_inputs;
1484  for (size_t i = 0; i < table_func->getTableFuncInputsSize(); ++i) {
1485  const auto table_func_inputs = visitor.visit(table_func->getTableFuncInputAt(i));
1486  used_inputs.insert(table_func_inputs.begin(), table_func_inputs.end());
1487  }
1488  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1489  return std::make_pair(used_inputs, used_inputs_owned);
1490 }
size_t getTableFuncInputsSize() const
Definition: RelAlgDag.h:2259
const RexScalar * getTableFuncInputAt(const size_t idx) const
Definition: RelAlgDag.h:2265

+ 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 1493 of file RelAlgExecutor.cpp.

References CHECK, and get_data_sink().

1493  {
1494  std::unordered_set<const RexInput*> used_inputs;
1495  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1496  const auto data_sink_node = get_data_sink(filter);
1497  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
1498  const auto source = data_sink_node->getInput(nest_level);
1499  const auto scan_source = dynamic_cast<const RelScan*>(source);
1500  if (scan_source) {
1501  CHECK(source->getOutputMetainfo().empty());
1502  for (size_t i = 0; i < scan_source->size(); ++i) {
1503  auto synthesized_used_input = new RexInput(scan_source, i);
1504  used_inputs_owned.emplace_back(synthesized_used_input);
1505  used_inputs.insert(synthesized_used_input);
1506  }
1507  } else {
1508  const auto& partial_in_metadata = source->getOutputMetainfo();
1509  for (size_t i = 0; i < partial_in_metadata.size(); ++i) {
1510  auto synthesized_used_input = new RexInput(source, i);
1511  used_inputs_owned.emplace_back(synthesized_used_input);
1512  used_inputs.insert(synthesized_used_input);
1513  }
1514  }
1515  }
1516  return std::make_pair(used_inputs, used_inputs_owned);
1517 }
#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 1520 of file RelAlgExecutor.cpp.

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

1520  {
1521  std::unordered_set<const RexInput*> used_inputs(logical_union->inputCount());
1522  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1523  used_inputs_owned.reserve(logical_union->inputCount());
1524  VLOG(3) << "logical_union->inputCount()=" << logical_union->inputCount();
1525  auto const n_inputs = logical_union->inputCount();
1526  for (size_t nest_level = 0; nest_level < n_inputs; ++nest_level) {
1527  auto input = logical_union->getInput(nest_level);
1528  for (size_t i = 0; i < input->size(); ++i) {
1529  used_inputs_owned.emplace_back(std::make_shared<RexInput>(input, i));
1530  used_inputs.insert(used_inputs_owned.back().get());
1531  }
1532  }
1533  return std::make_pair(std::move(used_inputs), std::move(used_inputs_owned));
1534 }
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:892
const size_t inputCount() const
Definition: RelAlgDag.h:890
#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 4193 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().

4193  {
4194  // 'designated initializers' don't compile on Windows for std 17
4195  // They require /std:c++20. They been removed for the windows port.
4196  switch (error_code) {
4198  return {"ERR_DIV_BY_ZERO", "Division by zero"};
4200  return {"ERR_OUT_OF_GPU_MEM",
4201 
4202  "Query couldn't keep the entire working set of columns in GPU memory"};
4204  return {"ERR_UNSUPPORTED_SELF_JOIN", "Self joins not supported yet"};
4206  return {"ERR_OUT_OF_CPU_MEM", "Not enough host memory to execute the query"};
4208  return {"ERR_OVERFLOW_OR_UNDERFLOW", "Overflow or underflow"};
4210  return {"ERR_OUT_OF_TIME", "Query execution has exceeded the time limit"};
4212  return {"ERR_INTERRUPTED", "Query execution has been interrupted"};
4214  return {"ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED",
4215  "Columnar conversion not supported for variable length types"};
4217  return {"ERR_TOO_MANY_LITERALS", "Too many literals in the query"};
4219  return {"ERR_STRING_CONST_IN_RESULTSET",
4220 
4221  "NONE ENCODED String types are not supported as input result set."};
4223  return {"ERR_OUT_OF_RENDER_MEM",
4224 
4225  "Insufficient GPU memory for query results in render output buffer "
4226  "sized by render-mem-bytes"};
4228  return {"ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY",
4229  "Streaming-Top-N not supported in Render Query"};
4231  return {"ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES",
4232  "Multiple distinct values encountered"};
4233  case Executor::ERR_GEOS:
4234  return {"ERR_GEOS", "ERR_GEOS"};
4236  return {"ERR_WIDTH_BUCKET_INVALID_ARGUMENT",
4237 
4238  "Arguments of WIDTH_BUCKET function does not satisfy the condition"};
4239  default:
4240  return {nullptr, nullptr};
4241  }
4242 }
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1439
static const int32_t ERR_GEOS
Definition: Execute.h:1445
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1441
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1442
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1443
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1440
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1431
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1435
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1437
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1438
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1434
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1444
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1432
static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT
Definition: Execute.h:1446
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1436

+ 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 3480 of file RelAlgExecutor.cpp.

References CHECK.

Referenced by RelAlgExecutor::executeWorkUnit().

3480  {
3481  CHECK(!table_infos.empty());
3482  const auto& first_table = table_infos.front();
3483  size_t max_num_groups = first_table.info.getNumTuplesUpperBound();
3484  for (const auto& table_info : table_infos) {
3485  if (table_info.info.getNumTuplesUpperBound() > max_num_groups) {
3486  max_num_groups = table_info.info.getNumTuplesUpperBound();
3487  }
3488  }
3489  return std::max(max_num_groups, size_t(1));
3490 }
#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:874

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

2816  {
2817  if (col_cv->get_is_null()) {
2818  *col_data = inline_fixed_encoding_null_val(columnType);
2819  } else {
2820  const int dict_id = columnType.get_comp_param();
2821  const auto col_datum = col_cv->get_constval();
2822  const auto& str = *col_datum.stringval;
2823  const auto dd = catalog.getMetadataForDict(dict_id);
2824  CHECK(dd && dd->stringDict);
2825  int32_t str_id = dd->stringDict->getOrAdd(str);
2826  if (!dd->dictIsTemp) {
2827  const auto checkpoint_ok = dd->stringDict->checkpoint();
2828  if (!checkpoint_ok) {
2829  throw std::runtime_error("Failed to checkpoint dictionary for column " +
2830  columnName);
2831  }
2832  }
2833  const bool invalid = str_id > max_valid_int_value<T>();
2834  if (invalid || str_id == inline_int_null_value<int32_t>()) {
2835  if (invalid) {
2836  LOG(ERROR) << "Could not encode string: " << str
2837  << ", the encoded value doesn't fit in " << sizeof(T) * 8
2838  << " bits. Will store NULL instead.";
2839  }
2840  str_id = inline_fixed_encoding_null_val(columnType);
2841  }
2842  *col_data = str_id;
2843  }
2844  return *col_data;
2845 }
#define LOG(tag)
Definition: Logger.h:216
bool get_is_null() const
Definition: Analyzer.h:342
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1976
std::string * stringval
Definition: Datum.h:54
Datum get_constval() const
Definition: Analyzer.h:343
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:389
#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 2848 of file RelAlgExecutor.cpp.

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

2851  {
2852  return insert_one_dict_str(col_data, cd->columnName, cd->columnType, col_cv, catalog);
2853 }
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 1972 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().

1972  {
1973  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1974  if (agg_expr && agg_expr->get_contains_agg()) {
1975  auto agg_type = agg_expr->get_aggtype();
1976  if (agg_type == SQLAgg::kMIN || agg_type == SQLAgg::kMAX ||
1977  agg_type == SQLAgg::kSUM || agg_type == SQLAgg::kAVG) {
1978  return true;
1979  }
1980  }
1981  return false;
1982 }
Definition: sqldefs.h:75
Definition: sqldefs.h:77
SQLAgg get_aggtype() const
Definition: Analyzer.h:1202
Definition: sqldefs.h:76
Definition: sqldefs.h:74

+ 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 1967 of file RelAlgExecutor.cpp.

References Analyzer::AggExpr::get_is_distinct().

Referenced by get_logical_type_for_expr().

1967  {
1968  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1969  return agg_expr && agg_expr->get_is_distinct();
1970 }
bool get_is_distinct() const
Definition: Analyzer.h:1205

+ 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 3492 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::groupby_exprs.

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

3492  {
3493  return ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front();
3494 }
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 2326 of file RelAlgExecutor.cpp.

References anonymous_namespace{QueryMemoryDescriptor.cpp}::any_of(), and RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

2326  {
2327  return std::any_of(ra_exe_unit.target_exprs.begin(),
2328  ra_exe_unit.target_exprs.end(),
2329  [](const Analyzer::Expr* expr) {
2330  return dynamic_cast<const Analyzer::WindowFunction*>(expr);
2331  });
2332 }
std::vector< Analyzer::Expr * > target_exprs
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)

+ Here is the call graph for this function:

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

4372  {
4373  CHECK_GE(left_deep_join->inputCount(), size_t(2));
4374  std::vector<JoinType> join_types(left_deep_join->inputCount() - 1, JoinType::INNER);
4375  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
4376  ++nesting_level) {
4377  if (left_deep_join->getOuterCondition(nesting_level)) {
4378  join_types[nesting_level - 1] = JoinType::LEFT;
4379  }
4380  auto cur_level_join_type = left_deep_join->getJoinType(nesting_level);
4381  if (cur_level_join_type == JoinType::SEMI || cur_level_join_type == JoinType::ANTI) {
4382  join_types[nesting_level - 1] = cur_level_join_type;
4383  }
4384  }
4385  return join_types;
4386 }
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:890

+ 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 4594 of file RelAlgExecutor.cpp.

Referenced by reverse_logical_distribution().

4595  {
4596  for (const auto& qual : haystack) {
4597  if (*qual == *needle) {
4598  return true;
4599  }
4600  }
4601  return false;
4602 }

+ 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:492
#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:2068

+ 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:189
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:206
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:2068

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

4608  {
4609  const auto expr_terms = qual_to_disjunctive_form(expr);
4610  CHECK_GE(expr_terms.size(), size_t(1));
4611  const auto& first_term = expr_terms.front();
4612  const auto first_term_factors = qual_to_conjunctive_form(first_term);
4613  std::vector<std::shared_ptr<Analyzer::Expr>> common_factors;
4614  // First, collect the conjunctive components common to all the disjunctive components.
4615  // Don't do it for simple qualifiers, we only care about expensive or join qualifiers.
4616  for (const auto& first_term_factor : first_term_factors.quals) {
4617  bool is_common =
4618  expr_terms.size() > 1; // Only report common factors for disjunction.
4619  for (size_t i = 1; i < expr_terms.size(); ++i) {
4620  const auto crt_term_factors = qual_to_conjunctive_form(expr_terms[i]);
4621  if (!list_contains_expression(crt_term_factors.quals, first_term_factor)) {
4622  is_common = false;
4623  break;
4624  }
4625  }
4626  if (is_common) {
4627  common_factors.push_back(first_term_factor);
4628  }
4629  }
4630  if (common_factors.empty()) {
4631  return expr;
4632  }
4633  // Now that the common expressions are known, collect the remaining expressions.
4634  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_terms;
4635  for (const auto& term : expr_terms) {
4636  const auto term_cf = qual_to_conjunctive_form(term);
4637  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_quals(
4638  term_cf.simple_quals.begin(), term_cf.simple_quals.end());
4639  for (const auto& qual : term_cf.quals) {
4640  if (!list_contains_expression(common_factors, qual)) {
4641  remaining_quals.push_back(qual);
4642  }
4643  }
4644  if (!remaining_quals.empty()) {
4645  remaining_terms.push_back(build_logical_expression(remaining_quals, kAND));
4646  }
4647  }
4648  // Reconstruct the expression with the transformation applied.
4649  const auto common_expr = build_logical_expression(common_factors, kAND);
4650  if (remaining_terms.empty()) {
4651  return common_expr;
4652  }
4653  const auto remaining_expr = build_logical_expression(remaining_terms, kOR);
4654  return Parser::OperExpr::normalize(kAND, kONE, common_expr, remaining_expr);
4655 }
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:71
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 4431 of file RelAlgExecutor.cpp.

References rewrite_expr().

Referenced by RelAlgExecutor::createCompoundWorkUnit().

4432  {
4433  std::list<std::shared_ptr<Analyzer::Expr>> rewritten_quals;
4434  for (const auto& qual : quals) {
4435  const auto rewritten_qual = rewrite_expr(qual.get());
4436  rewritten_quals.push_back(rewritten_qual ? rewritten_qual : qual);
4437  }
4438  return rewritten_quals;
4439 }
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 4567 of file RelAlgExecutor.cpp.

References CHECK, CHECK_GE, and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

4567  {
4568  CHECK(qual_expr);
4569  const auto bin_oper = dynamic_cast<const RexOperator*>(qual_expr);
4570  if (!bin_oper || bin_oper->getOperator() != kAND) {
4571  return {qual_expr};
4572  }
4573  CHECK_GE(bin_oper->size(), size_t(2));
4574  auto lhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(0));
4575  for (size_t i = 1; i < bin_oper->size(); ++i) {
4576  const auto rhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(i));
4577  lhs_cf.insert(lhs_cf.end(), rhs_cf.begin(), rhs_cf.end());
4578  }
4579  return lhs_cf;
4580 }
#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 1726 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSource().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1726  {
1727  return compound->getScalarSource(i);
1728 }
const RexScalar * getScalarSource(const size_t i) const
Definition: RelAlgDag.h:1842

+ 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 1730 of file RelAlgExecutor.cpp.

References RelProject::getProjectAt().

1730  {
1731  return project->getProjectAt(i);
1732 }
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1186

+ 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 1734 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputAt().

1734  {
1735  return table_func->getTableFuncInputAt(i);
1736 }
const RexScalar * getTableFuncInputAt(const size_t idx) const
Definition: RelAlgDag.h:2265

+ 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, true);
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:1899
std::vector< int > ChunkKey
Definition: types.h:36
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:243
PersistentStorageMgr * getPersistentStorageMgr() const
Definition: DataMgr.cpp:634
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:2068

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

1739  {
1740  const auto& ti = expr->get_type_info();
1741  if (!ti.is_string() || ti.get_compression() != kENCODING_NONE) {
1742  return expr;
1743  }
1744  auto transient_dict_ti = ti;
1745  transient_dict_ti.set_compression(kENCODING_DICT);
1746  transient_dict_ti.set_comp_param(TRANSIENT_DICT_ID);
1747  transient_dict_ti.set_fixed_size();
1748  return expr->add_cast(transient_dict_ti);
1749 }
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:310

+ 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 1751 of file RelAlgExecutor.cpp.

References fold_expr(), and set_transient_dict().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1753  {
1754  try {
1755  scalar_sources.push_back(set_transient_dict(fold_expr(expr.get())));
1756  } catch (...) {
1757  scalar_sources.push_back(fold_expr(expr.get()));
1758  }
1759 }
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 3524 of file RelAlgExecutor.cpp.

References g_columnar_large_projections, g_columnar_large_projections_threshold, and RelAlgExecutionUnit::scan_limit.

Referenced by RelAlgExecutor::executeWorkUnit().

3524  {
3527 }
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 4732 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().

4736  {
4737  CHECK_LE(size_t(1), ra_node->inputCount());
4738  CHECK_GE(size_t(2), ra_node->inputCount());
4739  const auto input = ra_node->getInput(nest_level);
4740  const auto it_rte_idx = input_to_nest_level.find(input);
4741  CHECK(it_rte_idx != input_to_nest_level.end());
4742  const int rte_idx = it_rte_idx->second;
4743  const int table_id = table_id_from_ra(input);
4744  std::vector<std::shared_ptr<Analyzer::Expr>> inputs;
4745  const auto scan_ra = dynamic_cast<const RelScan*>(input);
4746  int input_idx = 0;
4747  for (const auto& input_meta : in_metainfo) {
4748  inputs.push_back(
4749  std::make_shared<Analyzer::ColumnVar>(input_meta.get_type_info(),
4750  table_id,
4751  scan_ra ? input_idx + 1 : input_idx,
4752  rte_idx));
4753  ++input_idx;
4754  }
4755  return inputs;
4756 }
#define CHECK_GE(x, y)
Definition: Logger.h:235
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:892
#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:890

+ 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 1536 of file RelAlgExecutor.cpp.

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

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

1536  {
1537  const auto scan_ra = dynamic_cast<const RelScan*>(ra_node);
1538  if (scan_ra) {
1539  const auto td = scan_ra->getTableDescriptor();
1540  CHECK(td);
1541  return td->tableId;
1542  }
1543  return -ra_node->getId();
1544 }
unsigned getId() const
Definition: RelAlgDag.h:880
#define CHECK(condition)
Definition: Logger.h:222
const TableDescriptor * getTableDescriptor() const
Definition: RelAlgDag.h:982

+ 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 4941 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createUnionWorkUnit().

4942  {
4943  std::vector<TargetMetaInfo> const& tmis = input_node->getOutputMetainfo();
4944  VLOG(3) << "input_node->getOutputMetainfo()=" << shared::printContainer(tmis);
4945  const int negative_node_id = -input_node->getId();
4946  std::vector<std::shared_ptr<Analyzer::Expr>> target_exprs;
4947  target_exprs.reserve(tmis.size());
4948  for (size_t i = 0; i < tmis.size(); ++i) {
4949  target_exprs.push_back(std::make_shared<Analyzer::ColumnVar>(
4950  tmis[i].get_type_info(), negative_node_id, i, 0));
4951  }
4952  return target_exprs;
4953 }
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 2477 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::computeWindow().

2477  {
2478  const auto tuple = dynamic_cast<const Analyzer::ExpressionTuple*>(expr);
2479  if (tuple) {
2480  std::vector<std::shared_ptr<Analyzer::Expr>> transformed_tuple;
2481  for (const auto& element : tuple->getTuple()) {
2482  transformed_tuple.push_back(transform_to_inner(element.get()));
2483  }
2484  return makeExpr<Analyzer::ExpressionTuple>(transformed_tuple);
2485  }
2486  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
2487  if (!col) {
2488  throw std::runtime_error("Only columns supported in the window partition for now");
2489  }
2490  return makeExpr<Analyzer::ColumnVar>(
2491  col->get_type_info(), col->get_table_id(), col->get_column_id(), 1);
2492 }
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 1837 of file RelAlgExecutor.cpp.

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

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

1839  {
1840  if (!compound->isAggregate()) {
1841  return {nullptr};
1842  }
1843  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1844  for (size_t group_idx = 0; group_idx < compound->getGroupByCount(); ++group_idx) {
1845  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1846  }
1847  return groupby_exprs;
1848 }
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
const size_t getGroupByCount() const
Definition: RelAlgDag.h:1851
bool isAggregate() const
Definition: RelAlgDag.h:1853

+ 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 1850 of file RelAlgExecutor.cpp.

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

1852  {
1853  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1854  for (size_t group_idx = 0; group_idx < aggregate->getGroupByCount(); ++group_idx) {
1855  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1856  }
1857  return groupby_exprs;
1858 }
const size_t getGroupByCount() const
Definition: RelAlgDag.h:1324
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 1860 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createCompoundWorkUnit().

1861  {
1862  const auto filter_rex = compound->getFilterExpr();
1863  const auto filter_expr = filter_rex ? translator.translate(filter_rex) : nullptr;
1864  return filter_expr ? qual_to_conjunctive_form(fold_expr(filter_expr.get()))
1866 }
const RexScalar * getFilterExpr() const
Definition: RelAlgDag.h:1826
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
std::shared_ptr< Analyzer::Expr > translate(const RexScalar *rex) const
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 1771 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::translate(), and VLOG.

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

1774  {
1775  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1776  const size_t scalar_sources_size = get_scalar_sources_size(ra_node);
1777  VLOG(3) << "get_scalar_sources_size("
1778  << ra_node->toString(RelRexToStringConfig::defaults())
1779  << ") = " << scalar_sources_size;
1780  for (size_t i = 0; i < scalar_sources_size; ++i) {
1781  const auto scalar_rex = scalar_at(i, ra_node);
1782  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1783  // RexRef are synthetic scalars we append at the end of the real ones
1784  // for the sake of taking memory ownership, no real work needed here.
1785  continue;
1786  }
1787 
1788  const auto scalar_expr =
1789  rewrite_array_elements(translator.translate(scalar_rex).get());
1790  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1791  if (executor_type == ExecutorType::Native) {
1792  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1793  } else if (executor_type == ExecutorType::TableFunctions) {
1794  scalar_sources.push_back(fold_expr(rewritten_expr.get()));
1795  } else {
1796  scalar_sources.push_back(cast_dict_to_none(fold_expr(rewritten_expr.get())));
1797  }
1798  }
1799 
1800  return scalar_sources;
1801 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
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)
std::shared_ptr< Analyzer::Expr > translate(const RexScalar *rex) const
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 1804 of file RelAlgExecutor.cpp.

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

1810  {
1811  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1812  for (size_t i = 0; i < get_scalar_sources_size(ra_node); ++i) {
1813  const auto scalar_rex = scalar_at(i, ra_node);
1814  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1815  // RexRef are synthetic scalars we append at the end of the real ones
1816  // for the sake of taking memory ownership, no real work needed here.
1817  continue;
1818  }
1819 
1820  std::shared_ptr<Analyzer::Expr> translated_expr;
1821  if (i >= starting_projection_column_idx && i < get_scalar_sources_size(ra_node) - 1) {
1822  translated_expr = cast_to_column_type(translator.translate(scalar_rex),
1823  tableId,
1824  cat,
1825  colNames[i - starting_projection_column_idx]);
1826  } else {
1827  translated_expr = translator.translate(scalar_rex);
1828  }
1829  const auto scalar_expr = rewrite_array_elements(translated_expr.get());
1830  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1831  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1832  }
1833 
1834  return scalar_sources;
1835 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
std::string cat(Ts &&...args)
size_t get_scalar_sources_size(const RelCompound *compound)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::Expr > translate(const RexScalar *rex) const
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,
std::unordered_map< size_t, SQLTypeInfo > &  target_exprs_type_infos,
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 1891 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::translate(), RelAlgTranslator::translateAggregateRex(), and var_ref().

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

1898  {
1899  std::vector<Analyzer::Expr*> target_exprs;
1900  for (size_t i = 0; i < compound->size(); ++i) {
1901  const auto target_rex = compound->getTargetExpr(i);
1902  const auto target_rex_agg = dynamic_cast<const RexAgg*>(target_rex);
1903  std::shared_ptr<Analyzer::Expr> target_expr;
1904  if (target_rex_agg) {
1905  target_expr =
1906  RelAlgTranslator::translateAggregateRex(target_rex_agg, scalar_sources);
1907  conditionally_change_arg_to_int_type(i, target_expr, target_exprs_type_infos);
1908  } else {
1909  const auto target_rex_scalar = dynamic_cast<const RexScalar*>(target_rex);
1910  const auto target_rex_ref = dynamic_cast<const RexRef*>(target_rex_scalar);
1911  if (target_rex_ref) {
1912  const auto ref_idx = target_rex_ref->getIndex();
1913  CHECK_GE(ref_idx, size_t(1));
1914  CHECK_LE(ref_idx, groupby_exprs.size());
1915  const auto groupby_expr = *std::next(groupby_exprs.begin(), ref_idx - 1);
1916  target_expr = var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, ref_idx);
1917  } else {
1918  target_expr = translator.translate(target_rex_scalar);
1919  auto rewritten_expr = rewrite_expr(target_expr.get());
1920  target_expr = fold_expr(rewritten_expr.get());
1921  if (executor_type == ExecutorType::Native) {
1922  try {
1923  target_expr = set_transient_dict(target_expr);
1924  } catch (...) {
1925  // noop
1926  }
1927  } else {
1928  target_expr = cast_dict_to_none(target_expr);
1929  }
1930  }
1931  target_exprs_type_infos.emplace(i, target_expr->get_type_info());
1932  }
1933  CHECK(target_expr);
1934  target_exprs_owned.push_back(target_expr);
1935  target_exprs.push_back(target_expr.get());
1936  }
1937  return target_exprs;
1938 }
const Rex * getTargetExpr(const size_t i) const
Definition: RelAlgDag.h:1832
size_t getIndex() const
Definition: RelAlgDag.h:752
size_t size() const override
Definition: RelAlgDag.h:1824
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2982
#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)
void conditionally_change_arg_to_int_type(size_t target_expr_idx, std::shared_ptr< Analyzer::Expr > &target_expr, std::unordered_map< size_t, SQLTypeInfo > &target_exprs_type_infos)
std::shared_ptr< Analyzer::Expr > translate(const RexScalar *rex) const
#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,
std::unordered_map< size_t, SQLTypeInfo > &  target_exprs_type_infos,
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 1940 of file RelAlgExecutor.cpp.

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

1946  {
1947  std::vector<Analyzer::Expr*> target_exprs;
1948  size_t group_key_idx = 1;
1949  for (const auto& groupby_expr : groupby_exprs) {
1950  auto target_expr =
1951  var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, group_key_idx++);
1952  target_exprs_owned.push_back(target_expr);
1953  target_exprs.push_back(target_expr.get());
1954  }
1955 
1956  for (const auto& target_rex_agg : aggregate->getAggExprs()) {
1957  auto target_expr =
1958  RelAlgTranslator::translateAggregateRex(target_rex_agg.get(), scalar_sources);
1959  CHECK(target_expr);
1960  target_expr = fold_expr(target_expr.get());
1961  target_exprs_owned.push_back(target_expr);
1962  target_exprs.push_back(target_expr.get());
1963  }
1964  return target_exprs;
1965 }
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2982
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
Definition: RelAlgDag.h:1347
#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: