OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JoinFilterPushDown.cpp File Reference
#include "JoinFilterPushDown.h"
#include "DeepCopyVisitor.h"
#include "RelAlgExecutor.h"
+ Include dependency graph for JoinFilterPushDown.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{JoinFilterPushDown.cpp}::BindFilterToOutermostVisitor
 
class  anonymous_namespace{JoinFilterPushDown.cpp}::CollectInputColumnsVisitor
 

Namespaces

 anonymous_namespace{JoinFilterPushDown.cpp}
 

Functions

bool to_gather_info_for_filter_selectivity (const std::vector< InputTableInfo > &table_infos)
 
std::vector< PushedDownFilterInfofind_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)
 

Function Documentation

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 
)

Go through all tables involved in the relational algebra plan, and select potential candidates to be pushed down by calcite. For each filter we store a set of intermediate indices (previous, current, and next table) based on the column indices in their query string.

Definition at line 226 of file JoinFilterPushDown.cpp.

References CHECK_EQ, CHECK_GE, CHECK_LT, RelAlgExecutionUnit::input_descs, gpu_enabled::iota(), RelAlgExecutionUnit::join_quals, gpu_enabled::partial_sum(), run_benchmark_import::result, and ScalarExprVisitor< T >::visit().

Referenced by RelAlgExecutor::selectFiltersToBePushedDown().

229  {
230  std::vector<PushedDownFilterInfo> result;
231  if (left_deep_join_input_sizes.empty()) {
232  return result;
233  }
234  std::vector<size_t> input_size_prefix_sums(left_deep_join_input_sizes.size());
235  std::partial_sum(left_deep_join_input_sizes.begin(),
236  left_deep_join_input_sizes.end(),
237  input_size_prefix_sums.begin());
238  std::vector<int> to_original_rte_idx(ra_exe_unit.input_descs.size(),
239  ra_exe_unit.input_descs.size());
240  if (!input_permutation.empty()) {
241  CHECK_EQ(to_original_rte_idx.size(), input_permutation.size());
242  for (size_t i = 0; i < input_permutation.size(); ++i) {
243  CHECK_LT(input_permutation[i], to_original_rte_idx.size());
244  CHECK_EQ(static_cast<size_t>(to_original_rte_idx[input_permutation[i]]),
245  to_original_rte_idx.size());
246  to_original_rte_idx[input_permutation[i]] = i;
247  }
248  } else {
249  std::iota(to_original_rte_idx.begin(), to_original_rte_idx.end(), 0);
250  }
251  std::unordered_map<int, std::vector<std::shared_ptr<Analyzer::Expr>>>
252  filters_per_nesting_level;
253  for (const auto& level_conditions : ra_exe_unit.join_quals) {
255  for (const auto& cond : level_conditions.quals) {
256  const auto rte_indices = visitor.visit(cond.get());
257  if (rte_indices.size() > 1) {
258  continue;
259  }
260  const int rte_idx = (!rte_indices.empty()) ? *rte_indices.cbegin() : 0;
261  if (!rte_idx) {
262  continue;
263  }
264  CHECK_GE(rte_idx, 0);
265  CHECK_LT(static_cast<size_t>(rte_idx), to_original_rte_idx.size());
266  filters_per_nesting_level[to_original_rte_idx[rte_idx]].push_back(cond);
267  }
268  }
269  for (const auto& kv : filters_per_nesting_level) {
270  CHECK_GE(kv.first, 0);
271  CHECK_LT(static_cast<size_t>(kv.first), input_size_prefix_sums.size());
272  size_t input_prev = (kv.first > 1) ? input_size_prefix_sums[kv.first - 2] : 0;
273  size_t input_start = kv.first ? input_size_prefix_sums[kv.first - 1] : 0;
274  size_t input_next = input_size_prefix_sums[kv.first];
275  result.emplace_back(
276  PushedDownFilterInfo{kv.second, input_prev, input_start, input_next});
277  }
278  return result;
279 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::vector< InputDescriptor > input_descs
#define CHECK_GE(x, y)
Definition: Logger.h:235
T visit(const Analyzer::Expr *expr) const
const JoinQualsPerNestingLevel join_quals
DEVICE void partial_sum(ARGS &&...args)
Definition: gpu_enabled.h:87
#define CHECK_LT(x, y)
Definition: Logger.h:232
DEVICE void iota(ARGS &&...args)
Definition: gpu_enabled.h:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool to_gather_info_for_filter_selectivity ( const std::vector< InputTableInfo > &  table_infos)

The main purpose of this function is to prevent going through extra overhead of computing required statistics for finding the right candidates and then the actual push-down, unless the problem is large enough that such effort is potentially helpful.

Definition at line 199 of file JoinFilterPushDown.cpp.

Referenced by RelAlgExecutor::selectFiltersToBePushedDown().

200  {
201  if (table_infos.size() < 2) {
202  return false;
203  }
204  // we currently do not support filter push down when there is a self-join involved:
205  // TODO(Saman): prevent Calcite from optimizing self-joins to remove this exclusion
206  std::unordered_set<int> table_ids;
207  for (auto ti : table_infos) {
208  if (table_ids.find(ti.table_id) == table_ids.end()) {
209  table_ids.insert(ti.table_id);
210  } else {
211  // a self-join is involved
212  return false;
213  }
214  }
215  // TODO(Saman): add some extra heuristics to avoid preflight count and push down if it
216  // is not going to be helpful.
217  return true;
218 }

+ Here is the caller graph for this function: