OmniSciDB  c1a53651b2
 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)
 
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

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 2493 of file RelAlgDag.cpp.

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

Referenced by need_pushdown_generic_expr().

2494  {
2495  for (auto const& partition_key : window_expr->getPartitionKeys()) {
2496  auto partition_input = dynamic_cast<RexInput const*>(partition_key.get());
2497  if (!partition_input) {
2498  return true;
2499  }
2500  }
2501  for (auto const& order_key : window_expr->getOrderKeys()) {
2502  auto order_input = dynamic_cast<RexInput const*>(order_key.get());
2503  if (!order_input) {
2504  return true;
2505  }
2506  }
2507  for (size_t k = 0; k < window_expr->size(); k++) {
2508  if (!shared::dynamic_castable_to_any<RexInput, RexLiteral>(
2509  window_expr->getOperand(k))) {
2510  has_generic_expr_in_window_func = true;
2511  return true;
2512  }
2513  }
2514  return false;
2515 }

+ 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 1891 of file RelAlgDag.cpp.

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

1893  {
1894  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1895  if (index == 0 && agg_node->getGroupByCount() > 0) {
1896  return true;
1897  } else {
1898  // Is an aggregated target, only allow the project to be elided if the aggregate
1899  // target is simply passed through (i.e. if the top level expression attached to
1900  // the project node is a RexInput expression)
1901  return first_rex_is_input;
1902  }
1903  }
1904  return first_rex_is_input;
1905 }

+ 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 1950 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().

1950  {
1951  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1952  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1953  CHECK_EQ(divide_operator->size(), size_t(2));
1954  const auto case_operator =
1955  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1956  const auto second_window =
1957  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1958  if (case_operator && second_window &&
1959  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1960  if (is_window_function_sum(case_operator)) {
1961  return true;
1962  }
1963  }
1964  }
1965  return false;
1966 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t size() const
Definition: RelAlgDag.h:270
const RexScalar * getOperand(const size_t idx) const
Definition: RelAlgDag.h:272
SQLOps getOperator() const
Definition: RelAlgDag.h:282

+ 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 1970 of file RelAlgDag.cpp.

References CHECK_EQ, is_window_function_avg(), is_window_function_sum(), and kCAST.

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().

1970  {
1971  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1972  return true;
1973  }
1974 
1975  // unwrap from casts, if they exist
1976  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1977  if (rex_cast && rex_cast->getOperator() == kCAST) {
1978  CHECK_EQ(rex_cast->size(), size_t(1));
1979  return is_window_function_operator(rex_cast->getOperand(0));
1980  }
1981 
1983  return true;
1984  }
1985 
1986  return false;
1987 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Definition: sqldefs.h:48

+ 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 1936 of file RelAlgDag.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_avg(), and is_window_function_operator().

1936  {
1937  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1938  if (case_operator && case_operator->branchCount() == 1) {
1939  const auto then_window =
1940  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1941  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1942  return true;
1943  }
1944  }
1945  return false;
1946 }

+ 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 2517 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().

2518  {
2519  bool has_generic_expr_in_window_func = false;
2520  bool res = false;
2521  for (size_t i = 0; i < window_func_project_node->size(); ++i) {
2522  auto const projected_target = window_func_project_node->getProjectAt(i);
2523  if (auto const* window_expr =
2524  dynamic_cast<RexWindowFunctionOperator const*>(projected_target)) {
2525  res =
2526  find_generic_expr_in_window_func(window_expr, has_generic_expr_in_window_func);
2527  } else if (auto const* case_expr = dynamic_cast<RexCase const*>(projected_target)) {
2528  std::unordered_map<size_t, const RexScalar*> collected_window_func;
2529  WindowFunctionCollector collector(collected_window_func, true);
2530  collector.visit(case_expr);
2531  for (auto const& kv : collected_window_func) {
2532  auto const* candidate_window_expr =
2533  dynamic_cast<RexWindowFunctionOperator const*>(kv.second);
2534  CHECK(candidate_window_expr);
2535  res = find_generic_expr_in_window_func(candidate_window_expr,
2536  has_generic_expr_in_window_func);
2537  }
2538  }
2539  }
2540  return std::make_pair(has_generic_expr_in_window_func, res);
2541 }
bool find_generic_expr_in_window_func(RexWindowFunctionOperator const *window_expr, bool &has_generic_expr_in_window_func)
Definition: RelAlgDag.cpp:2493
#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 1608 of file RelAlgDag.cpp.

References CHECK, CHECK_LT, and run_benchmark_import::result.

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

1610  {
1611  std::vector<const Rex*> result;
1612  for (size_t i = 0; i < simple_project->size(); ++i) {
1613  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1614  CHECK(input_rex);
1615  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1616  result.push_back(target_exprs[input_rex->getIndex()]);
1617  }
1618  return result;
1619 }
size_t size() const override
Definition: RelAlgDag.h:1172
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1204
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function: