OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelAlgExecutor Class Reference

#include <RelAlgExecutor.h>

+ Inheritance diagram for RelAlgExecutor:
+ Collaboration diagram for RelAlgExecutor:

Classes

struct  TableFunctionWorkUnit
 
struct  WorkUnit
 

Public Types

using TargetInfoList = std::vector< TargetInfo >
 

Public Member Functions

 RelAlgExecutor (Executor *executor, const Catalog_Namespace::Catalog &cat)
 
ExecutionResult executeRelAlgQuery (const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
 
ExecutionResult executeRelAlgQueryWithFilterPushDown (const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
 
void prepareLeafExecution (const AggregatedColRange &agg_col_range, const StringDictionaryGenerations &string_dictionary_generations, const TableGenerations &table_generations)
 
ExecutionResult executeRelAlgSeq (const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms, const bool with_existing_temp_tables=false)
 
ExecutionResult executeRelAlgSubSeq (const RaExecutionSequence &seq, const std::pair< size_t, size_t > interval, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
 
FirstStepExecutionResult executeRelAlgQuerySingleStep (const RaExecutionSequence &seq, const size_t step_idx, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
 
void addLeafResult (const unsigned id, const AggregatedResult &result)
 
void registerSubquery (std::shared_ptr< RexSubQuery > subquery) noexcept
 
const std::vector
< std::shared_ptr< RexSubQuery > > & 
getSubqueries () const noexcept
 
AggregatedColRange computeColRangesCache (const RelAlgNode *ra)
 
StringDictionaryGenerations computeStringDictionaryGenerations (const RelAlgNode *ra)
 
TableGenerations computeTableGenerations (const RelAlgNode *ra)
 
ExecutorgetExecutor () const
 
void cleanupPostExecution ()
 

Static Public Member Functions

static std::string getErrorMessageFromCode (const int32_t error_code)
 

Private Member Functions

ExecutionResult executeRelAlgQueryNoRetry (const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
 
void executeRelAlgStep (const RaExecutionSequence &seq, const size_t step_idx, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
 
void executeUpdateViaCompound (const RelCompound *compound, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
 
void executeUpdateViaProject (const RelProject *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
 
void executeDeleteViaCompound (const RelCompound *compound, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
 
void executeDeleteViaProject (const RelProject *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
 
ExecutionResult executeCompound (const RelCompound *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
 
ExecutionResult executeAggregate (const RelAggregate *aggregate, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
 
ExecutionResult executeProject (const RelProject *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count)
 
ExecutionResult executeTableFunction (const RelTableFunction *, const CompilationOptions &, const ExecutionOptions &, const int64_t queue_time_ms)
 
void computeWindow (const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const ExecutionOptions &eo, ColumnCacheMap &column_cache_map, const int64_t queue_time_ms)
 
std::unique_ptr
< WindowFunctionContext
createWindowFunctionContext (const Analyzer::WindowFunction *window_func, const std::shared_ptr< Analyzer::BinOper > &partition_key_cond, const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos, const CompilationOptions &co, ColumnCacheMap &column_cache_map)
 
ExecutionResult executeFilter (const RelFilter *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
 
ExecutionResult executeSort (const RelSort *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
 
ExecutionResult executeLogicalValues (const RelLogicalValues *, const ExecutionOptions &)
 
ExecutionResult executeModify (const RelModify *modify, const ExecutionOptions &eo)
 
WorkUnit createSortInputWorkUnit (const RelSort *, const bool just_explain)
 
ExecutionResult executeWorkUnit (const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
 
size_t getNDVEstimation (const WorkUnit &work_unit, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo)
 
ssize_t getFilteredCountAll (const WorkUnit &work_unit, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo)
 
FilterSelectivity getFilterSelectivity (const std::vector< std::shared_ptr< Analyzer::Expr >> &filter_expressions, const CompilationOptions &co, const ExecutionOptions &eo)
 
std::vector< PushedDownFilterInfoselectFiltersToBePushedDown (const RelAlgExecutor::WorkUnit &work_unit, const CompilationOptions &co, const ExecutionOptions &eo)
 
bool isRowidLookup (const WorkUnit &work_unit)
 
ExecutionResult handleOutOfMemoryRetry (const RelAlgExecutor::WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const bool was_multifrag_kernel_launch, const int64_t queue_time_ms)
 
WorkUnit createWorkUnit (const RelAlgNode *, const SortInfo &, const bool just_explain)
 
WorkUnit createModifyCompoundWorkUnit (const RelCompound *compound, const SortInfo &sort_info, const bool just_explain)
 
WorkUnit createCompoundWorkUnit (const RelCompound *, const SortInfo &, const bool just_explain)
 
WorkUnit createAggregateWorkUnit (const RelAggregate *, const SortInfo &, const bool just_explain)
 
WorkUnit createModifyProjectWorkUnit (const RelProject *project, const SortInfo &sort_info, const bool just_explain)
 
WorkUnit createProjectWorkUnit (const RelProject *, const SortInfo &, const bool just_explain)
 
WorkUnit createFilterWorkUnit (const RelFilter *, const SortInfo &, const bool just_explain)
 
WorkUnit createJoinWorkUnit (const RelJoin *, const SortInfo &, const bool just_explain)
 
TableFunctionWorkUnit createTableFunctionWorkUnit (const RelTableFunction *table_func, const bool just_explain)
 
void addTemporaryTable (const int table_id, const ResultSetPtr &result)
 
void eraseFromTemporaryTables (const int table_id)
 
void handleNop (RaExecutionDesc &ed)
 
JoinQualsPerNestingLevel translateLeftDeepJoinFilter (const RelLeftDeepInnerJoin *join, const std::vector< InputDescriptor > &input_descs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
makeJoinQuals (const RexScalar *join_condition, const std::vector< JoinType > &join_types, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain) const
 
- Private Member Functions inherited from StorageIOFacility< RelAlgExecutorTraits >
 StorageIOFacility (ExecutorType *executor, CatalogType const &catalog)
 
ColumnValidationFunction yieldColumnValidator (TableDescriptorType const *table_descriptor)
 
UpdateCallback yieldUpdateCallback (UpdateTransactionParameters &update_parameters)
 
UpdateCallback yieldDeleteCallback (DeleteTransactionParameters &delete_parameters)
 

Static Private Member Functions

static void handlePersistentError (const int32_t error_code)
 

Private Attributes

Executorexecutor_
 
const Catalog_Namespace::Catalogcat_
 
TemporaryTables temporary_tables_
 
time_t now_
 
std::vector< std::shared_ptr
< Analyzer::Expr > > 
target_exprs_owned_
 
std::vector< std::shared_ptr
< RexSubQuery > > 
subqueries_
 
std::unordered_map< unsigned,
AggregatedResult
leaf_results_
 
int64_t queue_time_ms_
 

Static Private Attributes

static SpeculativeTopNBlacklist speculative_topn_blacklist_
 
static const size_t max_groups_buffer_entry_default_guess {16384}
 

Friends

class PendingExecutionClosure
 

Additional Inherited Members

- Private Types inherited from StorageIOFacility< RelAlgExecutorTraits >
using ExecutorType = typename RelAlgExecutorTraits::ExecutorType
 
using CatalogType = typename RelAlgExecutorTraits::CatalogType
 
using FragmentUpdaterType = UpdateLogForFragment
 
using UpdateCallback = typename FragmentUpdaterType::Callback
 
using IOFacility = DefaultIOFacet<>
 
using TableDescriptorType = typename RelAlgExecutorTraits::TableDescriptorType
 
using DeleteVictimOffsetList = typename IOFacility::DeleteVictimOffsetList
 
using UpdateTargetOffsetList = typename IOFacility::UpdateTargetOffsetList
 
using UpdateTargetTypeList = typename IOFacility::UpdateTargetTypeList
 
using UpdateTargetColumnNamesList = typename IOFacility::UpdateTargetColumnNamesList
 
using UpdateTargetColumnNameType = typename UpdateTargetColumnNamesList::value_type
 
using ColumnValidationFunction = typename IOFacility::ColumnValidationFunction
 
using StringSelector = Experimental::MetaTypeClass< Experimental::String >
 
using NonStringSelector = Experimental::UncapturedMetaTypeClass
 

Detailed Description

Definition at line 52 of file RelAlgExecutor.h.

Member Typedef Documentation

Definition at line 54 of file RelAlgExecutor.h.

Constructor & Destructor Documentation

RelAlgExecutor::RelAlgExecutor ( Executor executor,
const Catalog_Namespace::Catalog cat 
)
inline

Definition at line 56 of file RelAlgExecutor.h.

57  : StorageIOFacility(executor, cat)
58  , executor_(executor)
59  , cat_(cat)
60  , now_(0)
61  , queue_time_ms_(0) {}
int64_t queue_time_ms_
const Catalog_Namespace::Catalog & cat_
StorageIOFacility(ExecutorType *executor, CatalogType const &catalog)
Executor * executor_

Member Function Documentation

void RelAlgExecutor::addLeafResult ( const unsigned  id,
const AggregatedResult result 
)
inline

Definition at line 99 of file RelAlgExecutor.h.

References CHECK(), and leaf_results_.

99  {
100  const auto it_ok = leaf_results_.emplace(id, result);
101  CHECK(it_ok.second);
102  }
std::unordered_map< unsigned, AggregatedResult > leaf_results_
CHECK(cgen_state)

+ Here is the call graph for this function:

void RelAlgExecutor::addTemporaryTable ( const int  table_id,
const ResultSetPtr result 
)
inlineprivate

Definition at line 306 of file RelAlgExecutor.h.

References CHECK(), CHECK_LT, and temporary_tables_.

Referenced by executeRelAlgStep(), and handleNop().

306  {
307  CHECK_LT(size_t(0), result->colCount());
308  CHECK_LT(table_id, 0);
309  const auto it_ok = temporary_tables_.emplace(table_id, result);
310  CHECK(it_ok.second);
311  }
TemporaryTables temporary_tables_
CHECK(cgen_state)
#define CHECK_LT(x, y)
Definition: Logger.h:200

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::cleanupPostExecution ( )

Definition at line 179 of file RelAlgExecutor.cpp.

References CHECK(), and executor_.

Referenced by executeRelAlgQueryNoRetry().

179  {
180  CHECK(executor_);
181  executor_->row_set_mem_owner_ = nullptr;
182  executor_->lit_str_dict_proxy_ = nullptr;
183 }
CHECK(cgen_state)
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AggregatedColRange RelAlgExecutor::computeColRangesCache ( const RelAlgNode ra)

Definition at line 158 of file RelAlgExecutor.cpp.

References cat_, executor_, and get_physical_inputs().

158  {
159  AggregatedColRange agg_col_range_cache;
160  const auto phys_inputs = get_physical_inputs(cat_, ra);
161  return executor_->computeColRangesCache(phys_inputs);
162 }
const Catalog_Namespace::Catalog & cat_
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
Executor * executor_

+ Here is the call graph for this function:

StringDictionaryGenerations RelAlgExecutor::computeStringDictionaryGenerations ( const RelAlgNode ra)

Definition at line 164 of file RelAlgExecutor.cpp.

References cat_, executor_, and get_physical_inputs().

165  {
166  const auto phys_inputs = get_physical_inputs(cat_, ra);
167  return executor_->computeStringDictionaryGenerations(phys_inputs);
168 }
const Catalog_Namespace::Catalog & cat_
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
Executor * executor_

+ Here is the call graph for this function:

TableGenerations RelAlgExecutor::computeTableGenerations ( const RelAlgNode ra)

Definition at line 170 of file RelAlgExecutor.cpp.

References executor_, and get_physical_table_inputs().

170  {
171  const auto phys_table_ids = get_physical_table_inputs(ra);
172  return executor_->computeTableGenerations(phys_table_ids);
173 }
Executor * executor_
std::unordered_set< int > get_physical_table_inputs(const RelAlgNode *ra)

+ Here is the call graph for this function:

void RelAlgExecutor::computeWindow ( const RelAlgExecutionUnit ra_exe_unit,
const CompilationOptions co,
const ExecutionOptions eo,
ColumnCacheMap column_cache_map,
const int64_t  queue_time_ms 
)
private

Definition at line 1437 of file RelAlgExecutor.cpp.

References CHECK_EQ, WindowProjectNodeContext::create(), createWindowFunctionContext(), executor_, get_table_infos(), Analyzer::WindowFunction::getPartitionKeys(), RelAlgExecutionUnit::input_descs, kBOOLEAN, kBW_EQ, kONE, RelAlgExecutionUnit::target_exprs, and anonymous_namespace{RelAlgExecutor.cpp}::transform_to_inner().

Referenced by executeWorkUnit().

1441  {
1442  auto query_infos = get_table_infos(ra_exe_unit.input_descs, executor_);
1443  CHECK_EQ(query_infos.size(), size_t(1));
1444  if (query_infos.front().info.fragments.size() != 1) {
1445  throw std::runtime_error(
1446  "Only single fragment tables supported for window functions for now");
1447  }
1448  query_infos.push_back(query_infos.front());
1449  auto window_project_node_context = WindowProjectNodeContext::create();
1450  for (size_t target_index = 0; target_index < ra_exe_unit.target_exprs.size();
1451  ++target_index) {
1452  const auto& target_expr = ra_exe_unit.target_exprs[target_index];
1453  const auto window_func = dynamic_cast<const Analyzer::WindowFunction*>(target_expr);
1454  if (!window_func) {
1455  continue;
1456  }
1457  // Always use baseline layout hash tables for now, make the expression a tuple.
1458  const auto& partition_keys = window_func->getPartitionKeys();
1459  std::shared_ptr<Analyzer::Expr> partition_key_tuple;
1460  if (partition_keys.size() > 1) {
1461  partition_key_tuple = makeExpr<Analyzer::ExpressionTuple>(partition_keys);
1462  } else {
1463  if (partition_keys.empty()) {
1464  throw std::runtime_error(
1465  "Empty window function partitions are not supported yet");
1466  }
1467  CHECK_EQ(partition_keys.size(), size_t(1));
1468  partition_key_tuple = partition_keys.front();
1469  }
1470  // Creates a tautology equality with the partition expression on both sides.
1471  const auto partition_key_cond =
1472  makeExpr<Analyzer::BinOper>(kBOOLEAN,
1473  kBW_EQ,
1474  kONE,
1475  partition_key_tuple,
1476  transform_to_inner(partition_key_tuple.get()));
1477  auto context = createWindowFunctionContext(
1478  window_func, partition_key_cond, ra_exe_unit, query_infos, co, column_cache_map);
1479  context->compute();
1480  window_project_node_context->addWindowFunctionContext(std::move(context),
1481  target_index);
1482  }
1483 }
std::vector< Analyzer::Expr * > target_exprs
#define CHECK_EQ(x, y)
Definition: Logger.h:198
const std::vector< InputDescriptor > input_descs
std::shared_ptr< Analyzer::Expr > transform_to_inner(const Analyzer::Expr *expr)
static WindowProjectNodeContext * create()
Definition: sqldefs.h:69
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
Definition: sqldefs.h:31
std::unique_ptr< WindowFunctionContext > createWindowFunctionContext(const Analyzer::WindowFunction *window_func, const std::shared_ptr< Analyzer::BinOper > &partition_key_cond, const RelAlgExecutionUnit &ra_exe_unit, const std::vector< InputTableInfo > &query_infos, const CompilationOptions &co, ColumnCacheMap &column_cache_map)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getPartitionKeys() const
Definition: Analyzer.h:1400
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createAggregateWorkUnit ( const RelAggregate aggregate,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 2882 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, executor_, anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta(), RelAlgNode::getInput(), RelAlgNode::getOutputMetainfo(), RelAlgNode::inputCount(), max_groups_buffer_entry_default_guess, now_, RelAlgNode::setOutputMetainfo(), anonymous_namespace{RelAlgExecutor.cpp}::synthesize_inputs(), target_exprs_owned_, anonymous_namespace{RelAlgExecutor.cpp}::translate_groupby_exprs(), and anonymous_namespace{RelAlgExecutor.cpp}::translate_targets().

Referenced by createWorkUnit(), and executeAggregate().

2885  {
2886  std::vector<InputDescriptor> input_descs;
2887  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
2888  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
2889  const auto input_to_nest_level = get_input_nest_levels(aggregate, {});
2890  std::tie(input_descs, input_col_descs, used_inputs_owned) =
2891  get_input_desc(aggregate, input_to_nest_level, {}, cat_);
2892  const auto join_type = get_join_type(aggregate);
2893  QueryFeatureDescriptor query_features;
2894  RelAlgTranslator translator(cat_,
2895  executor_,
2896  input_to_nest_level,
2897  {join_type},
2898  now_,
2899  just_explain,
2900  query_features);
2901  CHECK_EQ(size_t(1), aggregate->inputCount());
2902  const auto source = aggregate->getInput(0);
2903  const auto& in_metainfo = source->getOutputMetainfo();
2904  const auto scalar_sources =
2905  synthesize_inputs(aggregate, size_t(0), in_metainfo, input_to_nest_level);
2906  const auto groupby_exprs = translate_groupby_exprs(aggregate, scalar_sources);
2907  const auto target_exprs = translate_targets(
2908  target_exprs_owned_, scalar_sources, groupby_exprs, aggregate, translator);
2909  const auto targets_meta = get_targets_meta(aggregate, target_exprs);
2910  aggregate->setOutputMetainfo(targets_meta);
2911  return {{input_descs,
2912  input_col_descs,
2913  {},
2914  {},
2915  {},
2916  groupby_exprs,
2917  target_exprs,
2918  nullptr,
2919  sort_info,
2920  0,
2921  query_features,
2922  false},
2923  aggregate,
2925  nullptr};
2926 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
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 * > 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)
static const size_t max_groups_buffer_entry_default_guess
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
std::list< std::shared_ptr< Analyzer::Expr > > translate_groupby_exprs(const RelCompound *compound, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
JoinType get_join_type(const RelAlgNode *ra)
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
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)
const size_t inputCount() const
const std::vector< TargetMetaInfo > & getOutputMetainfo() const
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createCompoundWorkUnit ( const RelCompound compound,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 2608 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, anonymous_namespace{RelAlgExecutor.cpp}::do_table_reordering(), executor_, g_from_table_reordering, anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), anonymous_namespace{RelAlgExecutor.cpp}::get_left_deep_join_input_sizes(), get_table_infos(), anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta(), RelAlgNode::getInput(), RelAlgNode::inputCount(), LEFT, anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types(), max_groups_buffer_entry_default_guess, now_, anonymous_namespace{RelAlgExecutor.cpp}::rewrite_quals(), RelAlgNode::setOutputMetainfo(), RelAlgExecutionUnit::simple_quals, RelCompound::size(), target_exprs_owned_, anonymous_namespace{RelAlgExecutor.cpp}::translate_groupby_exprs(), anonymous_namespace{RelAlgExecutor.cpp}::translate_quals(), anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources(), anonymous_namespace{RelAlgExecutor.cpp}::translate_targets(), and translateLeftDeepJoinFilter().

Referenced by createWorkUnit(), executeCompound(), and executeUpdateViaCompound().

2611  {
2612  std::vector<InputDescriptor> input_descs;
2613  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
2614  auto input_to_nest_level = get_input_nest_levels(compound, {});
2615  std::tie(input_descs, input_col_descs, std::ignore) =
2616  get_input_desc(compound, input_to_nest_level, {}, cat_);
2617  const auto query_infos = get_table_infos(input_descs, executor_);
2618  CHECK_EQ(size_t(1), compound->inputCount());
2619  const auto left_deep_join =
2620  dynamic_cast<const RelLeftDeepInnerJoin*>(compound->getInput(0));
2621  JoinQualsPerNestingLevel left_deep_join_quals;
2622  const auto join_types = left_deep_join ? left_deep_join_types(left_deep_join)
2623  : std::vector<JoinType>{get_join_type(compound)};
2624  std::vector<size_t> input_permutation;
2625  std::vector<size_t> left_deep_join_input_sizes;
2626  if (left_deep_join) {
2627  left_deep_join_input_sizes = get_left_deep_join_input_sizes(left_deep_join);
2628  left_deep_join_quals = translateLeftDeepJoinFilter(
2629  left_deep_join, input_descs, input_to_nest_level, just_explain);
2631  std::find(join_types.begin(), join_types.end(), JoinType::LEFT) ==
2632  join_types.end()) {
2633  input_permutation = do_table_reordering(input_descs,
2634  input_col_descs,
2635  left_deep_join_quals,
2636  input_to_nest_level,
2637  compound,
2638  query_infos,
2639  executor_);
2640  input_to_nest_level = get_input_nest_levels(compound, input_permutation);
2641  std::tie(input_descs, input_col_descs, std::ignore) =
2642  get_input_desc(compound, input_to_nest_level, input_permutation, cat_);
2643  left_deep_join_quals = translateLeftDeepJoinFilter(
2644  left_deep_join, input_descs, input_to_nest_level, just_explain);
2645  }
2646  }
2647  QueryFeatureDescriptor query_features;
2648  RelAlgTranslator translator(cat_,
2649  executor_,
2650  input_to_nest_level,
2651  join_types,
2652  now_,
2653  just_explain,
2654  query_features);
2655  const auto scalar_sources = translate_scalar_sources(compound, translator);
2656  const auto groupby_exprs = translate_groupby_exprs(compound, scalar_sources);
2657  const auto quals_cf = translate_quals(compound, translator);
2658  const auto target_exprs = translate_targets(
2659  target_exprs_owned_, scalar_sources, groupby_exprs, compound, translator);
2660  CHECK_EQ(compound->size(), target_exprs.size());
2661  const RelAlgExecutionUnit exe_unit = {input_descs,
2662  input_col_descs,
2663  quals_cf.simple_quals,
2664  rewrite_quals(quals_cf.quals),
2665  left_deep_join_quals,
2666  groupby_exprs,
2667  target_exprs,
2668  nullptr,
2669  sort_info,
2670  0,
2671  query_features,
2672  false};
2673  auto query_rewriter = std::make_unique<QueryRewriter>(query_infos, executor_);
2674  const auto rewritten_exe_unit = query_rewriter->rewrite(exe_unit);
2675  const auto targets_meta = get_targets_meta(compound, rewritten_exe_unit.target_exprs);
2676  compound->setOutputMetainfo(targets_meta);
2677  return {rewritten_exe_unit,
2678  compound,
2680  std::move(query_rewriter),
2681  input_permutation,
2682  left_deep_join_input_sizes};
2683 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
std::vector< JoinType > left_deep_join_types(const RelLeftDeepInnerJoin *left_deep_join)
JoinType
Definition: sqldefs.h:98
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< 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)
size_t size() const override
static const size_t max_groups_buffer_entry_default_guess
std::vector< JoinCondition > JoinQualsPerNestingLevel
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
bool g_from_table_reordering
Definition: Execute.cpp:77
std::list< std::shared_ptr< Analyzer::Expr > > translate_groupby_exprs(const RelCompound *compound, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
JoinType get_join_type(const RelAlgNode *ra)
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
std::vector< std::shared_ptr< Analyzer::Expr > > translate_scalar_sources(const RA *ra_node, const RelAlgTranslator &translator)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
QualsConjunctiveForm translate_quals(const RelCompound *compound, const RelAlgTranslator &translator)
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)
const size_t inputCount() const
Executor * executor_
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
JoinQualsPerNestingLevel translateLeftDeepJoinFilter(const RelLeftDeepInnerJoin *join, const std::vector< InputDescriptor > &input_descs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain)
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)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createFilterWorkUnit ( const RelFilter filter,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 3196 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, executor_, fold_expr(), get_exprs_not_owned(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), anonymous_namespace{RelAlgExecutor.cpp}::get_inputs_meta(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), RelFilter::getCondition(), RelAlgNode::inputCount(), max_groups_buffer_entry_default_guess, now_, rewrite_expr(), RelAlgNode::setOutputMetainfo(), and target_exprs_owned_.

Referenced by createWorkUnit(), and executeFilter().

3198  {
3199  CHECK_EQ(size_t(1), filter->inputCount());
3200  std::vector<InputDescriptor> input_descs;
3201  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
3202  std::vector<TargetMetaInfo> in_metainfo;
3203  std::vector<std::shared_ptr<RexInput>> used_inputs_owned;
3204  std::vector<std::shared_ptr<Analyzer::Expr>> target_exprs_owned;
3205 
3206  const auto input_to_nest_level = get_input_nest_levels(filter, {});
3207  std::tie(input_descs, input_col_descs, used_inputs_owned) =
3208  get_input_desc(filter, input_to_nest_level, {}, cat_);
3209  const auto join_type = get_join_type(filter);
3210  QueryFeatureDescriptor query_features;
3211  RelAlgTranslator translator(cat_,
3212  executor_,
3213  input_to_nest_level,
3214  {join_type},
3215  now_,
3216  just_explain,
3217  query_features);
3218  std::tie(in_metainfo, target_exprs_owned) =
3219  get_inputs_meta(filter, translator, used_inputs_owned, input_to_nest_level);
3220  const auto filter_expr = translator.translateScalarRex(filter->getCondition());
3221  const auto qual = fold_expr(filter_expr.get());
3222  target_exprs_owned_.insert(
3223  target_exprs_owned_.end(), target_exprs_owned.begin(), target_exprs_owned.end());
3224  const auto target_exprs = get_exprs_not_owned(target_exprs_owned);
3225  filter->setOutputMetainfo(in_metainfo);
3226  const auto rewritten_qual = rewrite_expr(qual.get());
3227  return {{input_descs,
3228  input_col_descs,
3229  {},
3230  {rewritten_qual ? rewritten_qual : qual},
3231  {},
3232  {nullptr},
3233  target_exprs,
3234  nullptr,
3235  sort_info,
3236  0},
3237  filter,
3239  nullptr};
3240 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
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)
static const size_t max_groups_buffer_entry_default_guess
const RexScalar * getCondition() const
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:214
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
const Catalog_Namespace::Catalog & cat_
JoinType get_join_type(const RelAlgNode *ra)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
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)
const size_t inputCount() const
Executor * executor_
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:

WorkUnit RelAlgExecutor::createJoinWorkUnit ( const RelJoin ,
const SortInfo ,
const bool  just_explain 
)
private
RelAlgExecutor::WorkUnit RelAlgExecutor::createModifyCompoundWorkUnit ( const RelCompound compound,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 2501 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, CHECK_GT, executor_, get_exprs_not_owned(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), anonymous_namespace{RelAlgExecutor.cpp}::get_modify_manipulated_targets_meta(), anonymous_namespace{RelAlgExecutor.cpp}::get_scalar_sources_size(), get_table_infos(), RelAlgNode::getInput(), ModifyManipulationTarget::getModifiedTableDescriptor(), ModifyManipulationTarget::getTargetColumnCount(), ModifyManipulationTarget::getTargetColumns(), RelAlgNode::inputCount(), anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types(), max_groups_buffer_entry_default_guess, now_, anonymous_namespace{RelAlgExecutor.cpp}::rewrite_quals(), RelAlgNode::setOutputMetainfo(), RelAlgExecutionUnit::simple_quals, RelCompound::size(), TableDescriptor::tableId, target_exprs_owned_, anonymous_namespace{RelAlgExecutor.cpp}::translate_groupby_exprs(), anonymous_namespace{RelAlgExecutor.cpp}::translate_quals(), anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources_for_update(), anonymous_namespace{RelAlgExecutor.cpp}::translate_targets_for_update(), translateLeftDeepJoinFilter(), and ScalarExprVisitor< T >::visit().

Referenced by executeDeleteViaCompound().

2504  {
2505  std::vector<InputDescriptor> input_descs;
2506  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
2507  auto input_to_nest_level = get_input_nest_levels(compound, {});
2508  std::tie(input_descs, input_col_descs, std::ignore) =
2509  get_input_desc(compound, input_to_nest_level, {}, cat_);
2510  const auto query_infos = get_table_infos(input_descs, executor_);
2511  CHECK_EQ(size_t(1), compound->inputCount());
2512  const auto left_deep_join =
2513  dynamic_cast<const RelLeftDeepInnerJoin*>(compound->getInput(0));
2514  JoinQualsPerNestingLevel left_deep_join_quals;
2515  const auto join_types = left_deep_join ? left_deep_join_types(left_deep_join)
2516  : std::vector<JoinType>{get_join_type(compound)};
2517  if (left_deep_join) {
2518  left_deep_join_quals = translateLeftDeepJoinFilter(
2519  left_deep_join, input_descs, input_to_nest_level, just_explain);
2520  }
2521  QueryFeatureDescriptor query_features;
2522  RelAlgTranslator translator(cat_,
2523  executor_,
2524  input_to_nest_level,
2525  join_types,
2526  now_,
2527  just_explain,
2528  query_features);
2529  size_t starting_projection_column_idx =
2530  get_scalar_sources_size(compound) - compound->getTargetColumnCount() - 1;
2531  CHECK_GT(starting_projection_column_idx, 0u);
2532  const auto scalar_sources =
2534  translator,
2535  compound->getModifiedTableDescriptor()->tableId,
2536  cat_,
2537  compound->getTargetColumns(),
2538  starting_projection_column_idx);
2539  const auto groupby_exprs = translate_groupby_exprs(compound, scalar_sources);
2540  const auto quals_cf = translate_quals(compound, translator);
2541  decltype(target_exprs_owned_) target_exprs_owned;
2542  translate_targets_for_update(target_exprs_owned,
2543  scalar_sources,
2544  groupby_exprs,
2545  compound,
2546  translator,
2547  compound->getModifiedTableDescriptor()->tableId,
2548  cat_,
2549  compound->getTargetColumns(),
2550  starting_projection_column_idx);
2551  target_exprs_owned_.insert(
2552  target_exprs_owned_.end(), target_exprs_owned.begin(), target_exprs_owned.end());
2553  const auto target_exprs = get_exprs_not_owned(target_exprs_owned);
2554  CHECK_EQ(compound->size(), target_exprs.size());
2555 
2556  const auto update_expr_iter =
2557  std::next(target_exprs.cbegin(), starting_projection_column_idx);
2558  decltype(target_exprs) filtered_target_exprs(update_expr_iter, target_exprs.end());
2559 
2560  UsedColumnsVisitor used_columns_visitor;
2561  std::unordered_set<int> id_accumulator;
2562 
2563  for (auto const& expr :
2564  boost::make_iterator_range(update_expr_iter, target_exprs.end())) {
2565  auto used_column_ids = used_columns_visitor.visit(expr);
2566  id_accumulator.insert(used_column_ids.begin(), used_column_ids.end());
2567  }
2568  for (auto const& expr : quals_cf.simple_quals) {
2569  auto simple_quals_used_column_ids = used_columns_visitor.visit(expr.get());
2570  id_accumulator.insert(simple_quals_used_column_ids.begin(),
2571  simple_quals_used_column_ids.end());
2572  }
2573  for (auto const& expr : quals_cf.quals) {
2574  auto quals_used_column_ids = used_columns_visitor.visit(expr.get());
2575  id_accumulator.insert(quals_used_column_ids.begin(), quals_used_column_ids.end());
2576  }
2577 
2578  decltype(input_col_descs) filtered_input_col_descs;
2579  for (auto col_desc : input_col_descs) {
2580  if (id_accumulator.find(col_desc->getColId()) != id_accumulator.end()) {
2581  filtered_input_col_descs.push_back(col_desc);
2582  }
2583  }
2584 
2585  const RelAlgExecutionUnit exe_unit = {input_descs,
2586  filtered_input_col_descs,
2587  quals_cf.simple_quals,
2588  rewrite_quals(quals_cf.quals),
2589  left_deep_join_quals,
2590  groupby_exprs,
2591  filtered_target_exprs,
2592  nullptr,
2593  sort_info,
2594  0,
2595  query_features,
2596  false};
2597  auto query_rewriter = std::make_unique<QueryRewriter>(query_infos, executor_);
2598  const auto rewritten_exe_unit = query_rewriter->rewrite(exe_unit);
2599  const auto targets_meta =
2600  get_modify_manipulated_targets_meta(compound, rewritten_exe_unit.target_exprs);
2601  compound->setOutputMetainfo(targets_meta);
2602  return {rewritten_exe_unit,
2603  compound,
2605  std::move(query_rewriter)};
2606 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
std::vector< JoinType > left_deep_join_types(const RelLeftDeepInnerJoin *left_deep_join)
JoinType
Definition: sqldefs.h:98
size_t get_scalar_sources_size(const RelCompound *compound)
static const size_t max_groups_buffer_entry_default_guess
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::vector< TargetMetaInfo > get_modify_manipulated_targets_meta(ModifyManipulationTarget const *manip_node, const std::vector< Analyzer::Expr * > &target_exprs)
std::vector< JoinCondition > JoinQualsPerNestingLevel
T visit(const Analyzer::Expr *expr) const
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:214
#define CHECK_GT(x, y)
Definition: Logger.h:202
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
std::vector< Analyzer::Expr * > translate_targets_for_update(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, int32_t tableId, const Catalog_Namespace::Catalog &cat, const ColumnNameList &colNames, size_t starting_projection_column_idx)
ColumnNameList const & getTargetColumns() const
std::list< std::shared_ptr< Analyzer::Expr > > translate_groupby_exprs(const RelCompound *compound, const std::vector< std::shared_ptr< Analyzer::Expr >> &scalar_sources)
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
JoinType get_join_type(const RelAlgNode *ra)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
QualsConjunctiveForm translate_quals(const RelCompound *compound, const RelAlgTranslator &translator)
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)
const size_t inputCount() const
Executor * executor_
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
JoinQualsPerNestingLevel translateLeftDeepJoinFilter(const RelLeftDeepInnerJoin *join, const std::vector< InputDescriptor > &input_descs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain)
TableDescriptor const * getModifiedTableDescriptor() const
std::list< std::shared_ptr< Analyzer::Expr > > rewrite_quals(const std::list< std::shared_ptr< Analyzer::Expr >> &quals)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createModifyProjectWorkUnit ( const RelProject project,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 2928 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, CHECK_GT, executor_, get_exprs_not_owned(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), anonymous_namespace{RelAlgExecutor.cpp}::get_modify_manipulated_targets_meta(), anonymous_namespace{RelAlgExecutor.cpp}::get_scalar_sources_size(), RelAlgNode::getInput(), ModifyManipulationTarget::getModifiedTableDescriptor(), ModifyManipulationTarget::getTargetColumnCount(), ModifyManipulationTarget::getTargetColumns(), anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types(), max_groups_buffer_entry_default_guess, now_, RelAlgNode::setOutputMetainfo(), RelProject::size(), TableDescriptor::tableId, target_exprs_owned_, anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources_for_update(), translateLeftDeepJoinFilter(), and ScalarExprVisitor< T >::visit().

Referenced by executeDeleteViaProject().

2931  {
2932  std::vector<InputDescriptor> input_descs;
2933  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
2934  auto input_to_nest_level = get_input_nest_levels(project, {});
2935  std::tie(input_descs, input_col_descs, std::ignore) =
2936  get_input_desc(project, input_to_nest_level, {}, cat_);
2937  const auto left_deep_join =
2938  dynamic_cast<const RelLeftDeepInnerJoin*>(project->getInput(0));
2939  JoinQualsPerNestingLevel left_deep_join_quals;
2940  const auto join_types = left_deep_join ? left_deep_join_types(left_deep_join)
2941  : std::vector<JoinType>{get_join_type(project)};
2942  if (left_deep_join) {
2943  left_deep_join_quals = translateLeftDeepJoinFilter(
2944  left_deep_join, input_descs, input_to_nest_level, just_explain);
2945  }
2946  QueryFeatureDescriptor query_features;
2947  RelAlgTranslator translator(cat_,
2948  executor_,
2949  input_to_nest_level,
2950  join_types,
2951  now_,
2952  just_explain,
2953  query_features);
2954  size_t starting_projection_column_idx =
2955  get_scalar_sources_size(project) - project->getTargetColumnCount() - 1;
2956  CHECK_GT(starting_projection_column_idx, 0u);
2957  auto target_exprs_owned =
2959  translator,
2960  project->getModifiedTableDescriptor()->tableId,
2961  cat_,
2962  project->getTargetColumns(),
2963  starting_projection_column_idx);
2964  target_exprs_owned_.insert(
2965  target_exprs_owned_.end(), target_exprs_owned.begin(), target_exprs_owned.end());
2966  const auto target_exprs = get_exprs_not_owned(target_exprs_owned);
2967  CHECK_EQ(project->size(), target_exprs.size());
2968 
2969  const auto update_expr_iter =
2970  std::next(target_exprs.cbegin(), starting_projection_column_idx);
2971  decltype(target_exprs) filtered_target_exprs(update_expr_iter, target_exprs.end());
2972 
2973  UsedColumnsVisitor used_columns_visitor;
2974  std::unordered_set<int> id_accumulator;
2975 
2976  for (auto const& expr :
2977  boost::make_iterator_range(update_expr_iter, target_exprs.end())) {
2978  auto used_column_ids = used_columns_visitor.visit(expr);
2979  id_accumulator.insert(used_column_ids.begin(), used_column_ids.end());
2980  }
2981 
2982  decltype(input_col_descs) filtered_input_col_descs;
2983  for (auto col_desc : input_col_descs) {
2984  if (id_accumulator.find(col_desc->getColId()) != id_accumulator.end()) {
2985  filtered_input_col_descs.push_back(col_desc);
2986  }
2987  }
2988 
2989  const auto targets_meta =
2990  get_modify_manipulated_targets_meta(project, filtered_target_exprs);
2991  project->setOutputMetainfo(targets_meta);
2992  return {{input_descs,
2993  filtered_input_col_descs,
2994  {},
2995  {},
2996  left_deep_join_quals,
2997  {nullptr},
2998  filtered_target_exprs,
2999  nullptr,
3000  sort_info,
3001  0,
3002  query_features,
3003  false},
3004  project,
3006  nullptr};
3007 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
std::vector< JoinType > left_deep_join_types(const RelLeftDeepInnerJoin *left_deep_join)
JoinType
Definition: sqldefs.h:98
size_t size() const override
size_t get_scalar_sources_size(const RelCompound *compound)
static const size_t max_groups_buffer_entry_default_guess
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::vector< TargetMetaInfo > get_modify_manipulated_targets_meta(ModifyManipulationTarget const *manip_node, const std::vector< Analyzer::Expr * > &target_exprs)
std::vector< JoinCondition > JoinQualsPerNestingLevel
T visit(const Analyzer::Expr *expr) const
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:214
#define CHECK_GT(x, y)
Definition: Logger.h:202
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
ColumnNameList const & getTargetColumns() const
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
JoinType get_join_type(const RelAlgNode *ra)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
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)
Executor * executor_
JoinQualsPerNestingLevel translateLeftDeepJoinFilter(const RelLeftDeepInnerJoin *join, const std::vector< InputDescriptor > &input_descs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain)
TableDescriptor const * getModifiedTableDescriptor() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createProjectWorkUnit ( const RelProject project,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 3009 of file RelAlgExecutor.cpp.

References cat_, anonymous_namespace{RelAlgExecutor.cpp}::do_table_reordering(), executor_, g_from_table_reordering, get_exprs_not_owned(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), anonymous_namespace{RelAlgExecutor.cpp}::get_left_deep_join_input_sizes(), get_table_infos(), anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta(), RelAlgNode::getInput(), anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types(), max_groups_buffer_entry_default_guess, now_, RelAlgNode::setOutputMetainfo(), target_exprs_owned_, anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources(), and translateLeftDeepJoinFilter().

Referenced by createWorkUnit(), executeProject(), and executeUpdateViaProject().

3011  {
3012  std::vector<InputDescriptor> input_descs;
3013  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
3014  auto input_to_nest_level = get_input_nest_levels(project, {});
3015  std::tie(input_descs, input_col_descs, std::ignore) =
3016  get_input_desc(project, input_to_nest_level, {}, cat_);
3017  const auto query_infos = get_table_infos(input_descs, executor_);
3018 
3019  const auto left_deep_join =
3020  dynamic_cast<const RelLeftDeepInnerJoin*>(project->getInput(0));
3021  JoinQualsPerNestingLevel left_deep_join_quals;
3022  const auto join_types = left_deep_join ? left_deep_join_types(left_deep_join)
3023  : std::vector<JoinType>{get_join_type(project)};
3024  std::vector<size_t> input_permutation;
3025  std::vector<size_t> left_deep_join_input_sizes;
3026  if (left_deep_join) {
3027  left_deep_join_input_sizes = get_left_deep_join_input_sizes(left_deep_join);
3028  const auto query_infos = get_table_infos(input_descs, executor_);
3029  left_deep_join_quals = translateLeftDeepJoinFilter(
3030  left_deep_join, input_descs, input_to_nest_level, just_explain);
3032  input_permutation = do_table_reordering(input_descs,
3033  input_col_descs,
3034  left_deep_join_quals,
3035  input_to_nest_level,
3036  project,
3037  query_infos,
3038  executor_);
3039  input_to_nest_level = get_input_nest_levels(project, input_permutation);
3040  std::tie(input_descs, input_col_descs, std::ignore) =
3041  get_input_desc(project, input_to_nest_level, input_permutation, cat_);
3042  left_deep_join_quals = translateLeftDeepJoinFilter(
3043  left_deep_join, input_descs, input_to_nest_level, just_explain);
3044  }
3045  }
3046 
3047  QueryFeatureDescriptor query_features;
3048  RelAlgTranslator translator(cat_,
3049  executor_,
3050  input_to_nest_level,
3051  join_types,
3052  now_,
3053  just_explain,
3054  query_features);
3055  const auto target_exprs_owned = translate_scalar_sources(project, translator);
3056  target_exprs_owned_.insert(
3057  target_exprs_owned_.end(), target_exprs_owned.begin(), target_exprs_owned.end());
3058  const auto target_exprs = get_exprs_not_owned(target_exprs_owned);
3059  const RelAlgExecutionUnit exe_unit = {input_descs,
3060  input_col_descs,
3061  {},
3062  {},
3063  left_deep_join_quals,
3064  {nullptr},
3065  target_exprs,
3066  nullptr,
3067  sort_info,
3068  0,
3069  query_features,
3070  false};
3071  auto query_rewriter = std::make_unique<QueryRewriter>(query_infos, executor_);
3072  const auto rewritten_exe_unit = query_rewriter->rewrite(exe_unit);
3073  const auto targets_meta = get_targets_meta(project, rewritten_exe_unit.target_exprs);
3074  project->setOutputMetainfo(targets_meta);
3075  return {rewritten_exe_unit,
3076  project,
3078  std::move(query_rewriter),
3079  input_permutation,
3080  left_deep_join_input_sizes};
3081 }
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
std::vector< JoinType > left_deep_join_types(const RelLeftDeepInnerJoin *left_deep_join)
JoinType
Definition: sqldefs.h:98
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)
static const size_t max_groups_buffer_entry_default_guess
std::vector< JoinCondition > JoinQualsPerNestingLevel
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:214
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
bool g_from_table_reordering
Definition: Execute.cpp:77
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
JoinType get_join_type(const RelAlgNode *ra)
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
std::vector< std::shared_ptr< Analyzer::Expr > > translate_scalar_sources(const RA *ra_node, const RelAlgTranslator &translator)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
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)
Executor * executor_
JoinQualsPerNestingLevel translateLeftDeepJoinFilter(const RelLeftDeepInnerJoin *join, const std::vector< InputDescriptor > &input_descs, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain)
std::vector< size_t > get_left_deep_join_input_sizes(const RelLeftDeepInnerJoin *left_deep_join)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createSortInputWorkUnit ( const RelSort sort,
const bool  just_explain 
)
private

Definition at line 1745 of file RelAlgExecutor.cpp.

References RelSort::collationCount(), SpeculativeTopNBlacklist::contains(), createWorkUnit(), Default, anonymous_namespace{RelAlgExecutor.cpp}::first_oe_is_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_order_entries(), anonymous_namespace{RelAlgExecutor.cpp}::get_scan_limit(), RelAlgNode::getInput(), RelSort::getLimit(), RelSort::getOffset(), max_groups_buffer_entry_default_guess, RelAlgNode::setOutputMetainfo(), speculative_topn_blacklist_, SpeculativeTopN, and StreamingTopN.

Referenced by executeRelAlgQuerySingleStep(), and executeSort().

1747  {
1748  const auto source = sort->getInput(0);
1749  const size_t limit = sort->getLimit();
1750  const size_t offset = sort->getOffset();
1751  const size_t scan_limit = sort->collationCount() ? 0 : get_scan_limit(source, limit);
1752  const size_t scan_total_limit =
1753  scan_limit ? get_scan_limit(source, scan_limit + offset) : 0;
1754  size_t max_groups_buffer_entry_guess{
1755  scan_total_limit ? scan_total_limit : max_groups_buffer_entry_default_guess};
1757  const auto order_entries = get_order_entries(sort);
1758  SortInfo sort_info{order_entries, sort_algorithm, limit, offset};
1759  auto source_work_unit = createWorkUnit(source, sort_info, just_explain);
1760  const auto& source_exe_unit = source_work_unit.exe_unit;
1761  if (source_exe_unit.groupby_exprs.size() == 1) {
1762  if (!source_exe_unit.groupby_exprs.front()) {
1763  sort_algorithm = SortAlgorithm::StreamingTopN;
1764  } else {
1765  if (speculative_topn_blacklist_.contains(source_exe_unit.groupby_exprs.front(),
1766  first_oe_is_desc(order_entries))) {
1767  sort_algorithm = SortAlgorithm::Default;
1768  }
1769  }
1770  }
1771 
1772  sort->setOutputMetainfo(source->getOutputMetainfo());
1773  // NB: the `body` field of the returned `WorkUnit` needs to be the `source` node,
1774  // not the `sort`. The aggregator needs the pre-sorted result from leaves.
1775  return {{source_exe_unit.input_descs,
1776  std::move(source_exe_unit.input_col_descs),
1777  source_exe_unit.simple_quals,
1778  source_exe_unit.quals,
1779  source_exe_unit.join_quals,
1780  source_exe_unit.groupby_exprs,
1781  source_exe_unit.target_exprs,
1782  nullptr,
1783  {sort_info.order_entries, sort_algorithm, limit, offset},
1784  scan_total_limit,
1785  source_exe_unit.query_features},
1786  source,
1787  max_groups_buffer_entry_guess,
1788  std::move(source_work_unit.query_rewriter),
1789  source_work_unit.input_permutation,
1790  source_work_unit.left_deep_join_input_sizes};
1791 }
size_t getOffset() const
bool contains(const std::shared_ptr< Analyzer::Expr > expr, const bool desc) const
WorkUnit createWorkUnit(const RelAlgNode *, const SortInfo &, const bool just_explain)
size_t get_scan_limit(const RelAlgNode *ra, const size_t limit)
static SpeculativeTopNBlacklist speculative_topn_blacklist_
static const size_t max_groups_buffer_entry_default_guess
SortAlgorithm
const RelAlgNode * getInput(const size_t idx) const
size_t collationCount() const
size_t getLimit() const
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
std::list< Analyzer::OrderEntry > get_order_entries(const RelSort *sort)
bool first_oe_is_desc(const std::list< Analyzer::OrderEntry > &order_entries)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::TableFunctionWorkUnit RelAlgExecutor::createTableFunctionWorkUnit ( const RelTableFunction table_func,
const bool  just_explain 
)
private

Definition at line 3083 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, CHECK_GT, executor_, table_functions::TableFunctionsFactory::get(), get_exprs_not_owned(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_desc(), anonymous_namespace{RelAlgExecutor.cpp}::get_input_nest_levels(), get_table_infos(), anonymous_namespace{RelAlgExecutor.cpp}::get_targets_meta(), RelTableFunction::getColInputsSize(), RelTableFunction::getFunctionName(), table_functions::TableFunction::getOutputSQLType(), RelTableFunction::getTableFuncInputAt(), RelAlgNode::inputCount(), now_, RelAlgNode::setOutputMetainfo(), TableFunctionExecutionUnit::target_exprs, target_exprs_owned_, to_string(), and anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources().

Referenced by executeTableFunction().

3085  {
3086  std::vector<InputDescriptor> input_descs;
3087  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
3088  auto input_to_nest_level = get_input_nest_levels(table_func, {});
3089  std::tie(input_descs, input_col_descs, std::ignore) =
3090  get_input_desc(table_func, input_to_nest_level, {}, cat_);
3091  const auto query_infos = get_table_infos(input_descs, executor_);
3092  CHECK_EQ(size_t(1), table_func->inputCount());
3093 
3094  QueryFeatureDescriptor query_features; // TODO(adb): remove/make optional
3095  RelAlgTranslator translator(
3096  cat_, executor_, input_to_nest_level, {}, now_, just_explain, query_features);
3097  const auto input_exprs_owned = translate_scalar_sources(table_func, translator);
3098  target_exprs_owned_.insert(
3099  target_exprs_owned_.end(), input_exprs_owned.begin(), input_exprs_owned.end());
3100  const auto input_exprs = get_exprs_not_owned(input_exprs_owned);
3101 
3102  std::vector<Analyzer::ColumnVar*> input_col_exprs;
3103  for (auto input_expr : input_exprs) {
3104  if (auto col_var = dynamic_cast<Analyzer::ColumnVar*>(input_expr)) {
3105  input_col_exprs.push_back(col_var);
3106  }
3107  }
3108  CHECK_EQ(input_col_exprs.size(), table_func->getColInputsSize());
3109 
3110  const auto& table_function_impl =
3112 
3113  std::vector<Analyzer::Expr*> table_func_outputs;
3114  for (size_t i = 0; i < table_function_impl.getOutputsSize(); i++) {
3115  const auto ti = table_function_impl.getOutputSQLType(i);
3116  target_exprs_owned_.push_back(std::make_shared<Analyzer::ColumnVar>(ti, 0, i, -1));
3117  table_func_outputs.push_back(target_exprs_owned_.back().get());
3118  }
3119 
3120  std::optional<size_t> output_row_multiplier;
3121  if (table_function_impl.hasUserSpecifiedOutputMultiplier()) {
3122  const auto parameter_index = table_function_impl.getOutputRowParameter();
3123  CHECK_GT(parameter_index, size_t(0));
3124  const auto parameter_expr = table_func->getTableFuncInputAt(parameter_index - 1);
3125  const auto parameter_expr_literal = dynamic_cast<const RexLiteral*>(parameter_expr);
3126  if (!parameter_expr_literal) {
3127  throw std::runtime_error(
3128  "Provided output buffer multiplier parameter is not a literal. Only literal "
3129  "values are supported with output buffer multiplier configured table "
3130  "functions.");
3131  }
3132  int64_t literal_val = parameter_expr_literal->getVal<int64_t>();
3133  if (literal_val < 0) {
3134  throw std::runtime_error("Provided output row multiplier " +
3135  std::to_string(literal_val) +
3136  " is not valid for table functions.");
3137  }
3138  output_row_multiplier = static_cast<size_t>(literal_val);
3139  }
3140 
3141  const TableFunctionExecutionUnit exe_unit = {
3142  input_descs,
3143  input_col_descs,
3144  input_exprs, // table function inputs
3145  input_col_exprs, // table function column inputs (duplicates w/ above)
3146  table_func_outputs, // table function projected exprs
3147  output_row_multiplier, // output buffer multiplier
3148  table_func->getFunctionName()};
3149  const auto targets_meta = get_targets_meta(table_func, exe_unit.target_exprs);
3150  table_func->setOutputMetainfo(targets_meta);
3151  return {exe_unit, table_func};
3152 }
SQLTypeInfo getOutputSQLType(const size_t idx) const
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unordered_map< const RelAlgNode *, int > get_input_nest_levels(const RelAlgNode *ra_node, const std::vector< size_t > &input_permutation)
static const TableFunction & get(const std::string &name)
std::vector< Analyzer::Expr * > get_exprs_not_owned(const std::vector< std::shared_ptr< Analyzer::Expr >> &exprs)
Definition: Execute.h:214
#define CHECK_GT(x, y)
Definition: Logger.h:202
std::string to_string(char const *&&v)
size_t getColInputsSize() const
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
const Catalog_Namespace::Catalog & cat_
std::vector< TargetMetaInfo > get_targets_meta(const RA *ra_node, const std::vector< Analyzer::Expr * > &target_exprs)
std::vector< std::shared_ptr< Analyzer::Expr > > translate_scalar_sources(const RA *ra_node, const RelAlgTranslator &translator)
const RexScalar * getTableFuncInputAt(const size_t idx) const
std::string getFunctionName() const
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
std::vector< Analyzer::Expr * > target_exprs
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)
const size_t inputCount() const
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr< WindowFunctionContext > RelAlgExecutor::createWindowFunctionContext ( const Analyzer::WindowFunction window_func,
const std::shared_ptr< Analyzer::BinOper > &  partition_key_cond,
const RelAlgExecutionUnit ra_exe_unit,
const std::vector< InputTableInfo > &  query_infos,
const CompilationOptions co,
ColumnCacheMap column_cache_map 
)
private

Definition at line 1485 of file RelAlgExecutor.cpp.

References CHECK(), CHECK_EQ, Data_Namespace::CPU_LEVEL, CompilationOptions::device_type_, executor_, ColumnFetcher::getOneColumnFragment(), Analyzer::WindowFunction::getOrderKeys(), GPU, Data_Namespace::GPU_LEVEL, and JoinHashTableInterface::OneToMany.

Referenced by computeWindow().

1491  {
1492  const auto memory_level = co.device_type_ == ExecutorDeviceType::GPU
1495  const auto join_table_or_err =
1496  executor_->buildHashTableForQualifier(partition_key_cond,
1497  query_infos,
1498  memory_level,
1500  column_cache_map);
1501  if (!join_table_or_err.fail_reason.empty()) {
1502  throw std::runtime_error(join_table_or_err.fail_reason);
1503  }
1504  CHECK(join_table_or_err.hash_table->getHashType() ==
1506  const auto& order_keys = window_func->getOrderKeys();
1507  std::vector<std::shared_ptr<Chunk_NS::Chunk>> chunks_owner;
1508  const size_t elem_count = query_infos.front().info.fragments.front().getNumTuples();
1509  auto context = std::make_unique<WindowFunctionContext>(
1510  window_func, join_table_or_err.hash_table, elem_count, co.device_type_);
1511  for (const auto& order_key : order_keys) {
1512  const auto order_col =
1513  std::dynamic_pointer_cast<const Analyzer::ColumnVar>(order_key);
1514  if (!order_col) {
1515  throw std::runtime_error("Only order by columns supported for now");
1516  }
1517  const int8_t* column;
1518  size_t join_col_elem_count;
1519  std::tie(column, join_col_elem_count) =
1521  *order_col,
1522  query_infos.front().info.fragments.front(),
1523  memory_level,
1524  0,
1525  chunks_owner,
1526  column_cache_map);
1527  CHECK_EQ(join_col_elem_count, elem_count);
1528  context->addOrderColumn(column, order_col.get(), chunks_owner);
1529  }
1530  return context;
1531 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:1404
CHECK(cgen_state)
static std::pair< const int8_t *, size_t > getOneColumnFragment(Executor *executor, const Analyzer::ColumnVar &hash_col, const Fragmenter_Namespace::FragmentInfo &fragment, const Data_Namespace::MemoryLevel effective_mem_lvl, const int device_id, std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner, ColumnCacheMap &column_cache)
ExecutorDeviceType device_type_
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelAlgExecutor::WorkUnit RelAlgExecutor::createWorkUnit ( const RelAlgNode node,
const SortInfo sort_info,
const bool  just_explain 
)
private

Definition at line 2332 of file RelAlgExecutor.cpp.

References CHECK(), createAggregateWorkUnit(), createCompoundWorkUnit(), createFilterWorkUnit(), and createProjectWorkUnit().

Referenced by createSortInputWorkUnit().

2334  {
2335  const auto compound = dynamic_cast<const RelCompound*>(node);
2336  if (compound) {
2337  return createCompoundWorkUnit(compound, sort_info, just_explain);
2338  }
2339  const auto project = dynamic_cast<const RelProject*>(node);
2340  if (project) {
2341  return createProjectWorkUnit(project, sort_info, just_explain);
2342  }
2343  const auto aggregate = dynamic_cast<const RelAggregate*>(node);
2344  if (aggregate) {
2345  return createAggregateWorkUnit(aggregate, sort_info, just_explain);
2346  }
2347  const auto filter = dynamic_cast<const RelFilter*>(node);
2348  CHECK(filter);
2349  return createFilterWorkUnit(filter, sort_info, just_explain);
2350 }
WorkUnit createProjectWorkUnit(const RelProject *, const SortInfo &, const bool just_explain)
WorkUnit createAggregateWorkUnit(const RelAggregate *, const SortInfo &, const bool just_explain)
WorkUnit createCompoundWorkUnit(const RelCompound *, const SortInfo &, const bool just_explain)
CHECK(cgen_state)
WorkUnit createFilterWorkUnit(const RelFilter *, const SortInfo &, const bool just_explain)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::eraseFromTemporaryTables ( const int  table_id)
inlineprivate

Definition at line 313 of file RelAlgExecutor.h.

References temporary_tables_.

313 { temporary_tables_.erase(table_id); }
TemporaryTables temporary_tables_
ExecutionResult RelAlgExecutor::executeAggregate ( const RelAggregate aggregate,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1310 of file RelAlgExecutor.cpp.

References createAggregateWorkUnit(), Default, executeWorkUnit(), RelAlgNode::getOutputMetainfo(), and ExecutionOptions::just_explain.

Referenced by executeRelAlgStep().

1314  {
1315  const auto work_unit = createAggregateWorkUnit(
1316  aggregate, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1317  return executeWorkUnit(work_unit,
1318  aggregate->getOutputMetainfo(),
1319  true,
1320  co,
1321  eo,
1322  render_info,
1323  queue_time_ms);
1324 }
WorkUnit createAggregateWorkUnit(const RelAggregate *, const SortInfo &, const bool just_explain)
ExecutionResult executeWorkUnit(const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
const std::vector< TargetMetaInfo > & getOutputMetainfo() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeCompound ( const RelCompound compound,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1293 of file RelAlgExecutor.cpp.

References createCompoundWorkUnit(), Default, executeWorkUnit(), RelAlgNode::getOutputMetainfo(), RelCompound::isAggregate(), and ExecutionOptions::just_explain.

Referenced by executeRelAlgStep().

1297  {
1298  const auto work_unit = createCompoundWorkUnit(
1299  compound, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1300  CompilationOptions co_compound = co;
1301  return executeWorkUnit(work_unit,
1302  compound->getOutputMetainfo(),
1303  compound->isAggregate(),
1304  co_compound,
1305  eo,
1306  render_info,
1307  queue_time_ms);
1308 }
WorkUnit createCompoundWorkUnit(const RelCompound *, const SortInfo &, const bool just_explain)
ExecutionResult executeWorkUnit(const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
const std::vector< TargetMetaInfo > & getOutputMetainfo() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::executeDeleteViaCompound ( const RelCompound compound,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1208 of file RelAlgExecutor.cpp.

References cat_, CPU, createModifyCompoundWorkUnit(), Default, CompilationOptions::device_type_, executor_, get_table_infos(), ModifyManipulationTarget::getModifiedTableDescriptor(), logger::INFO, CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), ExecutionOptions::just_explain, LOG, and StorageIOFacility< RelAlgExecutorTraits >::yieldDeleteCallback().

Referenced by executeRelAlgStep().

1212  {
1213  auto* table_descriptor = compound->getModifiedTableDescriptor();
1214  if (!table_descriptor->hasDeletedCol) {
1215  throw std::runtime_error(
1216  "DELETE only supported on tables with the vacuum attribute set to 'delayed'");
1217  }
1218 
1219  const auto work_unit = createModifyCompoundWorkUnit(
1220  compound, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1221  const auto table_infos = get_table_infos(work_unit.exe_unit, executor_);
1222  CompilationOptions co_project = co;
1224 
1225  try {
1227 
1228  DeleteTransactionParameters delete_params;
1229  auto delete_callback = yieldDeleteCallback(delete_params);
1230 
1231  executor_->executeUpdate(work_unit.exe_unit,
1232  table_infos,
1233  co_project,
1234  eo,
1235  cat_,
1236  executor_->row_set_mem_owner_,
1237  delete_callback);
1238  delete_params.finalizeTransaction();
1239  } catch (...) {
1240  LOG(INFO) << "Delete operation failed.";
1241  throw;
1242  }
1243 }
#define LOG(tag)
Definition: Logger.h:185
static void invalidateCaches()
const Catalog_Namespace::Catalog & cat_
WorkUnit createModifyCompoundWorkUnit(const RelCompound *compound, const SortInfo &sort_info, const bool just_explain)
ExecutorDeviceType device_type_
UpdateCallback yieldDeleteCallback(DeleteTransactionParameters &delete_parameters)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
Executor * executor_
TableDescriptor const * getModifiedTableDescriptor() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::executeDeleteViaProject ( const RelProject project,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1245 of file RelAlgExecutor.cpp.

References cat_, CHECK(), CHECK_EQ, CPU, createModifyProjectWorkUnit(), Default, CompilationOptions::device_type_, executor_, get_table_infos(), get_temporary_table(), RelAlgNode::getInput(), ModifyManipulationTarget::getModifiedTableDescriptor(), logger::INFO, RelAlgNode::inputCount(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), RelProject::isSimple(), ExecutionOptions::just_explain, LOG, temporary_tables_, and StorageIOFacility< RelAlgExecutorTraits >::yieldDeleteCallback().

Referenced by executeRelAlgStep().

1249  {
1250  auto* table_descriptor = project->getModifiedTableDescriptor();
1251  if (!table_descriptor->hasDeletedCol) {
1252  throw std::runtime_error(
1253  "DELETE only supported on tables with the vacuum attribute set to 'delayed'");
1254  }
1255 
1256  auto work_unit = createModifyProjectWorkUnit(
1257  project, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1258  const auto table_infos = get_table_infos(work_unit.exe_unit, executor_);
1259  CompilationOptions co_project = co;
1261 
1262  if (project->isSimple()) {
1263  CHECK_EQ(size_t(1), project->inputCount());
1264  const auto input_ra = project->getInput(0);
1265  if (dynamic_cast<const RelSort*>(input_ra)) {
1266  const auto& input_table =
1267  get_temporary_table(&temporary_tables_, -input_ra->getId());
1268  CHECK(input_table);
1269  work_unit.exe_unit.scan_limit = input_table->rowCount();
1270  }
1271  }
1272 
1273  try {
1275 
1276  DeleteTransactionParameters delete_params;
1277  auto delete_callback = yieldDeleteCallback(delete_params);
1278 
1279  executor_->executeUpdate(work_unit.exe_unit,
1280  table_infos,
1281  co_project,
1282  eo,
1283  cat_,
1284  executor_->row_set_mem_owner_,
1285  delete_callback);
1286  delete_params.finalizeTransaction();
1287  } catch (...) {
1288  LOG(INFO) << "Delete operation failed.";
1289  throw;
1290  }
1291 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define LOG(tag)
Definition: Logger.h:185
TemporaryTables temporary_tables_
static void invalidateCaches()
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:179
WorkUnit createModifyProjectWorkUnit(const RelProject *project, const SortInfo &sort_info, const bool just_explain)
CHECK(cgen_state)
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
bool isSimple() const
ExecutorDeviceType device_type_
UpdateCallback yieldDeleteCallback(DeleteTransactionParameters &delete_parameters)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
const size_t inputCount() const
Executor * executor_
TableDescriptor const * getModifiedTableDescriptor() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeFilter ( const RelFilter filter,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1533 of file RelAlgExecutor.cpp.

References createFilterWorkUnit(), Default, executeWorkUnit(), RelAlgNode::getOutputMetainfo(), and ExecutionOptions::just_explain.

Referenced by executeRelAlgStep().

1537  {
1538  const auto work_unit =
1539  createFilterWorkUnit(filter, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1540  return executeWorkUnit(
1541  work_unit, filter->getOutputMetainfo(), false, co, eo, render_info, queue_time_ms);
1542 }
ExecutionResult executeWorkUnit(const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
const std::vector< TargetMetaInfo > & getOutputMetainfo() const
WorkUnit createFilterWorkUnit(const RelFilter *, const SortInfo &, const bool just_explain)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeLogicalValues ( const RelLogicalValues logical_values,
const ExecutionOptions eo 
)
private

Definition at line 1560 of file RelAlgExecutor.cpp.

References QueryMemoryDescriptor::addColSlotInfo(), CPU, executor_, RelLogicalValues::getTupleType(), ExecutionOptions::just_explain, kCOUNT, kNULLT, NonGroupedAggregate, query_mem_desc, and RelAlgNode::setOutputMetainfo().

Referenced by executeRelAlgStep().

1562  {
1563  if (eo.just_explain) {
1564  throw std::runtime_error("EXPLAIN not supported for LogicalValues");
1565  }
1567  1,
1569  /*is_table_function=*/false);
1570 
1571  const auto& tuple_type = logical_values->getTupleType();
1572  for (size_t i = 0; i < tuple_type.size(); ++i) {
1573  query_mem_desc.addColSlotInfo({std::make_tuple(8, 8)});
1574  }
1575  logical_values->setOutputMetainfo(tuple_type);
1576  std::vector<std::unique_ptr<Analyzer::ColumnVar>> owned_column_expressions;
1577  std::vector<Analyzer::Expr*> target_expressions;
1578  for (const auto& tuple_component : tuple_type) {
1579  const auto column_var =
1580  new Analyzer::ColumnVar(tuple_component.get_type_info(), 0, 0, 0);
1581  target_expressions.push_back(column_var);
1582  owned_column_expressions.emplace_back(column_var);
1583  }
1584  std::vector<TargetInfo> target_infos;
1585  for (const auto& tuple_type_component : tuple_type) {
1586  target_infos.emplace_back(TargetInfo{false,
1587  kCOUNT,
1588  tuple_type_component.get_type_info(),
1589  SQLTypeInfo(kNULLT, false),
1590  false,
1591  false});
1592  }
1593  auto rs = std::make_shared<ResultSet>(target_infos,
1596  executor_->getRowSetMemoryOwner(),
1597  executor_);
1598  return {rs, tuple_type};
1599 }
const std::vector< TargetMetaInfo > getTupleType() const
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
Definition: sqldefs.h:71
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeModify ( const RelModify modify,
const ExecutionOptions eo 
)
private

Definition at line 1544 of file RelAlgExecutor.cpp.

References CPU, executor_, and ExecutionOptions::just_explain.

Referenced by executeRelAlgStep().

1545  {
1546  if (eo.just_explain) {
1547  throw std::runtime_error("EXPLAIN not supported for ModifyTable");
1548  }
1549 
1550  auto rs = std::make_shared<ResultSet>(TargetInfoList{},
1553  executor_->getRowSetMemoryOwner(),
1554  executor_);
1555 
1556  std::vector<TargetMetaInfo> empty_targets;
1557  return {rs, empty_targets};
1558 }
std::vector< TargetInfo > TargetInfoList
Executor * executor_

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeProject ( const RelProject project,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms,
const ssize_t  previous_count 
)
private

Definition at line 1339 of file RelAlgExecutor.cpp.

References CHECK(), CHECK_EQ, CPU, createProjectWorkUnit(), Default, executeWorkUnit(), get_temporary_table(), RelAlgNode::getInput(), RelAlgNode::getOutputMetainfo(), RelAlgNode::inputCount(), RelProject::isSimple(), ExecutionOptions::just_explain, and temporary_tables_.

Referenced by executeRelAlgStep().

1344  {
1345  auto work_unit =
1346  createProjectWorkUnit(project, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1347  CompilationOptions co_project = co;
1348  if (project->isSimple()) {
1349  CHECK_EQ(size_t(1), project->inputCount());
1350  const auto input_ra = project->getInput(0);
1351  if (dynamic_cast<const RelSort*>(input_ra)) {
1352  co_project.device_type_ = ExecutorDeviceType::CPU;
1353  const auto& input_table =
1354  get_temporary_table(&temporary_tables_, -input_ra->getId());
1355  CHECK(input_table);
1356  work_unit.exe_unit.scan_limit =
1357  std::min(input_table->getLimit(), input_table->rowCount());
1358  }
1359  }
1360  return executeWorkUnit(work_unit,
1361  project->getOutputMetainfo(),
1362  false,
1363  co_project,
1364  eo,
1365  render_info,
1366  queue_time_ms,
1367  previous_count);
1368 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
WorkUnit createProjectWorkUnit(const RelProject *, const SortInfo &, const bool just_explain)
TemporaryTables temporary_tables_
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:179
CHECK(cgen_state)
const RelAlgNode * getInput(const size_t idx) const
bool isSimple() const
ExecutionResult executeWorkUnit(const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
const size_t inputCount() const
const std::vector< TargetMetaInfo > & getOutputMetainfo() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeRelAlgQuery ( const std::string &  query_ra,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info 
)

Definition at line 66 of file RelAlgExecutor.cpp.

References CPU, DEBUG_TIMER, executeRelAlgQueryNoRetry(), CompilationOptions::explain_type_, g_allow_cpu_retry, CompilationOptions::hoist_literals_, logger::INFO, INJECT_TIMER, LOG, CompilationOptions::opt_level_, CompilationOptions::register_intel_jit_listener_, RenderInfo::setForceNonInSituData(), and CompilationOptions::with_dynamic_watchdog_.

Referenced by QueryRunner::QueryRunner::runSelectQuery().

69  {
70  auto timer = DEBUG_TIMER(__func__);
72  try {
73  return executeRelAlgQueryNoRetry(query_ra, co, eo, render_info);
74  } catch (const QueryMustRunOnCpu&) {
75  if (!g_allow_cpu_retry) {
76  throw;
77  }
78  }
79  LOG(INFO) << "Query unable to run in GPU mode, retrying on CPU";
81  co.hoist_literals_,
82  co.opt_level_,
84  co.explain_type_,
86  if (render_info) {
87  render_info->setForceNonInSituData();
88  }
89  return executeRelAlgQueryNoRetry(query_ra, co_cpu, eo, render_info);
90 }
ExecutionResult executeRelAlgQueryNoRetry(const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
void setForceNonInSituData()
Definition: RenderInfo.cpp:42
#define LOG(tag)
Definition: Logger.h:185
const ExecutorOptLevel opt_level_
#define INJECT_TIMER(DESC)
Definition: measure.h:91
const bool register_intel_jit_listener_
const ExecutorExplainType explain_type_
#define DEBUG_TIMER(name)
Definition: Logger.h:296
bool g_allow_cpu_retry
Definition: Execute.cpp:74
ExecutionResult executeRelAlgQuery(const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
const bool with_dynamic_watchdog_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeRelAlgQueryNoRetry ( const std::string &  query_ra,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info 
)
private

Definition at line 92 of file RelAlgExecutor.cpp.

References cat_, CHECK(), cleanupPostExecution(), deserialize_ra_dag(), RenderInfo::disallow_in_situ_only_if_final_ED_is_aggregate, executeRelAlgQueryWithFilterPushDown(), executeRelAlgSeq(), executor_, ExecutionOptions::find_push_down_candidates, g_enable_dynamic_watchdog, Catalog_Namespace::Catalog::get(), get_physical_inputs(), get_physical_table_inputs(), RenderInfo::getRenderQueryOptsPtr(), INJECT_TIMER, run_benchmark_import::result, RenderInfo::row_set_mem_owner, RenderInfo::setInSituDataIfUnset(), subqueries_, timer_start(), and timer_stop().

Referenced by executeRelAlgQuery().

95  {
97  decltype(subqueries_)().swap(subqueries_);
98 
99  const auto ra = deserialize_ra_dag(
100  query_ra, cat_, this, render_info ? render_info->getRenderQueryOptsPtr() : nullptr);
101 
102  // capture the lock acquistion time
103  auto clock_begin = timer_start();
104  std::lock_guard<std::mutex> lock(executor_->execute_mutex_);
105  int64_t queue_time_ms = timer_stop(clock_begin);
107  executor_->resetInterrupt();
108  }
109  ScopeGuard row_set_holder = [this, &render_info] {
110  if (render_info) {
111  // need to hold onto the RowSetMemOwner for potential
112  // string id lookups during render vega validation
113  render_info->row_set_mem_owner = executor_->row_set_mem_owner_;
114  }
116  };
117  const auto phys_inputs = get_physical_inputs(cat_, ra.get());
118  const auto phys_table_ids = get_physical_table_inputs(ra.get());
119  executor_->setCatalog(&cat_);
120  executor_->setupCaching(phys_inputs, phys_table_ids);
121 
122  ScopeGuard restore_metainfo_cache = [this] { executor_->clearMetaInfoCache(); };
123  auto ed_seq = RaExecutionSequence(ra.get());
124 
125  if (render_info) {
126  // set render to be non-insitu in certain situations.
128  ed_seq.size() > 1) {
129  // old logic
130  // disallow if more than one ED
131  render_info->setInSituDataIfUnset(false);
132  }
133  }
134 
135  if (eo.find_push_down_candidates) {
136  // this extra logic is mainly due to current limitations on multi-step queries
137  // and/or subqueries.
139  ed_seq, co, eo, render_info, queue_time_ms);
140  }
141 
142  // Dispatch the subqueries first
143  for (auto subquery : subqueries_) {
144  const auto subquery_ra = subquery->getRelAlg();
145  CHECK(subquery_ra);
146  if (subquery_ra->hasContextData()) {
147  continue;
148  }
149  // Execute the subquery and cache the result.
150  RelAlgExecutor ra_executor(executor_, cat_);
151  RaExecutionSequence subquery_seq(subquery_ra);
152  auto result = ra_executor.executeRelAlgSeq(subquery_seq, co, eo, nullptr, 0);
153  subquery->setExecutionResult(std::make_shared<ExecutionResult>(result));
154  }
155  return executeRelAlgSeq(ed_seq, co, eo, render_info, queue_time_ms);
156 }
ExecutionResult executeRelAlgQueryNoRetry(const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
const RenderQueryOptions * getRenderQueryOptsPtr() const
Definition: RenderInfo.cpp:100
ExecutionResult executeRelAlgSeq(const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms, const bool with_existing_temp_tables=false)
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
Definition: RenderInfo.h:34
std::vector< std::shared_ptr< RexSubQuery > > subqueries_
static std::shared_ptr< Catalog > get(const std::string &dbName)
Definition: Catalog.cpp:2990
ExecutionResult executeRelAlgQueryWithFilterPushDown(const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
bool setInSituDataIfUnset(const bool is_in_situ_data)
Definition: RenderInfo.cpp:95
TypeR::rep timer_stop(Type clock_begin)
Definition: measure.h:46
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
std::shared_ptr< const RelAlgNode > deserialize_ra_dag(const std::string &query_ra, const Catalog_Namespace::Catalog &cat, RelAlgExecutor *ra_executor, const RenderQueryOptions *render_opts)
bool disallow_in_situ_only_if_final_ED_is_aggregate
Definition: RenderInfo.h:42
const bool find_push_down_candidates
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
A container for relational algebra descriptors defining the execution order for a relational algebra ...
const Catalog_Namespace::Catalog & cat_
void cleanupPostExecution()
std::unordered_set< PhysicalInput > get_physical_inputs(const RelAlgNode *ra)
Executor * executor_
std::unordered_set< int > get_physical_table_inputs(const RelAlgNode *ra)
Type timer_start()
Definition: measure.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FirstStepExecutionResult RelAlgExecutor::executeRelAlgQuerySingleStep ( const RaExecutionSequence seq,
const size_t  step_idx,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info 
)

Definition at line 185 of file RelAlgExecutor.cpp.

References CHECK(), CHECK_EQ, createSortInputWorkUnit(), executeRelAlgSubSeq(), executor_, RaExecutionSequence::getDescriptor(), INJECT_TIMER, ExecutionOptions::just_explain, anonymous_namespace{RelAlgExecutor.cpp}::node_is_aggregate(), queue_time_ms_, Reduce, GroupByAndAggregate::shard_count_for_top_groups(), and Union.

190  {
191  INJECT_TIMER(executeRelAlgQueryStep);
192  auto exe_desc_ptr = seq.getDescriptor(step_idx);
193  CHECK(exe_desc_ptr);
194  const auto sort = dynamic_cast<const RelSort*>(exe_desc_ptr->getBody());
195 
196  size_t shard_count{0};
197  auto merge_type = [&shard_count](const RelAlgNode* body) -> MergeType {
198  return node_is_aggregate(body) && !shard_count ? MergeType::Reduce : MergeType::Union;
199  };
200 
201  if (sort) {
202  const auto source_work_unit = createSortInputWorkUnit(sort, eo.just_explain);
204  source_work_unit.exe_unit, *executor_->getCatalog());
205  if (!shard_count) {
206  // No point in sorting on the leaf, only execute the input to the sort node.
207  CHECK_EQ(size_t(1), sort->inputCount());
208  const auto source = sort->getInput(0);
209  if (sort->collationCount() || node_is_aggregate(source)) {
210  auto temp_seq = RaExecutionSequence(std::make_unique<RaExecutionDesc>(source));
211  CHECK_EQ(temp_seq.size(), size_t(1));
212  // Use subseq to avoid clearing existing temporary tables
213  return {executeRelAlgSubSeq(temp_seq, std::make_pair(0, 1), co, eo, nullptr, 0),
214  merge_type(source),
215  source->getId(),
216  false};
217  }
218  }
219  }
220  return {executeRelAlgSubSeq(seq,
221  std::make_pair(step_idx, step_idx + 1),
222  co,
223  eo,
224  render_info,
226  merge_type(exe_desc_ptr->getBody()),
227  exe_desc_ptr->getBody()->getId(),
228  false};
229 }
int64_t queue_time_ms_
#define CHECK_EQ(x, y)
Definition: Logger.h:198
RaExecutionDesc * getDescriptor(size_t idx) const
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
MergeType
A container for relational algebra descriptors defining the execution order for a relational algebra ...
ExecutionResult executeRelAlgSubSeq(const RaExecutionSequence &seq, const std::pair< size_t, size_t > interval, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
bool node_is_aggregate(const RelAlgNode *ra)
WorkUnit createSortInputWorkUnit(const RelSort *, const bool just_explain)
Executor * executor_
static size_t shard_count_for_top_groups(const RelAlgExecutionUnit &ra_exe_unit, const Catalog_Namespace::Catalog &catalog)

+ Here is the call graph for this function:

ExecutionResult RelAlgExecutor::executeRelAlgQueryWithFilterPushDown ( const RaExecutionSequence seq,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)

Definition at line 154 of file JoinFilterPushDown.cpp.

References ExecutionOptions::allow_loop_joins, ExecutionOptions::allow_multifrag, cat_, CHECK(), ExecutionOptions::dynamic_watchdog_time_limit, executeRelAlgSeq(), executor_, ExecutionOptions::find_push_down_candidates, ExecutionOptions::gpu_input_mem_limit_percent, ExecutionOptions::jit_debug, ExecutionOptions::just_calcite_explain, ExecutionOptions::just_explain, ExecutionOptions::just_validate, ExecutionOptions::output_columnar_hint, run_benchmark_import::result, RaExecutionSequence::size(), subqueries_, ExecutionOptions::with_dynamic_watchdog, and ExecutionOptions::with_watchdog.

Referenced by executeRelAlgQueryNoRetry().

159  {
160  // we currently do not fully support filter push down with
161  // multi-step execution and/or with subqueries
162  // TODO(Saman): add proper caching to enable filter push down for all cases
163  if (seq.size() > 1 || !subqueries_.empty()) {
164  if (eo.just_calcite_explain) {
165  return ExecutionResult(std::vector<PushedDownFilterInfo>{},
167  }
168  const ExecutionOptions eo_modified{eo.output_columnar_hint,
169  eo.allow_multifrag,
170  eo.just_explain,
171  eo.allow_loop_joins,
172  eo.with_watchdog,
173  eo.jit_debug,
174  eo.just_validate,
177  /*find_push_down_candidates=*/false,
178  /*just_calcite_explain=*/false,
180 
181  // Dispatch the subqueries first
182  for (auto subquery : subqueries_) {
183  // Execute the subquery and cache the result.
184  RelAlgExecutor ra_executor(executor_, cat_);
185  const auto subquery_ra = subquery->getRelAlg();
186  CHECK(subquery_ra);
187  RaExecutionSequence subquery_seq(subquery_ra);
188  auto result = ra_executor.executeRelAlgSeq(subquery_seq, co, eo, nullptr, 0);
189  subquery->setExecutionResult(std::make_shared<ExecutionResult>(result));
190  }
191  return executeRelAlgSeq(seq, co, eo_modified, render_info, queue_time_ms);
192  } else {
193  // Dispatch the subqueries first
194  for (auto subquery : subqueries_) {
195  // Execute the subquery and cache the result.
196  RelAlgExecutor ra_executor(executor_, cat_);
197  const auto subquery_ra = subquery->getRelAlg();
198  CHECK(subquery_ra);
199  RaExecutionSequence subquery_seq(subquery_ra);
200  auto result = ra_executor.executeRelAlgSeq(subquery_seq, co, eo, nullptr, 0);
201  subquery->setExecutionResult(std::make_shared<ExecutionResult>(result));
202  }
203  return executeRelAlgSeq(seq, co, eo, render_info, queue_time_ms);
204  }
205 }
ExecutionResult executeRelAlgSeq(const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms, const bool with_existing_temp_tables=false)
std::vector< std::shared_ptr< RexSubQuery > > subqueries_
const bool allow_multifrag
const bool find_push_down_candidates
CHECK(cgen_state)
const bool just_validate
const bool with_dynamic_watchdog
const double gpu_input_mem_limit_percent
A container for relational algebra descriptors defining the execution order for a relational algebra ...
const Catalog_Namespace::Catalog & cat_
const bool output_columnar_hint
const bool just_calcite_explain
const bool allow_loop_joins
const unsigned dynamic_watchdog_time_limit
Executor * executor_
const bool with_watchdog

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeRelAlgSeq ( const RaExecutionSequence seq,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms,
const bool  with_existing_temp_tables = false 
)

Definition at line 247 of file RelAlgExecutor.cpp.

References cat_, CHECK(), RaExecutionSequence::empty(), executeRelAlgStep(), executor_, RaExecutionSequence::getDescriptor(), INJECT_TIMER, ExecutionOptions::just_explain, now_, RaExecutionSequence::size(), target_exprs_owned_, and temporary_tables_.

Referenced by executeRelAlgQueryNoRetry(), and executeRelAlgQueryWithFilterPushDown().

252  {
254  if (!with_existing_temp_tables) {
255  decltype(temporary_tables_)().swap(temporary_tables_);
256  }
257  decltype(target_exprs_owned_)().swap(target_exprs_owned_);
258  executor_->catalog_ = &cat_;
259  executor_->temporary_tables_ = &temporary_tables_;
260 
261  time(&now_);
262  CHECK(!seq.empty());
263  const auto exec_desc_count = eo.just_explain ? size_t(1) : seq.size();
264 
265  for (size_t i = 0; i < exec_desc_count; i++) {
266  // only render on the last step
267  executeRelAlgStep(seq,
268  i,
269  co,
270  eo,
271  (i == exec_desc_count - 1) ? render_info : nullptr,
272  queue_time_ms);
273  }
274 
275  return seq.getDescriptor(exec_desc_count - 1)->getResult();
276 }
RaExecutionDesc * getDescriptor(size_t idx) const
ExecutionResult executeRelAlgSeq(const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms, const bool with_existing_temp_tables=false)
TemporaryTables temporary_tables_
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
const Catalog_Namespace::Catalog & cat_
void executeRelAlgStep(const RaExecutionSequence &seq, const size_t step_idx, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::executeRelAlgStep ( const RaExecutionSequence seq,
const size_t  step_idx,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 305 of file RelAlgExecutor.cpp.

References addTemporaryTable(), ExecutionOptions::allow_loop_joins, ExecutionOptions::allow_multifrag, CHECK(), ExecutionOptions::dynamic_watchdog_time_limit, executeAggregate(), executeCompound(), executeDeleteViaCompound(), executeDeleteViaProject(), executeFilter(), executeLogicalValues(), executeModify(), executeProject(), executeSort(), executeTableFunction(), executeUpdateViaCompound(), executeUpdateViaProject(), ExecutionOptions::find_push_down_candidates, g_cluster, g_skip_intermediate_count, RaExecutionSequence::getDescriptor(), ExecutionOptions::gpu_input_mem_limit_percent, handleNop(), INJECT_TIMER, ExecutionOptions::jit_debug, ExecutionOptions::just_calcite_explain, ExecutionOptions::just_explain, ExecutionOptions::just_validate, ExecutionOptions::output_columnar_hint, WindowProjectNodeContext::reset(), ExecutionOptions::with_dynamic_watchdog, and ExecutionOptions::with_watchdog.

Referenced by executeRelAlgSeq(), and executeRelAlgSubSeq().

310  {
313  auto exec_desc_ptr = seq.getDescriptor(step_idx);
314  CHECK(exec_desc_ptr);
315  auto& exec_desc = *exec_desc_ptr;
316  const auto body = exec_desc.getBody();
317  if (body->isNop()) {
318  handleNop(exec_desc);
319  return;
320  }
321  const ExecutionOptions eo_work_unit{
323  eo.allow_multifrag,
324  eo.just_explain,
325  eo.allow_loop_joins,
326  eo.with_watchdog && (step_idx == 0 || dynamic_cast<const RelProject*>(body)),
327  eo.jit_debug,
328  eo.just_validate,
334 
335  const auto compound = dynamic_cast<const RelCompound*>(body);
336  if (compound) {
337  if (compound->isDeleteViaSelect()) {
338  executeDeleteViaCompound(compound, co, eo_work_unit, render_info, queue_time_ms);
339  } else if (compound->isUpdateViaSelect()) {
340  executeUpdateViaCompound(compound, co, eo_work_unit, render_info, queue_time_ms);
341  } else {
342  exec_desc.setResult(
343  executeCompound(compound, co, eo_work_unit, render_info, queue_time_ms));
344  if (exec_desc.getResult().isFilterPushDownEnabled()) {
345  return;
346  }
347  addTemporaryTable(-compound->getId(), exec_desc.getResult().getDataPtr());
348  }
349  return;
350  }
351  const auto project = dynamic_cast<const RelProject*>(body);
352  if (project) {
353  if (project->isDeleteViaSelect()) {
354  executeDeleteViaProject(project, co, eo_work_unit, render_info, queue_time_ms);
355  } else if (project->isUpdateViaSelect()) {
356  executeUpdateViaProject(project, co, eo_work_unit, render_info, queue_time_ms);
357  } else {
358  ssize_t prev_count = -1;
359  // Disabling the intermediate count optimization in distributed, as the previous
360  // execution descriptor will likely not hold the aggregated result.
361  if (g_skip_intermediate_count && step_idx > 0 && !g_cluster) {
362  auto prev_exec_desc = seq.getDescriptor(step_idx - 1);
363  CHECK(prev_exec_desc);
364  if (dynamic_cast<const RelCompound*>(prev_exec_desc->getBody())) {
365  const auto& prev_exe_result = prev_exec_desc->getResult();
366  const auto prev_result = prev_exe_result.getRows();
367  if (prev_result) {
368  prev_count = static_cast<ssize_t>(prev_result->rowCount());
369  }
370  }
371  }
372  exec_desc.setResult(executeProject(
373  project, co, eo_work_unit, render_info, queue_time_ms, prev_count));
374  if (exec_desc.getResult().isFilterPushDownEnabled()) {
375  return;
376  }
377  addTemporaryTable(-project->getId(), exec_desc.getResult().getDataPtr());
378  }
379  return;
380  }
381  const auto aggregate = dynamic_cast<const RelAggregate*>(body);
382  if (aggregate) {
383  exec_desc.setResult(
384  executeAggregate(aggregate, co, eo_work_unit, render_info, queue_time_ms));
385  addTemporaryTable(-aggregate->getId(), exec_desc.getResult().getDataPtr());
386  return;
387  }
388  const auto filter = dynamic_cast<const RelFilter*>(body);
389  if (filter) {
390  exec_desc.setResult(
391  executeFilter(filter, co, eo_work_unit, render_info, queue_time_ms));
392  addTemporaryTable(-filter->getId(), exec_desc.getResult().getDataPtr());
393  return;
394  }
395  const auto sort = dynamic_cast<const RelSort*>(body);
396  if (sort) {
397  exec_desc.setResult(executeSort(sort, co, eo_work_unit, render_info, queue_time_ms));
398  if (exec_desc.getResult().isFilterPushDownEnabled()) {
399  return;
400  }
401  addTemporaryTable(-sort->getId(), exec_desc.getResult().getDataPtr());
402  return;
403  }
404  const auto logical_values = dynamic_cast<const RelLogicalValues*>(body);
405  if (logical_values) {
406  exec_desc.setResult(executeLogicalValues(logical_values, eo_work_unit));
407  addTemporaryTable(-logical_values->getId(), exec_desc.getResult().getDataPtr());
408  return;
409  }
410  const auto modify = dynamic_cast<const RelModify*>(body);
411  if (modify) {
412  exec_desc.setResult(executeModify(modify, eo_work_unit));
413  return;
414  }
415  const auto table_func = dynamic_cast<const RelTableFunction*>(body);
416  if (table_func) {
417  exec_desc.setResult(
418  executeTableFunction(table_func, co, eo_work_unit, queue_time_ms));
419  addTemporaryTable(-table_func->getId(), exec_desc.getResult().getDataPtr());
420  return;
421  }
422  CHECK(false);
423 }
ExecutionResult executeAggregate(const RelAggregate *aggregate, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
RaExecutionDesc * getDescriptor(size_t idx) const
ExecutionResult executeProject(const RelProject *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count)
bool g_cluster
ExecutionResult executeModify(const RelModify *modify, const ExecutionOptions &eo)
void addTemporaryTable(const int table_id, const ResultSetPtr &result)
ExecutionResult executeLogicalValues(const RelLogicalValues *, const ExecutionOptions &)
ExecutionResult executeFilter(const RelFilter *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
void handleNop(RaExecutionDesc &ed)
const bool allow_multifrag
const bool find_push_down_candidates
CHECK(cgen_state)
const bool just_validate
#define INJECT_TIMER(DESC)
Definition: measure.h:91
const bool with_dynamic_watchdog
const double gpu_input_mem_limit_percent
const bool output_columnar_hint
void executeRelAlgStep(const RaExecutionSequence &seq, const size_t step_idx, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
ExecutionResult executeTableFunction(const RelTableFunction *, const CompilationOptions &, const ExecutionOptions &, const int64_t queue_time_ms)
const bool just_calcite_explain
void executeDeleteViaCompound(const RelCompound *compound, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
void executeUpdateViaProject(const RelProject *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
ExecutionResult executeSort(const RelSort *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
void executeDeleteViaProject(const RelProject *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
const bool allow_loop_joins
bool g_skip_intermediate_count
void executeUpdateViaCompound(const RelCompound *compound, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
ExecutionResult executeCompound(const RelCompound *, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
const unsigned dynamic_watchdog_time_limit
const bool with_watchdog

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeRelAlgSubSeq ( const RaExecutionSequence seq,
const std::pair< size_t, size_t >  interval,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)

Definition at line 278 of file RelAlgExecutor.cpp.

References cat_, CHECK(), executeRelAlgStep(), executor_, RaExecutionSequence::getDescriptor(), INJECT_TIMER, ExecutionOptions::just_explain, now_, and temporary_tables_.

Referenced by executeRelAlgQuerySingleStep().

284  {
286  executor_->catalog_ = &cat_;
287  executor_->temporary_tables_ = &temporary_tables_;
288 
289  time(&now_);
290  CHECK(!eo.just_explain);
291 
292  for (size_t i = interval.first; i < interval.second; i++) {
293  // only render on the last step
294  executeRelAlgStep(seq,
295  i,
296  co,
297  eo,
298  (i == interval.second - 1) ? render_info : nullptr,
299  queue_time_ms);
300  }
301 
302  return seq.getDescriptor(interval.second - 1)->getResult();
303 }
RaExecutionDesc * getDescriptor(size_t idx) const
TemporaryTables temporary_tables_
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
const Catalog_Namespace::Catalog & cat_
ExecutionResult executeRelAlgSubSeq(const RaExecutionSequence &seq, const std::pair< size_t, size_t > interval, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
void executeRelAlgStep(const RaExecutionSequence &seq, const size_t step_idx, const CompilationOptions &, const ExecutionOptions &, RenderInfo *, const int64_t queue_time_ms)
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeSort ( const RelSort sort,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1631 of file RelAlgExecutor.cpp.

References SpeculativeTopNBlacklist::add(), GroupByAndAggregate::addTransientStringLiterals(), ExecutionOptions::allow_loop_joins, ExecutionOptions::allow_multifrag, CHECK(), CHECK_EQ, RelSort::collationCount(), createSortInputWorkUnit(), CompilationOptions::device_type_, ExecutionOptions::dynamic_watchdog_time_limit, executeWorkUnit(), executor_, ExecutionOptions::find_push_down_candidates, anonymous_namespace{RelAlgExecutor.cpp}::first_oe_is_desc(), g_cluster, anonymous_namespace{RelAlgExecutor.cpp}::get_order_entries(), RelAlgNode::getId(), RelAlgNode::getInput(), RelSort::getLimit(), RelSort::getOffset(), ExecutionResult::getRows(), ExecutionOptions::gpu_input_mem_limit_percent, RelAlgNode::inputCount(), RelSort::isEmptyResult(), ExecutionOptions::jit_debug, ExecutionOptions::just_calcite_explain, ExecutionOptions::just_explain, ExecutionOptions::just_validate, leaf_results_, anonymous_namespace{RelAlgExecutor.cpp}::node_is_aggregate(), ExecutionOptions::output_columnar_hint, run_benchmark_import::result, RelAlgNode::setOutputMetainfo(), speculative_topn_blacklist_, use_speculative_top_n(), ExecutionOptions::with_dynamic_watchdog, and ExecutionOptions::with_watchdog.

Referenced by executeRelAlgStep().

1635  {
1636  CHECK_EQ(size_t(1), sort->inputCount());
1637  const auto source = sort->getInput(0);
1638  if (dynamic_cast<const RelSort*>(source)) {
1639  throw std::runtime_error("Sort node not supported as input to another sort");
1640  }
1641  const bool is_aggregate = node_is_aggregate(source);
1642  auto it = leaf_results_.find(sort->getId());
1643  if (it != leaf_results_.end()) {
1644  // Add any transient string literals to the sdp on the agg
1645  const auto source_work_unit = createSortInputWorkUnit(sort, eo.just_explain);
1647  source_work_unit.exe_unit, executor_, executor_->row_set_mem_owner_);
1648 
1649  // Handle push-down for LIMIT for multi-node
1650  auto& aggregated_result = it->second;
1651  auto& result_rows = aggregated_result.rs;
1652  const size_t limit = sort->getLimit();
1653  const size_t offset = sort->getOffset();
1654  const auto order_entries = get_order_entries(sort);
1655  if (limit || offset) {
1656  if (!order_entries.empty()) {
1657  result_rows->sort(order_entries, limit + offset);
1658  }
1659  result_rows->dropFirstN(offset);
1660  if (limit) {
1661  result_rows->keepFirstN(limit);
1662  }
1663  }
1664  ExecutionResult result(result_rows, aggregated_result.targets_meta);
1665  sort->setOutputMetainfo(aggregated_result.targets_meta);
1666 
1667  return result;
1668  }
1669  while (true) {
1670  std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
1671  bool is_desc{false};
1672  try {
1673  const auto source_work_unit = createSortInputWorkUnit(sort, eo.just_explain);
1674  is_desc = first_oe_is_desc(source_work_unit.exe_unit.sort_info.order_entries);
1675  ExecutionOptions eo_copy = {
1677  eo.allow_multifrag,
1678  eo.just_explain,
1679  eo.allow_loop_joins,
1680  eo.with_watchdog,
1681  eo.jit_debug,
1682  eo.just_validate || sort->isEmptyResult(),
1688  };
1689 
1690  groupby_exprs = source_work_unit.exe_unit.groupby_exprs;
1691  auto source_result = executeWorkUnit(source_work_unit,
1692  source->getOutputMetainfo(),
1693  is_aggregate,
1694  co,
1695  eo_copy,
1696  render_info,
1697  queue_time_ms);
1698  if (render_info && render_info->isPotentialInSituRender()) {
1699  return source_result;
1700  }
1701  if (source_result.isFilterPushDownEnabled()) {
1702  return source_result;
1703  }
1704  auto rows_to_sort = source_result.getRows();
1705  if (eo.just_explain) {
1706  return {rows_to_sort, {}};
1707  }
1708  const size_t limit = sort->getLimit();
1709  const size_t offset = sort->getOffset();
1710  if (sort->collationCount() != 0 && !rows_to_sort->definitelyHasNoRows() &&
1711  !use_speculative_top_n(source_work_unit.exe_unit,
1712  rows_to_sort->getQueryMemDesc())) {
1713  rows_to_sort->sort(source_work_unit.exe_unit.sort_info.order_entries,
1714  limit + offset);
1715  }
1716  if (limit || offset) {
1717  if (g_cluster && sort->collationCount() == 0) {
1718  if (offset >= rows_to_sort->rowCount()) {
1719  rows_to_sort->dropFirstN(offset);
1720  } else {
1721  rows_to_sort->keepFirstN(limit + offset);
1722  }
1723  } else {
1724  rows_to_sort->dropFirstN(offset);
1725  if (limit) {
1726  rows_to_sort->keepFirstN(limit);
1727  }
1728  }
1729  }
1730  return {rows_to_sort, source_result.getTargetsMeta()};
1731  } catch (const SpeculativeTopNFailed&) {
1732  CHECK_EQ(size_t(1), groupby_exprs.size());
1733  speculative_topn_blacklist_.add(groupby_exprs.front(), is_desc);
1734  }
1735  }
1736  CHECK(false);
1737  return {std::make_shared<ResultSet>(std::vector<TargetInfo>{},
1738  co.device_type_,
1740  nullptr,
1741  executor_),
1742  {}};
1743 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
size_t getOffset() const
bool g_cluster
static SpeculativeTopNBlacklist speculative_topn_blacklist_
bool use_speculative_top_n(const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &query_mem_desc)
std::unordered_map< unsigned, AggregatedResult > leaf_results_
const bool allow_multifrag
const bool find_push_down_candidates
CHECK(cgen_state)
const bool just_validate
unsigned getId() const
const bool with_dynamic_watchdog
const double gpu_input_mem_limit_percent
const std::shared_ptr< ResultSet > & getRows() const
const RelAlgNode * getInput(const size_t idx) const
const bool output_columnar_hint
bool node_is_aggregate(const RelAlgNode *ra)
bool isEmptyResult() const
const bool just_calcite_explain
size_t collationCount() const
size_t getLimit() const
const bool allow_loop_joins
ExecutionResult executeWorkUnit(const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
void setOutputMetainfo(const std::vector< TargetMetaInfo > &targets_metainfo) const
std::list< Analyzer::OrderEntry > get_order_entries(const RelSort *sort)
WorkUnit createSortInputWorkUnit(const RelSort *, const bool just_explain)
void add(const std::shared_ptr< Analyzer::Expr > expr, const bool desc)
const size_t inputCount() const
const unsigned dynamic_watchdog_time_limit
Executor * executor_
const bool with_watchdog
bool first_oe_is_desc(const std::list< Analyzer::OrderEntry > &order_entries)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeTableFunction ( const RelTableFunction table_func,
const CompilationOptions co_in,
const ExecutionOptions eo,
const int64_t  queue_time_ms 
)
private

Definition at line 1370 of file RelAlgExecutor.cpp.

References cat_, CHECK(), createTableFunctionWorkUnit(), Executor::ERR_OUT_OF_GPU_MEM, executor_, g_cluster, g_enable_table_functions, get_table_infos(), QueryExecutionError::getErrorCode(), handlePersistentError(), INJECT_TIMER, ExecutionOptions::just_explain, and run_benchmark_import::result.

Referenced by executeRelAlgStep().

1373  {
1375 
1376  auto co = co_in;
1377 
1378  if (g_cluster) {
1379  throw std::runtime_error("Table functions not supported in distributed mode yet");
1380  }
1381  if (!g_enable_table_functions) {
1382  throw std::runtime_error("Table function support is disabled");
1383  }
1384 
1385  auto table_func_work_unit = createTableFunctionWorkUnit(table_func, eo.just_explain);
1386  const auto body = table_func_work_unit.body;
1387  CHECK(body);
1388 
1389  const auto table_infos =
1390  get_table_infos(table_func_work_unit.exe_unit.input_descs, executor_);
1391 
1392  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
1393  co.device_type_,
1395  nullptr,
1396  executor_),
1397  {}};
1398 
1399  try {
1400  result = {executor_->executeTableFunction(
1401  table_func_work_unit.exe_unit, table_infos, co, eo, cat_),
1402  body->getOutputMetainfo()};
1403  } catch (const QueryExecutionError& e) {
1406  throw std::runtime_error("Table function ran out of memory during execution");
1407  }
1408  result.setQueueTime(queue_time_ms);
1409  return result;
1410 }
int32_t getErrorCode() const
Definition: ErrorHandling.h:55
TableFunctionWorkUnit createTableFunctionWorkUnit(const RelTableFunction *table_func, const bool just_explain)
bool g_cluster
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
const Catalog_Namespace::Catalog & cat_
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1034
ExecutionResult executeTableFunction(const RelTableFunction *, const CompilationOptions &, const ExecutionOptions &, const int64_t queue_time_ms)
bool g_enable_table_functions
Definition: Execute.cpp:94
static void handlePersistentError(const int32_t error_code)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::executeUpdateViaCompound ( const RelCompound compound,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1116 of file RelAlgExecutor.cpp.

References cat_, CPU, createCompoundWorkUnit(), Default, CompilationOptions::device_type_, executor_, get_table_infos(), ModifyManipulationTarget::getModifiedTableDescriptor(), RelAlgNode::getOutputMetainfo(), ModifyManipulationTarget::getTargetColumns(), logger::INFO, CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), RelCompound::isAggregate(), ModifyManipulationTarget::isVarlenUpdateRequired(), ExecutionOptions::just_explain, LOG, ModifyManipulationTarget::validateTargetColumns(), StorageIOFacility< RelAlgExecutorTraits >::yieldColumnValidator(), and StorageIOFacility< RelAlgExecutorTraits >::yieldUpdateCallback().

Referenced by executeRelAlgStep().

1120  {
1121  if (!compound->validateTargetColumns(
1123  throw std::runtime_error(
1124  "Unsupported update operation encountered. (None-encoded string column updates "
1125  "are not supported.)");
1126  }
1127 
1128  const auto work_unit = createCompoundWorkUnit(
1129  compound, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1130  const auto table_infos = get_table_infos(work_unit.exe_unit, executor_);
1131  CompilationOptions co_project = co;
1133 
1134  try {
1136 
1137  UpdateTransactionParameters update_params(compound->getModifiedTableDescriptor(),
1138  compound->getTargetColumns(),
1139  compound->getOutputMetainfo(),
1140  compound->isVarlenUpdateRequired());
1141  auto update_callback = yieldUpdateCallback(update_params);
1142  executor_->executeUpdate(work_unit.exe_unit,
1143  table_infos,
1144  co_project,
1145  eo,
1146  cat_,
1147  executor_->row_set_mem_owner_,
1148  update_callback,
1149  compound->isAggregate());
1150  update_params.finalizeTransaction();
1151  } catch (...) {
1152  LOG(INFO) << "Update operation failed.";
1153  throw;
1154  }
1155 }
#define LOG(tag)
Definition: Logger.h:185
WorkUnit createCompoundWorkUnit(const RelCompound *, const SortInfo &, const bool just_explain)
static void invalidateCaches()
ColumnNameList const & getTargetColumns() const
const Catalog_Namespace::Catalog & cat_
ColumnValidationFunction yieldColumnValidator(TableDescriptorType const *table_descriptor)
ExecutorDeviceType device_type_
UpdateCallback yieldUpdateCallback(UpdateTransactionParameters &update_parameters)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
auto const isVarlenUpdateRequired() const
const std::vector< TargetMetaInfo > & getOutputMetainfo() const
Executor * executor_
TableDescriptor const * getModifiedTableDescriptor() const
bool validateTargetColumns(VALIDATION_FUNCTOR validator) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::executeUpdateViaProject ( const RelProject project,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms 
)
private

Definition at line 1157 of file RelAlgExecutor.cpp.

References cat_, CHECK(), CHECK_EQ, CPU, createProjectWorkUnit(), Default, CompilationOptions::device_type_, executor_, get_table_infos(), get_temporary_table(), RelAlgNode::getInput(), ModifyManipulationTarget::getModifiedTableDescriptor(), RelAlgNode::getOutputMetainfo(), ModifyManipulationTarget::getTargetColumns(), logger::INFO, RelAlgNode::inputCount(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), RelProject::isSimple(), ModifyManipulationTarget::isVarlenUpdateRequired(), ExecutionOptions::just_explain, LOG, temporary_tables_, ModifyManipulationTarget::validateTargetColumns(), StorageIOFacility< RelAlgExecutorTraits >::yieldColumnValidator(), and StorageIOFacility< RelAlgExecutorTraits >::yieldUpdateCallback().

Referenced by executeRelAlgStep().

1161  {
1162  if (!project->validateTargetColumns(
1164  throw std::runtime_error(
1165  "Unsupported update operation encountered. (None-encoded string column updates "
1166  "are not supported.)");
1167  }
1168 
1169  auto work_unit =
1170  createProjectWorkUnit(project, {{}, SortAlgorithm::Default, 0, 0}, eo.just_explain);
1171  const auto table_infos = get_table_infos(work_unit.exe_unit, executor_);
1172  CompilationOptions co_project = co;
1174 
1175  if (project->isSimple()) {
1176  CHECK_EQ(size_t(1), project->inputCount());
1177  const auto input_ra = project->getInput(0);
1178  if (dynamic_cast<const RelSort*>(input_ra)) {
1179  const auto& input_table =
1180  get_temporary_table(&temporary_tables_, -input_ra->getId());
1181  CHECK(input_table);
1182  work_unit.exe_unit.scan_limit = input_table->rowCount();
1183  }
1184  }
1185 
1186  try {
1188 
1189  UpdateTransactionParameters update_params(project->getModifiedTableDescriptor(),
1190  project->getTargetColumns(),
1191  project->getOutputMetainfo(),
1192  project->isVarlenUpdateRequired());
1193  auto update_callback = yieldUpdateCallback(update_params);
1194  executor_->executeUpdate(work_unit.exe_unit,
1195  table_infos,
1196  co_project,
1197  eo,
1198  cat_,
1199  executor_->row_set_mem_owner_,
1200  update_callback);
1201  update_params.finalizeTransaction();
1202  } catch (...) {
1203  LOG(INFO) << "Update operation failed.";
1204  throw;
1205  }
1206 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
WorkUnit createProjectWorkUnit(const RelProject *, const SortInfo &, const bool just_explain)
#define LOG(tag)
Definition: Logger.h:185
TemporaryTables temporary_tables_
static void invalidateCaches()
const ResultSetPtr & get_temporary_table(const TemporaryTables *temporary_tables, const int table_id)
Definition: Execute.h:179
CHECK(cgen_state)
ColumnNameList const & getTargetColumns() const
const Catalog_Namespace::Catalog & cat_
const RelAlgNode * getInput(const size_t idx) const
ColumnValidationFunction yieldColumnValidator(TableDescriptorType const *table_descriptor)
bool isSimple() const
ExecutorDeviceType device_type_
UpdateCallback yieldUpdateCallback(UpdateTransactionParameters &update_parameters)
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
const size_t inputCount() const
auto const isVarlenUpdateRequired() const
const std::vector< TargetMetaInfo > & getOutputMetainfo() const
Executor * executor_
TableDescriptor const * getModifiedTableDescriptor() const
bool validateTargetColumns(VALIDATION_FUNCTOR validator) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::executeWorkUnit ( const WorkUnit work_unit,
const std::vector< TargetMetaInfo > &  targets_meta,
const bool  is_agg,
const CompilationOptions co_in,
const ExecutionOptions eo,
RenderInfo render_info,
const int64_t  queue_time_ms,
const ssize_t  previous_count = -1 
)
private

Definition at line 1929 of file RelAlgExecutor.cpp.

References GroupByAndAggregate::addTransientStringLiterals(), RelAlgExecutor::WorkUnit::body, anonymous_namespace{RelAlgExecutor.cpp}::build_render_targets(), anonymous_namespace{RelAlgExecutor.cpp}::can_use_bump_allocator(), cat_, CHECK(), CHECK_EQ, CHECK_GT, anonymous_namespace{RelAlgExecutor.cpp}::compute_output_buffer_size(), computeWindow(), CPU, DEBUG_TIMER, anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), RelAlgExecutor::WorkUnit::exe_unit, anonymous_namespace{RelAlgExecutor.cpp}::exe_unit_has_quals(), executor_, ExecutionOptions::find_push_down_candidates, g_big_group_threshold, g_cluster, g_enable_window_functions, get_table_infos(), QueryExecutionError::getErrorCode(), getFilteredCountAll(), getNDVEstimation(), anonymous_namespace{RelAlgExecutor.cpp}::groups_approx_upper_bound(), handleOutOfMemoryRetry(), handlePersistentError(), INJECT_TIMER, anonymous_namespace{RelAlgExecutor.cpp}::is_agg(), anonymous_namespace{RelAlgExecutor.cpp}::is_window_execution_unit(), RenderInfo::isPotentialInSituRender(), isRowidLookup(), ExecutionOptions::just_calcite_explain, ExecutionOptions::just_explain, leaf_results_, RelAlgExecutor::WorkUnit::max_groups_buffer_entry_guess, run_benchmark_import::result, selectFiltersToBePushedDown(), RelAlgExecutionUnit::target_exprs, target_exprs_owned_, and QueryExecutionError::wasMultifragKernelLaunch().

Referenced by executeAggregate(), executeCompound(), executeFilter(), executeProject(), and executeSort().

1937  {
1939  auto timer = DEBUG_TIMER(__func__);
1940 
1941  auto co = co_in;
1942  ColumnCacheMap column_cache;
1943  if (is_window_execution_unit(work_unit.exe_unit)) {
1944  if (g_cluster) {
1945  throw std::runtime_error(
1946  "Window functions support not supported in distributed mode");
1947  }
1949  throw std::runtime_error("Window functions support is disabled");
1950  }
1951  co.device_type_ = ExecutorDeviceType::CPU;
1952  computeWindow(work_unit.exe_unit, co, eo, column_cache, queue_time_ms);
1953  }
1954  if (!eo.just_explain && eo.find_push_down_candidates) {
1955  // find potential candidates:
1956  auto selected_filters = selectFiltersToBePushedDown(work_unit, co, eo);
1957  if (!selected_filters.empty() || eo.just_calcite_explain) {
1958  return ExecutionResult(selected_filters, eo.find_push_down_candidates);
1959  }
1960  }
1961  const auto body = work_unit.body;
1962  CHECK(body);
1963  auto it = leaf_results_.find(body->getId());
1964  if (it != leaf_results_.end()) {
1966  work_unit.exe_unit, executor_, executor_->row_set_mem_owner_);
1967  auto& aggregated_result = it->second;
1968  auto& result_rows = aggregated_result.rs;
1969  ExecutionResult result(result_rows, aggregated_result.targets_meta);
1970  body->setOutputMetainfo(aggregated_result.targets_meta);
1971  if (render_info) {
1972  build_render_targets(*render_info, work_unit.exe_unit.target_exprs, targets_meta);
1973  }
1974  return result;
1975  }
1976  const auto table_infos = get_table_infos(work_unit.exe_unit, executor_);
1977 
1979  work_unit.exe_unit, table_infos, executor_, co.device_type_, target_exprs_owned_);
1980  auto max_groups_buffer_entry_guess = work_unit.max_groups_buffer_entry_guess;
1981  if (is_window_execution_unit(ra_exe_unit)) {
1982  CHECK_EQ(table_infos.size(), size_t(1));
1983  CHECK_EQ(table_infos.front().info.fragments.size(), size_t(1));
1984  max_groups_buffer_entry_guess =
1985  table_infos.front().info.fragments.front().getNumTuples();
1986  ra_exe_unit.scan_limit = max_groups_buffer_entry_guess;
1987  } else if (compute_output_buffer_size(ra_exe_unit) && !isRowidLookup(work_unit)) {
1988  if (previous_count > 0 && !exe_unit_has_quals(ra_exe_unit)) {
1989  ra_exe_unit.scan_limit = static_cast<size_t>(previous_count);
1990  } else {
1991  // TODO(adb): enable bump allocator path for render queries
1992  if (can_use_bump_allocator(ra_exe_unit, co, eo) && !render_info) {
1993  ra_exe_unit.scan_limit = 0;
1994  ra_exe_unit.use_bump_allocator = true;
1995  } else if (!eo.just_explain) {
1996  const auto filter_count_all = getFilteredCountAll(work_unit, true, co, eo);
1997  if (filter_count_all >= 0) {
1998  ra_exe_unit.scan_limit = std::max(filter_count_all, ssize_t(1));
1999  }
2000  }
2001  }
2002  }
2003 
2004  ExecutionResult result{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
2005  co.device_type_,
2007  nullptr,
2008  executor_),
2009  {}};
2010 
2011  auto execute_and_handle_errors =
2012  [&](const auto max_groups_buffer_entry_guess_in,
2013  const bool has_cardinality_estimation) -> ExecutionResult {
2014  // Note that the groups buffer entry guess may be modified during query execution.
2015  // Create a local copy so we can track those changes if we need to attempt a retry due
2016  // to OOM
2017  auto local_groups_buffer_entry_guess = max_groups_buffer_entry_guess_in;
2018  try {
2019  return {executor_->executeWorkUnit(local_groups_buffer_entry_guess,
2020  is_agg,
2021  table_infos,
2022  ra_exe_unit,
2023  co,
2024  eo,
2025  cat_,
2026  executor_->row_set_mem_owner_,
2027  render_info,
2028  has_cardinality_estimation,
2029  column_cache),
2030  targets_meta};
2031  } catch (const QueryExecutionError& e) {
2033  return handleOutOfMemoryRetry(
2034  {ra_exe_unit, work_unit.body, local_groups_buffer_entry_guess},
2035  targets_meta,
2036  is_agg,
2037  co,
2038  eo,
2039  render_info,
2041  queue_time_ms);
2042  }
2043  };
2044 
2045  try {
2046  result = execute_and_handle_errors(
2047  max_groups_buffer_entry_guess,
2049  } catch (const CardinalityEstimationRequired&) {
2050  const auto estimated_groups_buffer_entry_guess =
2051  2 * std::min(groups_approx_upper_bound(table_infos),
2052  getNDVEstimation(work_unit, is_agg, co, eo));
2053  CHECK_GT(estimated_groups_buffer_entry_guess, size_t(0));
2054  result = execute_and_handle_errors(estimated_groups_buffer_entry_guess, true);
2055  }
2056 
2057  result.setQueueTime(queue_time_ms);
2058  if (render_info) {
2059  build_render_targets(*render_info, work_unit.exe_unit.target_exprs, targets_meta);
2060  if (render_info->isPotentialInSituRender()) {
2061  // return an empty result (with the same queue time, and zero render time)
2062  return {
2063  std::make_shared<ResultSet>(queue_time_ms, 0, executor_->row_set_mem_owner_),
2064  {}};
2065  }
2066  }
2067  return result;
2068 }
bool is_agg(const Analyzer::Expr *expr)
#define CHECK_EQ(x, y)
Definition: Logger.h:198
int32_t getErrorCode() const
Definition: ErrorHandling.h:55
bool can_use_bump_allocator(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const ExecutionOptions &eo)
bool g_cluster
std::vector< PushedDownFilterInfo > selectFiltersToBePushedDown(const RelAlgExecutor::WorkUnit &work_unit, const CompilationOptions &co, const ExecutionOptions &eo)
std::unordered_map< unsigned, AggregatedResult > leaf_results_
size_t getNDVEstimation(const WorkUnit &work_unit, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo)
#define CHECK_GT(x, y)
Definition: Logger.h:202
bool is_window_execution_unit(const RelAlgExecutionUnit &ra_exe_unit)
void computeWindow(const RelAlgExecutionUnit &ra_exe_unit, const CompilationOptions &co, const ExecutionOptions &eo, ColumnCacheMap &column_cache_map, const int64_t queue_time_ms)
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
const bool find_push_down_candidates
CHECK(cgen_state)
#define INJECT_TIMER(DESC)
Definition: measure.h:91
const Catalog_Namespace::Catalog & cat_
size_t g_big_group_threshold
Definition: Execute.cpp:92
ExecutionResult handleOutOfMemoryRetry(const RelAlgExecutor::WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const bool was_multifrag_kernel_launch, const int64_t queue_time_ms)
size_t groups_approx_upper_bound(const std::vector< InputTableInfo > &table_infos)
void build_render_targets(RenderInfo &render_info, const std::vector< Analyzer::Expr * > &work_unit_target_exprs, const std::vector< TargetMetaInfo > &targets_meta)
bool g_enable_window_functions
Definition: Execute.cpp:93
ssize_t getFilteredCountAll(const WorkUnit &work_unit, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo)
const bool just_calcite_explain
bool isRowidLookup(const WorkUnit &work_unit)
bool exe_unit_has_quals(const RelAlgExecutionUnit ra_exe_unit)
static void handlePersistentError(const int32_t error_code)
bool compute_output_buffer_size(const RelAlgExecutionUnit &ra_exe_unit)
bool wasMultifragKernelLaunch() const
Definition: ErrorHandling.h:57
ExecutionResult executeWorkUnit(const WorkUnit &work_unit, const std::vector< TargetMetaInfo > &targets_meta, const bool is_agg, const CompilationOptions &co_in, const ExecutionOptions &eo, RenderInfo *, const int64_t queue_time_ms, const ssize_t previous_count=-1)
bool isPotentialInSituRender() const
Definition: RenderInfo.cpp:61
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
#define DEBUG_TIMER(name)
Definition: Logger.h:296
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
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)
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string RelAlgExecutor::getErrorMessageFromCode ( const int32_t  error_code)
static

Definition at line 2299 of file RelAlgExecutor.cpp.

References Executor::ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED, Executor::ERR_DIV_BY_ZERO, 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_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 to_string().

Referenced by getNDVEstimation(), and handlePersistentError().

2299  {
2300  if (error_code < 0) {
2301  return "Ran out of slots in the query output buffer";
2302  }
2303  switch (error_code) {
2305  return "Division by zero";
2307  return "Query couldn't keep the entire working set of columns in GPU memory";
2309  return "Self joins not supported yet";
2311  return "Not enough host memory to execute the query";
2313  return "Overflow or underflow";
2315  return "Query execution has exceeded the time limit";
2317  return "Query execution has been interrupted";
2319  return "Columnar conversion not supported for variable length types";
2321  return "Too many literals in the query";
2323  return "NONE ENCODED String types are not supported as input result set.";
2325  return "Not enough OpenGL memory to render the query results";
2327  return "Streaming-Top-N not supported in Render Query";
2328  }
2329  return "Other error: code " + std::to_string(error_code);
2330 }
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1042
static const int32_t ERR_TOO_MANY_LITERALS
Definition: Execute.h:1044
std::string to_string(char const *&&v)
static const int32_t ERR_STRING_CONST_IN_RESULTSET
Definition: Execute.h:1045
static const int32_t ERR_STREAMING_TOP_N_NOT_SUPPORTED_IN_RENDER_QUERY
Definition: Execute.h:1046
static const int32_t ERR_COLUMNAR_CONVERSION_NOT_SUPPORTED
Definition: Execute.h:1043
static const int32_t ERR_DIV_BY_ZERO
Definition: Execute.h:1033
static const int32_t ERR_OUT_OF_RENDER_MEM
Definition: Execute.h:1037
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
static const int32_t ERR_OVERFLOW_OR_UNDERFLOW
Definition: Execute.h:1039
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1041
static const int32_t ERR_UNSUPPORTED_SELF_JOIN
Definition: Execute.h:1036
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1034
static const int32_t ERR_OUT_OF_CPU_MEM
Definition: Execute.h:1038

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Executor * RelAlgExecutor::getExecutor ( ) const

Definition at line 175 of file RelAlgExecutor.cpp.

References executor_.

175  {
176  return executor_;
177 }
Executor * executor_
ssize_t RelAlgExecutor::getFilteredCountAll ( const WorkUnit work_unit,
const bool  is_agg,
const CompilationOptions co,
const ExecutionOptions eo 
)
private

Definition at line 2070 of file RelAlgExecutor.cpp.

References cat_, CHECK(), CHECK_EQ, CHECK_GE, create_count_all_execution_unit(), RelAlgExecutor::WorkUnit::exe_unit, executor_, g_bigint_count, get_table_infos(), kBIGINT, kCOUNT, kINT, LOG, and logger::WARNING.

Referenced by executeWorkUnit().

2073  {
2074  const auto count =
2075  makeExpr<Analyzer::AggExpr>(SQLTypeInfo(g_bigint_count ? kBIGINT : kINT, false),
2076  kCOUNT,
2077  nullptr,
2078  false,
2079  nullptr);
2080  const auto count_all_exe_unit =
2081  create_count_all_execution_unit(work_unit.exe_unit, count);
2082  size_t one{1};
2083  ResultSetPtr count_all_result;
2084  try {
2085  ColumnCacheMap column_cache;
2086  count_all_result =
2087  executor_->executeWorkUnit(one,
2088  is_agg,
2089  get_table_infos(work_unit.exe_unit, executor_),
2090  count_all_exe_unit,
2091  co,
2092  eo,
2093  cat_,
2094  executor_->row_set_mem_owner_,
2095  nullptr,
2096  false,
2097  column_cache);
2098  } catch (const std::exception& e) {
2099  LOG(WARNING) << "Failed to run pre-flight filtered count with error " << e.what();
2100  return -1;
2101  }
2102  const auto count_row = count_all_result->getNextRow(false, false);
2103  CHECK_EQ(size_t(1), count_row.size());
2104  const auto& count_tv = count_row.front();
2105  const auto count_scalar_tv = boost::get<ScalarTargetValue>(&count_tv);
2106  CHECK(count_scalar_tv);
2107  const auto count_ptr = boost::get<int64_t>(count_scalar_tv);
2108  CHECK(count_ptr);
2109  CHECK_GE(*count_ptr, 0);
2110  auto count_upper_bound = static_cast<size_t>(*count_ptr);
2111  return std::max(count_upper_bound, size_t(1));
2112 }
bool is_agg(const Analyzer::Expr *expr)
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define LOG(tag)
Definition: Logger.h:185
#define CHECK_GE(x, y)
Definition: Logger.h:203
std::shared_ptr< ResultSet > ResultSetPtr
RelAlgExecutionUnit create_count_all_execution_unit(const RelAlgExecutionUnit &ra_exe_unit, std::shared_ptr< Analyzer::Expr > replacement_target)
CHECK(cgen_state)
const Catalog_Namespace::Catalog & cat_
bool g_bigint_count
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
Definition: sqldefs.h:71
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
Definition: sqltypes.h:48
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FilterSelectivity RelAlgExecutor::getFilterSelectivity ( const std::vector< std::shared_ptr< Analyzer::Expr >> &  filter_expressions,
const CompilationOptions co,
const ExecutionOptions eo 
)
private

Given a set of filter expressions for a table, it launches a new COUNT query to compute the number of passing rows, and then generates a set of statistics related to those filters. Later, these stats are used to decide whether a filter should be pushed down or not.

Definition at line 57 of file JoinFilterPushDown.cpp.

References cat_, CHECK(), CHECK_EQ, Default, executor_, g_bigint_count, get_table_infos(), kBIGINT, kCOUNT, and kINT.

Referenced by selectFiltersToBePushedDown().

60  {
61  CollectInputColumnsVisitor input_columns_visitor;
62  std::list<std::shared_ptr<Analyzer::Expr>> quals;
63  std::unordered_set<InputColDescriptor> input_column_descriptors;
64  BindFilterToOutermostVisitor bind_filter_to_outermost;
65  for (const auto& filter_expr : filter_expressions) {
66  input_column_descriptors = input_columns_visitor.aggregateResult(
67  input_column_descriptors, input_columns_visitor.visit(filter_expr.get()));
68  quals.push_back(bind_filter_to_outermost.visit(filter_expr.get()));
69  }
70  std::vector<InputDescriptor> input_descs;
71  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
72  for (const auto& input_col_desc : input_column_descriptors) {
73  if (input_descs.empty()) {
74  input_descs.push_back(input_col_desc.getScanDesc());
75  } else {
76  CHECK(input_col_desc.getScanDesc() == input_descs.front());
77  }
78  input_col_descs.push_back(std::make_shared<const InputColDescriptor>(input_col_desc));
79  }
80  const auto count_expr =
81  makeExpr<Analyzer::AggExpr>(SQLTypeInfo(g_bigint_count ? kBIGINT : kINT, false),
82  kCOUNT,
83  nullptr,
84  false,
85  nullptr);
86  RelAlgExecutionUnit ra_exe_unit{input_descs,
87  input_col_descs,
88  {},
89  quals,
90  {},
91  {},
92  {count_expr.get()},
93  nullptr,
94  {{}, SortAlgorithm::Default, 0, 0},
95  0};
96  size_t one{1};
97  ResultSetPtr filtered_result;
98  const auto table_infos = get_table_infos(input_descs, executor_);
99  CHECK_EQ(size_t(1), table_infos.size());
100  const size_t total_rows_upper_bound = table_infos.front().info.getNumTuplesUpperBound();
101  try {
102  ColumnCacheMap column_cache;
103  filtered_result = executor_->executeWorkUnit(one,
104  true,
105  table_infos,
106  ra_exe_unit,
107  co,
108  eo,
109  cat_,
110  executor_->getRowSetMemoryOwner(),
111  nullptr,
112  false,
113  column_cache);
114  } catch (...) {
115  return {false, 1.0, 0};
116  }
117  const auto count_row = filtered_result->getNextRow(false, false);
118  CHECK_EQ(size_t(1), count_row.size());
119  const auto& count_tv = count_row.front();
120  const auto count_scalar_tv = boost::get<ScalarTargetValue>(&count_tv);
121  CHECK(count_scalar_tv);
122  const auto count_ptr = boost::get<int64_t>(count_scalar_tv);
123  CHECK(count_ptr);
124  const auto rows_passing = *count_ptr;
125  const auto rows_total = std::max(total_rows_upper_bound, size_t(1));
126  return {true, static_cast<float>(rows_passing) / rows_total, total_rows_upper_bound};
127 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::shared_ptr< ResultSet > ResultSetPtr
CHECK(cgen_state)
const Catalog_Namespace::Catalog & cat_
bool g_bigint_count
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852
Definition: sqldefs.h:71
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
Definition: sqltypes.h:48
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t RelAlgExecutor::getNDVEstimation ( const WorkUnit work_unit,
const bool  is_agg,
const CompilationOptions co,
const ExecutionOptions eo 
)
private

Definition at line 36 of file CardinalityEstimator.cpp.

References cat_, create_ndv_execution_unit(), Executor::ERR_INTERRUPTED, Executor::ERR_OUT_OF_TIME, RelAlgExecutor::WorkUnit::exe_unit, executor_, get_table_infos(), QueryExecutionError::getErrorCode(), getErrorMessageFromCode(), and UNREACHABLE.

Referenced by executeWorkUnit().

39  {
40  const auto estimator_exe_unit = create_ndv_execution_unit(work_unit.exe_unit);
41  size_t one{1};
42  ColumnCacheMap column_cache;
43  try {
44  const auto estimator_result =
45  executor_->executeWorkUnit(one,
46  is_agg,
47  get_table_infos(work_unit.exe_unit, executor_),
48  estimator_exe_unit,
49  co,
50  eo,
51  cat_,
52  executor_->row_set_mem_owner_,
53  nullptr,
54  false,
55  column_cache);
56  if (!estimator_result) {
57  return 1;
58  }
59  return std::max(estimator_result->getNDVEstimator(), size_t(1));
60  } catch (const QueryExecutionError& e) {
62  throw std::runtime_error("Cardinality estimation query ran out of time");
63  }
65  throw std::runtime_error("Cardinality estimation query has been interrupted");
66  }
67  throw std::runtime_error("Failed to run the cardinality estimation query: " +
69  }
70  UNREACHABLE();
71  return 1;
72 }
bool is_agg(const Analyzer::Expr *expr)
int32_t getErrorCode() const
Definition: ErrorHandling.h:55
static const int32_t ERR_INTERRUPTED
Definition: Execute.h:1042
#define UNREACHABLE()
Definition: Logger.h:234
RelAlgExecutionUnit create_ndv_execution_unit(const RelAlgExecutionUnit &ra_exe_unit)
const Catalog_Namespace::Catalog & cat_
static const int32_t ERR_OUT_OF_TIME
Definition: Execute.h:1041
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
static std::string getErrorMessageFromCode(const int32_t error_code)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::vector<std::shared_ptr<RexSubQuery> >& RelAlgExecutor::getSubqueries ( ) const
inlinenoexcept

Definition at line 108 of file RelAlgExecutor.h.

References subqueries_.

108  {
109  return subqueries_;
110  };
std::vector< std::shared_ptr< RexSubQuery > > subqueries_
void RelAlgExecutor::handleNop ( RaExecutionDesc ed)
private

Definition at line 425 of file RelAlgExecutor.cpp.

References addTemporaryTable(), CHECK(), CHECK_EQ, RaExecutionDesc::getBody(), and temporary_tables_.

Referenced by executeRelAlgStep().

425  {
426  // just set the result of the previous node as the result of no op
427  auto body = ed.getBody();
428  CHECK(dynamic_cast<const RelAggregate*>(body));
429  CHECK_EQ(size_t(1), body->inputCount());
430  const auto input = body->getInput(0);
431  body->setOutputMetainfo(input->getOutputMetainfo());
432  const auto it = temporary_tables_.find(-input->getId());
433  CHECK(it != temporary_tables_.end());
434  // set up temp table as it could be used by the outer query or next step
435  addTemporaryTable(-body->getId(), it->second);
436 
437  ed.setResult({it->second, input->getOutputMetainfo()});
438 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
TemporaryTables temporary_tables_
void addTemporaryTable(const int table_id, const ResultSetPtr &result)
CHECK(cgen_state)
const RelAlgNode * getBody() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExecutionResult RelAlgExecutor::handleOutOfMemoryRetry ( const RelAlgExecutor::WorkUnit work_unit,
const std::vector< TargetMetaInfo > &  targets_meta,
const bool  is_agg,
const CompilationOptions co,
const ExecutionOptions eo,
RenderInfo render_info,
const bool  was_multifrag_kernel_launch,
const int64_t  queue_time_ms 
)
private

Definition at line 2149 of file RelAlgExecutor.cpp.

References ExecutionOptions::allow_loop_joins, cat_, CHECK(), CPU, anonymous_namespace{RelAlgExecutor.cpp}::decide_approx_count_distinct_implementation(), CompilationOptions::device_type_, ExecutionOptions::dynamic_watchdog_time_limit, RelAlgExecutor::WorkUnit::exe_unit, executor_, g_enable_watchdog, get_table_infos(), QueryExecutionError::getErrorCode(), ExecutionOptions::gpu_input_mem_limit_percent, handlePersistentError(), CompilationOptions::hoist_literals_, ExecutionOptions::jit_debug, LOG, RelAlgExecutor::WorkUnit::max_groups_buffer_entry_guess, CompilationOptions::opt_level_, ExecutionOptions::output_columnar_hint, run_benchmark_import::result, RenderInfo::setForceNonInSituData(), target_exprs_owned_, RelAlgExecutionUnit::use_bump_allocator, VLOG, logger::WARNING, ExecutionOptions::with_dynamic_watchdog, CompilationOptions::with_dynamic_watchdog_, and ExecutionOptions::with_watchdog.

Referenced by executeWorkUnit().

2157  {
2158  // Disable the bump allocator
2159  // Note that this will have basically the same affect as using the bump allocator for
2160  // the kernel per fragment path. Need to unify the max_groups_buffer_entry_guess = 0
2161  // path and the bump allocator path for kernel per fragment execution.
2162  auto ra_exe_unit_in = work_unit.exe_unit;
2163  ra_exe_unit_in.use_bump_allocator = false;
2164 
2165  auto result = ExecutionResult{std::make_shared<ResultSet>(std::vector<TargetInfo>{},
2166  co.device_type_,
2168  nullptr,
2169  executor_),
2170  {}};
2171 
2172  const auto table_infos = get_table_infos(ra_exe_unit_in, executor_);
2173  auto max_groups_buffer_entry_guess = work_unit.max_groups_buffer_entry_guess;
2174  ExecutionOptions eo_no_multifrag{eo.output_columnar_hint,
2175  false,
2176  false,
2177  eo.allow_loop_joins,
2178  eo.with_watchdog,
2179  eo.jit_debug,
2180  false,
2183  false,
2184  false,
2186 
2187  if (was_multifrag_kernel_launch) {
2188  try {
2189  // Attempt to retry using the kernel per fragment path. The smaller input size
2190  // required may allow the entire kernel to execute in GPU memory.
2191  LOG(WARNING) << "Multifrag query ran out of memory, retrying with multifragment "
2192  "kernels disabled.";
2193  const auto ra_exe_unit = decide_approx_count_distinct_implementation(
2194  ra_exe_unit_in, table_infos, executor_, co.device_type_, target_exprs_owned_);
2195  ColumnCacheMap column_cache;
2196  result = {executor_->executeWorkUnit(max_groups_buffer_entry_guess,
2197  is_agg,
2198  table_infos,
2199  ra_exe_unit,
2200  co,
2201  eo_no_multifrag,
2202  cat_,
2203  executor_->row_set_mem_owner_,
2204  nullptr,
2205  true,
2206  column_cache),
2207  targets_meta};
2208  result.setQueueTime(queue_time_ms);
2209  } catch (const QueryExecutionError& e) {
2211  LOG(WARNING) << "Kernel per fragment query ran out of memory, retrying on CPU.";
2212  }
2213  }
2214 
2215  if (render_info) {
2216  render_info->setForceNonInSituData();
2217  }
2218 
2220  co.hoist_literals_,
2221  co.opt_level_,
2223 
2224  // Only reset the group buffer entry guess if we ran out of slots, which
2225  // suggests a
2226  // highly pathological input which prevented a good estimation of distinct tuple
2227  // count. For projection queries, this will force a per-fragment scan limit, which is
2228  // compatible with the CPU path
2229  VLOG(1) << "Resetting max groups buffer entry guess.";
2230  max_groups_buffer_entry_guess = 0;
2231 
2232  int iteration_ctr = -1;
2233  while (true) {
2234  iteration_ctr++;
2236  ra_exe_unit_in, table_infos, executor_, co_cpu.device_type_, target_exprs_owned_);
2237  ColumnCacheMap column_cache;
2238  try {
2239  result = {executor_->executeWorkUnit(max_groups_buffer_entry_guess,
2240  is_agg,
2241  table_infos,
2242  ra_exe_unit,
2243  co_cpu,
2244  eo_no_multifrag,
2245  cat_,
2246  executor_->row_set_mem_owner_,
2247  nullptr,
2248  true,
2249  column_cache),
2250  targets_meta};
2251  } catch (const QueryExecutionError& e) {
2252  // Ran out of slots
2253  if (e.getErrorCode() < 0) {
2254  // Even the conservative guess failed; it should only happen when we group
2255  // by a huge cardinality array. Maybe we should throw an exception instead?
2256  // Such a heavy query is entirely capable of exhausting all the host memory.
2257  CHECK(max_groups_buffer_entry_guess);
2258  // Only allow two iterations of increasingly large entry guesses up to a maximum
2259  // of 512MB per column per kernel
2260  if (g_enable_watchdog || iteration_ctr > 1) {
2261  throw std::runtime_error("Query ran out of output slots in the result");
2262  }
2263  max_groups_buffer_entry_guess *= 2;
2264  LOG(WARNING) << "Query ran out of slots in the output buffer, retrying with max "
2265  "groups buffer entry "
2266  "guess equal to "
2267  << max_groups_buffer_entry_guess;
2268  } else {
2270  }
2271  continue;
2272  }
2273  result.setQueueTime(queue_time_ms);
2274  return result;
2275  }
2276  return result;
2277 }
bool is_agg(const Analyzer::Expr *expr)
int32_t getErrorCode() const
Definition: ErrorHandling.h:55
void setForceNonInSituData()
Definition: RenderInfo.cpp:42
#define LOG(tag)
Definition: Logger.h:185
RelAlgExecutionUnit exe_unit
const ExecutorOptLevel opt_level_
bool g_enable_watchdog
std::vector< std::shared_ptr< Analyzer::Expr > > target_exprs_owned_
CHECK(cgen_state)
const bool with_dynamic_watchdog
const double gpu_input_mem_limit_percent
const Catalog_Namespace::Catalog & cat_
const bool output_columnar_hint
ExecutorDeviceType device_type_
static void handlePersistentError(const int32_t error_code)
const size_t max_groups_buffer_entry_guess
const bool allow_loop_joins
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
const bool with_dynamic_watchdog_
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)
const unsigned dynamic_watchdog_time_limit
Executor * executor_
#define VLOG(n)
Definition: Logger.h:280
const bool with_watchdog

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::handlePersistentError ( const int32_t  error_code)
staticprivate

Definition at line 2279 of file RelAlgExecutor.cpp.

References Executor::ERR_OUT_OF_GPU_MEM, Executor::ERR_SPECULATIVE_TOP_OOM, logger::ERROR, g_allow_cpu_retry, getErrorMessageFromCode(), logger::INFO, and LOG.

Referenced by executeTableFunction(), executeWorkUnit(), and handleOutOfMemoryRetry().

2279  {
2280  LOG(ERROR) << "Query execution failed with error "
2283  throw SpeculativeTopNFailed();
2284  }
2286  // We ran out of GPU memory, this doesn't count as an error if the query is
2287  // allowed to continue on CPU because retry on CPU is explicitly allowed through
2288  // --allow-cpu-retry.
2289  LOG(INFO) << "Query ran out of GPU memory, attempting punt to CPU";
2290  if (!g_allow_cpu_retry) {
2291  throw std::runtime_error(
2292  "Query ran out of GPU memory, unable to automatically retry on CPU");
2293  }
2294  return;
2295  }
2296  throw std::runtime_error(getErrorMessageFromCode(error_code));
2297 }
#define LOG(tag)
Definition: Logger.h:185
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
static const int32_t ERR_OUT_OF_GPU_MEM
Definition: Execute.h:1034
static const int32_t ERR_SPECULATIVE_TOP_OOM
Definition: Execute.h:1040
bool g_allow_cpu_retry
Definition: Execute.cpp:74
static std::string getErrorMessageFromCode(const int32_t error_code)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool RelAlgExecutor::isRowidLookup ( const WorkUnit work_unit)
private

Definition at line 2114 of file RelAlgExecutor.cpp.

References cat_, CHECK_EQ, RelAlgExecutor::WorkUnit::exe_unit, get_column_descriptor(), Analyzer::BinOper::get_left_operand(), RelAlgExecutionUnit::input_descs, kEQ, and TABLE.

Referenced by executeWorkUnit().

2114  {
2115  const auto& ra_exe_unit = work_unit.exe_unit;
2116  if (ra_exe_unit.input_descs.size() != 1) {
2117  return false;
2118  }
2119  const auto& table_desc = ra_exe_unit.input_descs.front();
2120  if (table_desc.getSourceType() != InputSourceType::TABLE) {
2121  return false;
2122  }
2123  const int table_id = table_desc.getTableId();
2124  for (const auto simple_qual : ra_exe_unit.simple_quals) {
2125  const auto comp_expr =
2126  std::dynamic_pointer_cast<const Analyzer::BinOper>(simple_qual);
2127  if (!comp_expr || comp_expr->get_optype() != kEQ) {
2128  return false;
2129  }
2130  const auto lhs = comp_expr->get_left_operand();
2131  const auto lhs_col = dynamic_cast<const Analyzer::ColumnVar*>(lhs);
2132  if (!lhs_col || !lhs_col->get_table_id() || lhs_col->get_rte_idx()) {
2133  return false;
2134  }
2135  const auto rhs = comp_expr->get_right_operand();
2136  const auto rhs_const = dynamic_cast<const Analyzer::Constant*>(rhs);
2137  if (!rhs_const) {
2138  return false;
2139  }
2140  auto cd = get_column_descriptor(lhs_col->get_column_id(), table_id, cat_);
2141  if (cd->isVirtualCol) {
2142  CHECK_EQ("rowid", cd->columnName);
2143  return true;
2144  }
2145  }
2146  return false;
2147 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
Definition: sqldefs.h:30
const Catalog_Namespace::Catalog & cat_
const Expr * get_left_operand() const
Definition: Analyzer.h:436
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:142

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list< std::shared_ptr< Analyzer::Expr > > RelAlgExecutor::makeJoinQuals ( const RexScalar join_condition,
const std::vector< JoinType > &  join_types,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level,
const bool  just_explain 
) const
private

Definition at line 2779 of file RelAlgExecutor.cpp.

References cat_, combine_equi_join_conditions(), executor_, anonymous_namespace{RelAlgExecutor.cpp}::get_bitwise_equals_conjunction(), now_, qual_to_conjunctive_form(), anonymous_namespace{RelAlgExecutor.cpp}::reverse_logical_distribution(), anonymous_namespace{RelAlgExecutor.cpp}::rex_to_conjunctive_form(), and RelAlgTranslator::translateScalarRex().

Referenced by translateLeftDeepJoinFilter().

2783  {
2784  QueryFeatureDescriptor query_features;
2785  RelAlgTranslator translator(cat_,
2786  executor_,
2787  input_to_nest_level,
2788  join_types,
2789  now_,
2790  just_explain,
2791  query_features);
2792  const auto rex_condition_cf = rex_to_conjunctive_form(join_condition);
2793  std::list<std::shared_ptr<Analyzer::Expr>> join_condition_quals;
2794  for (const auto rex_condition_component : rex_condition_cf) {
2795  const auto bw_equals = get_bitwise_equals_conjunction(rex_condition_component);
2796  const auto join_condition =
2797  reverse_logical_distribution(translator.translateScalarRex(
2798  bw_equals ? bw_equals.get() : rex_condition_component));
2799  auto join_condition_cf = qual_to_conjunctive_form(join_condition);
2800  join_condition_quals.insert(join_condition_quals.end(),
2801  join_condition_cf.quals.begin(),
2802  join_condition_cf.quals.end());
2803  join_condition_quals.insert(join_condition_quals.end(),
2804  join_condition_cf.simple_quals.begin(),
2805  join_condition_cf.simple_quals.end());
2806  }
2807  return combine_equi_join_conditions(join_condition_quals);
2808 }
std::unique_ptr< const RexOperator > get_bitwise_equals_conjunction(const RexScalar *scalar)
QualsConjunctiveForm qual_to_conjunctive_form(const std::shared_ptr< Analyzer::Expr > qual_expr)
std::vector< const RexScalar * > rex_to_conjunctive_form(const RexScalar *qual_expr)
const Catalog_Namespace::Catalog & cat_
std::shared_ptr< Analyzer::Expr > reverse_logical_distribution(const std::shared_ptr< Analyzer::Expr > &expr)
Executor * executor_
std::list< std::shared_ptr< Analyzer::Expr > > combine_equi_join_conditions(const std::list< std::shared_ptr< Analyzer::Expr >> &join_quals)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelAlgExecutor::prepareLeafExecution ( const AggregatedColRange agg_col_range,
const StringDictionaryGenerations string_dictionary_generations,
const TableGenerations table_generations 
)

Definition at line 231 of file RelAlgExecutor.cpp.

References executor_, g_enable_dynamic_watchdog, queue_time_ms_, timer_start(), and timer_stop().

234  {
235  // capture the lock acquistion time
236  auto clock_begin = timer_start();
238  executor_->resetInterrupt();
239  }
240  queue_time_ms_ = timer_stop(clock_begin);
241  executor_->row_set_mem_owner_ = std::make_shared<RowSetMemoryOwner>();
242  executor_->table_generations_ = table_generations;
243  executor_->agg_col_range_cache_ = agg_col_range;
244  executor_->string_dictionary_generations_ = string_dictionary_generations;
245 }
int64_t queue_time_ms_
TypeR::rep timer_stop(Type clock_begin)
Definition: measure.h:46
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:72
Executor * executor_
Type timer_start()
Definition: measure.h:40

+ Here is the call graph for this function:

void RelAlgExecutor::registerSubquery ( std::shared_ptr< RexSubQuery subquery)
inlinenoexcept

Definition at line 104 of file RelAlgExecutor.h.

References subqueries_.

Referenced by anonymous_namespace{RelAlgAbstractInterpreter.cpp}::parse_subquery().

104  {
105  subqueries_.push_back(subquery);
106  }
std::vector< std::shared_ptr< RexSubQuery > > subqueries_

+ Here is the caller graph for this function:

std::vector< PushedDownFilterInfo > RelAlgExecutor::selectFiltersToBePushedDown ( const RelAlgExecutor::WorkUnit work_unit,
const CompilationOptions co,
const ExecutionOptions eo 
)
private

Goes through all candidate filters and evaluate whether they pass the selectivity criteria or not.

Definition at line 133 of file JoinFilterPushDown.cpp.

References RelAlgExecutor::WorkUnit::exe_unit, executor_, find_push_down_filters(), get_table_infos(), getFilterSelectivity(), RelAlgExecutionUnit::input_descs, RelAlgExecutor::WorkUnit::input_permutation, RelAlgExecutor::WorkUnit::left_deep_join_input_sizes, and to_gather_info_for_filter_selectivity().

Referenced by executeWorkUnit().

136  {
137  const auto all_push_down_candidates =
139  work_unit.input_permutation,
140  work_unit.left_deep_join_input_sizes);
141  std::vector<PushedDownFilterInfo> selective_push_down_candidates;
142  const auto ti = get_table_infos(work_unit.exe_unit.input_descs, executor_);
144  for (const auto& candidate : all_push_down_candidates) {
145  const auto selectivity = getFilterSelectivity(candidate.filter_expressions, co, eo);
146  if (selectivity.is_valid && selectivity.isFilterSelectiveEnough()) {
147  selective_push_down_candidates.push_back(candidate);
148  }
149  }
150  }
151  return selective_push_down_candidates;
152 }
const std::vector< size_t > left_deep_join_input_sizes
RelAlgExecutionUnit exe_unit
FilterSelectivity getFilterSelectivity(const std::vector< std::shared_ptr< Analyzer::Expr >> &filter_expressions, const CompilationOptions &co, const ExecutionOptions &eo)
const std::vector< InputDescriptor > input_descs
bool to_gather_info_for_filter_selectivity(const std::vector< InputTableInfo > &table_infos)
std::vector< PushedDownFilterInfo > find_push_down_filters(const RelAlgExecutionUnit &ra_exe_unit, const std::vector< size_t > &input_permutation, const std::vector< size_t > &left_deep_join_input_sizes)
const std::vector< size_t > input_permutation
std::vector< InputTableInfo > get_table_infos(const std::vector< InputDescriptor > &input_descs, Executor *executor)
Executor * executor_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

JoinQualsPerNestingLevel RelAlgExecutor::translateLeftDeepJoinFilter ( const RelLeftDeepInnerJoin join,
const std::vector< InputDescriptor > &  input_descs,
const std::unordered_map< const RelAlgNode *, int > &  input_to_nest_level,
const bool  just_explain 
)
private

Definition at line 2813 of file RelAlgExecutor.cpp.

References CHECK(), CHECK_LE, RelLeftDeepInnerJoin::getInnerCondition(), RelLeftDeepInnerJoin::getOuterCondition(), INNER, LEFT, anonymous_namespace{RelAlgExecutor.cpp}::left_deep_join_types(), makeJoinQuals(), and run_benchmark_import::result.

Referenced by createCompoundWorkUnit(), createModifyCompoundWorkUnit(), createModifyProjectWorkUnit(), and createProjectWorkUnit().

2817  {
2818  const auto join_types = left_deep_join_types(join);
2819  const auto join_condition_quals = makeJoinQuals(
2820  join->getInnerCondition(), join_types, input_to_nest_level, just_explain);
2821  MaxRangeTableIndexVisitor rte_idx_visitor;
2822  JoinQualsPerNestingLevel result(input_descs.size() - 1);
2823  std::unordered_set<std::shared_ptr<Analyzer::Expr>> visited_quals;
2824  for (size_t rte_idx = 1; rte_idx < input_descs.size(); ++rte_idx) {
2825  const auto outer_condition = join->getOuterCondition(rte_idx);
2826  if (outer_condition) {
2827  result[rte_idx - 1].quals =
2828  makeJoinQuals(outer_condition, join_types, input_to_nest_level, just_explain);
2829  CHECK_LE(rte_idx, join_types.size());
2830  CHECK(join_types[rte_idx - 1] == JoinType::LEFT);
2831  result[rte_idx - 1].type = JoinType::LEFT;
2832  continue;
2833  }
2834  for (const auto qual : join_condition_quals) {
2835  if (visited_quals.count(qual)) {
2836  continue;
2837  }
2838  const auto qual_rte_idx = rte_idx_visitor.visit(qual.get());
2839  if (static_cast<size_t>(qual_rte_idx) <= rte_idx) {
2840  const auto it_ok = visited_quals.emplace(qual);
2841  CHECK(it_ok.second);
2842  result[rte_idx - 1].quals.push_back(qual);
2843  }
2844  }
2845  CHECK_LE(rte_idx, join_types.size());
2846  CHECK(join_types[rte_idx - 1] == JoinType::INNER);
2847  result[rte_idx - 1].type = JoinType::INNER;
2848  }
2849  return result;
2850 }
std::vector< JoinType > left_deep_join_types(const RelLeftDeepInnerJoin *left_deep_join)
const RexScalar * getOuterCondition(const size_t nesting_level) const
std::vector< JoinCondition > JoinQualsPerNestingLevel
CHECK(cgen_state)
#define CHECK_LE(x, y)
Definition: Logger.h:201
const RexScalar * getInnerCondition() const
std::list< std::shared_ptr< Analyzer::Expr > > makeJoinQuals(const RexScalar *join_condition, const std::vector< JoinType > &join_types, const std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, const bool just_explain) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class PendingExecutionClosure
friend

Definition at line 342 of file RelAlgExecutor.h.

Member Data Documentation

std::unordered_map<unsigned, AggregatedResult> RelAlgExecutor::leaf_results_
private

Definition at line 337 of file RelAlgExecutor.h.

Referenced by addLeafResult(), executeSort(), and executeWorkUnit().

const size_t RelAlgExecutor::max_groups_buffer_entry_default_guess {16384}
staticprivate
int64_t RelAlgExecutor::queue_time_ms_
private

Definition at line 338 of file RelAlgExecutor.h.

Referenced by executeRelAlgQuerySingleStep(), and prepareLeafExecution().

SpeculativeTopNBlacklist RelAlgExecutor::speculative_topn_blacklist_
staticprivate

Definition at line 339 of file RelAlgExecutor.h.

Referenced by createSortInputWorkUnit(), and executeSort().

std::vector<std::shared_ptr<RexSubQuery> > RelAlgExecutor::subqueries_
private

The documentation for this class was generated from the following files: