26 return makeExpr<Analyzer::ColumnVar>(
37 column_key.column_id, column_key.table_id, column_key.db_id, 0)};
42 const std::unordered_set<InputColDescriptor>& aggregate,
43 const std::unordered_set<InputColDescriptor>& next_result)
const override {
45 result.insert(next_result.begin(), next_result.end());
60 const std::vector<std::shared_ptr<Analyzer::Expr>>& filter_expressions,
63 CollectInputColumnsVisitor input_columns_visitor;
64 std::list<std::shared_ptr<Analyzer::Expr>> quals;
65 std::unordered_set<InputColDescriptor> input_column_descriptors;
66 BindFilterToOutermostVisitor bind_filter_to_outermost;
67 for (
const auto& filter_expr : filter_expressions) {
68 input_column_descriptors = input_columns_visitor.aggregateResult(
69 input_column_descriptors, input_columns_visitor.visit(filter_expr.get()));
70 quals.push_back(bind_filter_to_outermost.visit(filter_expr.get()));
72 std::vector<InputDescriptor> input_descs;
73 std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
74 for (
const auto& input_col_desc : input_column_descriptors) {
75 if (input_descs.empty()) {
76 input_descs.push_back(input_col_desc.getScanDesc());
78 CHECK(input_col_desc.getScanDesc() == input_descs.front());
80 input_col_descs.push_back(std::make_shared<const InputColDescriptor>(input_col_desc));
82 const auto count_expr =
102 CHECK_EQ(
size_t(1), table_infos.size());
103 const size_t total_rows_upper_bound = table_infos.front().info.getNumTuplesUpperBound();
106 filtered_result =
executor_->executeWorkUnit(
107 one,
true, table_infos, ra_exe_unit, co, eo,
nullptr,
false, column_cache);
109 return {
false, 1.0, 0};
111 const auto count_row = filtered_result->getNextRow(
false,
false);
112 CHECK_EQ(
size_t(1), count_row.size());
113 const auto& count_tv = count_row.front();
114 const auto count_scalar_tv = boost::get<ScalarTargetValue>(&count_tv);
115 CHECK(count_scalar_tv);
116 const auto count_ptr = boost::get<int64_t>(count_scalar_tv);
118 const auto rows_passing = *count_ptr;
119 const auto rows_total = std::max(total_rows_upper_bound,
size_t(1));
120 return {
true,
static_cast<float>(rows_passing) / rows_total, total_rows_upper_bound};
131 const auto all_push_down_candidates =
135 std::vector<PushedDownFilterInfo> selective_push_down_candidates;
138 for (
const auto& candidate : all_push_down_candidates) {
140 if (selectivity.is_valid && selectivity.isFilterSelectiveEnough()) {
141 selective_push_down_candidates.push_back(candidate);
145 return selective_push_down_candidates;
153 const int64_t queue_time_ms) {
158 if (seq.
size() > 1 || !subqueries.empty()) {
163 auto eo_modified = eo;
165 eo_modified.just_calcite_explain =
false;
168 for (
auto subquery : subqueries) {
171 const auto subquery_ra = subquery->getRelAlg();
176 subquery->setExecutionResult(std::make_shared<ExecutionResult>(
result));
189 const std::vector<InputTableInfo>& table_infos) {
190 if (table_infos.size() < 2) {
195 std::unordered_set<shared::TableKey> table_keys;
196 for (
auto ti : table_infos) {
197 if (table_keys.find(ti.table_key) == table_keys.end()) {
198 table_keys.insert(ti.table_key);
217 const std::vector<size_t>& input_permutation,
218 const std::vector<size_t>& left_deep_join_input_sizes) {
219 std::vector<PushedDownFilterInfo>
result;
220 if (left_deep_join_input_sizes.empty()) {
223 std::vector<size_t> input_size_prefix_sums(left_deep_join_input_sizes.size());
225 left_deep_join_input_sizes.end(),
226 input_size_prefix_sums.begin());
227 std::vector<int> to_original_rte_idx(ra_exe_unit.
input_descs.size(),
229 if (!input_permutation.empty()) {
230 CHECK_EQ(to_original_rte_idx.size(), input_permutation.size());
231 for (
size_t i = 0; i < input_permutation.size(); ++i) {
232 CHECK_LT(input_permutation[i], to_original_rte_idx.size());
233 CHECK_EQ(static_cast<size_t>(to_original_rte_idx[input_permutation[i]]),
234 to_original_rte_idx.size());
235 to_original_rte_idx[input_permutation[i]] = i;
238 std::iota(to_original_rte_idx.begin(), to_original_rte_idx.end(), 0);
240 std::unordered_map<int, std::vector<std::shared_ptr<Analyzer::Expr>>>
241 filters_per_nesting_level;
242 for (
const auto& level_conditions : ra_exe_unit.
join_quals) {
244 for (
const auto& cond : level_conditions.quals) {
245 const auto rte_indices = visitor.
visit(cond.get());
246 if (rte_indices.size() > 1) {
249 const int rte_idx = (!rte_indices.empty()) ? *rte_indices.cbegin() : 0;
254 CHECK_LT(static_cast<size_t>(rte_idx), to_original_rte_idx.size());
255 filters_per_nesting_level[to_original_rte_idx[rte_idx]].push_back(cond);
258 for (
const auto& kv : filters_per_nesting_level) {
260 CHECK_LT(static_cast<size_t>(kv.first), input_size_prefix_sums.size());
261 size_t input_prev = (kv.first > 1) ? input_size_prefix_sums[kv.first - 2] : 0;
262 size_t input_start = kv.first ? input_size_prefix_sums[kv.first - 1] : 0;
263 size_t input_next = input_size_prefix_sums[kv.first];
bool find_push_down_candidates
const std::vector< size_t > left_deep_join_input_sizes
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)
RelAlgExecutionUnit exe_unit
ExecutionResult executeRelAlgQueryWithFilterPushDown(const RaExecutionSequence &seq, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info, const int64_t queue_time_ms)
FilterSelectivity getFilterSelectivity(const std::vector< std::shared_ptr< Analyzer::Expr >> &filter_expressions, const CompilationOptions &co, const ExecutionOptions &eo)
std::vector< InputDescriptor > input_descs
std::vector< PushedDownFilterInfo > selectFiltersToBePushedDown(const RelAlgExecutor::WorkUnit &work_unit, const CompilationOptions &co, const ExecutionOptions &eo)
std::shared_ptr< ResultSet > ResultSetPtr
T visit(const Analyzer::Expr *expr) const
const std::vector< std::shared_ptr< RexSubQuery > > & getSubqueries() const noexcept
bool just_calcite_explain
bool to_gather_info_for_filter_selectivity(const std::vector< InputTableInfo > &table_infos)
const JoinQualsPerNestingLevel join_quals
A container for relational algebra descriptors defining the execution order for a relational algebra ...
DEVICE void partial_sum(ARGS &&...args)
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
const SQLTypeInfo & get_type_info() const
const shared::ColumnKey & getColumnKey() const
std::shared_ptr< Analyzer::Expr > visitColumnVar(const Analyzer::ColumnVar *col_var) const override
DEVICE void iota(ARGS &&...args)
std::unordered_map< shared::TableKey, std::unordered_map< int, std::shared_ptr< const ColumnarResults >>> ColumnCacheMap