OmniSciDB  c0231cc57d
 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 4478 of file RelAlgExecutor.cpp.

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

Referenced by reverse_logical_distribution().

4480  {
4481  CHECK(!factors.empty());
4482  auto acc = factors.front();
4483  for (size_t i = 1; i < factors.size(); ++i) {
4484  acc = Parser::OperExpr::normalize(sql_op, kONE, acc, factors[i]);
4485  }
4486  return acc;
4487 }
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr, const Executor *executor=nullptr)
Definition: ParserNode.cpp:370
Definition: sqldefs.h:70
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 216 of file RelAlgExecutor.cpp.

References CHECK_EQ, and RenderInfo::targets.

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

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

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

Referenced by RelAlgExecutor::executeWorkUnit().

3441  {
3442  if (!is_projection(ra_exe_unit)) {
3443  return false;
3444  }
3445  if (render_info && render_info->isInSitu()) {
3446  return false;
3447  }
3448  if (!ra_exe_unit.sort_info.order_entries.empty()) {
3449  // disable output columnar when we have top-sort node query
3450  return false;
3451  }
3452  for (const auto& target_expr : ra_exe_unit.target_exprs) {
3453  // We don't currently support varlen columnar projections, so
3454  // return false if we find one
3455  if (target_expr->get_type_info().is_varlen()) {
3456  return false;
3457  }
3458  }
3459  if (auto top_project = dynamic_cast<const RelProject*>(body)) {
3460  if (top_project->isRowwiseOutputForced()) {
3461  return false;
3462  }
3463  }
3464  return true;
3465 }
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 3565 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().

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

+ Here is the caller graph for this function:

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

Definition at line 1705 of file RelAlgExecutor.cpp.

References kENCODING_DICT, and kTEXT.

Referenced by translate_scalar_sources(), and translate_targets().

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

+ Here is the caller graph for this function:

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

Definition at line 421 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 786 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1558 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc_impl().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

Definition at line 3478 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

3478  {
3479  for (const auto target_expr : ra_exe_unit.target_exprs) {
3480  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
3481  return false;
3482  }
3483  }
3484  if (ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front() &&
3485  (!ra_exe_unit.scan_limit || ra_exe_unit.scan_limit > Executor::high_scan_limit)) {
3486  return true;
3487  }
3488  return false;
3489 }
std::vector< Analyzer::Expr * > target_exprs
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
static const size_t high_scan_limit
Definition: Execute.h:602

+ Here is the caller graph for this function:

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

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

3501  {
3502  RelAlgExecutionUnit ra_exe_unit = ra_exe_unit_in;
3503  for (size_t i = 0; i < ra_exe_unit.target_exprs.size(); ++i) {
3504  const auto target_expr = ra_exe_unit.target_exprs[i];
3505  const auto agg_info = get_target_info(target_expr, g_bigint_count);
3506  if (agg_info.agg_kind != kAPPROX_COUNT_DISTINCT) {
3507  continue;
3508  }
3509  CHECK(dynamic_cast<const Analyzer::AggExpr*>(target_expr));
3510  const auto arg = static_cast<Analyzer::AggExpr*>(target_expr)->get_own_arg();
3511  CHECK(arg);
3512  const auto& arg_ti = arg->get_type_info();
3513  // Avoid calling getExpressionRange for variable length types (string and array),
3514  // it'd trigger an assertion since that API expects to be called only for types
3515  // for which the notion of range is well-defined. A bit of a kludge, but the
3516  // logic to reject these types anyway is at lower levels in the stack and not
3517  // really worth pulling into a separate function for now.
3518  if (!(arg_ti.is_number() || arg_ti.is_boolean() || arg_ti.is_time() ||
3519  (arg_ti.is_string() && arg_ti.get_compression() == kENCODING_DICT))) {
3520  continue;
3521  }
3522  const auto arg_range = getExpressionRange(arg.get(), table_infos, executor);
3523  if (arg_range.getType() != ExpressionRangeType::Integer) {
3524  continue;
3525  }
3526  // When running distributed, the threshold for using the precise implementation
3527  // must be consistent across all leaves, otherwise we could have a mix of precise
3528  // and approximate bitmaps and we cannot aggregate them.
3529  const auto device_type = g_cluster ? ExecutorDeviceType::GPU : device_type_in;
3530  const auto bitmap_sz_bits = arg_range.getIntMax() - arg_range.getIntMin() + 1;
3531  const auto sub_bitmap_count =
3532  get_count_distinct_sub_bitmap_count(bitmap_sz_bits, ra_exe_unit, device_type);
3533  int64_t approx_bitmap_sz_bits{0};
3534  const auto error_rate = static_cast<Analyzer::AggExpr*>(target_expr)->get_arg1();
3535  if (error_rate) {
3536  CHECK(error_rate->get_type_info().get_type() == kINT);
3537  CHECK_GE(error_rate->get_constval().intval, 1);
3538  approx_bitmap_sz_bits = hll_size_for_rate(error_rate->get_constval().intval);
3539  } else {
3540  approx_bitmap_sz_bits = g_hll_precision_bits;
3541  }
3542  CountDistinctDescriptor approx_count_distinct_desc{CountDistinctImplType::Bitmap,
3543  arg_range.getIntMin(),
3544  approx_bitmap_sz_bits,
3545  true,
3546  device_type,
3547  sub_bitmap_count};
3548  CountDistinctDescriptor precise_count_distinct_desc{CountDistinctImplType::Bitmap,
3549  arg_range.getIntMin(),
3550  bitmap_sz_bits,
3551  false,
3552  device_type,
3553  sub_bitmap_count};
3554  if (approx_count_distinct_desc.bitmapPaddedSizeBytes() >=
3555  precise_count_distinct_desc.bitmapPaddedSizeBytes()) {
3556  auto precise_count_distinct = makeExpr<Analyzer::AggExpr>(
3557  get_agg_type(kCOUNT, arg.get()), kCOUNT, arg, true, nullptr);
3558  target_exprs_owned.push_back(precise_count_distinct);
3559  ra_exe_unit.target_exprs[i] = precise_count_distinct.get();
3560  }
3561  }
3562  return ra_exe_unit;
3563 }
std::vector< Analyzer::Expr * > target_exprs
int hll_size_for_rate(const int err_percent)
Definition: HyperLogLog.h:113
#define CHECK_GE(x, y)
Definition: Logger.h:235
SQLTypeInfo get_agg_type(const SQLAgg agg_kind, const Analyzer::Expr *arg_expr)
int g_hll_precision_bits
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
Definition: TargetInfo.h:97
size_t get_count_distinct_sub_bitmap_count(const size_t bitmap_sz_bits, const RelAlgExecutionUnit &ra_exe_unit, const ExecutorDeviceType device_type)
bool g_bigint_count
ExpressionRange getExpressionRange(const Analyzer::BinOper *expr, const std::vector< InputTableInfo > &query_infos, const Executor *, boost::optional< std::list< std::shared_ptr< Analyzer::Expr >>> simple_quals)
Definition: sqldefs.h:77
#define CHECK(condition)
Definition: Logger.h:222
bool g_cluster
Definition: sqltypes.h:59

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

4292  {
4293  if (g_cluster) {
4294  // Disable table reordering in distributed mode. The aggregator does not have enough
4295  // information to break ties
4296  return {};
4297  }
4298  const auto& cat = *executor->getCatalog();
4299  for (const auto& table_info : query_infos) {
4300  if (table_info.table_id < 0) {
4301  continue;
4302  }
4303  const auto td = cat.getMetadataForTable(table_info.table_id);
4304  CHECK(td);
4305  if (table_is_replicated(td)) {
4306  return {};
4307  }
4308  }
4309  const auto input_permutation =
4310  get_node_input_permutation(left_deep_join_quals, query_infos, executor);
4311  input_to_nest_level = get_input_nest_levels(node, input_permutation);
4312  std::tie(input_descs, input_col_descs, std::ignore) =
4313  get_input_desc(node, input_to_nest_level, input_permutation, cat);
4314  return input_permutation;
4315 }
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 3491 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

3491  {
3492  return !(ra_exe_unit.quals.empty() && ra_exe_unit.join_quals.empty() &&
3493  ra_exe_unit.simple_quals.empty());
3494 }
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 3169 of file RelAlgExecutor.cpp.

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

3169  {
3170  return !order_entries.empty() && order_entries.front().is_desc;
3171 }

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

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

Referenced by get_bitwise_equals_conjunction().

4200  {
4201  const auto condition = dynamic_cast<const RexOperator*>(scalar);
4202  if (!condition || condition->getOperator() != kOR || condition->size() != 2) {
4203  return nullptr;
4204  }
4205  const auto equi_join_condition =
4206  dynamic_cast<const RexOperator*>(condition->getOperand(0));
4207  if (!equi_join_condition || equi_join_condition->getOperator() != kEQ) {
4208  return nullptr;
4209  }
4210  const auto both_are_null_condition =
4211  dynamic_cast<const RexOperator*>(condition->getOperand(1));
4212  if (!both_are_null_condition || both_are_null_condition->getOperator() != kAND ||
4213  both_are_null_condition->size() != 2) {
4214  return nullptr;
4215  }
4216  const auto lhs_is_null =
4217  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(0));
4218  const auto rhs_is_null =
4219  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(1));
4220  if (!lhs_is_null || !rhs_is_null || lhs_is_null->getOperator() != kISNULL ||
4221  rhs_is_null->getOperator() != kISNULL) {
4222  return nullptr;
4223  }
4224  CHECK_EQ(size_t(1), lhs_is_null->size());
4225  CHECK_EQ(size_t(1), rhs_is_null->size());
4226  CHECK_EQ(size_t(2), equi_join_condition->size());
4227  const auto eq_lhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(0));
4228  const auto eq_rhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(1));
4229  const auto is_null_lhs = dynamic_cast<const RexInput*>(lhs_is_null->getOperand(0));
4230  const auto is_null_rhs = dynamic_cast<const RexInput*>(rhs_is_null->getOperand(0));
4231  if (!eq_lhs || !eq_rhs || !is_null_lhs || !is_null_rhs) {
4232  return nullptr;
4233  }
4234  std::vector<std::unique_ptr<const RexScalar>> eq_operands;
4235  if (*eq_lhs == *is_null_lhs && *eq_rhs == *is_null_rhs) {
4236  RexDeepCopyVisitor deep_copy_visitor;
4237  auto lhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(0));
4238  auto rhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(1));
4239  eq_operands.emplace_back(lhs_op_copy.release());
4240  eq_operands.emplace_back(rhs_op_copy.release());
4241  return boost::make_unique<const RexOperator>(
4242  kBW_EQ, eq_operands, equi_join_condition->getType());
4243  }
4244  return nullptr;
4245 }
#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 4247 of file RelAlgExecutor.cpp.

References CHECK_GE, get_bitwise_equals(), and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

4248  {
4249  const auto condition = dynamic_cast<const RexOperator*>(scalar);
4250  if (condition && condition->getOperator() == kAND) {
4251  CHECK_GE(condition->size(), size_t(2));
4252  auto acc = get_bitwise_equals(condition->getOperand(0));
4253  if (!acc) {
4254  return nullptr;
4255  }
4256  for (size_t i = 1; i < condition->size(); ++i) {
4257  std::vector<std::unique_ptr<const RexScalar>> and_operands;
4258  and_operands.emplace_back(std::move(acc));
4259  and_operands.emplace_back(get_bitwise_equals_conjunction(condition->getOperand(i)));
4260  acc =
4261  boost::make_unique<const RexOperator>(kAND, and_operands, condition->getType());
4262  }
4263  return acc;
4264  }
4265  return get_bitwise_equals(scalar);
4266 }
std::unique_ptr< const RexOperator > get_bitwise_equals_conjunction(const RexScalar *scalar)
#define CHECK_GE(x, y)
Definition: Logger.h:235
Definition: sqldefs.h:36
std::unique_ptr< const RexOperator > get_bitwise_equals(const RexScalar *scalar)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1353 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1644 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1590 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1490 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 5139 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createFilterWorkUnit().

5142  {
5143  std::vector<TargetMetaInfo> in_metainfo;
5144  std::vector<std::shared_ptr<Analyzer::Expr>> exprs_owned;
5145  const auto data_sink_node = get_data_sink(filter);
5146  auto input_it = inputs_owned.begin();
5147  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
5148  const auto source = data_sink_node->getInput(nest_level);
5149  const auto scan_source = dynamic_cast<const RelScan*>(source);
5150  if (scan_source) {
5151  CHECK(source->getOutputMetainfo().empty());
5152  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources_owned;
5153  for (size_t i = 0; i < scan_source->size(); ++i, ++input_it) {
5154  scalar_sources_owned.push_back(translator.translate(input_it->get()));
5155  }
5156  const auto source_metadata =
5157  get_targets_meta(scan_source, get_raw_pointers(scalar_sources_owned));
5158  in_metainfo.insert(
5159  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
5160  exprs_owned.insert(
5161  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
5162  } else {
5163  const auto& source_metadata = source->getOutputMetainfo();
5164  input_it += source_metadata.size();
5165  in_metainfo.insert(
5166  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
5167  const auto scalar_sources_owned = synthesize_inputs(
5168  data_sink_node, nest_level, source_metadata, input_to_nest_level);
5169  exprs_owned.insert(
5170  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
5171  }
5172  }
5173  return std::make_pair(in_metainfo, exprs_owned);
5174 }
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 1513 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc_impl().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

4188  {
4189  auto sink = get_data_sink(ra);
4190  if (auto join = dynamic_cast<const RelJoin*>(sink)) {
4191  return join->getJoinType();
4192  }
4193  if (dynamic_cast<const RelLeftDeepInnerJoin*>(sink)) {
4194  return JoinType::INNER;
4195  }
4196 
4197  return JoinType::INVALID;
4198 }
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 4317 of file RelAlgExecutor.cpp.

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

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

4318  {
4319  std::vector<size_t> input_sizes;
4320  for (size_t i = 0; i < left_deep_join->inputCount(); ++i) {
4321  const auto inputs = get_node_output(left_deep_join->getInput(i));
4322  input_sizes.push_back(inputs.size());
4323  }
4324  return input_sizes;
4325 }
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
const size_t inputCount() const
Definition: RelAlgDag.h:824
RANodeOutput get_node_output(const RelAlgNode *ra_node)
Definition: RelAlgDag.cpp:370

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

1928  {
1929  if (is_count_distinct(&expr)) {
1930  return SQLTypeInfo(kBIGINT, false);
1931  } else if (is_agg(&expr)) {
1933  }
1934  return get_logical_type_info(expr.get_type_info());
1935 }
bool is_agg(const Analyzer::Expr *expr)
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1242
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1221
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:1818
size_t collationCount() const
Definition: RelAlgDag.h:1816

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 74 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 4654 of file RelAlgExecutor.cpp.

References shared::transform().

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

4655  {
4656  std::vector<Analyzer::Expr*> output(input.size());
4657  auto const raw_ptr = [](auto& shared_ptr) { return shared_ptr.get(); };
4658  std::transform(input.cbegin(), input.cend(), output.begin(), raw_ptr);
4659  return output;
4660 }
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1658 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSourcesSize().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1662 of file RelAlgExecutor.cpp.

References RelProject::size().

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

+ Here is the call graph for this function:

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

Definition at line 1666 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputsSize().

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

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

Referenced by RelAlgExecutor::createSortInputWorkUnit().

3160  {
3161  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
3162  if (aggregate) {
3163  return 0;
3164  }
3165  const auto compound = dynamic_cast<const RelCompound*>(ra);
3166  return (compound && compound->isAggregate()) ? 0 : limit;
3167 }

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

1940  {
1941  std::vector<TargetMetaInfo> targets_meta;
1942  CHECK_EQ(ra_node->size(), target_exprs.size());
1943  for (size_t i = 0; i < ra_node->size(); ++i) {
1944  CHECK(target_exprs[i]);
1945  // TODO(alex): remove the count distinct type fixup.
1946  targets_meta.emplace_back(ra_node->getFieldName(i),
1947  get_logical_type_for_expr(*target_exprs[i]),
1948  target_exprs[i]->get_type_info());
1949  }
1950  return targets_meta;
1951 }
#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 1954 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 380 of file RelAlgExecutor.cpp.

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

Referenced by check_none_encoded_string_cast_tuple_limit().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1371 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1386 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 1412 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 1424 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 1437 of file RelAlgExecutor.cpp.

References CHECK, and get_data_sink().

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

+ Here is the call graph for this function:

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

Definition at line 1464 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

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

4089  {
4090  // 'designated initializers' don't compile on Windows for std 17
4091  // They require /std:c++20. They been removed for the windows port.
4092  switch (error_code) {
4094  return {"ERR_DIV_BY_ZERO", "Division by zero"};
4096  return {"ERR_OUT_OF_GPU_MEM",
4097 
4098  "Query couldn't keep the entire working set of columns in GPU memory"};
4100  return {"ERR_UNSUPPORTED_SELF_JOIN", "Self joins not supported yet"};
4102  return {"ERR_OUT_OF_CPU_MEM", "Not enough host memory to execute the query"};
4104  return {"ERR_OVERFLOW_OR_UNDERFLOW", "Overflow or underflow"};
4106  return {"ERR_OUT_OF_TIME", "Query execution has exceeded the time limit"};
4108  return {"ERR_INTERRUPTED", "Query execution has been interrupted"};
4110  return {"ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED",
4111  "Columnar conversion not supported for variable length types"};
4113  return {"ERR_TOO_MANY_LITERALS", "Too many literals in the query"};
4115  return {"ERR_STRING_CONST_IN_RESULTSET",
4116 
4117  "NONE ENCODED String types are not supported as input result set."};
4119  return {"ERR_OUT_OF_RENDER_MEM",
4120 
4121  "Insufficient GPU memory for query results in render output buffer "
4122  "sized by render-mem-bytes"};
4124  return {"ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY",
4125  "Streaming-Top-N not supported in Render Query"};
4127  return {"ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES",
4128  "Multiple distinct values encountered"};
4129  case Executor::ERR_GEOS:
4130  return {"ERR_GEOS", "ERR_GEOS"};
4132  return {"ERR_WIDTH_BUCKET_INVALID_ARGUMENT",
4133 
4134  "Arguments of WIDTH_BUCKET function does not satisfy the condition"};
4135  default:
4136  return {nullptr, nullptr};
4137  }
4138 }
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1378
static const int32_t ERR_GEOS
Definition: Execute.h:1384
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1380
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1381
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1382
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1379
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1370
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1374
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1376
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1377
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1373
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1383
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1371
static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT
Definition: Execute.h:1385
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1375

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

References CHECK.

Referenced by RelAlgExecutor::executeWorkUnit().

3423  {
3424  CHECK(!table_infos.empty());
3425  const auto& first_table = table_infos.front();
3426  size_t max_num_groups = first_table.info.getNumTuplesUpperBound();
3427  for (const auto& table_info : table_infos) {
3428  if (table_info.info.getNumTuplesUpperBound() > max_num_groups) {
3429  max_num_groups = table_info.info.getNumTuplesUpperBound();
3430  }
3431  }
3432  return std::max(max_num_groups, size_t(1));
3433 }
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

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

Definition at line 199 of file RelAlgExecutor.cpp.

References EMPTY_HASHED_PLAN_DAG_KEY, and RelAlgNode::getQueryPlanDagHash().

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

2761  {
2762  if (col_cv->get_is_null()) {
2763  *col_data = inline_fixed_encoding_null_val(columnType);
2764  } else {
2765  const int dict_id = columnType.get_comp_param();
2766  const auto col_datum = col_cv->get_constval();
2767  const auto& str = *col_datum.stringval;
2768  const auto dd = catalog.getMetadataForDict(dict_id);
2769  CHECK(dd && dd->stringDict);
2770  int32_t str_id = dd->stringDict->getOrAdd(str);
2771  if (!dd->dictIsTemp) {
2772  const auto checkpoint_ok = dd->stringDict->checkpoint();
2773  if (!checkpoint_ok) {
2774  throw std::runtime_error("Failed to checkpoint dictionary for column " +
2775  columnName);
2776  }
2777  }
2778  const bool invalid = str_id > max_valid_int_value<T>();
2779  if (invalid || str_id == inline_int_null_value<int32_t>()) {
2780  if (invalid) {
2781  LOG(ERROR) << "Could not encode string: " << str
2782  << ", the encoded value doesn't fit in " << sizeof(T) * 8
2783  << " bits. Will store NULL instead.";
2784  }
2785  str_id = inline_fixed_encoding_null_val(columnType);
2786  }
2787  *col_data = str_id;
2788  }
2789  return *col_data;
2790 }
#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:1960
std::string * stringval
Definition: sqltypes.h:240
Datum get_constval() const
Definition: Analyzer.h:343
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:413
#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 2793 of file RelAlgExecutor.cpp.

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

2796  {
2797  return insert_one_dict_str(col_data, cd->columnName, cd->columnType, col_cv, catalog);
2798 }
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 1916 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().

1916  {
1917  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1918  if (agg_expr && agg_expr->get_contains_agg()) {
1919  auto agg_type = agg_expr->get_aggtype();
1920  if (agg_type == SQLAgg::kMIN || agg_type == SQLAgg::kMAX ||
1921  agg_type == SQLAgg::kSUM || agg_type == SQLAgg::kAVG) {
1922  return true;
1923  }
1924  }
1925  return false;
1926 }
Definition: sqldefs.h:74
Definition: sqldefs.h:76
SQLAgg get_aggtype() const
Definition: Analyzer.h:1202
Definition: sqldefs.h:75
Definition: sqldefs.h:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1911 of file RelAlgExecutor.cpp.

References Analyzer::AggExpr::get_is_distinct().

Referenced by get_logical_type_for_expr().

1911  {
1912  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1913  return agg_expr && agg_expr->get_is_distinct();
1914 }
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 3435 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::groupby_exprs.

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

3435  {
3436  return ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front();
3437 }
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 2270 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

2270  {
2271  return std::any_of(ra_exe_unit.target_exprs.begin(),
2272  ra_exe_unit.target_exprs.end(),
2273  [](const Analyzer::Expr* expr) {
2274  return dynamic_cast<const Analyzer::WindowFunction*>(expr);
2275  });
2276 }
std::vector< Analyzer::Expr * > target_exprs

+ Here is the caller graph for this function:

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

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

4268  {
4269  CHECK_GE(left_deep_join->inputCount(), size_t(2));
4270  std::vector<JoinType> join_types(left_deep_join->inputCount() - 1, JoinType::INNER);
4271  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
4272  ++nesting_level) {
4273  if (left_deep_join->getOuterCondition(nesting_level)) {
4274  join_types[nesting_level - 1] = JoinType::LEFT;
4275  }
4276  auto cur_level_join_type = left_deep_join->getJoinType(nesting_level);
4277  if (cur_level_join_type == JoinType::SEMI || cur_level_join_type == JoinType::ANTI) {
4278  join_types[nesting_level - 1] = cur_level_join_type;
4279  }
4280  }
4281  return join_types;
4282 }
const RexScalar * getOuterCondition(const size_t nesting_level) const
#define CHECK_GE(x, y)
Definition: Logger.h:235
const JoinType getJoinType(const size_t nesting_level) const
const size_t inputCount() const
Definition: RelAlgDag.h:824

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4490 of file RelAlgExecutor.cpp.

Referenced by reverse_logical_distribution().

4491  {
4492  for (const auto& qual : haystack) {
4493  if (*qual == *needle) {
4494  return true;
4495  }
4496  }
4497  return false;
4498 }

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 139 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 128 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

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

4504  {
4505  const auto expr_terms = qual_to_disjunctive_form(expr);
4506  CHECK_GE(expr_terms.size(), size_t(1));
4507  const auto& first_term = expr_terms.front();
4508  const auto first_term_factors = qual_to_conjunctive_form(first_term);
4509  std::vector<std::shared_ptr<Analyzer::Expr>> common_factors;
4510  // First, collect the conjunctive components common to all the disjunctive components.
4511  // Don't do it for simple qualifiers, we only care about expensive or join qualifiers.
4512  for (const auto& first_term_factor : first_term_factors.quals) {
4513  bool is_common =
4514  expr_terms.size() > 1; // Only report common factors for disjunction.
4515  for (size_t i = 1; i < expr_terms.size(); ++i) {
4516  const auto crt_term_factors = qual_to_conjunctive_form(expr_terms[i]);
4517  if (!list_contains_expression(crt_term_factors.quals, first_term_factor)) {
4518  is_common = false;
4519  break;
4520  }
4521  }
4522  if (is_common) {
4523  common_factors.push_back(first_term_factor);
4524  }
4525  }
4526  if (common_factors.empty()) {
4527  return expr;
4528  }
4529  // Now that the common expressions are known, collect the remaining expressions.
4530  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_terms;
4531  for (const auto& term : expr_terms) {
4532  const auto term_cf = qual_to_conjunctive_form(term);
4533  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_quals(
4534  term_cf.simple_quals.begin(), term_cf.simple_quals.end());
4535  for (const auto& qual : term_cf.quals) {
4536  if (!list_contains_expression(common_factors, qual)) {
4537  remaining_quals.push_back(qual);
4538  }
4539  }
4540  if (!remaining_quals.empty()) {
4541  remaining_terms.push_back(build_logical_expression(remaining_quals, kAND));
4542  }
4543  }
4544  // Reconstruct the expression with the transformation applied.
4545  const auto common_expr = build_logical_expression(common_factors, kAND);
4546  if (remaining_terms.empty()) {
4547  return common_expr;
4548  }
4549  const auto remaining_expr = build_logical_expression(remaining_terms, kOR);
4550  return Parser::OperExpr::normalize(kAND, kONE, common_expr, remaining_expr);
4551 }
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr, const Executor *executor=nullptr)
Definition: ParserNode.cpp:370
Definition: sqldefs.h:37
#define CHECK_GE(x, y)
Definition: Logger.h:235
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
bool list_contains_expression(const QualsList &haystack, const std::shared_ptr< Analyzer::Expr > &needle)
Definition: sqldefs.h:36
std::shared_ptr< Analyzer::Expr > build_logical_expression(const std::vector< std::shared_ptr< Analyzer::Expr >> &factors, const SQLOps sql_op)
Definition: sqldefs.h:70
std::vector< std::shared_ptr< Analyzer::Expr > > qual_to_disjunctive_form(const std::shared_ptr< Analyzer::Expr > &qual_expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4327 of file RelAlgExecutor.cpp.

References rewrite_expr().

Referenced by RelAlgExecutor::createCompoundWorkUnit().

4328  {
4329  std::list<std::shared_ptr<Analyzer::Expr>> rewritten_quals;
4330  for (const auto& qual : quals) {
4331  const auto rewritten_qual = rewrite_expr(qual.get());
4332  rewritten_quals.push_back(rewritten_qual ? rewritten_qual : qual);
4333  }
4334  return rewritten_quals;
4335 }
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 4463 of file RelAlgExecutor.cpp.

References CHECK, CHECK_GE, and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

4463  {
4464  CHECK(qual_expr);
4465  const auto bin_oper = dynamic_cast<const RexOperator*>(qual_expr);
4466  if (!bin_oper || bin_oper->getOperator() != kAND) {
4467  return {qual_expr};
4468  }
4469  CHECK_GE(bin_oper->size(), size_t(2));
4470  auto lhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(0));
4471  for (size_t i = 1; i < bin_oper->size(); ++i) {
4472  const auto rhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(i));
4473  lhs_cf.insert(lhs_cf.end(), rhs_cf.begin(), rhs_cf.end());
4474  }
4475  return lhs_cf;
4476 }
#define CHECK_GE(x, y)
Definition: Logger.h:235
std::vector< const RexScalar * > rex_to_conjunctive_form(const RexScalar *qual_expr)
Definition: sqldefs.h:36
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

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

Definition at line 1670 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSource().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1674 of file RelAlgExecutor.cpp.

References RelProject::getProjectAt().

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

+ Here is the call graph for this function:

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

Definition at line 1678 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputAt().

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

+ Here is the call graph for this function:

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

Definition at line 86 of file RelAlgExecutor.cpp.

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

Referenced by prepare_foreign_table_for_execution().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1682 of file RelAlgExecutor.cpp.

References kENCODING_DICT, kENCODING_NONE, and TRANSIENT_DICT_ID.

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

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

+ Here is the caller graph for this function:

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

Definition at line 1695 of file RelAlgExecutor.cpp.

References fold_expr(), and set_transient_dict().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 3467 of file RelAlgExecutor.cpp.

References g_columnar_large_projections, g_columnar_large_projections_threshold, and RelAlgExecutionUnit::scan_limit.

Referenced by RelAlgExecutor::executeWorkUnit().

3467  {
3470 }
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 4628 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().

4632  {
4633  CHECK_LE(size_t(1), ra_node->inputCount());
4634  CHECK_GE(size_t(2), ra_node->inputCount());
4635  const auto input = ra_node->getInput(nest_level);
4636  const auto it_rte_idx = input_to_nest_level.find(input);
4637  CHECK(it_rte_idx != input_to_nest_level.end());
4638  const int rte_idx = it_rte_idx->second;
4639  const int table_id = table_id_from_ra(input);
4640  std::vector<std::shared_ptr<Analyzer::Expr>> inputs;
4641  const auto scan_ra = dynamic_cast<const RelScan*>(input);
4642  int input_idx = 0;
4643  for (const auto& input_meta : in_metainfo) {
4644  inputs.push_back(
4645  std::make_shared<Analyzer::ColumnVar>(input_meta.get_type_info(),
4646  table_id,
4647  scan_ra ? input_idx + 1 : input_idx,
4648  rte_idx));
4649  ++input_idx;
4650  }
4651  return inputs;
4652 }
#define CHECK_GE(x, y)
Definition: Logger.h:235
const RelAlgNode * getInput(const size_t idx) const
Definition: RelAlgDag.h:826
#define CHECK_LE(x, y)
Definition: Logger.h:233
int table_id_from_ra(const RelAlgNode *ra_node)
#define CHECK(condition)
Definition: Logger.h:222
const size_t inputCount() const
Definition: RelAlgDag.h:824

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1480 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 4837 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createUnionWorkUnit().

4838  {
4839  std::vector<TargetMetaInfo> const& tmis = input_node->getOutputMetainfo();
4840  VLOG(3) << "input_node->getOutputMetainfo()=" << shared::printContainer(tmis);
4841  const int negative_node_id = -input_node->getId();
4842  std::vector<std::shared_ptr<Analyzer::Expr>> target_exprs;
4843  target_exprs.reserve(tmis.size());
4844  for (size_t i = 0; i < tmis.size(); ++i) {
4845  target_exprs.push_back(std::make_shared<Analyzer::ColumnVar>(
4846  tmis[i].get_type_info(), negative_node_id, i, 0));
4847  }
4848  return target_exprs;
4849 }
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 2421 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::computeWindow().

2421  {
2422  const auto tuple = dynamic_cast<const Analyzer::ExpressionTuple*>(expr);
2423  if (tuple) {
2424  std::vector<std::shared_ptr<Analyzer::Expr>> transformed_tuple;
2425  for (const auto& element : tuple->getTuple()) {
2426  transformed_tuple.push_back(transform_to_inner(element.get()));
2427  }
2428  return makeExpr<Analyzer::ExpressionTuple>(transformed_tuple);
2429  }
2430  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
2431  if (!col) {
2432  throw std::runtime_error("Only columns supported in the window partition for now");
2433  }
2434  return makeExpr<Analyzer::ColumnVar>(
2435  col->get_type_info(), col->get_table_id(), col->get_column_id(), 1);
2436 }
std::shared_ptr< Analyzer::Expr > transform_to_inner(const Analyzer::Expr *expr)

+ Here is the caller graph for this function:

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

Definition at line 1781 of file RelAlgExecutor.cpp.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1794 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 1804 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createCompoundWorkUnit().

1805  {
1806  const auto filter_rex = compound->getFilterExpr();
1807  const auto filter_expr = filter_rex ? translator.translate(filter_rex) : nullptr;
1808  return filter_expr ? qual_to_conjunctive_form(fold_expr(filter_expr.get()))
1810 }
const RexScalar * getFilterExpr() const
Definition: RelAlgDag.h:1715
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 1715 of file RelAlgExecutor.cpp.

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

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

1718  {
1719  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1720  const size_t scalar_sources_size = get_scalar_sources_size(ra_node);
1721  VLOG(3) << "get_scalar_sources_size("
1722  << ra_node->toString(RelRexToStringConfig::defaults())
1723  << ") = " << scalar_sources_size;
1724  for (size_t i = 0; i < scalar_sources_size; ++i) {
1725  const auto scalar_rex = scalar_at(i, ra_node);
1726  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1727  // RexRef are synthetic scalars we append at the end of the real ones
1728  // for the sake of taking memory ownership, no real work needed here.
1729  continue;
1730  }
1731 
1732  const auto scalar_expr =
1733  rewrite_array_elements(translator.translate(scalar_rex).get());
1734  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1735  if (executor_type == ExecutorType::Native) {
1736  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1737  } else if (executor_type == ExecutorType::TableFunctions) {
1738  scalar_sources.push_back(fold_expr(rewritten_expr.get()));
1739  } else {
1740  scalar_sources.push_back(cast_dict_to_none(fold_expr(rewritten_expr.get())));
1741  }
1742  }
1743 
1744  return scalar_sources;
1745 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
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 1748 of file RelAlgExecutor.cpp.

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

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

1842  {
1843  std::vector<Analyzer::Expr*> target_exprs;
1844  for (size_t i = 0; i < compound->size(); ++i) {
1845  const auto target_rex = compound->getTargetExpr(i);
1846  const auto target_rex_agg = dynamic_cast<const RexAgg*>(target_rex);
1847  std::shared_ptr<Analyzer::Expr> target_expr;
1848  if (target_rex_agg) {
1849  target_expr =
1850  RelAlgTranslator::translateAggregateRex(target_rex_agg, scalar_sources);
1851  conditionally_change_arg_to_int_type(i, target_expr, target_exprs_type_infos);
1852  } else {
1853  const auto target_rex_scalar = dynamic_cast<const RexScalar*>(target_rex);
1854  const auto target_rex_ref = dynamic_cast<const RexRef*>(target_rex_scalar);
1855  if (target_rex_ref) {
1856  const auto ref_idx = target_rex_ref->getIndex();
1857  CHECK_GE(ref_idx, size_t(1));
1858  CHECK_LE(ref_idx, groupby_exprs.size());
1859  const auto groupby_expr = *std::next(groupby_exprs.begin(), ref_idx - 1);
1860  target_expr = var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, ref_idx);
1861  } else {
1862  target_expr = translator.translate(target_rex_scalar);
1863  auto rewritten_expr = rewrite_expr(target_expr.get());
1864  target_expr = fold_expr(rewritten_expr.get());
1865  if (executor_type == ExecutorType::Native) {
1866  try {
1867  target_expr = set_transient_dict(target_expr);
1868  } catch (...) {
1869  // noop
1870  }
1871  } else {
1872  target_expr = cast_dict_to_none(target_expr);
1873  }
1874  }
1875  target_exprs_type_infos.emplace(i, target_expr->get_type_info());
1876  }
1877  CHECK(target_expr);
1878  target_exprs_owned.push_back(target_expr);
1879  target_exprs.push_back(target_expr.get());
1880  }
1881  return target_exprs;
1882 }
const Rex * getTargetExpr(const size_t i) const
Definition: RelAlgDag.h:1721
size_t getIndex() const
Definition: RelAlgDag.h:693
size_t size() const override
Definition: RelAlgDag.h:1713
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2826
#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 1884 of file RelAlgExecutor.cpp.

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

1890  {
1891  std::vector<Analyzer::Expr*> target_exprs;
1892  size_t group_key_idx = 1;
1893  for (const auto& groupby_expr : groupby_exprs) {
1894  auto target_expr =
1895  var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, group_key_idx++);
1896  target_exprs_owned.push_back(target_expr);
1897  target_exprs.push_back(target_expr.get());
1898  }
1899 
1900  for (const auto& target_rex_agg : aggregate->getAggExprs()) {
1901  auto target_expr =
1902  RelAlgTranslator::translateAggregateRex(target_rex_agg.get(), scalar_sources);
1903  CHECK(target_expr);
1904  target_expr = fold_expr(target_expr.get());
1905  target_exprs_owned.push_back(target_expr);
1906  target_exprs.push_back(target_expr.get());
1907  }
1908  return target_exprs;
1909 }
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2826
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
Definition: RelAlgDag.h:1260
#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: