OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 215 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().

218  {
219  std::vector<PushedDownFilterInfo> result;
220  if (left_deep_join_input_sizes.empty()) {
221  return result;
222  }
223  std::vector<size_t> input_size_prefix_sums(left_deep_join_input_sizes.size());
224  std::partial_sum(left_deep_join_input_sizes.begin(),
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(),
228  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;
236  }
237  } else {
238  std::iota(to_original_rte_idx.begin(), to_original_rte_idx.end(), 0);
239  }
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) {
247  continue;
248  }
249  const int rte_idx = (!rte_indices.empty()) ? *rte_indices.cbegin() : 0;
250  if (!rte_idx) {
251  continue;
252  }
253  CHECK_GE(rte_idx, 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);
256  }
257  }
258  for (const auto& kv : filters_per_nesting_level) {
259  CHECK_GE(kv.first, 0);
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];
264  result.emplace_back(
265  PushedDownFilterInfo{kv.second, input_prev, input_start, input_next});
266  }
267  return result;
268 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< InputDescriptor > input_descs
#define CHECK_GE(x, y)
Definition: Logger.h:306
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:303
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 188 of file JoinFilterPushDown.cpp.

Referenced by RelAlgExecutor::selectFiltersToBePushedDown().

189  {
190  if (table_infos.size() < 2) {
191  return false;
192  }
193  // we currently do not support filter push down when there is a self-join involved:
194  // TODO(Saman): prevent Calcite from optimizing self-joins to remove this exclusion
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);
199  } else {
200  // a self-join is involved
201  return false;
202  }
203  }
204  // TODO(Saman): add some extra heuristics to avoid preflight count and push down if it
205  // is not going to be helpful.
206  return true;
207 }

+ Here is the caller graph for this function:

Variable Documentation

bool g_enable_filter_push_down

Definition at line 98 of file Execute.cpp.

float g_filter_push_down_high_frac

Definition at line 100 of file Execute.cpp.

float g_filter_push_down_low_frac

Definition at line 99 of file Execute.cpp.

size_t g_filter_push_down_passing_row_ubound

Definition at line 101 of file Execute.cpp.