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

Classes

class  RelLeftDeepTreeIdsCollector
 
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 is_extracted_dag_valid (ExtractedPlanDag &dag)
 
void check_sort_node_source_constraint (const RelSort *sort)
 
const RelAlgNodeget_data_sink (const RelAlgNode *ra_node)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelCompound *compound, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelAggregate *aggregate, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelProject *project, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelTableFunction *table_func, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelFilter *filter, const Catalog_Namespace::Catalog &cat)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_used_inputs (const RelLogicalUnion *logical_union, const Catalog_Namespace::Catalog &)
 
int table_id_from_ra (const RelAlgNode *ra_node)
 
std::unordered_map< const
RelAlgNode *, int > 
get_input_nest_levels (const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
 
std::pair< std::unordered_set
< const RexInput * >
, std::vector< std::shared_ptr
< RexInput > > > 
get_join_source_used_inputs (const RelAlgNode *ra_node, const Catalog_Namespace::Catalog &cat)
 
void collect_used_input_desc (std::vector< InputDescriptor > &input_descs, const Catalog_Namespace::Catalog &cat, std::unordered_set< std::shared_ptr< const InputColDescriptor >> &input_col_descs_unique, const RelAlgNode *ra_node, const std::unordered_set< const RexInput * > &source_used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
 
template<class RA >
std::pair< std::vector
< InputDescriptor >, std::list
< std::shared_ptr< const
InputColDescriptor > > > 
get_input_desc_impl (const RA *ra_node, const std::unordered_set< const RexInput * > &used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< size_t > &input_permutation, const Catalog_Namespace::Catalog &cat)
 
template<class RA >
std::tuple< std::vector
< InputDescriptor >, std::list
< std::shared_ptr< const
InputColDescriptor >
>, std::vector
< std::shared_ptr< RexInput > > > 
get_input_desc (const RA *ra_node, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const std::vector< size_t > &input_permutation, const Catalog_Namespace::Catalog &cat)
 
size_t get_scalar_sources_size (const RelCompound *compound)
 
size_t get_scalar_sources_size (const RelProject *project)
 
size_t get_scalar_sources_size (const RelTableFunction *table_func)
 
const RexScalarscalar_at (const size_t i, const RelCompound *compound)
 
const RexScalarscalar_at (const size_t i, const RelProject *project)
 
const RexScalarscalar_at (const size_t i, const RelTableFunction *table_func)
 
std::shared_ptr< Analyzer::Exprset_transient_dict (const std::shared_ptr< Analyzer::Expr > expr)
 
void set_transient_dict_maybe (std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::shared_ptr< Analyzer::Expr > &expr)
 
std::shared_ptr< Analyzer::Exprcast_dict_to_none (const std::shared_ptr< Analyzer::Expr > &input)
 
template<class RA >
std::vector< std::shared_ptr
< Analyzer::Expr > > 
translate_scalar_sources (const RA *ra_node, const RelAlgTranslator &translator, const ::ExecutorType executor_type)
 
template<class RA >
std::vector< std::shared_ptr
< Analyzer::Expr > > 
translate_scalar_sources_for_update (const RA *ra_node, const RelAlgTranslator &translator, int32_t tableId, const Catalog_Namespace::Catalog &cat, const ColumnNameList &colNames, size_t starting_projection_column_idx)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
translate_groupby_exprs (const RelCompound *compound, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
translate_groupby_exprs (const RelAggregate *aggregate, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
 
QualsConjunctiveForm translate_quals (const RelCompound *compound, const RelAlgTranslator &translator)
 
std::vector< Analyzer::Expr * > translate_targets (std::vector< std::shared_ptr< Analyzer::Expr >> &target_exprs_owned, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const RelCompound *compound, const RelAlgTranslator &translator, const ExecutorType executor_type)
 
std::vector< Analyzer::Expr * > translate_targets (std::vector< std::shared_ptr< Analyzer::Expr >> &target_exprs_owned, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::list< std::shared_ptr< Analyzer::Expr >> &groupby_exprs, const RelAggregate *aggregate, const RelAlgTranslator &translator)
 
bool is_count_distinct (const Analyzer::Expr *expr)
 
bool is_agg (const Analyzer::Expr *expr)
 
SQLTypeInfo get_logical_type_for_expr (const Analyzer::Expr &expr)
 
template<class RA >
std::vector< TargetMetaInfoget_targets_meta (const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
 
template<>
std::vector< TargetMetaInfoget_targets_meta (const RelFilter *filter, const std::vector< Analyzer::Expr * > &target_exprs)
 
bool is_window_execution_unit (const RelAlgExecutionUnit &ra_exe_unit)
 
std::shared_ptr< Analyzer::Exprtransform_to_inner (const Analyzer::Expr *expr)
 
template<class T >
int64_t insert_one_dict_str (T *col_data, const std::string &columnName, const SQLTypeInfo &columnType, const Analyzer::Constant *col_cv, const Catalog_Namespace::Catalog &catalog)
 
template<class T >
int64_t insert_one_dict_str (T *col_data, const ColumnDescriptor *cd, const Analyzer::Constant *col_cv, const Catalog_Namespace::Catalog &catalog)
 
int64_t int_value_from_numbers_ptr (const SQLTypeInfo &type_info, const int8_t *data)
 
const TableDescriptorget_shard_for_key (const TableDescriptor *td, const Catalog_Namespace::Catalog &cat, const Fragmenter_Namespace::InsertData &data)
 
std::list< Analyzer::OrderEntryget_order_entries (const RelSort *sort)
 
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 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)
 
void build_render_targets (RenderInfo &render_info, const std::vector< Analyzer::Expr * > &work_unit_target_exprs, const std::vector< TargetMetaInfo > &targets_meta)
 
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< 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 3818 of file RelAlgExecutor.cpp.

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

Referenced by reverse_logical_distribution().

3820  {
3821  CHECK(!factors.empty());
3822  auto acc = factors.front();
3823  for (size_t i = 1; i < factors.size(); ++i) {
3824  acc = Parser::OperExpr::normalize(sql_op, kONE, acc, factors[i]);
3825  }
3826  return acc;
3827 }
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)
Definition: ParserNode.cpp:291
Definition: sqldefs.h:69
#define CHECK(condition)
Definition: Logger.h:209

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

References CHECK_EQ, i, and RenderInfo::targets.

Referenced by RelAlgExecutor::executeWorkUnit().

2988  {
2989  CHECK_EQ(work_unit_target_exprs.size(), targets_meta.size());
2990  render_info.targets.clear();
2991  for (size_t i = 0; i < targets_meta.size(); ++i) {
2992  render_info.targets.emplace_back(std::make_shared<Analyzer::TargetEntry>(
2993  targets_meta[i].get_resname(),
2994  work_unit_target_exprs[i]->get_shared_ptr(),
2995  false));
2996  }
2997 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::vector< std::shared_ptr< Analyzer::TargetEntry > > targets
Definition: RenderInfo.h:36

+ Here is the caller graph for this function:

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

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

3001  {
3003  !eo.output_columnar_hint && ra_exe_unit.sort_info.order_entries.empty();
3004 }
const std::list< Analyzer::OrderEntry > order_entries
ExecutorDeviceType device_type
bool g_enable_bump_allocator
Definition: Execute.cpp:113

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

References kENCODING_DICT, and kTEXT.

Referenced by translate_scalar_sources(), and translate_targets().

1380  {
1381  const auto& input_ti = input->get_type_info();
1382  if (input_ti.is_string() && input_ti.get_compression() == kENCODING_DICT) {
1383  return input->add_cast(SQLTypeInfo(kTEXT, input_ti.get_notnull()));
1384  }
1385  return input;
1386 }
Definition: sqltypes.h:52

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

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

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

529  {
530  CHECK_EQ(size_t(1), sort->inputCount());
531  const auto source = sort->getInput(0);
532  if (dynamic_cast<const RelSort*>(source)) {
533  throw std::runtime_error("Sort node not supported as input to another sort");
534  }
535 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const RelAlgNode * getInput(const size_t idx) const
const size_t inputCount() const

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

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

Referenced by get_input_desc_impl().

1233  {
1234  VLOG(3) << "ra_node=" << ra_node->toString()
1235  << " input_col_descs_unique.size()=" << input_col_descs_unique.size()
1236  << " source_used_inputs.size()=" << source_used_inputs.size();
1237  for (const auto used_input : source_used_inputs) {
1238  const auto input_ra = used_input->getSourceNode();
1239  const int table_id = table_id_from_ra(input_ra);
1240  const auto col_id = used_input->getIndex();
1241  auto it = input_to_nest_level.find(input_ra);
1242  if (it != input_to_nest_level.end()) {
1243  const int input_desc = it->second;
1244  input_col_descs_unique.insert(std::make_shared<const InputColDescriptor>(
1245  dynamic_cast<const RelScan*>(input_ra)
1246  ? cat.getColumnIdBySpi(table_id, col_id + 1)
1247  : col_id,
1248  table_id,
1249  input_desc));
1250  } else if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1251  throw std::runtime_error("Bushy joins not supported");
1252  }
1253  }
1254 }
int table_id_from_ra(const RelAlgNode *ra_node)
virtual std::string toString() const =0
#define VLOG(n)
Definition: Logger.h:303
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:1618

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

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

Referenced by RelAlgExecutor::executeWorkUnit().

2899  {
2900  for (const auto target_expr : ra_exe_unit.target_exprs) {
2901  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
2902  return false;
2903  }
2904  }
2905  if (ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front() &&
2906  (!ra_exe_unit.scan_limit || ra_exe_unit.scan_limit > Executor::high_scan_limit)) {
2907  return true;
2908  }
2909  return false;
2910 }
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:479

+ 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 2917 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(), i, Integer, kAPPROX_COUNT_DISTINCT, kCOUNT, kENCODING_DICT, kINT, and RelAlgExecutionUnit::target_exprs.

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

2922  {
2923  RelAlgExecutionUnit ra_exe_unit = ra_exe_unit_in;
2924  for (size_t i = 0; i < ra_exe_unit.target_exprs.size(); ++i) {
2925  const auto target_expr = ra_exe_unit.target_exprs[i];
2926  const auto agg_info = get_target_info(target_expr, g_bigint_count);
2927  if (agg_info.agg_kind != kAPPROX_COUNT_DISTINCT) {
2928  continue;
2929  }
2930  CHECK(dynamic_cast<const Analyzer::AggExpr*>(target_expr));
2931  const auto arg = static_cast<Analyzer::AggExpr*>(target_expr)->get_own_arg();
2932  CHECK(arg);
2933  const auto& arg_ti = arg->get_type_info();
2934  // Avoid calling getExpressionRange for variable length types (string and array),
2935  // it'd trigger an assertion since that API expects to be called only for types
2936  // for which the notion of range is well-defined. A bit of a kludge, but the
2937  // logic to reject these types anyway is at lower levels in the stack and not
2938  // really worth pulling into a separate function for now.
2939  if (!(arg_ti.is_number() || arg_ti.is_boolean() || arg_ti.is_time() ||
2940  (arg_ti.is_string() && arg_ti.get_compression() == kENCODING_DICT))) {
2941  continue;
2942  }
2943  const auto arg_range = getExpressionRange(arg.get(), table_infos, executor);
2944  if (arg_range.getType() != ExpressionRangeType::Integer) {
2945  continue;
2946  }
2947  // When running distributed, the threshold for using the precise implementation
2948  // must be consistent across all leaves, otherwise we could have a mix of precise
2949  // and approximate bitmaps and we cannot aggregate them.
2950  const auto device_type = g_cluster ? ExecutorDeviceType::GPU : device_type_in;
2951  const auto bitmap_sz_bits = arg_range.getIntMax() - arg_range.getIntMin() + 1;
2952  const auto sub_bitmap_count =
2953  get_count_distinct_sub_bitmap_count(bitmap_sz_bits, ra_exe_unit, device_type);
2954  int64_t approx_bitmap_sz_bits{0};
2955  const auto error_rate = static_cast<Analyzer::AggExpr*>(target_expr)->get_arg1();
2956  if (error_rate) {
2957  CHECK(error_rate->get_type_info().get_type() == kINT);
2958  CHECK_GE(error_rate->get_constval().intval, 1);
2959  approx_bitmap_sz_bits = hll_size_for_rate(error_rate->get_constval().intval);
2960  } else {
2961  approx_bitmap_sz_bits = g_hll_precision_bits;
2962  }
2963  CountDistinctDescriptor approx_count_distinct_desc{CountDistinctImplType::Bitmap,
2964  arg_range.getIntMin(),
2965  approx_bitmap_sz_bits,
2966  true,
2967  device_type,
2968  sub_bitmap_count};
2969  CountDistinctDescriptor precise_count_distinct_desc{CountDistinctImplType::Bitmap,
2970  arg_range.getIntMin(),
2971  bitmap_sz_bits,
2972  false,
2973  device_type,
2974  sub_bitmap_count};
2975  if (approx_count_distinct_desc.bitmapPaddedSizeBytes() >=
2976  precise_count_distinct_desc.bitmapPaddedSizeBytes()) {
2977  auto precise_count_distinct = makeExpr<Analyzer::AggExpr>(
2978  get_agg_type(kCOUNT, arg.get()), kCOUNT, arg, true, nullptr);
2979  target_exprs_owned.push_back(precise_count_distinct);
2980  ra_exe_unit.target_exprs[i] = precise_count_distinct.get();
2981  }
2982  }
2983  return ra_exe_unit;
2984 }
std::vector< Analyzer::Expr * > target_exprs
int hll_size_for_rate(const int err_percent)
Definition: HyperLogLog.h:115
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:92
#define CHECK_GE(x, y)
Definition: Logger.h:222
SQLTypeInfo get_agg_type(const SQLAgg agg_kind, const Analyzer::Expr *arg_expr)
int g_hll_precision_bits
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:76
#define CHECK(condition)
Definition: Logger.h:209
bool g_cluster
Definition: sqltypes.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

3630  {
3631  if (g_cluster) {
3632  // Disable table reordering in distributed mode. The aggregator does not have enough
3633  // information to break ties
3634  return {};
3635  }
3636  const auto& cat = *executor->getCatalog();
3637  for (const auto& table_info : query_infos) {
3638  if (table_info.table_id < 0) {
3639  continue;
3640  }
3641  const auto td = cat.getMetadataForTable(table_info.table_id);
3642  CHECK(td);
3643  if (table_is_replicated(td)) {
3644  return {};
3645  }
3646  }
3647  const auto input_permutation =
3648  get_node_input_permutation(left_deep_join_quals, query_infos, executor);
3649  input_to_nest_level = get_input_nest_levels(node, input_permutation);
3650  std::tie(input_descs, input_col_descs, std::ignore) =
3651  get_input_desc(node, input_to_nest_level, input_permutation, cat);
3652  return input_permutation;
3653 }
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:209
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 2912 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

2912  {
2913  return !(ra_exe_unit.quals.empty() && ra_exe_unit.join_quals.empty() &&
2914  ra_exe_unit.simple_quals.empty());
2915 }
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 2678 of file RelAlgExecutor.cpp.

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

2678  {
2679  return !order_entries.empty() && order_entries.front().is_desc;
2680 }

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

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

Referenced by get_bitwise_equals_conjunction().

3538  {
3539  const auto condition = dynamic_cast<const RexOperator*>(scalar);
3540  if (!condition || condition->getOperator() != kOR || condition->size() != 2) {
3541  return nullptr;
3542  }
3543  const auto equi_join_condition =
3544  dynamic_cast<const RexOperator*>(condition->getOperand(0));
3545  if (!equi_join_condition || equi_join_condition->getOperator() != kEQ) {
3546  return nullptr;
3547  }
3548  const auto both_are_null_condition =
3549  dynamic_cast<const RexOperator*>(condition->getOperand(1));
3550  if (!both_are_null_condition || both_are_null_condition->getOperator() != kAND ||
3551  both_are_null_condition->size() != 2) {
3552  return nullptr;
3553  }
3554  const auto lhs_is_null =
3555  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(0));
3556  const auto rhs_is_null =
3557  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(1));
3558  if (!lhs_is_null || !rhs_is_null || lhs_is_null->getOperator() != kISNULL ||
3559  rhs_is_null->getOperator() != kISNULL) {
3560  return nullptr;
3561  }
3562  CHECK_EQ(size_t(1), lhs_is_null->size());
3563  CHECK_EQ(size_t(1), rhs_is_null->size());
3564  CHECK_EQ(size_t(2), equi_join_condition->size());
3565  const auto eq_lhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(0));
3566  const auto eq_rhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(1));
3567  const auto is_null_lhs = dynamic_cast<const RexInput*>(lhs_is_null->getOperand(0));
3568  const auto is_null_rhs = dynamic_cast<const RexInput*>(rhs_is_null->getOperand(0));
3569  if (!eq_lhs || !eq_rhs || !is_null_lhs || !is_null_rhs) {
3570  return nullptr;
3571  }
3572  std::vector<std::unique_ptr<const RexScalar>> eq_operands;
3573  if (*eq_lhs == *is_null_lhs && *eq_rhs == *is_null_rhs) {
3574  RexDeepCopyVisitor deep_copy_visitor;
3575  auto lhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(0));
3576  auto rhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(1));
3577  eq_operands.emplace_back(lhs_op_copy.release());
3578  eq_operands.emplace_back(rhs_op_copy.release());
3579  return boost::make_unique<const RexOperator>(
3580  kBW_EQ, eq_operands, equi_join_condition->getType());
3581  }
3582  return nullptr;
3583 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
Definition: sqldefs.h:38
Definition: sqldefs.h:30
virtual T visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
Definition: sqldefs.h:37
Definition: sqldefs.h:31

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

References CHECK_GE, get_bitwise_equals(), i, and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

3586  {
3587  const auto condition = dynamic_cast<const RexOperator*>(scalar);
3588  if (condition && condition->getOperator() == kAND) {
3589  CHECK_GE(condition->size(), size_t(2));
3590  auto acc = get_bitwise_equals(condition->getOperand(0));
3591  if (!acc) {
3592  return nullptr;
3593  }
3594  for (size_t i = 1; i < condition->size(); ++i) {
3595  std::vector<std::unique_ptr<const RexScalar>> and_operands;
3596  and_operands.emplace_back(std::move(acc));
3597  and_operands.emplace_back(get_bitwise_equals_conjunction(condition->getOperand(i)));
3598  acc =
3599  boost::make_unique<const RexOperator>(kAND, and_operands, condition->getType());
3600  }
3601  return acc;
3602  }
3603  return get_bitwise_equals(scalar);
3604 }
std::unique_ptr< const RexOperator > get_bitwise_equals_conjunction(const RexScalar *scalar)
#define CHECK_GE(x, y)
Definition: Logger.h:222
Definition: sqldefs.h:37
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 1026 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().

1026  {
1027  if (auto table_func = dynamic_cast<const RelTableFunction*>(ra_node)) {
1028  return table_func;
1029  }
1030  if (auto join = dynamic_cast<const RelJoin*>(ra_node)) {
1031  CHECK_EQ(size_t(2), join->inputCount());
1032  return join;
1033  }
1034  if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1035  CHECK_EQ(size_t(1), ra_node->inputCount());
1036  }
1037  auto only_src = ra_node->getInput(0);
1038  const bool is_join = dynamic_cast<const RelJoin*>(only_src) ||
1039  dynamic_cast<const RelLeftDeepInnerJoin*>(only_src);
1040  return is_join ? only_src : ra_node;
1041 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::string join(T const &container, std::string const &delim)
const RelAlgNode * getInput(const size_t idx) const
const size_t inputCount() const

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

1321  {
1322  std::unordered_set<const RexInput*> used_inputs;
1323  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1324  std::tie(used_inputs, used_inputs_owned) = get_used_inputs(ra_node, cat);
1325  VLOG(3) << "used_inputs.size() = " << used_inputs.size();
1326  auto input_desc_pair = get_input_desc_impl(
1327  ra_node, used_inputs, input_to_nest_level, input_permutation, cat);
1328  return std::make_tuple(
1329  input_desc_pair.first, input_desc_pair.second, used_inputs_owned);
1330 }
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:303

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

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

Referenced by get_input_desc().

1263  {
1264  std::vector<InputDescriptor> input_descs;
1265  const auto data_sink_node = get_data_sink(ra_node);
1266  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1267  const auto input_node_idx =
1268  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1269  auto input_ra = data_sink_node->getInput(input_node_idx);
1270  const int table_id = table_id_from_ra(input_ra);
1271  input_descs.emplace_back(table_id, input_idx);
1272  }
1273  std::sort(input_descs.begin(),
1274  input_descs.end(),
1275  [](const InputDescriptor& lhs, const InputDescriptor& rhs) {
1276  return lhs.getNestLevel() < rhs.getNestLevel();
1277  });
1278  std::unordered_set<std::shared_ptr<const InputColDescriptor>> input_col_descs_unique;
1279  collect_used_input_desc(input_descs,
1280  cat,
1281  input_col_descs_unique, // modified
1282  ra_node,
1283  used_inputs,
1284  input_to_nest_level);
1285  std::unordered_set<const RexInput*> join_source_used_inputs;
1286  std::vector<std::shared_ptr<RexInput>> join_source_used_inputs_owned;
1287  std::tie(join_source_used_inputs, join_source_used_inputs_owned) =
1288  get_join_source_used_inputs(ra_node, cat);
1289  collect_used_input_desc(input_descs,
1290  cat,
1291  input_col_descs_unique, // modified
1292  ra_node,
1293  join_source_used_inputs,
1294  input_to_nest_level);
1295  std::vector<std::shared_ptr<const InputColDescriptor>> input_col_descs(
1296  input_col_descs_unique.begin(), input_col_descs_unique.end());
1297 
1298  std::sort(input_col_descs.begin(),
1299  input_col_descs.end(),
1300  [](std::shared_ptr<const InputColDescriptor> const& lhs,
1301  std::shared_ptr<const InputColDescriptor> const& rhs) {
1302  return std::make_tuple(lhs->getScanDesc().getNestLevel(),
1303  lhs->getColId(),
1304  lhs->getScanDesc().getTableId()) <
1305  std::make_tuple(rhs->getScanDesc().getNestLevel(),
1306  rhs->getColId(),
1307  rhs->getScanDesc().getTableId());
1308  });
1309  return {input_descs,
1310  std::list<std::shared_ptr<const InputColDescriptor>>(input_col_descs.begin(),
1311  input_col_descs.end())};
1312 }
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)
int getNestLevel() const

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

References CHECK, 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().

1165  {
1166  const auto data_sink_node = get_data_sink(ra_node);
1167  std::unordered_map<const RelAlgNode*, int> input_to_nest_level;
1168  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1169  const auto input_node_idx =
1170  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1171  const auto input_ra = data_sink_node->getInput(input_node_idx);
1172  // Having a non-zero mapped value (input_idx) results in the query being interpretted
1173  // as a JOIN within CodeGenerator::codegenColVar() due to rte_idx being set to the
1174  // mapped value (input_idx) which originates here. This would be incorrect for UNION.
1175  size_t const idx = dynamic_cast<const RelLogicalUnion*>(ra_node) ? 0 : input_idx;
1176  const auto it_ok = input_to_nest_level.emplace(input_ra, idx);
1177  CHECK(it_ok.second);
1178  LOG_IF(INFO, !input_permutation.empty())
1179  << "Assigned input " << input_ra->toString() << " to nest level " << input_idx;
1180  }
1181  return input_to_nest_level;
1182 }
#define LOG_IF(severity, condition)
Definition: Logger.h:299
#define CHECK(condition)
Definition: Logger.h:209
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 4449 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createFilterWorkUnit().

4452  {
4453  std::vector<TargetMetaInfo> in_metainfo;
4454  std::vector<std::shared_ptr<Analyzer::Expr>> exprs_owned;
4455  const auto data_sink_node = get_data_sink(filter);
4456  auto input_it = inputs_owned.begin();
4457  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
4458  const auto source = data_sink_node->getInput(nest_level);
4459  const auto scan_source = dynamic_cast<const RelScan*>(source);
4460  if (scan_source) {
4461  CHECK(source->getOutputMetainfo().empty());
4462  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources_owned;
4463  for (size_t i = 0; i < scan_source->size(); ++i, ++input_it) {
4464  scalar_sources_owned.push_back(translator.translateScalarRex(input_it->get()));
4465  }
4466  const auto source_metadata =
4467  get_targets_meta(scan_source, get_exprs_not_owned(scalar_sources_owned));
4468  in_metainfo.insert(
4469  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
4470  exprs_owned.insert(
4471  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
4472  } else {
4473  const auto& source_metadata = source->getOutputMetainfo();
4474  input_it += source_metadata.size();
4475  in_metainfo.insert(
4476  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
4477  const auto scalar_sources_owned = synthesize_inputs(
4478  data_sink_node, nest_level, source_metadata, input_to_nest_level);
4479  exprs_owned.insert(
4480  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
4481  }
4482  }
4483  return std::make_pair(in_metainfo, exprs_owned);
4484 }
std::vector< std::shared_ptr< Analyzer::Expr > > synthesize_inputs(const RelAlgNode *ra_node, const size_t nest_level, const std::vector< TargetMetaInfo > &in_metainfo, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:249
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
#define CHECK(condition)
Definition: Logger.h:209
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 1185 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc_impl().

1186  {
1187  const auto data_sink_node = get_data_sink(ra_node);
1188  if (auto join = dynamic_cast<const RelJoin*>(data_sink_node)) {
1189  CHECK_EQ(join->inputCount(), 2u);
1190  const auto condition = join->getCondition();
1191  RexUsedInputsVisitor visitor(cat);
1192  auto condition_inputs = visitor.visit(condition);
1193  std::vector<std::shared_ptr<RexInput>> condition_inputs_owned(
1194  visitor.get_inputs_owned());
1195  return std::make_pair(condition_inputs, condition_inputs_owned);
1196  }
1197 
1198  if (auto left_deep_join = dynamic_cast<const RelLeftDeepInnerJoin*>(data_sink_node)) {
1199  CHECK_GE(left_deep_join->inputCount(), 2u);
1200  const auto condition = left_deep_join->getInnerCondition();
1201  RexUsedInputsVisitor visitor(cat);
1202  auto result = visitor.visit(condition);
1203  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
1204  ++nesting_level) {
1205  const auto outer_condition = left_deep_join->getOuterCondition(nesting_level);
1206  if (outer_condition) {
1207  const auto outer_result = visitor.visit(outer_condition);
1208  result.insert(outer_result.begin(), outer_result.end());
1209  }
1210  }
1211  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1212  return std::make_pair(result, used_inputs_owned);
1213  }
1214 
1215  if (dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1216  CHECK_GT(ra_node->inputCount(), 1u) << ra_node->toString();
1217  } else if (dynamic_cast<const RelTableFunction*>(ra_node)) {
1218  // no-op
1219  CHECK_GE(ra_node->inputCount(), 0u) << ra_node->toString();
1220  } else {
1221  CHECK_EQ(ra_node->inputCount(), 1u) << ra_node->toString();
1222  }
1223  return std::make_pair(std::unordered_set<const RexInput*>{},
1224  std::vector<std::shared_ptr<RexInput>>{});
1225 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
std::string join(T const &container, std::string const &delim)
#define CHECK_GE(x, y)
Definition: Logger.h:222
#define CHECK_GT(x, y)
Definition: Logger.h:221
virtual std::string toString() const =0
const size_t inputCount() const
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 3526 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().

3526  {
3527  auto sink = get_data_sink(ra);
3528  if (auto join = dynamic_cast<const RelJoin*>(sink)) {
3529  return join->getJoinType();
3530  }
3531  if (dynamic_cast<const RelLeftDeepInnerJoin*>(sink)) {
3532  return JoinType::INNER;
3533  }
3534 
3535  return JoinType::INVALID;
3536 }
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 3655 of file RelAlgExecutor.cpp.

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

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

3656  {
3657  std::vector<size_t> input_sizes;
3658  for (size_t i = 0; i < left_deep_join->inputCount(); ++i) {
3659  const auto inputs = get_node_output(left_deep_join->getInput(i));
3660  input_sizes.push_back(inputs.size());
3661  }
3662  return input_sizes;
3663 }
const RelAlgNode * getInput(const size_t idx) const
RANodeOutput get_node_output(const RelAlgNode *ra_node)
const size_t inputCount() const

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

1575  {
1576  if (is_count_distinct(&expr)) {
1577  return SQLTypeInfo(kBIGINT, false);
1578  } else if (is_agg(&expr)) {
1580  }
1581  return get_logical_type_info(expr.get_type_info());
1582 }
bool is_agg(const Analyzer::Expr *expr)
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1070
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1049
bool is_count_distinct(const Analyzer::Expr *expr)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77

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

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

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

2658  {
2659  std::list<Analyzer::OrderEntry> result;
2660  for (size_t i = 0; i < sort->collationCount(); ++i) {
2661  const auto sort_field = sort->getCollation(i);
2662  result.emplace_back(sort_field.getField() + 1,
2663  sort_field.getSortDir() == SortDirection::Descending,
2664  sort_field.getNullsPosition() == NullSortedPosition::First);
2665  }
2666  return result;
2667 }
SortField getCollation(const size_t i) const
size_t collationCount() const

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

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

71  {
72  auto phys_inputs = get_physical_inputs(ra);
73  std::unordered_set<PhysicalInput> phys_inputs2;
74  for (auto& phi : phys_inputs) {
75  phys_inputs2.insert(
76  PhysicalInput{cat.getColumnIdBySpi(phi.table_id, phi.col_id), phi.table_id});
77  }
78  return phys_inputs2;
79 }
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:1618

+ Here is the call graph for this function:

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

Definition at line 1332 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSourcesSize().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1332  {
1333  return compound->getScalarSourcesSize();
1334 }
const size_t getScalarSourcesSize() const

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

References RelProject::size().

1336  {
1337  return project->size();
1338 }
size_t size() const override

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

References RelTableFunction::getTableFuncInputsSize().

1340  {
1341  return table_func->getTableFuncInputsSize();
1342 }
size_t getTableFuncInputsSize() const

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

Referenced by RelAlgExecutor::createSortInputWorkUnit().

2669  {
2670  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
2671  if (aggregate) {
2672  return 0;
2673  }
2674  const auto compound = dynamic_cast<const RelCompound*>(ra);
2675  return (compound && compound->isAggregate()) ? 0 : limit;
2676 }

+ Here is the caller graph for this function:

const TableDescriptor* anonymous_namespace{RelAlgExecutor.cpp}::get_shard_for_key ( const TableDescriptor td,
const Catalog_Namespace::Catalog cat,
const Fragmenter_Namespace::InsertData data 
)

Definition at line 2343 of file RelAlgExecutor.cpp.

References CHECK, Fragmenter_Namespace::InsertData::columnIds, Fragmenter_Namespace::InsertData::data, Catalog_Namespace::Catalog::getPhysicalTablesDescriptors(), Catalog_Namespace::Catalog::getShardColumnMetadataForTable(), i, int_value_from_numbers_ptr(), and SHARD_FOR_KEY.

Referenced by RelAlgExecutor::executeSimpleInsert().

2345  {
2346  auto shard_column_md = cat.getShardColumnMetadataForTable(td);
2347  CHECK(shard_column_md);
2348  auto sharded_column_id = shard_column_md->columnId;
2349  const TableDescriptor* shard{nullptr};
2350  for (size_t i = 0; i < data.columnIds.size(); ++i) {
2351  if (data.columnIds[i] == sharded_column_id) {
2352  const auto shard_tables = cat.getPhysicalTablesDescriptors(td);
2353  const auto shard_count = shard_tables.size();
2354  CHECK(data.data[i].numbersPtr);
2355  auto value = int_value_from_numbers_ptr(shard_column_md->columnType,
2356  data.data[i].numbersPtr);
2357  const size_t shard_idx = SHARD_FOR_KEY(value, shard_count);
2358  shard = shard_tables[shard_idx];
2359  break;
2360  }
2361  }
2362  return shard;
2363 }
int64_t int_value_from_numbers_ptr(const SQLTypeInfo &type_info, const int8_t *data)
const ColumnDescriptor * getShardColumnMetadataForTable(const TableDescriptor *td) const
Definition: Catalog.cpp:4086
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logical_table_desc, bool populate_fragmenter=true) const
Definition: Catalog.cpp:4104
std::vector< DataBlockPtr > data
the number of rows being inserted
Definition: Fragmenter.h:64
#define CHECK(condition)
Definition: Logger.h:209
std::vector< int > columnIds
identifies the table into which the data is being inserted
Definition: Fragmenter.h:62
#define SHARD_FOR_KEY(key, num_shards)
Definition: shard_key.h:20

+ Here is the call graph for this function:

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

References CHECK, CHECK_EQ, get_logical_type_for_expr(), and i.

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

1587  {
1588  std::vector<TargetMetaInfo> targets_meta;
1589  CHECK_EQ(ra_node->size(), target_exprs.size());
1590  for (size_t i = 0; i < ra_node->size(); ++i) {
1591  CHECK(target_exprs[i]);
1592  // TODO(alex): remove the count distinct type fixup.
1593  targets_meta.emplace_back(ra_node->getFieldName(i),
1594  get_logical_type_for_expr(*target_exprs[i]),
1595  target_exprs[i]->get_type_info());
1596  }
1597  return targets_meta;
1598 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
SQLTypeInfo get_logical_type_for_expr(const Analyzer::Expr &expr)
#define CHECK(condition)
Definition: Logger.h:209

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

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

1603  {
1604  RelAlgNode const* input0 = filter->getInput(0);
1605  if (auto const* input = dynamic_cast<RelCompound const*>(input0)) {
1606  return get_targets_meta(input, target_exprs);
1607  } else if (auto const* input = dynamic_cast<RelProject const*>(input0)) {
1608  return get_targets_meta(input, target_exprs);
1609  } else if (auto const* input = dynamic_cast<RelLogicalUnion const*>(input0)) {
1610  return get_targets_meta(input, target_exprs);
1611  } else if (auto const* input = dynamic_cast<RelAggregate const*>(input0)) {
1612  return get_targets_meta(input, target_exprs);
1613  } else if (auto const* input = dynamic_cast<RelScan const*>(input0)) {
1614  return get_targets_meta(input, target_exprs);
1615  }
1616  UNREACHABLE() << "Unhandled node type: " << input0->toString();
1617  return {};
1618 }
#define UNREACHABLE()
Definition: Logger.h:253
const RelAlgNode * getInput(const size_t idx) const
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
virtual std::string toString() const =0

+ 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 RelCompound compound,
const Catalog_Namespace::Catalog cat 
)

Definition at line 1044 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc().

1044  {
1045  RexUsedInputsVisitor visitor(cat);
1046  const auto filter_expr = compound->getFilterExpr();
1047  std::unordered_set<const RexInput*> used_inputs =
1048  filter_expr ? visitor.visit(filter_expr) : std::unordered_set<const RexInput*>{};
1049  const auto sources_size = compound->getScalarSourcesSize();
1050  for (size_t i = 0; i < sources_size; ++i) {
1051  const auto source_inputs = visitor.visit(compound->getScalarSource(i));
1052  used_inputs.insert(source_inputs.begin(), source_inputs.end());
1053  }
1054  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1055  return std::make_pair(used_inputs, used_inputs_owned);
1056 }
const RexScalar * getFilterExpr() const
const size_t getScalarSourcesSize() const
const RexScalar * getScalarSource(const size_t i) const

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

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

1059  {
1060  CHECK_EQ(size_t(1), aggregate->inputCount());
1061  std::unordered_set<const RexInput*> used_inputs;
1062  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1063  const auto source = aggregate->getInput(0);
1064  const auto& in_metainfo = source->getOutputMetainfo();
1065  const auto group_count = aggregate->getGroupByCount();
1066  CHECK_GE(in_metainfo.size(), group_count);
1067  for (size_t i = 0; i < group_count; ++i) {
1068  auto synthesized_used_input = new RexInput(source, i);
1069  used_inputs_owned.emplace_back(synthesized_used_input);
1070  used_inputs.insert(synthesized_used_input);
1071  }
1072  for (const auto& agg_expr : aggregate->getAggExprs()) {
1073  for (size_t i = 0; i < agg_expr->size(); ++i) {
1074  const auto operand_idx = agg_expr->getOperand(i);
1075  CHECK_GE(in_metainfo.size(), static_cast<size_t>(operand_idx));
1076  auto synthesized_used_input = new RexInput(source, operand_idx);
1077  used_inputs_owned.emplace_back(synthesized_used_input);
1078  used_inputs.insert(synthesized_used_input);
1079  }
1080  }
1081  return std::make_pair(used_inputs, used_inputs_owned);
1082 }
const size_t getGroupByCount() const
#define CHECK_EQ(x, y)
Definition: Logger.h:217
#define CHECK_GE(x, y)
Definition: Logger.h:222
const RelAlgNode * getInput(const size_t idx) const
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
const size_t inputCount() const
const std::vector< TargetMetaInfo > & getOutputMetainfo() const

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

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

1085  {
1086  RexUsedInputsVisitor visitor(cat);
1087  std::unordered_set<const RexInput*> used_inputs;
1088  for (size_t i = 0; i < project->size(); ++i) {
1089  const auto proj_inputs = visitor.visit(project->getProjectAt(i));
1090  used_inputs.insert(proj_inputs.begin(), proj_inputs.end());
1091  }
1092  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1093  return std::make_pair(used_inputs, used_inputs_owned);
1094 }
size_t size() const override
const RexScalar * getProjectAt(const size_t idx) const

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

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

1098  {
1099  RexUsedInputsVisitor visitor(cat);
1100  std::unordered_set<const RexInput*> used_inputs;
1101  for (size_t i = 0; i < table_func->getTableFuncInputsSize(); ++i) {
1102  const auto table_func_inputs = visitor.visit(table_func->getTableFuncInputAt(i));
1103  used_inputs.insert(table_func_inputs.begin(), table_func_inputs.end());
1104  }
1105  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1106  return std::make_pair(used_inputs, used_inputs_owned);
1107 }
size_t getTableFuncInputsSize() const
const RexScalar * getTableFuncInputAt(const size_t idx) const

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

References CHECK, get_data_sink(), and i.

1110  {
1111  std::unordered_set<const RexInput*> used_inputs;
1112  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1113  const auto data_sink_node = get_data_sink(filter);
1114  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
1115  const auto source = data_sink_node->getInput(nest_level);
1116  const auto scan_source = dynamic_cast<const RelScan*>(source);
1117  if (scan_source) {
1118  CHECK(source->getOutputMetainfo().empty());
1119  for (size_t i = 0; i < scan_source->size(); ++i) {
1120  auto synthesized_used_input = new RexInput(scan_source, i);
1121  used_inputs_owned.emplace_back(synthesized_used_input);
1122  used_inputs.insert(synthesized_used_input);
1123  }
1124  } else {
1125  const auto& partial_in_metadata = source->getOutputMetainfo();
1126  for (size_t i = 0; i < partial_in_metadata.size(); ++i) {
1127  auto synthesized_used_input = new RexInput(source, i);
1128  used_inputs_owned.emplace_back(synthesized_used_input);
1129  used_inputs.insert(synthesized_used_input);
1130  }
1131  }
1132  }
1133  return std::make_pair(used_inputs, used_inputs_owned);
1134 }
#define CHECK(condition)
Definition: Logger.h:209
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 1137 of file RelAlgExecutor.cpp.

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

1137  {
1138  std::unordered_set<const RexInput*> used_inputs(logical_union->inputCount());
1139  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1140  used_inputs_owned.reserve(logical_union->inputCount());
1141  VLOG(3) << "logical_union->inputCount()=" << logical_union->inputCount();
1142  auto const n_inputs = logical_union->inputCount();
1143  for (size_t nest_level = 0; nest_level < n_inputs; ++nest_level) {
1144  auto input = logical_union->getInput(nest_level);
1145  for (size_t i = 0; i < input->size(); ++i) {
1146  used_inputs_owned.emplace_back(std::make_shared<RexInput>(input, i));
1147  used_inputs.insert(used_inputs_owned.back().get());
1148  }
1149  }
1150  return std::make_pair(std::move(used_inputs), std::move(used_inputs_owned));
1151 }
const RelAlgNode * getInput(const size_t idx) const
const size_t inputCount() const
#define VLOG(n)
Definition: Logger.h:303

+ Here is the call graph for this function:

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

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

3428  {
3429  // 'designated initializers' don't compile on Windows for std 17
3430  // They require /std:c++20. They been removed for the windows port.
3431  switch (error_code) {
3433  return {"ERR_DIV_BY_ZERO", "Division by zero"};
3435  return {"ERR_OUT_OF_GPU_MEM",
3436 
3437  "Query couldn't keep the entire working set of columns in GPU memory"};
3439  return {"ERR_UNSUPPORTED_SELF_JOIN", "Self joins not supported yet"};
3441  return {"ERR_OUT_OF_CPU_MEM", "Not enough host memory to execute the query"};
3443  return {"ERR_OVERFLOW_OR_UNDERFLOW", "Overflow or underflow"};
3445  return {"ERR_OUT_OF_TIME", "Query execution has exceeded the time limit"};
3447  return {"ERR_INTERRUPTED", "Query execution has been interrupted"};
3449  return {"ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED",
3450  "Columnar conversion not supported for variable length types"};
3452  return {"ERR_TOO_MANY_LITERALS", "Too many literals in the query"};
3454  return {"ERR_STRING_CONST_IN_RESULTSET",
3455 
3456  "NONE ENCODED String types are not supported as input result set."};
3458  return {"ERR_OUT_OF_RENDER_MEM",
3459 
3460  "Insufficient GPU memory for query results in render output buffer "
3461  "sized by render-mem-bytes"};
3463  return {"ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY",
3464  "Streaming-Top-N not supported in Render Query"};
3466  return {"ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES",
3467  "Multiple distinct values encountered"};
3468  case Executor::ERR_GEOS:
3469  return {"ERR_GEOS", "ERR_GEOS"};
3471  return {"ERR_WIDTH_BUCKET_INVALID_ARGUMENT",
3472 
3473  "Arguments of WIDTH_BUCKET function does not satisfy the condition"};
3474  default:
3475  return {nullptr, nullptr};
3476  }
3477 }
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1163
static const int32_t ERR_GEOS
Definition: Execute.h:1169
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1165
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1166
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1167
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1164
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1155
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1159
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1161
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1162
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1158
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1168
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1156
static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT
Definition: Execute.h:1170
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1160

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

References CHECK.

Referenced by RelAlgExecutor::executeWorkUnit().

2881  {
2882  CHECK(!table_infos.empty());
2883  const auto& first_table = table_infos.front();
2884  size_t max_num_groups = first_table.info.getNumTuplesUpperBound();
2885  for (const auto& table_info : table_infos) {
2886  if (table_info.info.getNumTuplesUpperBound() > max_num_groups) {
2887  max_num_groups = table_info.info.getNumTuplesUpperBound();
2888  }
2889  }
2890  return std::max(max_num_groups, size_t(1));
2891 }
#define CHECK(condition)
Definition: Logger.h:209

+ 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 2241 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 omnisci.dtypes::T.

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

2245  {
2246  if (col_cv->get_is_null()) {
2247  *col_data = inline_fixed_encoding_null_val(columnType);
2248  } else {
2249  const int dict_id = columnType.get_comp_param();
2250  const auto col_datum = col_cv->get_constval();
2251  const auto& str = *col_datum.stringval;
2252  const auto dd = catalog.getMetadataForDict(dict_id);
2253  CHECK(dd && dd->stringDict);
2254  int32_t str_id = dd->stringDict->getOrAdd(str);
2255  if (!dd->dictIsTemp) {
2256  const auto checkpoint_ok = dd->stringDict->checkpoint();
2257  if (!checkpoint_ok) {
2258  throw std::runtime_error("Failed to checkpoint dictionary for column " +
2259  columnName);
2260  }
2261  }
2262  const bool invalid = str_id > max_valid_int_value<T>();
2263  if (invalid || str_id == inline_int_null_value<int32_t>()) {
2264  if (invalid) {
2265  LOG(ERROR) << "Could not encode string: " << str
2266  << ", the encoded value doesn't fit in " << sizeof(T) * 8
2267  << " bits. Will store NULL instead.";
2268  }
2269  str_id = inline_fixed_encoding_null_val(columnType);
2270  }
2271  *col_data = str_id;
2272  }
2273  return *col_data;
2274 }
#define LOG(tag)
Definition: Logger.h:203
bool get_is_null() const
Definition: Analyzer.h:333
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1537
std::string * stringval
Definition: sqltypes.h:220
Datum get_constval() const
Definition: Analyzer.h:334
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
#define CHECK(condition)
Definition: Logger.h:209
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 2277 of file RelAlgExecutor.cpp.

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

2280  {
2281  return insert_one_dict_str(col_data, cd->columnName, cd->columnType, col_cv, catalog);
2282 }
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:

int64_t anonymous_namespace{RelAlgExecutor.cpp}::int_value_from_numbers_ptr ( const SQLTypeInfo type_info,
const int8_t *  data 
)

Definition at line 2306 of file RelAlgExecutor.cpp.

References CHECK, SQLTypeInfo::get_compression(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), kBIGINT, kCHAR, kDATE, kENCODING_DICT, kINT, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, and kVARCHAR.

Referenced by get_shard_for_key().

2306  {
2307  size_t sz = 0;
2308  switch (type_info.get_type()) {
2309  case kTINYINT:
2310  case kSMALLINT:
2311  case kINT:
2312  case kBIGINT:
2313  case kTIMESTAMP:
2314  case kTIME:
2315  case kDATE:
2316  sz = type_info.get_logical_size();
2317  break;
2318  case kTEXT:
2319  case kVARCHAR:
2320  case kCHAR:
2321  CHECK(type_info.get_compression() == kENCODING_DICT);
2322  sz = type_info.get_size();
2323  break;
2324  default:
2325  CHECK(false) << "Unexpected sharding key datatype";
2326  }
2327 
2328  switch (sz) {
2329  case 1:
2330  return *(reinterpret_cast<const int8_t*>(data));
2331  case 2:
2332  return *(reinterpret_cast<const int16_t*>(data));
2333  case 4:
2334  return *(reinterpret_cast<const int32_t*>(data));
2335  case 8:
2336  return *(reinterpret_cast<const int64_t*>(data));
2337  default:
2338  CHECK(false);
2339  return 0;
2340  }
2341 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
Definition: sqltypes.h:49
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
int get_logical_size() const
Definition: sqltypes.h:340
Definition: sqltypes.h:52
Definition: sqltypes.h:53
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
Definition: sqltypes.h:41
#define CHECK(condition)
Definition: Logger.h:209
Definition: sqltypes.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1563 of file RelAlgExecutor.cpp.

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

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

1563  {
1564  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1565  if (agg_expr && agg_expr->get_contains_agg()) {
1566  auto agg_type = agg_expr->get_aggtype();
1567  if (agg_type == SQLAgg::kMIN || agg_type == SQLAgg::kMAX ||
1568  agg_type == SQLAgg::kSUM || agg_type == SQLAgg::kAVG) {
1569  return true;
1570  }
1571  }
1572  return false;
1573 }
Definition: sqldefs.h:73
Definition: sqldefs.h:75
SQLAgg get_aggtype() const
Definition: Analyzer.h:1249
Definition: sqldefs.h:74
Definition: sqldefs.h:72

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

References Analyzer::AggExpr::get_is_distinct().

Referenced by get_logical_type_for_expr().

1558  {
1559  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1560  return agg_expr && agg_expr->get_is_distinct();
1561 }
bool get_is_distinct() const
Definition: Analyzer.h:1252

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgExecutor.cpp}::is_extracted_dag_valid ( ExtractedPlanDag dag)

Definition at line 185 of file RelAlgExecutor.cpp.

References ExtractedPlanDag::contain_not_supported_rel_node, EMPTY_QUERY_PLAN, and ExtractedPlanDag::extracted_dag.

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

185  {
186  return !dag.contain_not_supported_rel_node &&
187  dag.extracted_dag.compare(EMPTY_QUERY_PLAN) != 0;
188 }
const QueryPlan extracted_dag
constexpr char const * EMPTY_QUERY_PLAN

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

References RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

1891  {
1892  return std::any_of(ra_exe_unit.target_exprs.begin(),
1893  ra_exe_unit.target_exprs.end(),
1894  [](const Analyzer::Expr* expr) {
1895  return dynamic_cast<const Analyzer::WindowFunction*>(expr);
1896  });
1897 }
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 3606 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().

3606  {
3607  CHECK_GE(left_deep_join->inputCount(), size_t(2));
3608  std::vector<JoinType> join_types(left_deep_join->inputCount() - 1, JoinType::INNER);
3609  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
3610  ++nesting_level) {
3611  if (left_deep_join->getOuterCondition(nesting_level)) {
3612  join_types[nesting_level - 1] = JoinType::LEFT;
3613  }
3614  auto cur_level_join_type = left_deep_join->getJoinType(nesting_level);
3615  if (cur_level_join_type == JoinType::SEMI || cur_level_join_type == JoinType::ANTI) {
3616  join_types[nesting_level - 1] = cur_level_join_type;
3617  }
3618  }
3619  return join_types;
3620 }
const RexScalar * getOuterCondition(const size_t nesting_level) const
#define CHECK_GE(x, y)
Definition: Logger.h:222
const JoinType getJoinType(const size_t nesting_level) const
const size_t inputCount() const

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

Referenced by reverse_logical_distribution().

3831  {
3832  for (const auto& qual : haystack) {
3833  if (*qual == *needle) {
3834  return true;
3835  }
3836  }
3837  return false;
3838 }

+ Here is the caller graph for this function:

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

Definition at line 63 of file RelAlgExecutor.cpp.

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

63  {
64  const auto compound = dynamic_cast<const RelCompound*>(ra);
65  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
66  return ((compound && compound->isAggregate()) || aggregate);
67 }

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

References CPU, Data_Namespace::CPU_LEVEL, Data_Namespace::DataMgr::deleteChunksWithPrefix(), CompilationOptions::device_type, g_enable_system_tables, get_physical_inputs(), Catalog_Namespace::Catalog::getDatabaseId(), Catalog_Namespace::Catalog::getDataMgr(), and Catalog_Namespace::Catalog::getMetadataForTable().

Referenced by RelAlgExecutor::executeRelAlgQueryNoRetry().

162  {
164  std::set<int32_t> system_table_ids;
165  for (const auto& physical_input : get_physical_inputs(&ra_node)) {
166  int table_id = physical_input.table_id;
167  auto table = catalog.getMetadataForTable(table_id, false);
168  if (table && table->is_system_table) {
169  system_table_ids.emplace(table_id);
170  }
171  }
172  // Execute on CPU for queries involving system tables
173  if (!system_table_ids.empty() && co.device_type != ExecutorDeviceType::CPU) {
174  throw QueryMustRunOnCpu();
175  }
176  // Clear any previously cached data, since system tables depend on point in time data
177  // snapshots.
178  for (const auto table_id : system_table_ids) {
180  ChunkKey{catalog.getDatabaseId(), table_id}, Data_Namespace::CPU_LEVEL);
181  }
182  }
183 }
std::vector< int > ChunkKey
Definition: types.h:37
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:222
bool g_enable_system_tables
Definition: SysCatalog.cpp:65
int getDatabaseId() const
Definition: Catalog.h:275
ExecutorDeviceType device_type
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:489
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)

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

References prepare_string_dictionaries(), and set_parallelism_hints().

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

152  {
153  // Iterate through ra_node inputs for types that need to be loaded pre-execution
154  // If they do not have valid metadata, load them into CPU memory to generate
155  // the metadata and leave them ready to be used by the query
156  set_parallelism_hints(ra_node, catalog);
157  prepare_string_dictionaries(ra_node, catalog);
158 }
void prepare_string_dictionaries(const RelAlgNode &ra_node, const Catalog_Namespace::Catalog &catalog)
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 116 of file RelAlgExecutor.cpp.

References CHECK, Data_Namespace::CPU_LEVEL, StorageType::FOREIGN_TABLE, get_physical_inputs(), Chunk_NS::Chunk::getChunk(), Catalog_Namespace::Catalog::getColumnIdBySpi(), Catalog_Namespace::Catalog::getDatabaseId(), Catalog_Namespace::Catalog::getDataMgr(), Catalog_Namespace::Catalog::getForeignTable(), Catalog_Namespace::Catalog::getMetadataForColumn(), Catalog_Namespace::Catalog::getMetadataForTable(), and foreign_storage::is_metadata_placeholder().

Referenced by prepare_foreign_table_for_execution().

117  {
118  for (const auto& physical_input : get_physical_inputs(&ra_node)) {
119  int table_id = physical_input.table_id;
120  auto table = catalog.getMetadataForTable(table_id, false);
121  if (table && table->storageType == StorageType::FOREIGN_TABLE) {
122  int col_id = catalog.getColumnIdBySpi(table_id, physical_input.col_id);
123  const auto col_desc = catalog.getMetadataForColumn(table_id, col_id);
124  auto foreign_table = catalog.getForeignTable(table_id);
125  if (col_desc->columnType.is_dict_encoded_type()) {
126  CHECK(foreign_table->fragmenter != nullptr);
127  for (const auto& fragment :
128  foreign_table->fragmenter->getFragmentsForQuery().fragments) {
129  ChunkKey chunk_key = {
130  catalog.getDatabaseId(), table_id, col_id, fragment.fragmentId};
131  const ChunkMetadataMap& metadata_map = fragment.getChunkMetadataMap();
132  CHECK(metadata_map.find(col_id) != metadata_map.end());
133  if (foreign_storage::is_metadata_placeholder(*(metadata_map.at(col_id)))) {
134  // When this goes out of scope it will stay in CPU cache but become
135  // evictable
136  std::shared_ptr<Chunk_NS::Chunk> chunk =
137  Chunk_NS::Chunk::getChunk(col_desc,
138  &(catalog.getDataMgr()),
139  chunk_key,
141  0,
142  0,
143  0);
144  }
145  }
146  }
147  }
148  }
149 }
const foreign_storage::ForeignTable * getForeignTable(const std::string &tableName) const
Definition: Catalog.cpp:1485
std::vector< int > ChunkKey
Definition: types.h:37
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:222
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
int getDatabaseId() const
Definition: Catalog.h:275
bool is_metadata_placeholder(const ChunkMetadata &metadata)
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)
Definition: Chunk.cpp:28
#define CHECK(condition)
Definition: Logger.h:209
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:1618

+ 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}::reverse_logical_distribution ( const std::shared_ptr< Analyzer::Expr > &  expr)

Definition at line 3843 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::makeJoinQuals().

3844  {
3845  const auto expr_terms = qual_to_disjunctive_form(expr);
3846  CHECK_GE(expr_terms.size(), size_t(1));
3847  const auto& first_term = expr_terms.front();
3848  const auto first_term_factors = qual_to_conjunctive_form(first_term);
3849  std::vector<std::shared_ptr<Analyzer::Expr>> common_factors;
3850  // First, collect the conjunctive components common to all the disjunctive components.
3851  // Don't do it for simple qualifiers, we only care about expensive or join qualifiers.
3852  for (const auto& first_term_factor : first_term_factors.quals) {
3853  bool is_common =
3854  expr_terms.size() > 1; // Only report common factors for disjunction.
3855  for (size_t i = 1; i < expr_terms.size(); ++i) {
3856  const auto crt_term_factors = qual_to_conjunctive_form(expr_terms[i]);
3857  if (!list_contains_expression(crt_term_factors.quals, first_term_factor)) {
3858  is_common = false;
3859  break;
3860  }
3861  }
3862  if (is_common) {
3863  common_factors.push_back(first_term_factor);
3864  }
3865  }
3866  if (common_factors.empty()) {
3867  return expr;
3868  }
3869  // Now that the common expressions are known, collect the remaining expressions.
3870  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_terms;
3871  for (const auto& term : expr_terms) {
3872  const auto term_cf = qual_to_conjunctive_form(term);
3873  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_quals(
3874  term_cf.simple_quals.begin(), term_cf.simple_quals.end());
3875  for (const auto& qual : term_cf.quals) {
3876  if (!list_contains_expression(common_factors, qual)) {
3877  remaining_quals.push_back(qual);
3878  }
3879  }
3880  if (!remaining_quals.empty()) {
3881  remaining_terms.push_back(build_logical_expression(remaining_quals, kAND));
3882  }
3883  }
3884  // Reconstruct the expression with the transformation applied.
3885  const auto common_expr = build_logical_expression(common_factors, kAND);
3886  if (remaining_terms.empty()) {
3887  return common_expr;
3888  }
3889  const auto remaining_expr = build_logical_expression(remaining_terms, kOR);
3890  return Parser::OperExpr::normalize(kAND, kONE, common_expr, remaining_expr);
3891 }
Definition: sqldefs.h:38
#define CHECK_GE(x, y)
Definition: Logger.h:222
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:37
std::shared_ptr< Analyzer::Expr > build_logical_expression(const std::vector< std::shared_ptr< Analyzer::Expr >> &factors, const SQLOps sql_op)
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)
Definition: ParserNode.cpp:291
Definition: sqldefs.h:69
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 3665 of file RelAlgExecutor.cpp.

References rewrite_expr().

Referenced by RelAlgExecutor::createCompoundWorkUnit().

3666  {
3667  std::list<std::shared_ptr<Analyzer::Expr>> rewritten_quals;
3668  for (const auto& qual : quals) {
3669  const auto rewritten_qual = rewrite_expr(qual.get());
3670  rewritten_quals.push_back(rewritten_qual ? rewritten_qual : qual);
3671  }
3672  return rewritten_quals;
3673 }
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 3803 of file RelAlgExecutor.cpp.

References CHECK, CHECK_GE, i, and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

3803  {
3804  CHECK(qual_expr);
3805  const auto bin_oper = dynamic_cast<const RexOperator*>(qual_expr);
3806  if (!bin_oper || bin_oper->getOperator() != kAND) {
3807  return {qual_expr};
3808  }
3809  CHECK_GE(bin_oper->size(), size_t(2));
3810  auto lhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(0));
3811  for (size_t i = 1; i < bin_oper->size(); ++i) {
3812  const auto rhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(i));
3813  lhs_cf.insert(lhs_cf.end(), rhs_cf.begin(), rhs_cf.end());
3814  }
3815  return lhs_cf;
3816 }
#define CHECK_GE(x, y)
Definition: Logger.h:222
std::vector< const RexScalar * > rex_to_conjunctive_form(const RexScalar *qual_expr)
Definition: sqldefs.h:37
#define CHECK(condition)
Definition: Logger.h:209

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

References RelCompound::getScalarSource().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1344  {
1345  return compound->getScalarSource(i);
1346 }
const RexScalar * getScalarSource(const size_t i) const

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

References RelProject::getProjectAt().

1348  {
1349  return project->getProjectAt(i);
1350 }
const RexScalar * getProjectAt(const size_t idx) const

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

References RelTableFunction::getTableFuncInputAt().

1352  {
1353  return table_func->getTableFuncInputAt(i);
1354 }
const RexScalar * getTableFuncInputAt(const size_t idx) const

+ 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 81 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(), and Data_Namespace::DataMgr::getPersistentStorageMgr().

Referenced by prepare_foreign_table_for_execution().

82  {
83  std::map<ChunkKey, std::set<foreign_storage::ForeignStorageMgr::ParallelismHint>>
84  parallelism_hints_per_table;
85  for (const auto& physical_input : get_physical_inputs(&ra_node)) {
86  int table_id = physical_input.table_id;
87  auto table = catalog.getMetadataForTable(table_id, false);
88  if (table && table->storageType == StorageType::FOREIGN_TABLE &&
89  !table->is_system_table) {
90  int col_id = catalog.getColumnIdBySpi(table_id, physical_input.col_id);
91  const auto col_desc = catalog.getMetadataForColumn(table_id, col_id);
92  auto foreign_table = catalog.getForeignTable(table_id);
93  for (const auto& fragment :
94  foreign_table->fragmenter->getFragmentsForQuery().fragments) {
95  Chunk_NS::Chunk chunk{col_desc};
96  ChunkKey chunk_key = {
97  catalog.getDatabaseId(), table_id, col_id, fragment.fragmentId};
98  // do not include chunk hints that are in CPU memory
99  if (!chunk.isChunkOnDevice(
100  &catalog.getDataMgr(), chunk_key, Data_Namespace::CPU_LEVEL, 0)) {
101  parallelism_hints_per_table[{catalog.getDatabaseId(), table_id}].insert(
103  fragment.fragmentId});
104  }
105  }
106  }
107  }
108  if (!parallelism_hints_per_table.empty()) {
109  auto foreign_storage_mgr =
111  CHECK(foreign_storage_mgr);
112  foreign_storage_mgr->setParallelismHints(parallelism_hints_per_table);
113  }
114 }
const foreign_storage::ForeignTable * getForeignTable(const std::string &tableName) const
Definition: Catalog.cpp:1485
std::vector< int > ChunkKey
Definition: types.h:37
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:222
PersistentStorageMgr * getPersistentStorageMgr() const
Definition: DataMgr.cpp:632
foreign_storage::ForeignStorageMgr * getForeignStorageMgr() const
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
int getDatabaseId() const
Definition: Catalog.h:275
#define CHECK(condition)
Definition: Logger.h:209
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:1618

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

1357  {
1358  const auto& ti = expr->get_type_info();
1359  if (!ti.is_string() || ti.get_compression() != kENCODING_NONE) {
1360  return expr;
1361  }
1362  auto transient_dict_ti = ti;
1363  transient_dict_ti.set_compression(kENCODING_DICT);
1364  transient_dict_ti.set_comp_param(TRANSIENT_DICT_ID);
1365  transient_dict_ti.set_fixed_size();
1366  return expr->add_cast(transient_dict_ti);
1367 }
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:259

+ Here is the caller graph for this function:

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

Definition at line 1369 of file RelAlgExecutor.cpp.

References fold_expr(), and set_transient_dict().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1371  {
1372  try {
1373  scalar_sources.push_back(set_transient_dict(fold_expr(expr.get())));
1374  } catch (...) {
1375  scalar_sources.push_back(fold_expr(expr.get()));
1376  }
1377 }
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:

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 3966 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().

3970  {
3971  CHECK_LE(size_t(1), ra_node->inputCount());
3972  CHECK_GE(size_t(2), ra_node->inputCount());
3973  const auto input = ra_node->getInput(nest_level);
3974  const auto it_rte_idx = input_to_nest_level.find(input);
3975  CHECK(it_rte_idx != input_to_nest_level.end());
3976  const int rte_idx = it_rte_idx->second;
3977  const int table_id = table_id_from_ra(input);
3978  std::vector<std::shared_ptr<Analyzer::Expr>> inputs;
3979  const auto scan_ra = dynamic_cast<const RelScan*>(input);
3980  int input_idx = 0;
3981  for (const auto& input_meta : in_metainfo) {
3982  inputs.push_back(
3983  std::make_shared<Analyzer::ColumnVar>(input_meta.get_type_info(),
3984  table_id,
3985  scan_ra ? input_idx + 1 : input_idx,
3986  rte_idx));
3987  ++input_idx;
3988  }
3989  return inputs;
3990 }
#define CHECK_GE(x, y)
Definition: Logger.h:222
const RelAlgNode * getInput(const size_t idx) const
#define CHECK_LE(x, y)
Definition: Logger.h:220
int table_id_from_ra(const RelAlgNode *ra_node)
#define CHECK(condition)
Definition: Logger.h:209
const size_t inputCount() const

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

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

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

1153  {
1154  const auto scan_ra = dynamic_cast<const RelScan*>(ra_node);
1155  if (scan_ra) {
1156  const auto td = scan_ra->getTableDescriptor();
1157  CHECK(td);
1158  return td->tableId;
1159  }
1160  return -ra_node->getId();
1161 }
unsigned getId() const
#define CHECK(condition)
Definition: Logger.h:209
const TableDescriptor * getTableDescriptor() const

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

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

Referenced by RelAlgExecutor::createUnionWorkUnit().

4168  {
4169  std::vector<TargetMetaInfo> const& tmis = input_node->getOutputMetainfo();
4170  VLOG(3) << "input_node->getOutputMetainfo()=" << shared::printContainer(tmis);
4171  const int negative_node_id = -input_node->getId();
4172  std::vector<std::shared_ptr<Analyzer::Expr>> target_exprs;
4173  target_exprs.reserve(tmis.size());
4174  for (size_t i = 0; i < tmis.size(); ++i) {
4175  target_exprs.push_back(std::make_shared<Analyzer::ColumnVar>(
4176  tmis[i].get_type_info(), negative_node_id, i, 0));
4177  }
4178  return target_exprs;
4179 }
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:105
#define VLOG(n)
Definition: Logger.h:303

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

Referenced by RelAlgExecutor::computeWindow().

1986  {
1987  const auto tuple = dynamic_cast<const Analyzer::ExpressionTuple*>(expr);
1988  if (tuple) {
1989  std::vector<std::shared_ptr<Analyzer::Expr>> transformed_tuple;
1990  for (const auto& element : tuple->getTuple()) {
1991  transformed_tuple.push_back(transform_to_inner(element.get()));
1992  }
1993  return makeExpr<Analyzer::ExpressionTuple>(transformed_tuple);
1994  }
1995  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
1996  if (!col) {
1997  throw std::runtime_error("Only columns supported in the window partition for now");
1998  }
1999  return makeExpr<Analyzer::ColumnVar>(
2000  col->get_type_info(), col->get_table_id(), col->get_column_id(), 1);
2001 }
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 1454 of file RelAlgExecutor.cpp.

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

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

1456  {
1457  if (!compound->isAggregate()) {
1458  return {nullptr};
1459  }
1460  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1461  for (size_t group_idx = 0; group_idx < compound->getGroupByCount(); ++group_idx) {
1462  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1463  }
1464  return groupby_exprs;
1465 }
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
const size_t getGroupByCount() const
bool isAggregate() const

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

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

1469  {
1470  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1471  for (size_t group_idx = 0; group_idx < aggregate->getGroupByCount(); ++group_idx) {
1472  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1473  }
1474  return groupby_exprs;
1475 }
const size_t getGroupByCount() const
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 1477 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createCompoundWorkUnit().

1478  {
1479  const auto filter_rex = compound->getFilterExpr();
1480  const auto filter_expr =
1481  filter_rex ? translator.translateScalarRex(filter_rex) : nullptr;
1482  return filter_expr ? qual_to_conjunctive_form(fold_expr(filter_expr.get()))
1484 }
const RexScalar * getFilterExpr() const
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1389 of file RelAlgExecutor.cpp.

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

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

1392  {
1393  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1394  const size_t scalar_sources_size = get_scalar_sources_size(ra_node);
1395  VLOG(3) << "get_scalar_sources_size(" << ra_node->toString()
1396  << ") = " << scalar_sources_size;
1397  for (size_t i = 0; i < scalar_sources_size; ++i) {
1398  const auto scalar_rex = scalar_at(i, ra_node);
1399  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1400  // RexRef are synthetic scalars we append at the end of the real ones
1401  // for the sake of taking memory ownership, no real work needed here.
1402  continue;
1403  }
1404 
1405  const auto scalar_expr =
1406  rewrite_array_elements(translator.translateScalarRex(scalar_rex).get());
1407  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1408  if (executor_type == ExecutorType::Native) {
1409  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1410  } else if (executor_type == ExecutorType::TableFunctions) {
1411  scalar_sources.push_back(fold_expr(rewritten_expr.get()));
1412  } else {
1413  scalar_sources.push_back(cast_dict_to_none(fold_expr(rewritten_expr.get())));
1414  }
1415  }
1416 
1417  return scalar_sources;
1418 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t get_scalar_sources_size(const RelCompound *compound)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::Expr > cast_dict_to_none(const std::shared_ptr< Analyzer::Expr > &input)
const RexScalar * scalar_at(const size_t i, const RelCompound *compound)
#define VLOG(n)
Definition: Logger.h:303
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 1421 of file RelAlgExecutor.cpp.

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

1427  {
1428  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1429  for (size_t i = 0; i < get_scalar_sources_size(ra_node); ++i) {
1430  const auto scalar_rex = scalar_at(i, ra_node);
1431  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1432  // RexRef are synthetic scalars we append at the end of the real ones
1433  // for the sake of taking memory ownership, no real work needed here.
1434  continue;
1435  }
1436 
1437  std::shared_ptr<Analyzer::Expr> translated_expr;
1438  if (i >= starting_projection_column_idx && i < get_scalar_sources_size(ra_node) - 1) {
1439  translated_expr = cast_to_column_type(translator.translateScalarRex(scalar_rex),
1440  tableId,
1441  cat,
1442  colNames[i - starting_projection_column_idx]);
1443  } else {
1444  translated_expr = translator.translateScalarRex(scalar_rex);
1445  }
1446  const auto scalar_expr = rewrite_array_elements(translated_expr.get());
1447  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1448  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1449  }
1450 
1451  return scalar_sources;
1452 }
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
std::string cat(Ts &&...args)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t get_scalar_sources_size(const RelCompound *compound)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
const RexScalar * scalar_at(const size_t i, const RelCompound *compound)
void set_transient_dict_maybe(std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources, const std::shared_ptr< Analyzer::Expr > &expr)

+ Here is the call graph for this function:

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

Definition at line 1486 of file RelAlgExecutor.cpp.

References cast_dict_to_none(), CHECK, CHECK_GE, CHECK_LE, fold_expr(), RexRef::getIndex(), RelCompound::getTargetExpr(), i, Analyzer::Var::kGROUPBY, Native, rewrite_expr(), set_transient_dict(), RelCompound::size(), RelAlgTranslator::translateAggregateRex(), RelAlgTranslator::translateScalarRex(), and var_ref().

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

1492  {
1493  std::vector<Analyzer::Expr*> target_exprs;
1494  for (size_t i = 0; i < compound->size(); ++i) {
1495  const auto target_rex = compound->getTargetExpr(i);
1496  const auto target_rex_agg = dynamic_cast<const RexAgg*>(target_rex);
1497  std::shared_ptr<Analyzer::Expr> target_expr;
1498  if (target_rex_agg) {
1499  target_expr =
1500  RelAlgTranslator::translateAggregateRex(target_rex_agg, scalar_sources);
1501  } else {
1502  const auto target_rex_scalar = dynamic_cast<const RexScalar*>(target_rex);
1503  const auto target_rex_ref = dynamic_cast<const RexRef*>(target_rex_scalar);
1504  if (target_rex_ref) {
1505  const auto ref_idx = target_rex_ref->getIndex();
1506  CHECK_GE(ref_idx, size_t(1));
1507  CHECK_LE(ref_idx, groupby_exprs.size());
1508  const auto groupby_expr = *std::next(groupby_exprs.begin(), ref_idx - 1);
1509  target_expr = var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, ref_idx);
1510  } else {
1511  target_expr = translator.translateScalarRex(target_rex_scalar);
1512  auto rewritten_expr = rewrite_expr(target_expr.get());
1513  target_expr = fold_expr(rewritten_expr.get());
1514  if (executor_type == ExecutorType::Native) {
1515  try {
1516  target_expr = set_transient_dict(target_expr);
1517  } catch (...) {
1518  // noop
1519  }
1520  } else {
1521  target_expr = cast_dict_to_none(target_expr);
1522  }
1523  }
1524  }
1525  CHECK(target_expr);
1526  target_exprs_owned.push_back(target_expr);
1527  target_exprs.push_back(target_expr.get());
1528  }
1529  return target_exprs;
1530 }
const Rex * getTargetExpr(const size_t i) const
size_t getIndex() const
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
size_t size() const override
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:1976
#define CHECK_GE(x, y)
Definition: Logger.h:222
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::Expr > cast_dict_to_none(const std::shared_ptr< Analyzer::Expr > &input)
#define CHECK_LE(x, y)
Definition: Logger.h:220
#define CHECK(condition)
Definition: Logger.h:209
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)
static std::shared_ptr< Analyzer::Expr > translateAggregateRex(const RexAgg *rex, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1532 of file RelAlgExecutor.cpp.

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

1537  {
1538  std::vector<Analyzer::Expr*> target_exprs;
1539  size_t group_key_idx = 1;
1540  for (const auto& groupby_expr : groupby_exprs) {
1541  auto target_expr =
1542  var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, group_key_idx++);
1543  target_exprs_owned.push_back(target_expr);
1544  target_exprs.push_back(target_expr.get());
1545  }
1546 
1547  for (const auto& target_rex_agg : aggregate->getAggExprs()) {
1548  auto target_expr =
1549  RelAlgTranslator::translateAggregateRex(target_rex_agg.get(), scalar_sources);
1550  CHECK(target_expr);
1551  target_expr = fold_expr(target_expr.get());
1552  target_exprs_owned.push_back(target_expr);
1553  target_exprs.push_back(target_expr.get());
1554  }
1555  return target_exprs;
1556 }
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:1976
const std::vector< std::unique_ptr< const RexAgg > > & getAggExprs() const
#define CHECK(condition)
Definition: Logger.h:209
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: