OmniSciDB  16c4e035a1
 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 is_projection (const RelAlgExecutionUnit &ra_exe_unit)
 
bool should_output_columnar (const RelAlgExecutionUnit &ra_exe_unit, const RenderInfo *render_info)
 
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< Analyzer::Expr * > get_raw_pointers (std::vector< std::shared_ptr< Analyzer::Expr >> const &input)
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
target_exprs_for_union (RelAlgNode const *input_node)
 
std::pair< std::vector
< TargetMetaInfo >
, std::vector< std::shared_ptr
< Analyzer::Expr > > > 
get_inputs_meta (const RelFilter *filter, const RelAlgTranslator &translator, const std::vector< std::shared_ptr< RexInput >> &inputs_owned, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
 

Function Documentation

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

Definition at line 3873 of file RelAlgExecutor.cpp.

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

Referenced by reverse_logical_distribution().

3875  {
3876  CHECK(!factors.empty());
3877  auto acc = factors.front();
3878  for (size_t i = 1; i < factors.size(); ++i) {
3879  acc = Parser::OperExpr::normalize(sql_op, kONE, acc, factors[i]);
3880  }
3881  return acc;
3882 }
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:307
Definition: sqldefs.h:69
#define CHECK(condition)
Definition: Logger.h:211

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

References CHECK_EQ, i, and RenderInfo::targets.

Referenced by RelAlgExecutor::executeWorkUnit().

3031  {
3032  CHECK_EQ(work_unit_target_exprs.size(), targets_meta.size());
3033  render_info.targets.clear();
3034  for (size_t i = 0; i < targets_meta.size(); ++i) {
3035  render_info.targets.emplace_back(std::make_shared<Analyzer::TargetEntry>(
3036  targets_meta[i].get_resname(),
3037  work_unit_target_exprs[i]->get_shared_ptr(),
3038  false));
3039  }
3040 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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 3042 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().

3044  {
3046  !eo.output_columnar_hint && ra_exe_unit.sort_info.order_entries.empty();
3047 }
const std::list< Analyzer::OrderEntry > order_entries
ExecutorDeviceType device_type
bool g_enable_bump_allocator
Definition: Execute.cpp:114

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

References kENCODING_DICT, and kTEXT.

Referenced by translate_scalar_sources(), and translate_targets().

1397  {
1398  const auto& input_ti = input->get_type_info();
1399  if (input_ti.is_string() && input_ti.get_compression() == kENCODING_DICT) {
1400  return input->add_cast(SQLTypeInfo(kTEXT, input_ti.get_notnull()));
1401  }
1402  return input;
1403 }
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 555 of file RelAlgExecutor.cpp.

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

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

555  {
556  CHECK_EQ(size_t(1), sort->inputCount());
557  const auto source = sort->getInput(0);
558  if (dynamic_cast<const RelSort*>(source)) {
559  throw std::runtime_error("Sort node not supported as input to another sort");
560  }
561 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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 1249 of file RelAlgExecutor.cpp.

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

Referenced by get_input_desc_impl().

1255  {
1256  VLOG(3) << "ra_node=" << ra_node->toString()
1257  << " input_col_descs_unique.size()=" << input_col_descs_unique.size()
1258  << " source_used_inputs.size()=" << source_used_inputs.size();
1259  for (const auto used_input : source_used_inputs) {
1260  const auto input_ra = used_input->getSourceNode();
1261  const int table_id = table_id_from_ra(input_ra);
1262  const auto col_id = used_input->getIndex();
1263  auto it = input_to_nest_level.find(input_ra);
1264  if (it != input_to_nest_level.end()) {
1265  const int input_desc = it->second;
1266  input_col_descs_unique.insert(std::make_shared<const InputColDescriptor>(
1267  dynamic_cast<const RelScan*>(input_ra)
1268  ? cat.getColumnIdBySpi(table_id, col_id + 1)
1269  : col_id,
1270  table_id,
1271  input_desc));
1272  } else if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1273  throw std::runtime_error("Bushy joins not supported");
1274  }
1275  }
1276 }
int table_id_from_ra(const RelAlgNode *ra_node)
virtual std::string toString() const =0
#define VLOG(n)
Definition: Logger.h:305
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:1635

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

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

Referenced by RelAlgExecutor::executeWorkUnit().

2942  {
2943  for (const auto target_expr : ra_exe_unit.target_exprs) {
2944  if (dynamic_cast<const Analyzer::AggExpr*>(target_expr)) {
2945  return false;
2946  }
2947  }
2948  if (ra_exe_unit.groupby_exprs.size() == 1 && !ra_exe_unit.groupby_exprs.front() &&
2949  (!ra_exe_unit.scan_limit || ra_exe_unit.scan_limit > Executor::high_scan_limit)) {
2950  return true;
2951  }
2952  return false;
2953 }
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:472

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

2965  {
2966  RelAlgExecutionUnit ra_exe_unit = ra_exe_unit_in;
2967  for (size_t i = 0; i < ra_exe_unit.target_exprs.size(); ++i) {
2968  const auto target_expr = ra_exe_unit.target_exprs[i];
2969  const auto agg_info = get_target_info(target_expr, g_bigint_count);
2970  if (agg_info.agg_kind != kAPPROX_COUNT_DISTINCT) {
2971  continue;
2972  }
2973  CHECK(dynamic_cast<const Analyzer::AggExpr*>(target_expr));
2974  const auto arg = static_cast<Analyzer::AggExpr*>(target_expr)->get_own_arg();
2975  CHECK(arg);
2976  const auto& arg_ti = arg->get_type_info();
2977  // Avoid calling getExpressionRange for variable length types (string and array),
2978  // it'd trigger an assertion since that API expects to be called only for types
2979  // for which the notion of range is well-defined. A bit of a kludge, but the
2980  // logic to reject these types anyway is at lower levels in the stack and not
2981  // really worth pulling into a separate function for now.
2982  if (!(arg_ti.is_number() || arg_ti.is_boolean() || arg_ti.is_time() ||
2983  (arg_ti.is_string() && arg_ti.get_compression() == kENCODING_DICT))) {
2984  continue;
2985  }
2986  const auto arg_range = getExpressionRange(arg.get(), table_infos, executor);
2987  if (arg_range.getType() != ExpressionRangeType::Integer) {
2988  continue;
2989  }
2990  // When running distributed, the threshold for using the precise implementation
2991  // must be consistent across all leaves, otherwise we could have a mix of precise
2992  // and approximate bitmaps and we cannot aggregate them.
2993  const auto device_type = g_cluster ? ExecutorDeviceType::GPU : device_type_in;
2994  const auto bitmap_sz_bits = arg_range.getIntMax() - arg_range.getIntMin() + 1;
2995  const auto sub_bitmap_count =
2996  get_count_distinct_sub_bitmap_count(bitmap_sz_bits, ra_exe_unit, device_type);
2997  int64_t approx_bitmap_sz_bits{0};
2998  const auto error_rate = static_cast<Analyzer::AggExpr*>(target_expr)->get_arg1();
2999  if (error_rate) {
3000  CHECK(error_rate->get_type_info().get_type() == kINT);
3001  CHECK_GE(error_rate->get_constval().intval, 1);
3002  approx_bitmap_sz_bits = hll_size_for_rate(error_rate->get_constval().intval);
3003  } else {
3004  approx_bitmap_sz_bits = g_hll_precision_bits;
3005  }
3006  CountDistinctDescriptor approx_count_distinct_desc{CountDistinctImplType::Bitmap,
3007  arg_range.getIntMin(),
3008  approx_bitmap_sz_bits,
3009  true,
3010  device_type,
3011  sub_bitmap_count};
3012  CountDistinctDescriptor precise_count_distinct_desc{CountDistinctImplType::Bitmap,
3013  arg_range.getIntMin(),
3014  bitmap_sz_bits,
3015  false,
3016  device_type,
3017  sub_bitmap_count};
3018  if (approx_count_distinct_desc.bitmapPaddedSizeBytes() >=
3019  precise_count_distinct_desc.bitmapPaddedSizeBytes()) {
3020  auto precise_count_distinct = makeExpr<Analyzer::AggExpr>(
3021  get_agg_type(kCOUNT, arg.get()), kCOUNT, arg, true, nullptr);
3022  target_exprs_owned.push_back(precise_count_distinct);
3023  ra_exe_unit.target_exprs[i] = precise_count_distinct.get();
3024  }
3025  }
3026  return ra_exe_unit;
3027 }
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:224
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:211
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 3678 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().

3685  {
3686  if (g_cluster) {
3687  // Disable table reordering in distributed mode. The aggregator does not have enough
3688  // information to break ties
3689  return {};
3690  }
3691  const auto& cat = *executor->getCatalog();
3692  for (const auto& table_info : query_infos) {
3693  if (table_info.table_id < 0) {
3694  continue;
3695  }
3696  const auto td = cat.getMetadataForTable(table_info.table_id);
3697  CHECK(td);
3698  if (table_is_replicated(td)) {
3699  return {};
3700  }
3701  }
3702  const auto input_permutation =
3703  get_node_input_permutation(left_deep_join_quals, query_infos, executor);
3704  input_to_nest_level = get_input_nest_levels(node, input_permutation);
3705  std::tie(input_descs, input_col_descs, std::ignore) =
3706  get_input_desc(node, input_to_nest_level, input_permutation, cat);
3707  return input_permutation;
3708 }
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:211
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 2955 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

2955  {
2956  return !(ra_exe_unit.quals.empty() && ra_exe_unit.join_quals.empty() &&
2957  ra_exe_unit.simple_quals.empty());
2958 }
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 2702 of file RelAlgExecutor.cpp.

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

2702  {
2703  return !order_entries.empty() && order_entries.front().is_desc;
2704 }

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

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

Referenced by get_bitwise_equals_conjunction().

3593  {
3594  const auto condition = dynamic_cast<const RexOperator*>(scalar);
3595  if (!condition || condition->getOperator() != kOR || condition->size() != 2) {
3596  return nullptr;
3597  }
3598  const auto equi_join_condition =
3599  dynamic_cast<const RexOperator*>(condition->getOperand(0));
3600  if (!equi_join_condition || equi_join_condition->getOperator() != kEQ) {
3601  return nullptr;
3602  }
3603  const auto both_are_null_condition =
3604  dynamic_cast<const RexOperator*>(condition->getOperand(1));
3605  if (!both_are_null_condition || both_are_null_condition->getOperator() != kAND ||
3606  both_are_null_condition->size() != 2) {
3607  return nullptr;
3608  }
3609  const auto lhs_is_null =
3610  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(0));
3611  const auto rhs_is_null =
3612  dynamic_cast<const RexOperator*>(both_are_null_condition->getOperand(1));
3613  if (!lhs_is_null || !rhs_is_null || lhs_is_null->getOperator() != kISNULL ||
3614  rhs_is_null->getOperator() != kISNULL) {
3615  return nullptr;
3616  }
3617  CHECK_EQ(size_t(1), lhs_is_null->size());
3618  CHECK_EQ(size_t(1), rhs_is_null->size());
3619  CHECK_EQ(size_t(2), equi_join_condition->size());
3620  const auto eq_lhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(0));
3621  const auto eq_rhs = dynamic_cast<const RexInput*>(equi_join_condition->getOperand(1));
3622  const auto is_null_lhs = dynamic_cast<const RexInput*>(lhs_is_null->getOperand(0));
3623  const auto is_null_rhs = dynamic_cast<const RexInput*>(rhs_is_null->getOperand(0));
3624  if (!eq_lhs || !eq_rhs || !is_null_lhs || !is_null_rhs) {
3625  return nullptr;
3626  }
3627  std::vector<std::unique_ptr<const RexScalar>> eq_operands;
3628  if (*eq_lhs == *is_null_lhs && *eq_rhs == *is_null_rhs) {
3629  RexDeepCopyVisitor deep_copy_visitor;
3630  auto lhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(0));
3631  auto rhs_op_copy = deep_copy_visitor.visit(equi_join_condition->getOperand(1));
3632  eq_operands.emplace_back(lhs_op_copy.release());
3633  eq_operands.emplace_back(rhs_op_copy.release());
3634  return boost::make_unique<const RexOperator>(
3635  kBW_EQ, eq_operands, equi_join_condition->getType());
3636  }
3637  return nullptr;
3638 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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 3640 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::makeJoinQuals().

3641  {
3642  const auto condition = dynamic_cast<const RexOperator*>(scalar);
3643  if (condition && condition->getOperator() == kAND) {
3644  CHECK_GE(condition->size(), size_t(2));
3645  auto acc = get_bitwise_equals(condition->getOperand(0));
3646  if (!acc) {
3647  return nullptr;
3648  }
3649  for (size_t i = 1; i < condition->size(); ++i) {
3650  std::vector<std::unique_ptr<const RexScalar>> and_operands;
3651  and_operands.emplace_back(std::move(acc));
3652  and_operands.emplace_back(get_bitwise_equals_conjunction(condition->getOperand(i)));
3653  acc =
3654  boost::make_unique<const RexOperator>(kAND, and_operands, condition->getType());
3655  }
3656  return acc;
3657  }
3658  return get_bitwise_equals(scalar);
3659 }
std::unique_ptr< const RexOperator > get_bitwise_equals_conjunction(const RexScalar *scalar)
#define CHECK_GE(x, y)
Definition: Logger.h:224
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 1048 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().

1048  {
1049  if (auto table_func = dynamic_cast<const RelTableFunction*>(ra_node)) {
1050  return table_func;
1051  }
1052  if (auto join = dynamic_cast<const RelJoin*>(ra_node)) {
1053  CHECK_EQ(size_t(2), join->inputCount());
1054  return join;
1055  }
1056  if (!dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1057  CHECK_EQ(size_t(1), ra_node->inputCount());
1058  }
1059  auto only_src = ra_node->getInput(0);
1060  const bool is_join = dynamic_cast<const RelJoin*>(only_src) ||
1061  dynamic_cast<const RelLeftDeepInnerJoin*>(only_src);
1062  return is_join ? only_src : ra_node;
1063 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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 1335 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().

1338  {
1339  std::unordered_set<const RexInput*> used_inputs;
1340  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1341  std::tie(used_inputs, used_inputs_owned) = get_used_inputs(ra_node, cat);
1342  VLOG(3) << "used_inputs.size() = " << used_inputs.size();
1343  auto input_desc_pair = get_input_desc_impl(
1344  ra_node, used_inputs, input_to_nest_level, input_permutation, cat);
1345  return std::make_tuple(
1346  input_desc_pair.first, input_desc_pair.second, used_inputs_owned);
1347 }
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:305

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

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

Referenced by get_input_desc().

1285  {
1286  std::vector<InputDescriptor> input_descs;
1287  const auto data_sink_node = get_data_sink(ra_node);
1288  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1289  const auto input_node_idx =
1290  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1291  auto input_ra = data_sink_node->getInput(input_node_idx);
1292  const int table_id = table_id_from_ra(input_ra);
1293  input_descs.emplace_back(table_id, input_idx);
1294  }
1295  std::unordered_set<std::shared_ptr<const InputColDescriptor>> input_col_descs_unique;
1296  collect_used_input_desc(input_descs,
1297  cat,
1298  input_col_descs_unique, // modified
1299  ra_node,
1300  used_inputs,
1301  input_to_nest_level);
1302  std::unordered_set<const RexInput*> join_source_used_inputs;
1303  std::vector<std::shared_ptr<RexInput>> join_source_used_inputs_owned;
1304  std::tie(join_source_used_inputs, join_source_used_inputs_owned) =
1305  get_join_source_used_inputs(ra_node, cat);
1306  collect_used_input_desc(input_descs,
1307  cat,
1308  input_col_descs_unique, // modified
1309  ra_node,
1310  join_source_used_inputs,
1311  input_to_nest_level);
1312  std::vector<std::shared_ptr<const InputColDescriptor>> input_col_descs(
1313  input_col_descs_unique.begin(), input_col_descs_unique.end());
1314 
1315  std::sort(input_col_descs.begin(),
1316  input_col_descs.end(),
1317  [](std::shared_ptr<const InputColDescriptor> const& lhs,
1318  std::shared_ptr<const InputColDescriptor> const& rhs) {
1319  return std::make_tuple(lhs->getScanDesc().getNestLevel(),
1320  lhs->getColId(),
1321  lhs->getScanDesc().getTableId()) <
1322  std::make_tuple(rhs->getScanDesc().getNestLevel(),
1323  rhs->getColId(),
1324  rhs->getScanDesc().getTableId());
1325  });
1326  return {input_descs,
1327  std::list<std::shared_ptr<const InputColDescriptor>>(input_col_descs.begin(),
1328  input_col_descs.end())};
1329 }
void collect_used_input_desc(std::vector< InputDescriptor > &input_descs, const Catalog_Namespace::Catalog &cat, std::unordered_set< std::shared_ptr< const InputColDescriptor >> &input_col_descs_unique, const RelAlgNode *ra_node, const std::unordered_set< const RexInput * > &source_used_inputs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
std::pair< std::unordered_set< const RexInput * >, std::vector< std::shared_ptr< RexInput > > > get_join_source_used_inputs(const RelAlgNode *ra_node, const Catalog_Namespace::Catalog &cat)
int table_id_from_ra(const RelAlgNode *ra_node)
const RelAlgNode * get_data_sink(const RelAlgNode *ra_node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

1187  {
1188  const auto data_sink_node = get_data_sink(ra_node);
1189  std::unordered_map<const RelAlgNode*, int> input_to_nest_level;
1190  for (size_t input_idx = 0; input_idx < data_sink_node->inputCount(); ++input_idx) {
1191  const auto input_node_idx =
1192  input_permutation.empty() ? input_idx : input_permutation[input_idx];
1193  const auto input_ra = data_sink_node->getInput(input_node_idx);
1194  // Having a non-zero mapped value (input_idx) results in the query being interpretted
1195  // as a JOIN within CodeGenerator::codegenColVar() due to rte_idx being set to the
1196  // mapped value (input_idx) which originates here. This would be incorrect for UNION.
1197  size_t const idx = dynamic_cast<const RelLogicalUnion*>(ra_node) ? 0 : input_idx;
1198  const auto it_ok = input_to_nest_level.emplace(input_ra, idx);
1199  CHECK(it_ok.second);
1200  LOG_IF(INFO, !input_permutation.empty())
1201  << "Assigned input " << input_ra->toString() << " to nest level " << input_idx;
1202  }
1203  return input_to_nest_level;
1204 }
#define LOG_IF(severity, condition)
Definition: Logger.h:301
#define CHECK(condition)
Definition: Logger.h:211
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 4517 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createFilterWorkUnit().

4520  {
4521  std::vector<TargetMetaInfo> in_metainfo;
4522  std::vector<std::shared_ptr<Analyzer::Expr>> exprs_owned;
4523  const auto data_sink_node = get_data_sink(filter);
4524  auto input_it = inputs_owned.begin();
4525  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
4526  const auto source = data_sink_node->getInput(nest_level);
4527  const auto scan_source = dynamic_cast<const RelScan*>(source);
4528  if (scan_source) {
4529  CHECK(source->getOutputMetainfo().empty());
4530  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources_owned;
4531  for (size_t i = 0; i < scan_source->size(); ++i, ++input_it) {
4532  scalar_sources_owned.push_back(translator.translateScalarRex(input_it->get()));
4533  }
4534  const auto source_metadata =
4535  get_targets_meta(scan_source, get_raw_pointers(scalar_sources_owned));
4536  in_metainfo.insert(
4537  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
4538  exprs_owned.insert(
4539  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
4540  } else {
4541  const auto& source_metadata = source->getOutputMetainfo();
4542  input_it += source_metadata.size();
4543  in_metainfo.insert(
4544  in_metainfo.end(), source_metadata.begin(), source_metadata.end());
4545  const auto scalar_sources_owned = synthesize_inputs(
4546  data_sink_node, nest_level, source_metadata, input_to_nest_level);
4547  exprs_owned.insert(
4548  exprs_owned.end(), scalar_sources_owned.begin(), scalar_sources_owned.end());
4549  }
4550  }
4551  return std::make_pair(in_metainfo, exprs_owned);
4552 }
std::vector< Analyzer::Expr * > get_raw_pointers(std::vector< std::shared_ptr< Analyzer::Expr >> const &input)
std::vector< std::shared_ptr< Analyzer::Expr > > synthesize_inputs(const RelAlgNode *ra_node, const size_t nest_level, const std::vector< TargetMetaInfo > &in_metainfo, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level)
std::shared_ptr< Analyzer::Expr > translateScalarRex(const RexScalar *rex) const
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
#define CHECK(condition)
Definition: Logger.h:211
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 1207 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().

1208  {
1209  const auto data_sink_node = get_data_sink(ra_node);
1210  if (auto join = dynamic_cast<const RelJoin*>(data_sink_node)) {
1211  CHECK_EQ(join->inputCount(), 2u);
1212  const auto condition = join->getCondition();
1213  RexUsedInputsVisitor visitor(cat);
1214  auto condition_inputs = visitor.visit(condition);
1215  std::vector<std::shared_ptr<RexInput>> condition_inputs_owned(
1216  visitor.get_inputs_owned());
1217  return std::make_pair(condition_inputs, condition_inputs_owned);
1218  }
1219 
1220  if (auto left_deep_join = dynamic_cast<const RelLeftDeepInnerJoin*>(data_sink_node)) {
1221  CHECK_GE(left_deep_join->inputCount(), 2u);
1222  const auto condition = left_deep_join->getInnerCondition();
1223  RexUsedInputsVisitor visitor(cat);
1224  auto result = visitor.visit(condition);
1225  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
1226  ++nesting_level) {
1227  const auto outer_condition = left_deep_join->getOuterCondition(nesting_level);
1228  if (outer_condition) {
1229  const auto outer_result = visitor.visit(outer_condition);
1230  result.insert(outer_result.begin(), outer_result.end());
1231  }
1232  }
1233  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1234  return std::make_pair(result, used_inputs_owned);
1235  }
1236 
1237  if (dynamic_cast<const RelLogicalUnion*>(ra_node)) {
1238  CHECK_GT(ra_node->inputCount(), 1u) << ra_node->toString();
1239  } else if (dynamic_cast<const RelTableFunction*>(ra_node)) {
1240  // no-op
1241  CHECK_GE(ra_node->inputCount(), 0u) << ra_node->toString();
1242  } else {
1243  CHECK_EQ(ra_node->inputCount(), 1u) << ra_node->toString();
1244  }
1245  return std::make_pair(std::unordered_set<const RexInput*>{},
1246  std::vector<std::shared_ptr<RexInput>>{});
1247 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
std::string join(T const &container, std::string const &delim)
#define CHECK_GE(x, y)
Definition: Logger.h:224
#define CHECK_GT(x, y)
Definition: Logger.h:223
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 3581 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().

3581  {
3582  auto sink = get_data_sink(ra);
3583  if (auto join = dynamic_cast<const RelJoin*>(sink)) {
3584  return join->getJoinType();
3585  }
3586  if (dynamic_cast<const RelLeftDeepInnerJoin*>(sink)) {
3587  return JoinType::INNER;
3588  }
3589 
3590  return JoinType::INVALID;
3591 }
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 3710 of file RelAlgExecutor.cpp.

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

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

3711  {
3712  std::vector<size_t> input_sizes;
3713  for (size_t i = 0; i < left_deep_join->inputCount(); ++i) {
3714  const auto inputs = get_node_output(left_deep_join->getInput(i));
3715  input_sizes.push_back(inputs.size());
3716  }
3717  return input_sizes;
3718 }
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 1592 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().

1592  {
1593  if (is_count_distinct(&expr)) {
1594  return SQLTypeInfo(kBIGINT, false);
1595  } else if (is_agg(&expr)) {
1597  }
1598  return get_logical_type_info(expr.get_type_info());
1599 }
bool is_agg(const Analyzer::Expr *expr)
SQLTypeInfo get_nullable_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1085
SQLTypeInfo get_logical_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1064
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 2682 of file RelAlgExecutor.cpp.

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

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

2682  {
2683  std::list<Analyzer::OrderEntry> result;
2684  for (size_t i = 0; i < sort->collationCount(); ++i) {
2685  const auto sort_field = sort->getCollation(i);
2686  result.emplace_back(sort_field.getField() + 1,
2687  sort_field.getSortDir() == SortDirection::Descending,
2688  sort_field.getNullsPosition() == NullSortedPosition::First);
2689  }
2690  return result;
2691 }
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 71 of file RelAlgExecutor.cpp.

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

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

+ Here is the call graph for this function:

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

Definition at line 4047 of file RelAlgExecutor.cpp.

References shared::transform().

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

4048  {
4049  std::vector<Analyzer::Expr*> output(input.size());
4050  auto const raw_ptr = [](auto& shared_ptr) { return shared_ptr.get(); };
4051  std::transform(input.cbegin(), input.cend(), output.begin(), raw_ptr);
4052  return output;
4053 }
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:290

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1349 of file RelAlgExecutor.cpp.

References RelCompound::getScalarSourcesSize().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1349  {
1350  return compound->getScalarSourcesSize();
1351 }
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 1353 of file RelAlgExecutor.cpp.

References RelProject::size().

1353  {
1354  return project->size();
1355 }
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 1357 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputsSize().

1357  {
1358  return table_func->getTableFuncInputsSize();
1359 }
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 2693 of file RelAlgExecutor.cpp.

Referenced by RelAlgExecutor::createSortInputWorkUnit().

2693  {
2694  const auto aggregate = dynamic_cast<const RelAggregate*>(ra);
2695  if (aggregate) {
2696  return 0;
2697  }
2698  const auto compound = dynamic_cast<const RelCompound*>(ra);
2699  return (compound && compound->isAggregate()) ? 0 : limit;
2700 }

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

2366  {
2367  auto shard_column_md = cat.getShardColumnMetadataForTable(td);
2368  CHECK(shard_column_md);
2369  auto sharded_column_id = shard_column_md->columnId;
2370  const TableDescriptor* shard{nullptr};
2371  for (size_t i = 0; i < data.columnIds.size(); ++i) {
2372  if (data.columnIds[i] == sharded_column_id) {
2373  const auto shard_tables = cat.getPhysicalTablesDescriptors(td);
2374  const auto shard_count = shard_tables.size();
2375  CHECK(data.data[i].numbersPtr);
2376  auto value = int_value_from_numbers_ptr(shard_column_md->columnType,
2377  data.data[i].numbersPtr);
2378  const size_t shard_idx = SHARD_FOR_KEY(value, shard_count);
2379  shard = shard_tables[shard_idx];
2380  break;
2381  }
2382  }
2383  return shard;
2384 }
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:4107
std::vector< const TableDescriptor * > getPhysicalTablesDescriptors(const TableDescriptor *logical_table_desc, bool populate_fragmenter=true) const
Definition: Catalog.cpp:4125
std::vector< DataBlockPtr > data
the number of rows being inserted
Definition: Fragmenter.h:71
#define CHECK(condition)
Definition: Logger.h:211
std::vector< int > columnIds
identifies the table into which the data is being inserted
Definition: Fragmenter.h:69
#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 1602 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().

1604  {
1605  std::vector<TargetMetaInfo> targets_meta;
1606  CHECK_EQ(ra_node->size(), target_exprs.size());
1607  for (size_t i = 0; i < ra_node->size(); ++i) {
1608  CHECK(target_exprs[i]);
1609  // TODO(alex): remove the count distinct type fixup.
1610  targets_meta.emplace_back(ra_node->getFieldName(i),
1611  get_logical_type_for_expr(*target_exprs[i]),
1612  target_exprs[i]->get_type_info());
1613  }
1614  return targets_meta;
1615 }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
SQLTypeInfo get_logical_type_for_expr(const Analyzer::Expr &expr)
#define CHECK(condition)
Definition: Logger.h:211

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

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

1620  {
1621  RelAlgNode const* input0 = filter->getInput(0);
1622  if (auto const* input = dynamic_cast<RelCompound const*>(input0)) {
1623  return get_targets_meta(input, target_exprs);
1624  } else if (auto const* input = dynamic_cast<RelProject const*>(input0)) {
1625  return get_targets_meta(input, target_exprs);
1626  } else if (auto const* input = dynamic_cast<RelLogicalUnion const*>(input0)) {
1627  return get_targets_meta(input, target_exprs);
1628  } else if (auto const* input = dynamic_cast<RelAggregate const*>(input0)) {
1629  return get_targets_meta(input, target_exprs);
1630  } else if (auto const* input = dynamic_cast<RelScan const*>(input0)) {
1631  return get_targets_meta(input, target_exprs);
1632  }
1633  UNREACHABLE() << "Unhandled node type: " << input0->toString();
1634  return {};
1635 }
#define UNREACHABLE()
Definition: Logger.h:255
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 1066 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().

1066  {
1067  RexUsedInputsVisitor visitor(cat);
1068  const auto filter_expr = compound->getFilterExpr();
1069  std::unordered_set<const RexInput*> used_inputs =
1070  filter_expr ? visitor.visit(filter_expr) : std::unordered_set<const RexInput*>{};
1071  const auto sources_size = compound->getScalarSourcesSize();
1072  for (size_t i = 0; i < sources_size; ++i) {
1073  const auto source_inputs = visitor.visit(compound->getScalarSource(i));
1074  used_inputs.insert(source_inputs.begin(), source_inputs.end());
1075  }
1076  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1077  return std::make_pair(used_inputs, used_inputs_owned);
1078 }
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 1081 of file RelAlgExecutor.cpp.

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

1081  {
1082  CHECK_EQ(size_t(1), aggregate->inputCount());
1083  std::unordered_set<const RexInput*> used_inputs;
1084  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1085  const auto source = aggregate->getInput(0);
1086  const auto& in_metainfo = source->getOutputMetainfo();
1087  const auto group_count = aggregate->getGroupByCount();
1088  CHECK_GE(in_metainfo.size(), group_count);
1089  for (size_t i = 0; i < group_count; ++i) {
1090  auto synthesized_used_input = new RexInput(source, i);
1091  used_inputs_owned.emplace_back(synthesized_used_input);
1092  used_inputs.insert(synthesized_used_input);
1093  }
1094  for (const auto& agg_expr : aggregate->getAggExprs()) {
1095  for (size_t i = 0; i < agg_expr->size(); ++i) {
1096  const auto operand_idx = agg_expr->getOperand(i);
1097  CHECK_GE(in_metainfo.size(), static_cast<size_t>(operand_idx));
1098  auto synthesized_used_input = new RexInput(source, operand_idx);
1099  used_inputs_owned.emplace_back(synthesized_used_input);
1100  used_inputs.insert(synthesized_used_input);
1101  }
1102  }
1103  return std::make_pair(used_inputs, used_inputs_owned);
1104 }
const size_t getGroupByCount() const
#define CHECK_EQ(x, y)
Definition: Logger.h:219
#define CHECK_GE(x, y)
Definition: Logger.h:224
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 1107 of file RelAlgExecutor.cpp.

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

1107  {
1108  RexUsedInputsVisitor visitor(cat);
1109  std::unordered_set<const RexInput*> used_inputs;
1110  for (size_t i = 0; i < project->size(); ++i) {
1111  const auto proj_inputs = visitor.visit(project->getProjectAt(i));
1112  used_inputs.insert(proj_inputs.begin(), proj_inputs.end());
1113  }
1114  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1115  return std::make_pair(used_inputs, used_inputs_owned);
1116 }
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 1119 of file RelAlgExecutor.cpp.

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

1120  {
1121  RexUsedInputsVisitor visitor(cat);
1122  std::unordered_set<const RexInput*> used_inputs;
1123  for (size_t i = 0; i < table_func->getTableFuncInputsSize(); ++i) {
1124  const auto table_func_inputs = visitor.visit(table_func->getTableFuncInputAt(i));
1125  used_inputs.insert(table_func_inputs.begin(), table_func_inputs.end());
1126  }
1127  std::vector<std::shared_ptr<RexInput>> used_inputs_owned(visitor.get_inputs_owned());
1128  return std::make_pair(used_inputs, used_inputs_owned);
1129 }
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 1132 of file RelAlgExecutor.cpp.

References CHECK, get_data_sink(), and i.

1132  {
1133  std::unordered_set<const RexInput*> used_inputs;
1134  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1135  const auto data_sink_node = get_data_sink(filter);
1136  for (size_t nest_level = 0; nest_level < data_sink_node->inputCount(); ++nest_level) {
1137  const auto source = data_sink_node->getInput(nest_level);
1138  const auto scan_source = dynamic_cast<const RelScan*>(source);
1139  if (scan_source) {
1140  CHECK(source->getOutputMetainfo().empty());
1141  for (size_t i = 0; i < scan_source->size(); ++i) {
1142  auto synthesized_used_input = new RexInput(scan_source, i);
1143  used_inputs_owned.emplace_back(synthesized_used_input);
1144  used_inputs.insert(synthesized_used_input);
1145  }
1146  } else {
1147  const auto& partial_in_metadata = source->getOutputMetainfo();
1148  for (size_t i = 0; i < partial_in_metadata.size(); ++i) {
1149  auto synthesized_used_input = new RexInput(source, i);
1150  used_inputs_owned.emplace_back(synthesized_used_input);
1151  used_inputs.insert(synthesized_used_input);
1152  }
1153  }
1154  }
1155  return std::make_pair(used_inputs, used_inputs_owned);
1156 }
#define CHECK(condition)
Definition: Logger.h:211
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 1159 of file RelAlgExecutor.cpp.

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

1159  {
1160  std::unordered_set<const RexInput*> used_inputs(logical_union->inputCount());
1161  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
1162  used_inputs_owned.reserve(logical_union->inputCount());
1163  VLOG(3) << "logical_union->inputCount()=" << logical_union->inputCount();
1164  auto const n_inputs = logical_union->inputCount();
1165  for (size_t nest_level = 0; nest_level < n_inputs; ++nest_level) {
1166  auto input = logical_union->getInput(nest_level);
1167  for (size_t i = 0; i < input->size(); ++i) {
1168  used_inputs_owned.emplace_back(std::make_shared<RexInput>(input, i));
1169  used_inputs.insert(used_inputs_owned.back().get());
1170  }
1171  }
1172  return std::make_pair(std::move(used_inputs), std::move(used_inputs_owned));
1173 }
const RelAlgNode * getInput(const size_t idx) const
const size_t inputCount() const
#define VLOG(n)
Definition: Logger.h:305

+ Here is the call graph for this function:

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

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

3483  {
3484  // 'designated initializers' don't compile on Windows for std 17
3485  // They require /std:c++20. They been removed for the windows port.
3486  switch (error_code) {
3488  return {"ERR_DIV_BY_ZERO", "Division by zero"};
3490  return {"ERR_OUT_OF_GPU_MEM",
3491 
3492  "Query couldn't keep the entire working set of columns in GPU memory"};
3494  return {"ERR_UNSUPPORTED_SELF_JOIN", "Self joins not supported yet"};
3496  return {"ERR_OUT_OF_CPU_MEM", "Not enough host memory to execute the query"};
3498  return {"ERR_OVERFLOW_OR_UNDERFLOW", "Overflow or underflow"};
3500  return {"ERR_OUT_OF_TIME", "Query execution has exceeded the time limit"};
3502  return {"ERR_INTERRUPTED", "Query execution has been interrupted"};
3504  return {"ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED",
3505  "Columnar conversion not supported for variable length types"};
3507  return {"ERR_TOO_MANY_LITERALS", "Too many literals in the query"};
3509  return {"ERR_STRING_CONST_IN_RESULTSET",
3510 
3511  "NONE ENCODED String types are not supported as input result set."};
3513  return {"ERR_OUT_OF_RENDER_MEM",
3514 
3515  "Insufficient GPU memory for query results in render output buffer "
3516  "sized by render-mem-bytes"};
3518  return {"ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY",
3519  "Streaming-Top-N not supported in Render Query"};
3521  return {"ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES",
3522  "Multiple distinct values encountered"};
3523  case Executor::ERR_GEOS:
3524  return {"ERR_GEOS", "ERR_GEOS"};
3526  return {"ERR_WIDTH_BUCKET_INVALID_ARGUMENT",
3527 
3528  "Arguments of WIDTH_BUCKET function does not satisfy the condition"};
3529  default:
3530  return {nullptr, nullptr};
3531  }
3532 }
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1172
static const int32_t ERR_GEOS
Definition: Execute.h:1178
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1174
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1175
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1176
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1173
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1164
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1168
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1170
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1171
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1167
static const int32_t ERR_SINGLE_VALUE_FOUND_MULTIPLE_VALUES
Definition: Execute.h:1177
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1165
static const int32_t ERR_WIDTH_BUCKET_INVALID_ARGUMENT
Definition: Execute.h:1179
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1169

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

References CHECK.

Referenced by RelAlgExecutor::executeWorkUnit().

2905  {
2906  CHECK(!table_infos.empty());
2907  const auto& first_table = table_infos.front();
2908  size_t max_num_groups = first_table.info.getNumTuplesUpperBound();
2909  for (const auto& table_info : table_infos) {
2910  if (table_info.info.getNumTuplesUpperBound() > max_num_groups) {
2911  max_num_groups = table_info.info.getNumTuplesUpperBound();
2912  }
2913  }
2914  return std::max(max_num_groups, size_t(1));
2915 }
#define CHECK(condition)
Definition: Logger.h:211

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

2266  {
2267  if (col_cv->get_is_null()) {
2268  *col_data = inline_fixed_encoding_null_val(columnType);
2269  } else {
2270  const int dict_id = columnType.get_comp_param();
2271  const auto col_datum = col_cv->get_constval();
2272  const auto& str = *col_datum.stringval;
2273  const auto dd = catalog.getMetadataForDict(dict_id);
2274  CHECK(dd && dd->stringDict);
2275  int32_t str_id = dd->stringDict->getOrAdd(str);
2276  if (!dd->dictIsTemp) {
2277  const auto checkpoint_ok = dd->stringDict->checkpoint();
2278  if (!checkpoint_ok) {
2279  throw std::runtime_error("Failed to checkpoint dictionary for column " +
2280  columnName);
2281  }
2282  }
2283  const bool invalid = str_id > max_valid_int_value<T>();
2284  if (invalid || str_id == inline_int_null_value<int32_t>()) {
2285  if (invalid) {
2286  LOG(ERROR) << "Could not encode string: " << str
2287  << ", the encoded value doesn't fit in " << sizeof(T) * 8
2288  << " bits. Will store NULL instead.";
2289  }
2290  str_id = inline_fixed_encoding_null_val(columnType);
2291  }
2292  *col_data = str_id;
2293  }
2294  return *col_data;
2295 }
#define LOG(tag)
Definition: Logger.h:205
bool get_is_null() const
Definition: Analyzer.h:333
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1554
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:211
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 2298 of file RelAlgExecutor.cpp.

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

2301  {
2302  return insert_one_dict_str(col_data, cd->columnName, cd->columnType, col_cv, catalog);
2303 }
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 2327 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().

2327  {
2328  size_t sz = 0;
2329  switch (type_info.get_type()) {
2330  case kTINYINT:
2331  case kSMALLINT:
2332  case kINT:
2333  case kBIGINT:
2334  case kTIMESTAMP:
2335  case kTIME:
2336  case kDATE:
2337  sz = type_info.get_logical_size();
2338  break;
2339  case kTEXT:
2340  case kVARCHAR:
2341  case kCHAR:
2342  CHECK(type_info.get_compression() == kENCODING_DICT);
2343  sz = type_info.get_size();
2344  break;
2345  default:
2346  CHECK(false) << "Unexpected sharding key datatype";
2347  }
2348 
2349  switch (sz) {
2350  case 1:
2351  return *(reinterpret_cast<const int8_t*>(data));
2352  case 2:
2353  return *(reinterpret_cast<const int16_t*>(data));
2354  case 4:
2355  return *(reinterpret_cast<const int32_t*>(data));
2356  case 8:
2357  return *(reinterpret_cast<const int64_t*>(data));
2358  default:
2359  CHECK(false);
2360  return 0;
2361  }
2362 }
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:349
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:211
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 1580 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().

1580  {
1581  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1582  if (agg_expr && agg_expr->get_contains_agg()) {
1583  auto agg_type = agg_expr->get_aggtype();
1584  if (agg_type == SQLAgg::kMIN || agg_type == SQLAgg::kMAX ||
1585  agg_type == SQLAgg::kSUM || agg_type == SQLAgg::kAVG) {
1586  return true;
1587  }
1588  }
1589  return false;
1590 }
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 1575 of file RelAlgExecutor.cpp.

References Analyzer::AggExpr::get_is_distinct().

Referenced by get_logical_type_for_expr().

1575  {
1576  const auto agg_expr = dynamic_cast<const Analyzer::AggExpr*>(expr);
1577  return agg_expr && agg_expr->get_is_distinct();
1578 }
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 205 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().

205  {
206  return !dag.contain_not_supported_rel_node &&
207  dag.extracted_dag.compare(EMPTY_QUERY_PLAN) != 0;
208 }
const QueryPlan extracted_dag
constexpr char const * EMPTY_QUERY_PLAN

+ Here is the caller graph for this function:

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

Definition at line 2917 of file RelAlgExecutor.cpp.

References RelAlgExecutionUnit::groupby_exprs.

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

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

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

References RelAlgExecutionUnit::target_exprs.

Referenced by RelAlgExecutor::executeWorkUnit().

1921  {
1922  return std::any_of(ra_exe_unit.target_exprs.begin(),
1923  ra_exe_unit.target_exprs.end(),
1924  [](const Analyzer::Expr* expr) {
1925  return dynamic_cast<const Analyzer::WindowFunction*>(expr);
1926  });
1927 }
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 3661 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().

3661  {
3662  CHECK_GE(left_deep_join->inputCount(), size_t(2));
3663  std::vector<JoinType> join_types(left_deep_join->inputCount() - 1, JoinType::INNER);
3664  for (size_t nesting_level = 1; nesting_level <= left_deep_join->inputCount() - 1;
3665  ++nesting_level) {
3666  if (left_deep_join->getOuterCondition(nesting_level)) {
3667  join_types[nesting_level - 1] = JoinType::LEFT;
3668  }
3669  auto cur_level_join_type = left_deep_join->getJoinType(nesting_level);
3670  if (cur_level_join_type == JoinType::SEMI || cur_level_join_type == JoinType::ANTI) {
3671  join_types[nesting_level - 1] = cur_level_join_type;
3672  }
3673  }
3674  return join_types;
3675 }
const RexScalar * getOuterCondition(const size_t nesting_level) const
#define CHECK_GE(x, y)
Definition: Logger.h:224
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 3885 of file RelAlgExecutor.cpp.

Referenced by reverse_logical_distribution().

3886  {
3887  for (const auto& qual : haystack) {
3888  if (*qual == *needle) {
3889  return true;
3890  }
3891  }
3892  return false;
3893 }

+ Here is the caller graph for this function:

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

Definition at line 65 of file RelAlgExecutor.cpp.

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

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

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

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

Referenced by RelAlgExecutor::executeRelAlgQueryNoRetry().

164  {
166  std::map<int32_t, std::vector<int32_t>> system_table_columns_by_table_id;
167  for (const auto& physical_input : get_physical_inputs(&ra_node)) {
168  int table_id = physical_input.table_id;
169  auto table = catalog.getMetadataForTable(table_id, false);
170  if (table && table->is_system_table) {
171  auto column_id = catalog.getColumnIdBySpi(table_id, physical_input.col_id);
172  system_table_columns_by_table_id[table_id].emplace_back(column_id);
173  }
174  }
175  // Execute on CPU for queries involving system tables
176  if (!system_table_columns_by_table_id.empty() &&
178  throw QueryMustRunOnCpu();
179  }
180 
181  for (const auto& [table_id, column_ids] : system_table_columns_by_table_id) {
182  // Clear any previously cached data, since system tables depend on point in
183  // time data snapshots.
185  ChunkKey{catalog.getDatabaseId(), table_id}, Data_Namespace::CPU_LEVEL);
186  auto td = catalog.getMetadataForTable(table_id);
187  CHECK(td);
188  CHECK(td->fragmenter);
189  auto fragment_count = td->fragmenter->getFragmentsForQuery().fragments.size();
190  CHECK_LE(fragment_count, static_cast<size_t>(1));
191  if (fragment_count > 0) {
192  for (auto column_id : column_ids) {
193  // Prefetch system table chunks in order to force chunk statistics metadata
194  // computation.
195  auto cd = catalog.getMetadataForColumn(table_id, column_id);
196  ChunkKey chunk_key{catalog.getDatabaseId(), table_id, column_id, 0};
198  cd, &(catalog.getDataMgr()), chunk_key, Data_Namespace::CPU_LEVEL, 0, 0, 0);
199  }
200  }
201  }
202  }
203 }
std::vector< int > ChunkKey
Definition: types.h:37
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:226
bool g_enable_system_tables
Definition: SysCatalog.cpp:65
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
int getDatabaseId() const
Definition: Catalog.h:281
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:30
ExecutorDeviceType device_type
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:493
#define CHECK_LE(x, y)
Definition: Logger.h:222
#define CHECK(condition)
Definition: Logger.h:211
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)
const int getColumnIdBySpi(const int tableId, const size_t spi) const
Definition: Catalog.cpp:1635

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

References prepare_string_dictionaries(), and set_parallelism_hints().

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

154  {
155  // Iterate through ra_node inputs for types that need to be loaded pre-execution
156  // If they do not have valid metadata, load them into CPU memory to generate
157  // the metadata and leave them ready to be used by the query
158  set_parallelism_hints(ra_node, catalog);
159  prepare_string_dictionaries(ra_node, catalog);
160 }
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 118 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().

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

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

3899  {
3900  const auto expr_terms = qual_to_disjunctive_form(expr);
3901  CHECK_GE(expr_terms.size(), size_t(1));
3902  const auto& first_term = expr_terms.front();
3903  const auto first_term_factors = qual_to_conjunctive_form(first_term);
3904  std::vector<std::shared_ptr<Analyzer::Expr>> common_factors;
3905  // First, collect the conjunctive components common to all the disjunctive components.
3906  // Don't do it for simple qualifiers, we only care about expensive or join qualifiers.
3907  for (const auto& first_term_factor : first_term_factors.quals) {
3908  bool is_common =
3909  expr_terms.size() > 1; // Only report common factors for disjunction.
3910  for (size_t i = 1; i < expr_terms.size(); ++i) {
3911  const auto crt_term_factors = qual_to_conjunctive_form(expr_terms[i]);
3912  if (!list_contains_expression(crt_term_factors.quals, first_term_factor)) {
3913  is_common = false;
3914  break;
3915  }
3916  }
3917  if (is_common) {
3918  common_factors.push_back(first_term_factor);
3919  }
3920  }
3921  if (common_factors.empty()) {
3922  return expr;
3923  }
3924  // Now that the common expressions are known, collect the remaining expressions.
3925  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_terms;
3926  for (const auto& term : expr_terms) {
3927  const auto term_cf = qual_to_conjunctive_form(term);
3928  std::vector<std::shared_ptr<Analyzer::Expr>> remaining_quals(
3929  term_cf.simple_quals.begin(), term_cf.simple_quals.end());
3930  for (const auto& qual : term_cf.quals) {
3931  if (!list_contains_expression(common_factors, qual)) {
3932  remaining_quals.push_back(qual);
3933  }
3934  }
3935  if (!remaining_quals.empty()) {
3936  remaining_terms.push_back(build_logical_expression(remaining_quals, kAND));
3937  }
3938  }
3939  // Reconstruct the expression with the transformation applied.
3940  const auto common_expr = build_logical_expression(common_factors, kAND);
3941  if (remaining_terms.empty()) {
3942  return common_expr;
3943  }
3944  const auto remaining_expr = build_logical_expression(remaining_terms, kOR);
3945  return Parser::OperExpr::normalize(kAND, kONE, common_expr, remaining_expr);
3946 }
Definition: sqldefs.h:38
#define CHECK_GE(x, y)
Definition: Logger.h:224
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:307
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 3720 of file RelAlgExecutor.cpp.

References rewrite_expr().

Referenced by RelAlgExecutor::createCompoundWorkUnit().

3721  {
3722  std::list<std::shared_ptr<Analyzer::Expr>> rewritten_quals;
3723  for (const auto& qual : quals) {
3724  const auto rewritten_qual = rewrite_expr(qual.get());
3725  rewritten_quals.push_back(rewritten_qual ? rewritten_qual : qual);
3726  }
3727  return rewritten_quals;
3728 }
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 3858 of file RelAlgExecutor.cpp.

References CHECK, CHECK_GE, i, and kAND.

Referenced by RelAlgExecutor::makeJoinQuals().

3858  {
3859  CHECK(qual_expr);
3860  const auto bin_oper = dynamic_cast<const RexOperator*>(qual_expr);
3861  if (!bin_oper || bin_oper->getOperator() != kAND) {
3862  return {qual_expr};
3863  }
3864  CHECK_GE(bin_oper->size(), size_t(2));
3865  auto lhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(0));
3866  for (size_t i = 1; i < bin_oper->size(); ++i) {
3867  const auto rhs_cf = rex_to_conjunctive_form(bin_oper->getOperand(i));
3868  lhs_cf.insert(lhs_cf.end(), rhs_cf.begin(), rhs_cf.end());
3869  }
3870  return lhs_cf;
3871 }
#define CHECK_GE(x, y)
Definition: Logger.h:224
std::vector< const RexScalar * > rex_to_conjunctive_form(const RexScalar *qual_expr)
Definition: sqldefs.h:37
#define CHECK(condition)
Definition: Logger.h:211

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

References RelCompound::getScalarSource().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1361  {
1362  return compound->getScalarSource(i);
1363 }
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 1365 of file RelAlgExecutor.cpp.

References RelProject::getProjectAt().

1365  {
1366  return project->getProjectAt(i);
1367 }
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 1369 of file RelAlgExecutor.cpp.

References RelTableFunction::getTableFuncInputAt().

1369  {
1370  return table_func->getTableFuncInputAt(i);
1371 }
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 83 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().

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

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

1374  {
1375  const auto& ti = expr->get_type_info();
1376  if (!ti.is_string() || ti.get_compression() != kENCODING_NONE) {
1377  return expr;
1378  }
1379  auto transient_dict_ti = ti;
1380  transient_dict_ti.set_compression(kENCODING_DICT);
1381  transient_dict_ti.set_comp_param(TRANSIENT_DICT_ID);
1382  transient_dict_ti.set_fixed_size();
1383  return expr->add_cast(transient_dict_ti);
1384 }
#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 1386 of file RelAlgExecutor.cpp.

References fold_expr(), and set_transient_dict().

Referenced by translate_scalar_sources(), and translate_scalar_sources_for_update().

1388  {
1389  try {
1390  scalar_sources.push_back(set_transient_dict(fold_expr(expr.get())));
1391  } catch (...) {
1392  scalar_sources.push_back(fold_expr(expr.get()));
1393  }
1394 }
std::shared_ptr< Analyzer::Expr > set_transient_dict(const std::shared_ptr< Analyzer::Expr > expr)
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2921 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::executeWorkUnit().

2922  {
2923  if (!is_projection(ra_exe_unit)) {
2924  return false;
2925  }
2926  if (render_info && render_info->isPotentialInSituRender()) {
2927  return false;
2928  }
2929  if (!ra_exe_unit.sort_info.order_entries.empty()) {
2930  // disable output columnar when we have top-sort node query
2931  return false;
2932  }
2933  return ra_exe_unit.scan_limit >= g_columnar_large_projections_threshold;
2934 }
const std::list< Analyzer::OrderEntry > order_entries
bool is_projection(const RelAlgExecutionUnit &ra_exe_unit)
bool isPotentialInSituRender() const
Definition: RenderInfo.cpp:63
size_t g_columnar_large_projections_threshold

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

4025  {
4026  CHECK_LE(size_t(1), ra_node->inputCount());
4027  CHECK_GE(size_t(2), ra_node->inputCount());
4028  const auto input = ra_node->getInput(nest_level);
4029  const auto it_rte_idx = input_to_nest_level.find(input);
4030  CHECK(it_rte_idx != input_to_nest_level.end());
4031  const int rte_idx = it_rte_idx->second;
4032  const int table_id = table_id_from_ra(input);
4033  std::vector<std::shared_ptr<Analyzer::Expr>> inputs;
4034  const auto scan_ra = dynamic_cast<const RelScan*>(input);
4035  int input_idx = 0;
4036  for (const auto& input_meta : in_metainfo) {
4037  inputs.push_back(
4038  std::make_shared<Analyzer::ColumnVar>(input_meta.get_type_info(),
4039  table_id,
4040  scan_ra ? input_idx + 1 : input_idx,
4041  rte_idx));
4042  ++input_idx;
4043  }
4044  return inputs;
4045 }
#define CHECK_GE(x, y)
Definition: Logger.h:224
const RelAlgNode * getInput(const size_t idx) const
#define CHECK_LE(x, y)
Definition: Logger.h:222
int table_id_from_ra(const RelAlgNode *ra_node)
#define CHECK(condition)
Definition: Logger.h:211
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 1175 of file RelAlgExecutor.cpp.

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

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

1175  {
1176  const auto scan_ra = dynamic_cast<const RelScan*>(ra_node);
1177  if (scan_ra) {
1178  const auto td = scan_ra->getTableDescriptor();
1179  CHECK(td);
1180  return td->tableId;
1181  }
1182  return -ra_node->getId();
1183 }
unsigned getId() const
#define CHECK(condition)
Definition: Logger.h:211
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 4230 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createUnionWorkUnit().

4231  {
4232  std::vector<TargetMetaInfo> const& tmis = input_node->getOutputMetainfo();
4233  VLOG(3) << "input_node->getOutputMetainfo()=" << shared::printContainer(tmis);
4234  const int negative_node_id = -input_node->getId();
4235  std::vector<std::shared_ptr<Analyzer::Expr>> target_exprs;
4236  target_exprs.reserve(tmis.size());
4237  for (size_t i = 0; i < tmis.size(); ++i) {
4238  target_exprs.push_back(std::make_shared<Analyzer::ColumnVar>(
4239  tmis[i].get_type_info(), negative_node_id, i, 0));
4240  }
4241  return target_exprs;
4242 }
PrintContainer< CONTAINER > printContainer(CONTAINER &container)
Definition: misc.h:106
#define VLOG(n)
Definition: Logger.h:305

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

Referenced by RelAlgExecutor::computeWindow().

2016  {
2017  const auto tuple = dynamic_cast<const Analyzer::ExpressionTuple*>(expr);
2018  if (tuple) {
2019  std::vector<std::shared_ptr<Analyzer::Expr>> transformed_tuple;
2020  for (const auto& element : tuple->getTuple()) {
2021  transformed_tuple.push_back(transform_to_inner(element.get()));
2022  }
2023  return makeExpr<Analyzer::ExpressionTuple>(transformed_tuple);
2024  }
2025  const auto col = dynamic_cast<const Analyzer::ColumnVar*>(expr);
2026  if (!col) {
2027  throw std::runtime_error("Only columns supported in the window partition for now");
2028  }
2029  return makeExpr<Analyzer::ColumnVar>(
2030  col->get_type_info(), col->get_table_id(), col->get_column_id(), 1);
2031 }
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 1471 of file RelAlgExecutor.cpp.

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

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

1473  {
1474  if (!compound->isAggregate()) {
1475  return {nullptr};
1476  }
1477  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1478  for (size_t group_idx = 0; group_idx < compound->getGroupByCount(); ++group_idx) {
1479  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1480  }
1481  return groupby_exprs;
1482 }
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 1484 of file RelAlgExecutor.cpp.

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

1486  {
1487  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1488  for (size_t group_idx = 0; group_idx < aggregate->getGroupByCount(); ++group_idx) {
1489  groupby_exprs.push_back(set_transient_dict(scalar_sources[group_idx]));
1490  }
1491  return groupby_exprs;
1492 }
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 1494 of file RelAlgExecutor.cpp.

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

Referenced by RelAlgExecutor::createCompoundWorkUnit().

1495  {
1496  const auto filter_rex = compound->getFilterExpr();
1497  const auto filter_expr =
1498  filter_rex ? translator.translateScalarRex(filter_rex) : nullptr;
1499  return filter_expr ? qual_to_conjunctive_form(fold_expr(filter_expr.get()))
1501 }
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 1406 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().

1409  {
1410  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1411  const size_t scalar_sources_size = get_scalar_sources_size(ra_node);
1412  VLOG(3) << "get_scalar_sources_size(" << ra_node->toString()
1413  << ") = " << scalar_sources_size;
1414  for (size_t i = 0; i < scalar_sources_size; ++i) {
1415  const auto scalar_rex = scalar_at(i, ra_node);
1416  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1417  // RexRef are synthetic scalars we append at the end of the real ones
1418  // for the sake of taking memory ownership, no real work needed here.
1419  continue;
1420  }
1421 
1422  const auto scalar_expr =
1423  rewrite_array_elements(translator.translateScalarRex(scalar_rex).get());
1424  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1425  if (executor_type == ExecutorType::Native) {
1426  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1427  } else if (executor_type == ExecutorType::TableFunctions) {
1428  scalar_sources.push_back(fold_expr(rewritten_expr.get()));
1429  } else {
1430  scalar_sources.push_back(cast_dict_to_none(fold_expr(rewritten_expr.get())));
1431  }
1432  }
1433 
1434  return scalar_sources;
1435 }
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:305
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 1438 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().

1444  {
1445  std::vector<std::shared_ptr<Analyzer::Expr>> scalar_sources;
1446  for (size_t i = 0; i < get_scalar_sources_size(ra_node); ++i) {
1447  const auto scalar_rex = scalar_at(i, ra_node);
1448  if (dynamic_cast<const RexRef*>(scalar_rex)) {
1449  // RexRef are synthetic scalars we append at the end of the real ones
1450  // for the sake of taking memory ownership, no real work needed here.
1451  continue;
1452  }
1453 
1454  std::shared_ptr<Analyzer::Expr> translated_expr;
1455  if (i >= starting_projection_column_idx && i < get_scalar_sources_size(ra_node) - 1) {
1456  translated_expr = cast_to_column_type(translator.translateScalarRex(scalar_rex),
1457  tableId,
1458  cat,
1459  colNames[i - starting_projection_column_idx]);
1460  } else {
1461  translated_expr = translator.translateScalarRex(scalar_rex);
1462  }
1463  const auto scalar_expr = rewrite_array_elements(translated_expr.get());
1464  const auto rewritten_expr = rewrite_expr(scalar_expr.get());
1465  set_transient_dict_maybe(scalar_sources, rewritten_expr);
1466  }
1467 
1468  return scalar_sources;
1469 }
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 1503 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().

1509  {
1510  std::vector<Analyzer::Expr*> target_exprs;
1511  for (size_t i = 0; i < compound->size(); ++i) {
1512  const auto target_rex = compound->getTargetExpr(i);
1513  const auto target_rex_agg = dynamic_cast<const RexAgg*>(target_rex);
1514  std::shared_ptr<Analyzer::Expr> target_expr;
1515  if (target_rex_agg) {
1516  target_expr =
1517  RelAlgTranslator::translateAggregateRex(target_rex_agg, scalar_sources);
1518  } else {
1519  const auto target_rex_scalar = dynamic_cast<const RexScalar*>(target_rex);
1520  const auto target_rex_ref = dynamic_cast<const RexRef*>(target_rex_scalar);
1521  if (target_rex_ref) {
1522  const auto ref_idx = target_rex_ref->getIndex();
1523  CHECK_GE(ref_idx, size_t(1));
1524  CHECK_LE(ref_idx, groupby_exprs.size());
1525  const auto groupby_expr = *std::next(groupby_exprs.begin(), ref_idx - 1);
1526  target_expr = var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, ref_idx);
1527  } else {
1528  target_expr = translator.translateScalarRex(target_rex_scalar);
1529  auto rewritten_expr = rewrite_expr(target_expr.get());
1530  target_expr = fold_expr(rewritten_expr.get());
1531  if (executor_type == ExecutorType::Native) {
1532  try {
1533  target_expr = set_transient_dict(target_expr);
1534  } catch (...) {
1535  // noop
1536  }
1537  } else {
1538  target_expr = cast_dict_to_none(target_expr);
1539  }
1540  }
1541  }
1542  CHECK(target_expr);
1543  target_exprs_owned.push_back(target_expr);
1544  target_exprs.push_back(target_expr.get());
1545  }
1546  return target_exprs;
1547 }
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:224
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:222
#define CHECK(condition)
Definition: Logger.h:211
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 1549 of file RelAlgExecutor.cpp.

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

1554  {
1555  std::vector<Analyzer::Expr*> target_exprs;
1556  size_t group_key_idx = 1;
1557  for (const auto& groupby_expr : groupby_exprs) {
1558  auto target_expr =
1559  var_ref(groupby_expr.get(), Analyzer::Var::kGROUPBY, group_key_idx++);
1560  target_exprs_owned.push_back(target_expr);
1561  target_exprs.push_back(target_expr.get());
1562  }
1563 
1564  for (const auto& target_rex_agg : aggregate->getAggExprs()) {
1565  auto target_expr =
1566  RelAlgTranslator::translateAggregateRex(target_rex_agg.get(), scalar_sources);
1567  CHECK(target_expr);
1568  target_expr = fold_expr(target_expr.get());
1569  target_exprs_owned.push_back(target_expr);
1570  target_exprs.push_back(target_expr.get());
1571  }
1572  return target_exprs;
1573 }
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:211
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: