29 if (!crt_bin || !prev_bin) {
35 crt_bin->get_optype() != prev_bin->get_optype()) {
39 auto get_rhs_col_var = [](
const auto bin_oper) {
45 if (string_oper && string_oper->getArity() >= 1UL) {
47 std::dynamic_pointer_cast<Analyzer::ColumnVar>(string_oper->getOwnArg(0));
53 const std::shared_ptr<Analyzer::ColumnVar> crt_inner_col_var = get_rhs_col_var(crt_bin);
54 const std::shared_ptr<Analyzer::ColumnVar> prev_inner_col_var =
55 get_rhs_col_var(prev_bin);
56 if (!crt_inner_col_var || !prev_inner_col_var) {
60 const auto crt_outer_rte_set = visitor.
visit(crt_bin->get_left_operand());
61 const auto prev_outer_rte_set = visitor.
visit(prev_bin->get_left_operand());
63 if (crt_outer_rte_set.size() != 1 || prev_outer_rte_set.size() != 1 ||
64 crt_outer_rte_set != prev_outer_rte_set) {
67 if (crt_inner_col_var->getTableKey() != prev_inner_col_var->getTableKey() ||
68 crt_inner_col_var->get_rte_idx() != prev_inner_col_var->get_rte_idx()) {
75 const std::vector<std::shared_ptr<Analyzer::Expr>>& crt_coalesced_quals) {
76 std::list<std::shared_ptr<Analyzer::Expr>> join_quals;
77 std::vector<std::shared_ptr<Analyzer::Expr>> lhs_tuple;
78 std::vector<std::shared_ptr<Analyzer::Expr>> rhs_tuple;
80 for (
const auto& qual : crt_coalesced_quals) {
83 not_null = not_null && qual_binary->get_type_info().get_notnull();
84 const auto lhs_col =
remove_cast(qual_binary->get_own_left_operand());
85 const auto rhs_col =
remove_cast(qual_binary->get_own_right_operand());
86 const auto lhs_ti = lhs_col->get_type_info();
92 lhs_tuple.push_back(lhs_col);
93 rhs_tuple.push_back(rhs_col);
95 join_quals.push_back(qual);
98 CHECK(!crt_coalesced_quals.empty());
99 const auto first_qual =
102 CHECK_EQ(lhs_tuple.size(), rhs_tuple.size());
103 if (lhs_tuple.size() > 0) {
104 join_quals.push_front(std::make_shared<Analyzer::BinOper>(
107 first_qual->get_optype(),
109 lhs_tuple.size() > 1 ? std::make_shared<Analyzer::ExpressionTuple>(lhs_tuple)
111 rhs_tuple.size() > 1 ? std::make_shared<Analyzer::ExpressionTuple>(rhs_tuple)
112 : rhs_tuple.front()));
120 const std::vector<std::shared_ptr<Analyzer::Expr>>& crt_coalesced_quals) {
121 if (crt_coalesced_quals.size() == 1) {
122 return {crt_coalesced_quals.front()};
130 const std::list<std::shared_ptr<Analyzer::Expr>>& join_quals) {
131 if (join_quals.empty()) {
134 std::list<std::shared_ptr<Analyzer::Expr>> coalesced_quals;
135 std::vector<std::shared_ptr<Analyzer::Expr>> crt_coalesced_quals;
136 for (
const auto& simple_join_qual : join_quals) {
137 if (crt_coalesced_quals.empty()) {
138 crt_coalesced_quals.push_back(simple_join_qual);
142 !
can_combine_with(simple_join_qual.get(), crt_coalesced_quals.back().get())) {
143 coalesced_quals.splice(coalesced_quals.end(),
145 crt_coalesced_quals.clear();
147 crt_coalesced_quals.push_back(simple_join_qual);
149 if (!crt_coalesced_quals.empty()) {
150 coalesced_quals.splice(coalesced_quals.end(),
153 return coalesced_quals;
157 const std::shared_ptr<Analyzer::BinOper>& join_qual) {
158 std::vector<std::shared_ptr<Analyzer::Expr>> singleton_qual_list;
159 singleton_qual_list.push_back(join_qual);
Defines data structures for the semantic analysis phase of query processing.
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
#define IS_EQUIVALENCE(X)
std::list< std::shared_ptr< Analyzer::Expr > > coalesce_singleton_equi_join(const std::shared_ptr< Analyzer::BinOper > &join_qual)
T visit(const Analyzer::Expr *expr) const
std::list< std::shared_ptr< Analyzer::Expr > > make_composite_equals(const std::vector< std::shared_ptr< Analyzer::Expr >> &crt_coalesced_quals)
bool can_combine_with(const Analyzer::Expr *crt, const Analyzer::Expr *prev)
Expression class for string functions The "arg" constructor parameter must be an expression that reso...
const size_t g_maximum_conditions_to_coalesce
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 > > combine_equi_join_conditions(const std::list< std::shared_ptr< Analyzer::Expr >> &join_quals)