OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JoinFilterPushDown.h File Reference
#include <cstddef>
#include <numeric>
#include "QueryEngine/InputMetadata.h"
#include "QueryEngine/RangeTableIndexVisitor.h"
+ Include dependency graph for JoinFilterPushDown.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PushedDownFilterInfo
 
struct  FilterSelectivity
 

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)
 

Variables

bool g_enable_filter_push_down
 
float g_filter_push_down_low_frac
 
float g_filter_push_down_high_frac
 
size_t g_filter_push_down_passing_row_ubound
 

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 238 of file JoinFilterPushDown.cpp.

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

Referenced by RelAlgExecutor::selectFiltersToBePushedDown().

241  {
242  std::vector<PushedDownFilterInfo> result;
243  if (left_deep_join_input_sizes.empty()) {
244  return result;
245  }
246  std::vector<size_t> input_size_prefix_sums(left_deep_join_input_sizes.size());
247  std::partial_sum(left_deep_join_input_sizes.begin(),
248  left_deep_join_input_sizes.end(),
249  input_size_prefix_sums.begin());
250  std::vector<int> to_original_rte_idx(ra_exe_unit.input_descs.size(),
251  ra_exe_unit.input_descs.size());
252  if (!input_permutation.empty()) {
253  CHECK_EQ(to_original_rte_idx.size(), input_permutation.size());
254  for (size_t i = 0; i < input_permutation.size(); ++i) {
255  CHECK_LT(input_permutation[i], to_original_rte_idx.size());
256  CHECK_EQ(static_cast<size_t>(to_original_rte_idx[input_permutation[i]]),
257  to_original_rte_idx.size());
258  to_original_rte_idx[input_permutation[i]] = i;
259  }
260  } else {
261  std::iota(to_original_rte_idx.begin(), to_original_rte_idx.end(), 0);
262  }
263  std::unordered_map<int, std::vector<std::shared_ptr<Analyzer::Expr>>>
264  filters_per_nesting_level;
265  for (const auto& level_conditions : ra_exe_unit.join_quals) {
267  for (const auto& cond : level_conditions.quals) {
268  const auto rte_indices = visitor.visit(cond.get());
269  if (rte_indices.size() > 1) {
270  continue;
271  }
272  const int rte_idx = (!rte_indices.empty()) ? *rte_indices.cbegin() : 0;
273  if (!rte_idx) {
274  continue;
275  }
276  CHECK_GE(rte_idx, 0);
277  CHECK_LT(static_cast<size_t>(rte_idx), to_original_rte_idx.size());
278  filters_per_nesting_level[to_original_rte_idx[rte_idx]].push_back(cond);
279  }
280  }
281  for (const auto& kv : filters_per_nesting_level) {
282  CHECK_GE(kv.first, 0);
283  CHECK_LT(static_cast<size_t>(kv.first), input_size_prefix_sums.size());
284  size_t input_prev = (kv.first > 1) ? input_size_prefix_sums[kv.first - 2] : 0;
285  size_t input_start = kv.first ? input_size_prefix_sums[kv.first - 1] : 0;
286  size_t input_next = input_size_prefix_sums[kv.first];
287  result.emplace_back(
288  PushedDownFilterInfo{kv.second, input_prev, input_start, input_next});
289  }
290  return result;
291 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
#define CHECK_GE(x, y)
Definition: Logger.h:203
T visit(const Analyzer::Expr *expr) const
const std::vector< InputDescriptor > input_descs
const JoinQualsPerNestingLevel join_quals
#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:

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 211 of file JoinFilterPushDown.cpp.

Referenced by RelAlgExecutor::selectFiltersToBePushedDown().

212  {
213  if (table_infos.size() < 2) {
214  return false;
215  }
216  // we currently do not support filter push down when there is a self-join involved:
217  // TODO(Saman): prevent Calcite from optimizing self-joins to remove this exclusion
218  std::unordered_set<int> table_ids;
219  for (auto ti : table_infos) {
220  if (table_ids.find(ti.table_id) == table_ids.end()) {
221  table_ids.insert(ti.table_id);
222  } else {
223  // a self-join is involved
224  return false;
225  }
226  }
227  // TODO(Saman): add some extra heuristics to avoid preflight count and push down if it
228  // is not going to be helpful.
229  return true;
230 }

+ Here is the caller graph for this function:

Variable Documentation

bool g_enable_filter_push_down

Definition at line 82 of file Execute.cpp.

float g_filter_push_down_high_frac
float g_filter_push_down_low_frac
size_t g_filter_push_down_passing_row_ubound