OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp} Namespace Reference

Classes

class  RexInputReplacementVisitor
 
class  CoalesceSecondaryProjectVisitor
 

Functions

std::vector< const Rex * > reproject_targets (const RelProject *simple_project, const std::vector< const Rex * > &target_exprs) noexcept
 
bool input_can_be_coalesced (const RelAlgNode *parent_node, const size_t index, const bool first_rex_is_input)
 
bool is_window_function_sum (const RexScalar *rex)
 
bool is_window_function_avg (const RexScalar *rex)
 
bool is_window_function_operator (const RexScalar *rex)
 
void create_rex_input_for_new_project_node (RelAlgNode const *node, std::vector< std::unique_ptr< const RexScalar >> &scalar_exprs, std::vector< std::string > &fields)
 
bool find_generic_expr_in_window_func (RexWindowFunctionOperator const *window_expr, bool &has_generic_expr_in_window_func)
 
std::pair< bool, bool > need_pushdown_generic_expr (RelProject const *window_func_project_node)
 

Function Documentation

void anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::create_rex_input_for_new_project_node ( RelAlgNode const *  node,
std::vector< std::unique_ptr< const RexScalar >> &  scalar_exprs,
std::vector< std::string > &  fields 
)

Definition at line 2118 of file RelAlgDag.cpp.

References RelAlgNode::size().

Referenced by anonymous_namespace{RelAlgDag.cpp}::handle_agg_over_join().

2121  {
2122  for (size_t i = 0; i < node->size(); i++) {
2123  auto new_rex_input = std::make_unique<RexInput>(node, i);
2124  scalar_exprs.emplace_back(std::move(new_rex_input));
2125  fields.emplace_back("");
2126  }
2127 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::find_generic_expr_in_window_func ( RexWindowFunctionOperator const *  window_expr,
bool &  has_generic_expr_in_window_func 
)

Definition at line 2588 of file RelAlgDag.cpp.

References RexOperator::getOperand(), RexWindowFunctionOperator::getOrderKeys(), RexWindowFunctionOperator::getPartitionKeys(), and RexOperator::size().

Referenced by need_pushdown_generic_expr().

2589  {
2590  for (auto const& partition_key : window_expr->getPartitionKeys()) {
2591  auto partition_input = dynamic_cast<RexInput const*>(partition_key.get());
2592  if (!partition_input) {
2593  return true;
2594  }
2595  }
2596  for (auto const& order_key : window_expr->getOrderKeys()) {
2597  auto order_input = dynamic_cast<RexInput const*>(order_key.get());
2598  if (!order_input) {
2599  return true;
2600  }
2601  }
2602  for (size_t k = 0; k < window_expr->size(); k++) {
2603  if (!shared::dynamic_castable_to_any<RexInput, RexLiteral>(
2604  window_expr->getOperand(k))) {
2605  has_generic_expr_in_window_func = true;
2606  return true;
2607  }
2608  }
2609  return false;
2610 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::input_can_be_coalesced ( const RelAlgNode parent_node,
const size_t  index,
const bool  first_rex_is_input 
)

Definition at line 1922 of file RelAlgDag.cpp.

Referenced by anonymous_namespace{RelAlgDag.cpp}::coalesce_nodes(), and anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::CoalesceSecondaryProjectVisitor::visitInput().

1924  {
1925  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1926  if (index == 0 && agg_node->getGroupByCount() > 0) {
1927  return true;
1928  } else {
1929  // Is an aggregated target, only allow the project to be elided if the aggregate
1930  // target is simply passed through (i.e. if the top level expression attached to
1931  // the project node is a RexInput expression)
1932  return first_rex_is_input;
1933  }
1934  }
1935  return first_rex_is_input;
1936 }

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::is_window_function_avg ( const RexScalar rex)

Definition at line 1981 of file RelAlgDag.cpp.

References CHECK_EQ, COUNT, RexOperator::getOperand(), RexOperator::getOperator(), is_window_function_sum(), kDIVIDE, and RexOperator::size().

Referenced by is_window_function_operator().

1981  {
1982  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1983  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1984  CHECK_EQ(divide_operator->size(), size_t(2));
1985  const auto case_operator =
1986  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1987  const auto second_window =
1988  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1989  if (case_operator && second_window &&
1990  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1991  if (is_window_function_sum(case_operator)) {
1992  return true;
1993  }
1994  }
1995  }
1996  return false;
1997 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t size() const
Definition: RelAlgDag.h:364
const RexScalar * getOperand(const size_t idx) const
Definition: RelAlgDag.h:366
SQLOps getOperator() const
Definition: RelAlgDag.h:376

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::is_window_function_operator ( const RexScalar rex)

Definition at line 2001 of file RelAlgDag.cpp.

References is_window_function_avg(), and is_window_function_sum().

Referenced by RelProject::hasWindowFunctionExpr(), anonymous_namespace{RelAlgDag.cpp}::separate_window_function_expressions(), anonymous_namespace{RelAlgDag.cpp}::WindowFunctionCollector::visitCase(), and anonymous_namespace{RelAlgDag.cpp}::WindowFunctionCollector::visitOperator().

2001  {
2002  return dynamic_cast<const RexWindowFunctionOperator*>(rex) ||
2004 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::is_window_function_sum ( const RexScalar rex)

Definition at line 1967 of file RelAlgDag.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_avg(), and is_window_function_operator().

1967  {
1968  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1969  if (case_operator && case_operator->branchCount() == 1) {
1970  const auto then_window =
1971  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1972  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1973  return true;
1974  }
1975  }
1976  return false;
1977 }

+ Here is the caller graph for this function:

std::pair<bool, bool> anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::need_pushdown_generic_expr ( RelProject const *  window_func_project_node)

Definition at line 2612 of file RelAlgDag.cpp.

References CHECK, find_generic_expr_in_window_func(), RelProject::getProjectAt(), run_benchmark_import::res, and RelProject::size().

Referenced by anonymous_namespace{RelAlgDag.cpp}::add_window_function_pre_project().

2613  {
2614  bool has_generic_expr_in_window_func = false;
2615  bool res = false;
2616  for (size_t i = 0; i < window_func_project_node->size(); ++i) {
2617  auto const projected_target = window_func_project_node->getProjectAt(i);
2618  if (auto const* window_expr =
2619  dynamic_cast<RexWindowFunctionOperator const*>(projected_target)) {
2620  res =
2621  find_generic_expr_in_window_func(window_expr, has_generic_expr_in_window_func);
2622  } else if (auto const* case_expr = dynamic_cast<RexCase const*>(projected_target)) {
2623  std::unordered_map<size_t, const RexScalar*> collected_window_func;
2624  WindowFunctionCollector collector(collected_window_func, true);
2625  collector.visit(case_expr);
2626  for (auto const& kv : collected_window_func) {
2627  auto const* candidate_window_expr =
2628  dynamic_cast<RexWindowFunctionOperator const*>(kv.second);
2629  CHECK(candidate_window_expr);
2630  res = find_generic_expr_in_window_func(candidate_window_expr,
2631  has_generic_expr_in_window_func);
2632  }
2633  }
2634  }
2635  return std::make_pair(has_generic_expr_in_window_func, res);
2636 }
bool find_generic_expr_in_window_func(RexWindowFunctionOperator const *window_expr, bool &has_generic_expr_in_window_func)
Definition: RelAlgDag.cpp:2588
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<const Rex*> anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::reproject_targets ( const RelProject simple_project,
const std::vector< const Rex * > &  target_exprs 
)
noexcept

Definition at line 1639 of file RelAlgDag.cpp.

References CHECK, CHECK_LT, and run_benchmark_import::result.

Referenced by anonymous_namespace{RelAlgDag.cpp}::create_compound().

1641  {
1642  std::vector<const Rex*> result;
1643  for (size_t i = 0; i < simple_project->size(); ++i) {
1644  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1645  CHECK(input_rex);
1646  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1647  result.push_back(target_exprs[input_rex->getIndex()]);
1648  }
1649  return result;
1650 }
size_t size() const override
Definition: RelAlgDag.h:1320
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1352
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function: