OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{EquiJoinCondition.cpp} Namespace Reference

Functions

bool can_combine_with (const Analyzer::Expr *crt, const Analyzer::Expr *prev)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
make_composite_equals_impl (const std::vector< std::shared_ptr< Analyzer::Expr >> &crt_coalesced_quals)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
make_composite_equals (const std::vector< std::shared_ptr< Analyzer::Expr >> &crt_coalesced_quals)
 

Function Documentation

bool anonymous_namespace{EquiJoinCondition.cpp}::can_combine_with ( const Analyzer::Expr crt,
const Analyzer::Expr prev 
)

Definition at line 25 of file EquiJoinCondition.cpp.

References IS_EQUIVALENCE, kONE, remove_cast(), and ScalarExprVisitor< T >::visit().

Referenced by combine_equi_join_conditions().

25  {
26  const auto crt_bin = dynamic_cast<const Analyzer::BinOper*>(crt);
27  const auto prev_bin = dynamic_cast<const Analyzer::BinOper*>(prev);
28  if (!crt_bin || !prev_bin) {
29  return false;
30  }
31  if (!IS_EQUIVALENCE(crt_bin->get_optype()) || crt_bin->get_qualifier() != kONE ||
32  !IS_EQUIVALENCE(prev_bin->get_optype()) || prev_bin->get_qualifier() != kONE ||
33  // We could accept a mix of kEQ and kBW_EQ, but don't bother for now.
34  crt_bin->get_optype() != prev_bin->get_optype()) {
35  return false;
36  }
37 
38  auto get_rhs_col_var = [](const auto bin_oper) {
39  auto inner_col_var = std::dynamic_pointer_cast<Analyzer::ColumnVar>(
40  remove_cast(bin_oper->get_own_right_operand()));
41  if (!inner_col_var) {
42  const auto string_oper = std::dynamic_pointer_cast<Analyzer::StringOper>(
43  remove_cast(bin_oper->get_own_right_operand()));
44  if (string_oper && string_oper->getArity() >= 1UL) {
45  inner_col_var =
46  std::dynamic_pointer_cast<Analyzer::ColumnVar>(string_oper->getOwnArg(0));
47  }
48  }
49  return inner_col_var;
50  };
51 
52  const std::shared_ptr<Analyzer::ColumnVar> crt_inner_col_var = get_rhs_col_var(crt_bin);
53  const std::shared_ptr<Analyzer::ColumnVar> prev_inner_col_var =
54  get_rhs_col_var(prev_bin);
55  if (!crt_inner_col_var || !prev_inner_col_var) {
56  return false;
57  }
59  const auto crt_outer_rte_set = visitor.visit(crt_bin->get_left_operand());
60  const auto prev_outer_rte_set = visitor.visit(prev_bin->get_left_operand());
61  // We shouldn't treat mixed nesting levels columns as a composite key tuple.
62  if (crt_outer_rte_set.size() != 1 || prev_outer_rte_set.size() != 1 ||
63  crt_outer_rte_set != prev_outer_rte_set) {
64  return false;
65  }
66  if (crt_inner_col_var->get_table_id() != prev_inner_col_var->get_table_id() ||
67  crt_inner_col_var->get_rte_idx() != prev_inner_col_var->get_rte_idx()) {
68  return false;
69  }
70  return true;
71 }
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4138
#define IS_EQUIVALENCE(X)
Definition: sqldefs.h:69
T visit(const Analyzer::Expr *expr) const
Definition: sqldefs.h:71
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1463

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{EquiJoinCondition.cpp}::make_composite_equals ( const std::vector< std::shared_ptr< Analyzer::Expr >> &  crt_coalesced_quals)

Definition at line 118 of file EquiJoinCondition.cpp.

References make_composite_equals_impl().

Referenced by combine_equi_join_conditions().

119  {
120  if (crt_coalesced_quals.size() == 1) {
121  return {crt_coalesced_quals.front()};
122  }
123  return make_composite_equals_impl(crt_coalesced_quals);
124 }
std::list< std::shared_ptr< Analyzer::Expr > > make_composite_equals_impl(const std::vector< std::shared_ptr< Analyzer::Expr >> &crt_coalesced_quals)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > anonymous_namespace{EquiJoinCondition.cpp}::make_composite_equals_impl ( const std::vector< std::shared_ptr< Analyzer::Expr >> &  crt_coalesced_quals)

Definition at line 73 of file EquiJoinCondition.cpp.

References CHECK, CHECK_EQ, IS_NUMBER, IS_STRING, kBOOLEAN, kENCODING_DICT, kONE, and remove_cast().

Referenced by coalesce_singleton_equi_join(), and make_composite_equals().

74  {
75  std::list<std::shared_ptr<Analyzer::Expr>> join_quals;
76  std::vector<std::shared_ptr<Analyzer::Expr>> lhs_tuple;
77  std::vector<std::shared_ptr<Analyzer::Expr>> rhs_tuple;
78  bool not_null{true};
79  for (const auto& qual : crt_coalesced_quals) {
80  const auto qual_binary = std::dynamic_pointer_cast<Analyzer::BinOper>(qual);
81  CHECK(qual_binary);
82  not_null = not_null && qual_binary->get_type_info().get_notnull();
83  const auto lhs_col = remove_cast(qual_binary->get_own_left_operand());
84  const auto rhs_col = remove_cast(qual_binary->get_own_right_operand());
85  const auto lhs_ti = lhs_col->get_type_info();
86  // Coalesce cols for integers, bool, and dict encoded strings. Forces baseline hash
87  // join.
88  if (IS_NUMBER(lhs_ti.get_type()) ||
89  (IS_STRING(lhs_ti.get_type()) && lhs_ti.get_compression() == kENCODING_DICT) ||
90  (lhs_ti.get_type() == kBOOLEAN)) {
91  lhs_tuple.push_back(lhs_col);
92  rhs_tuple.push_back(rhs_col);
93  } else {
94  join_quals.push_back(qual);
95  }
96  }
97  CHECK(!crt_coalesced_quals.empty());
98  const auto first_qual =
99  std::dynamic_pointer_cast<Analyzer::BinOper>(crt_coalesced_quals.front());
100  CHECK(first_qual);
101  CHECK_EQ(lhs_tuple.size(), rhs_tuple.size());
102  if (lhs_tuple.size() > 0) {
103  join_quals.push_front(std::make_shared<Analyzer::BinOper>(
104  SQLTypeInfo(kBOOLEAN, not_null),
105  false,
106  first_qual->get_optype(),
107  kONE,
108  lhs_tuple.size() > 1 ? std::make_shared<Analyzer::ExpressionTuple>(lhs_tuple)
109  : lhs_tuple.front(),
110  rhs_tuple.size() > 1 ? std::make_shared<Analyzer::ExpressionTuple>(rhs_tuple)
111  : rhs_tuple.front()));
112  }
113  return join_quals;
114 }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4138
Definition: sqldefs.h:71
#define IS_STRING(T)
Definition: sqltypes.h:250
#define CHECK(condition)
Definition: Logger.h:223
#define IS_NUMBER(T)
Definition: sqltypes.h:247

+ Here is the call graph for this function:

+ Here is the caller graph for this function: