OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExpressionRewrite.cpp File Reference
#include "QueryEngine/ExpressionRewrite.h"
#include <algorithm>
#include <boost/locale/conversion.hpp>
#include <unordered_set>
#include "Analyzer/Analyzer.h"
#include "Logger/Logger.h"
#include "Parser/ParserNode.h"
#include "QueryEngine/DeepCopyVisitor.h"
#include "QueryEngine/Execute.h"
#include "QueryEngine/RelAlgTranslator.h"
#include "QueryEngine/ScalarExprVisitor.h"
#include "QueryEngine/WindowExpressionRewrite.h"
#include "Shared/sqldefs.h"
#include "StringOps/StringOps.h"
+ Include dependency graph for ExpressionRewrite.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{ExpressionRewrite.cpp}::OrToInVisitor
 
class  anonymous_namespace{ExpressionRewrite.cpp}::RecursiveOrToInVisitor
 
class  anonymous_namespace{ExpressionRewrite.cpp}::ArrayElementStringLiteralEncodingVisitor
 
class  anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor
 
class  JoinCoveredQualVisitor
 

Namespaces

 anonymous_namespace{ExpressionRewrite.cpp}
 

Functions

const Analyzer::Expranonymous_namespace{ExpressionRewrite.cpp}::strip_likelihood (const Analyzer::Expr *expr)
 
Analyzer::ExpressionPtr rewrite_array_elements (Analyzer::Expr const *expr)
 
Analyzer::ExpressionPtr rewrite_expr (const Analyzer::Expr *expr)
 
boost::optional
< OverlapsJoinConjunction
rewrite_overlaps_conjunction (const std::shared_ptr< Analyzer::Expr > expr, const std::vector< InputDescriptor > &input_table_info, const OverlapsJoinRewriteType rewrite_type, const Executor *executor)
 
std::list< std::shared_ptr
< Analyzer::Expr > > 
strip_join_covered_filter_quals (const std::list< std::shared_ptr< Analyzer::Expr >> &quals, const JoinQualsPerNestingLevel &join_quals)
 
std::shared_ptr< Analyzer::Exprfold_expr (const Analyzer::Expr *expr)
 
bool self_join_not_covered_by_left_deep_tree (const Analyzer::ColumnVar *key_side, const Analyzer::ColumnVar *val_side, const int max_rte_covered)
 
const int get_max_rte_scan_table (std::unordered_map< int, llvm::Value * > &scan_idx_to_hash_pos)
 

Function Documentation

std::shared_ptr<Analyzer::Expr> fold_expr ( const Analyzer::Expr expr)

Definition at line 1155 of file ExpressionRewrite.cpp.

References kBIGINT, and anonymous_namespace{ExpressionRewrite.cpp}::strip_likelihood().

Referenced by RelAlgExecutor::createFilterWorkUnit(), RelAlgExecutor::makeJoinQuals(), anonymous_namespace{RelAlgExecutor.cpp}::set_transient_dict_maybe(), anonymous_namespace{RelAlgExecutor.cpp}::translate_quals(), anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources(), anonymous_namespace{RelAlgExecutor.cpp}::translate_targets(), RelAlgTranslator::translateBinaryGeoFunction(), RelAlgTranslator::translateDatePlusMinus(), RelAlgTranslator::translateGeoComparison(), and RelAlgTranslator::translateGeoFunctionArg().

1155  {
1156  if (!expr) {
1157  return nullptr;
1158  }
1159  const auto expr_no_likelihood = strip_likelihood(expr);
1160  ConstantFoldingVisitor visitor;
1161  auto rewritten_expr = visitor.visit(expr_no_likelihood);
1162  if (visitor.get_num_overflows() > 0 && rewritten_expr->get_type_info().is_integer() &&
1163  rewritten_expr->get_type_info().get_type() != kBIGINT) {
1164  auto rewritten_expr_const =
1165  std::dynamic_pointer_cast<const Analyzer::Constant>(rewritten_expr);
1166  if (!rewritten_expr_const) {
1167  // Integer expression didn't fold completely the first time due to
1168  // overflows in smaller type subexpressions, trying again with a cast
1169  const auto& ti = SQLTypeInfo(kBIGINT, false);
1170  auto bigint_expr_no_likelihood = expr_no_likelihood->deep_copy()->add_cast(ti);
1171  auto rewritten_expr_take2 = visitor.visit(bigint_expr_no_likelihood.get());
1172  auto rewritten_expr_take2_const =
1173  std::dynamic_pointer_cast<Analyzer::Constant>(rewritten_expr_take2);
1174  if (rewritten_expr_take2_const) {
1175  // Managed to fold, switch to the new constant
1176  rewritten_expr = rewritten_expr_take2_const;
1177  }
1178  }
1179  }
1180  const auto expr_with_likelihood = dynamic_cast<const Analyzer::LikelihoodExpr*>(expr);
1181  if (expr_with_likelihood) {
1182  // Add back likelihood
1183  return std::make_shared<Analyzer::LikelihoodExpr>(
1184  rewritten_expr, expr_with_likelihood->get_likelihood());
1185  }
1186  return rewritten_expr;
1187 }
const Analyzer::Expr * strip_likelihood(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int get_max_rte_scan_table ( std::unordered_map< int, llvm::Value * > &  scan_idx_to_hash_pos)

Definition at line 1200 of file ExpressionRewrite.cpp.

Referenced by BaselineJoinHashTable::codegenKey(), PerfectJoinHashTable::codegenMatchingSet(), and PerfectJoinHashTable::codegenSlot().

1201  {
1202  int ret = INT32_MIN;
1203  for (auto& kv : scan_idx_to_hash_pos) {
1204  if (kv.first > ret) {
1205  ret = kv.first;
1206  }
1207  }
1208  return ret;
1209 }

+ Here is the caller graph for this function:

Analyzer::ExpressionPtr rewrite_array_elements ( Analyzer::Expr const *  expr)

Definition at line 769 of file ExpressionRewrite.cpp.

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources(), and anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources_for_update().

769  {
770  return ArrayElementStringLiteralEncodingVisitor().visit(expr);
771 }

+ Here is the caller graph for this function:

Analyzer::ExpressionPtr rewrite_expr ( const Analyzer::Expr expr)

Definition at line 773 of file ExpressionRewrite.cpp.

References rewrite_avg_window(), rewrite_sum_window(), and anonymous_namespace{ExpressionRewrite.cpp}::strip_likelihood().

Referenced by RelAlgExecutor::createFilterWorkUnit(), qual_to_conjunctive_form(), qual_to_disjunctive_form(), anonymous_namespace{RelAlgExecutor.cpp}::rewrite_quals(), QueryRewriter::rewriteConstrainedByIn(), anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources(), anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources_for_update(), and anonymous_namespace{RelAlgExecutor.cpp}::translate_targets().

773  {
774  const auto sum_window = rewrite_sum_window(expr);
775  if (sum_window) {
776  return sum_window;
777  }
778  const auto avg_window = rewrite_avg_window(expr);
779  if (avg_window) {
780  return avg_window;
781  }
782  const auto expr_no_likelihood = strip_likelihood(expr);
783  // The following check is not strictly needed, but seems silly to transform a
784  // simple string comparison to an IN just to codegen the same thing anyway.
785 
786  RecursiveOrToInVisitor visitor;
787  auto rewritten_expr = visitor.visit(expr_no_likelihood);
788  const auto expr_with_likelihood =
789  std::dynamic_pointer_cast<const Analyzer::LikelihoodExpr>(rewritten_expr);
790  if (expr_with_likelihood) {
791  // Add back likelihood
792  return std::make_shared<Analyzer::LikelihoodExpr>(
793  rewritten_expr, expr_with_likelihood->get_likelihood());
794  }
795  return rewritten_expr;
796 }
std::shared_ptr< Analyzer::WindowFunction > rewrite_avg_window(const Analyzer::Expr *expr)
std::shared_ptr< Analyzer::WindowFunction > rewrite_sum_window(const Analyzer::Expr *expr)
const Analyzer::Expr * strip_likelihood(const Analyzer::Expr *expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boost::optional<OverlapsJoinConjunction> rewrite_overlaps_conjunction ( const std::shared_ptr< Analyzer::Expr expr,
const std::vector< InputDescriptor > &  input_table_info,
const OverlapsJoinRewriteType  rewrite_type,
const Executor executor 
)

Definition at line 798 of file ExpressionRewrite.cpp.

References run_benchmark_import::args, cat(), CHECK, CHECK_EQ, CHECK_GE, Analyzer::Expr::collect_rte_idx(), convert_to_range_join_oper(), g_enable_hashjoin_many_to_many, logger::INFO, is_constructed_point(), OverlapsJoinSupportedFunction::is_many_to_many_func(), OverlapsJoinSupportedFunction::is_point_poly_rewrite_target_func(), OverlapsJoinSupportedFunction::is_poly_mpoly_rewrite_target_func(), OverlapsJoinSupportedFunction::is_poly_point_rewrite_target_func(), OverlapsJoinSupportedFunction::is_range_join_rewrite_target_func(), kARRAY, kBOOLEAN, kDOUBLE, kGEOGRAPHY, kLE, kONE, kOVERLAPS, kPOINT, LOG, OVERLAPS_JOIN, RANGE_JOIN, OverlapsJoinSupportedFunction::ST_APPROX_OVERLAPS_MULTIPOLYGON_POINT_sv, OverlapsJoinSupportedFunction::ST_DISTANCE_sv, OverlapsJoinSupportedFunction::ST_DWITHIN_POINT_POINT_sv, OverlapsJoinSupportedFunction::ST_OVERLAPS_sv, ScalarExprVisitor< T >::visit(), VLOG, and logger::WARNING.

Referenced by QueryRewriter::rewriteOverlapsJoin().

802  {
803  auto collect_table_cardinality = [](const Analyzer::Expr* lhs,
804  const Analyzer::Expr* rhs,
805  const Executor* executor) {
806  const auto lhs_cv = dynamic_cast<const Analyzer::ColumnVar*>(lhs);
807  const auto rhs_cv = dynamic_cast<const Analyzer::ColumnVar*>(rhs);
808  if (lhs_cv && rhs_cv) {
809  const auto cat = executor->getCatalog();
810  const auto inner_table_metadata = cat->getMetadataForTable(lhs_cv->get_table_id());
811  const auto outer_table_metadata = cat->getMetadataForTable(rhs_cv->get_table_id());
812  if (inner_table_metadata->fragmenter && outer_table_metadata->fragmenter) {
813  return std::make_pair<int64_t, int64_t>(
814  inner_table_metadata->fragmenter->getNumRows(),
815  outer_table_metadata->fragmenter->getNumRows());
816  }
817  }
818  // otherwise, return an invalid table cardinality
819  return std::make_pair<int64_t, int64_t>(-1, -1);
820  };
821 
822  auto has_invalid_join_col_order = [](const Analyzer::Expr* lhs,
823  const Analyzer::Expr* rhs) {
824  // Check for compatible join ordering. If the join ordering does not match expected
825  // ordering for overlaps, the join builder will fail.
826  std::set<int> lhs_rte_idx;
827  lhs->collect_rte_idx(lhs_rte_idx);
828  CHECK(!lhs_rte_idx.empty());
829  std::set<int> rhs_rte_idx;
830  rhs->collect_rte_idx(rhs_rte_idx);
831  CHECK(!rhs_rte_idx.empty());
832  auto has_invalid_num_join_cols = lhs_rte_idx.size() > 1 || rhs_rte_idx.size() > 1;
833  auto has_invalid_rte_idx = lhs_rte_idx > rhs_rte_idx;
834  return std::make_pair(has_invalid_num_join_cols || has_invalid_rte_idx,
835  has_invalid_rte_idx);
836  };
837 
839  [&](std::string_view func_name,
840  const std::shared_ptr<Analyzer::Expr> expr,
841  const Analyzer::BinOper* range_join_expr,
842  const Analyzer::GeoOperator* lhs,
843  const Analyzer::Constant* rhs,
844  const Executor* executor) -> std::shared_ptr<Analyzer::BinOper> {
846  CHECK_EQ(lhs->size(), size_t(2));
847  auto l_arg = lhs->getOperand(0);
848  auto r_arg = lhs->getOperand(1);
849  const bool is_geography = l_arg->get_type_info().get_subtype() == kGEOGRAPHY ||
850  r_arg->get_type_info().get_subtype() == kGEOGRAPHY;
851  if (is_geography) {
852  VLOG(1) << "Range join not yet supported for geodesic distance "
853  << expr->toString();
854  return nullptr;
855  }
856 
857  // Check for compatible join ordering. If the join ordering does not match expected
858  // ordering for overlaps, the join builder will fail.
859  Analyzer::Expr* range_join_arg = r_arg;
860  Analyzer::Expr* bin_oper_arg = l_arg;
861  auto invalid_range_join_qual =
862  has_invalid_join_col_order(bin_oper_arg, range_join_arg);
863  if (invalid_range_join_qual.second &&
864  collect_table_cardinality(range_join_arg, bin_oper_arg, executor).first > 0 &&
865  lhs->getOperand(0)->get_type_info().get_type() == kPOINT) {
866  r_arg = lhs->getOperand(0);
867  l_arg = lhs->getOperand(1);
868  VLOG(1) << "Swap range join qual's input arguments to exploit overlaps "
869  "hash join framework";
870  invalid_range_join_qual.first = false;
871  }
872 
873  if (invalid_range_join_qual.first) {
874  LOG(INFO) << "Unable to rewrite " << func_name
875  << " to overlaps conjunction. Cannot build hash table over LHS type. "
876  "Check join order.\n"
877  << range_join_expr->toString();
878  return nullptr;
879  }
880 
881  const bool inclusive = range_join_expr->get_optype() == kLE;
882  auto range_expr = makeExpr<Analyzer::RangeOper>(
883  inclusive, inclusive, r_arg->deep_copy(), rhs->deep_copy());
884  VLOG(1) << "Successfully converted to overlaps join";
885  return makeExpr<Analyzer::BinOper>(
886  kBOOLEAN, kOVERLAPS, kONE, l_arg->deep_copy(), range_expr);
887  }
888  return nullptr;
889  };
890 
891  /*
892  * Currently, our overlaps hash join framework supports limited join quals especially
893  * when 1) the FunctionOperator is listed in the function list, i.e.,
894  * is_overlaps_supported_func, 2) the argument order of the join qual must match the
895  * input argument order of the corresponding native function, and 3) input tables match
896  * rte index requirement (the column used to build a hash table has larger rte compared
897  * with that of probing column) And depending on the type of the function, we try to
898  * convert it to corresponding overlaps hash join qual if possible After rewriting, we
899  * create an overlaps join operator which is converted from the original expression and
900  * return OverlapsJoinConjunction object which is a pair of 1) the original expr and 2)
901  * converted overlaps join expr Here, returning the original expr means we additionally
902  * call its corresponding native function to compute the result accurately (i.e.,
903  * overlaps hash join operates a kind of filter expression which may include
904  * false-positive of the true resultset) Note that ST_Overlaps is the only function that
905  * does not return the original expr
906  * */
907  std::shared_ptr<Analyzer::BinOper> overlaps_oper{nullptr};
908  bool needs_to_return_original_expr = false;
909  std::string func_name{""};
910  if (rewrite_type == OverlapsJoinRewriteType::OVERLAPS_JOIN) {
911  auto func_oper = dynamic_cast<Analyzer::FunctionOper*>(expr.get());
912  CHECK(func_oper);
913  func_name = func_oper->getName();
916  LOG(WARNING) << "Many-to-many hashjoin support is disabled, unable to rewrite "
917  << func_oper->toString() << " to use accelerated geo join.";
918  return boost::none;
919  }
920  DeepCopyVisitor deep_copy_visitor;
922  CHECK_GE(func_oper->getArity(), size_t(2));
923  // this case returns {empty quals, overlaps join quals} b/c our join key matching
924  // logic for this case is the same as the implementation of ST_Overlaps function
925  // Note that we can build an overlaps join hash table regardless of table ordering
926  // and the argument order in this case b/c selecting lhs and rhs by arguments 0
927  // and 1 always match the rte index requirement (rte_lhs < rte_rhs)
928  // so what table ordering we take, the rte index requirement satisfies
929  // TODO(adb): we will likely want to actually check for true overlaps, but this
930  // works for now
931  auto lhs = func_oper->getOwnArg(0);
932  auto rewritten_lhs = deep_copy_visitor.visit(lhs.get());
933  CHECK(rewritten_lhs);
934 
935  auto rhs = func_oper->getOwnArg(1);
936  auto rewritten_rhs = deep_copy_visitor.visit(rhs.get());
937  CHECK(rewritten_rhs);
938  overlaps_oper = makeExpr<Analyzer::BinOper>(
939  kBOOLEAN, kOVERLAPS, kONE, rewritten_lhs, rewritten_rhs);
941  CHECK_EQ(func_oper->getArity(), size_t(8));
942  const auto lhs = func_oper->getOwnArg(0);
943  const auto rhs = func_oper->getOwnArg(1);
944  // the correctness of geo args used in the ST_DWithin function is checked by
945  // geo translation logic, i.e., RelAlgTranslator::translateTernaryGeoFunction
946  const auto distance_const_val =
947  dynamic_cast<const Analyzer::Constant*>(func_oper->getArg(7));
948  if (lhs && rhs && distance_const_val) {
949  std::vector<std::shared_ptr<Analyzer::Expr>> args{lhs, rhs};
950  auto range_oper = makeExpr<Analyzer::GeoOperator>(
951  SQLTypeInfo(kDOUBLE, 0, 8, true),
953  args,
954  std::nullopt);
955  auto distance_oper = makeExpr<Analyzer::BinOper>(
956  kBOOLEAN, kLE, kONE, range_oper, distance_const_val->deep_copy());
957  VLOG(1) << "Rewrite " << func_oper->getName() << " to ST_Distance_Point_Point";
958  overlaps_oper =
960  distance_oper,
961  distance_oper.get(),
962  range_oper.get(),
963  distance_const_val,
964  executor);
965  needs_to_return_original_expr = true;
966  }
968  func_name)) {
969  // in the five functions fall into this case,
970  // ST_Contains is for a pair of polygons, and for ST_Intersect cases they are
971  // combo of polygon and multipolygon so what table orders we choose, rte index
972  // requirement for overlaps join can be satisfied if we choose lhs and rhs
973  // from left-to-right order (i.e., get lhs from the arg-1 instead of arg-3)
974  // Note that we choose them from right-to-left argument order in the past
975  CHECK_GE(func_oper->getArity(), size_t(4));
976  auto lhs = func_oper->getOwnArg(1);
977  auto rewritten_lhs = deep_copy_visitor.visit(lhs.get());
978  CHECK(rewritten_lhs);
979  auto rhs = func_oper->getOwnArg(3);
980  auto rewritten_rhs = deep_copy_visitor.visit(rhs.get());
981  CHECK(rewritten_rhs);
982 
983  overlaps_oper = makeExpr<Analyzer::BinOper>(
984  kBOOLEAN, kOVERLAPS, kONE, rewritten_lhs, rewritten_rhs);
985  needs_to_return_original_expr = true;
987  func_name)) {
988  // now, we try to look at one more chance to exploit overlaps hash join by
989  // rewriting the qual as: ST_INTERSECT(POLY, POINT) -> ST_INTERSECT(POINT, POLY)
990  // to support efficient evaluation of 1) ST_Intersects_Point_Polygon and
991  // 2) ST_Intersects_Point_MultiPolygon based on our overlaps hash join framework
992  // here, we have implementation of native functions for both 1) Point-Polygon pair
993  // and 2) Polygon-Point pair, but we currently do not support hash table
994  // generation on top of point column thus, the goal of this rewriting is to place
995  // a non-point geometry to the right-side of the overlaps join operator (to build
996  // hash table based on it) iff the inner table is larger than that of non-point
997  // geometry (to reduce expensive hash join performance)
998  size_t point_arg_idx = 0;
999  size_t poly_arg_idx = 2;
1000  if (func_oper->getOwnArg(point_arg_idx)->get_type_info().get_type() != kPOINT) {
1001  point_arg_idx = 2;
1002  poly_arg_idx = 1;
1003  }
1004  auto point_cv = func_oper->getOwnArg(point_arg_idx);
1005  auto poly_cv = func_oper->getOwnArg(poly_arg_idx);
1006  CHECK_EQ(point_cv->get_type_info().get_type(), kPOINT);
1007  CHECK_EQ(poly_cv->get_type_info().get_type(), kARRAY);
1008  auto rewritten_lhs = deep_copy_visitor.visit(point_cv.get());
1009  CHECK(rewritten_lhs);
1010  auto rewritten_rhs = deep_copy_visitor.visit(poly_cv.get());
1011  CHECK(rewritten_rhs);
1012  VLOG(1) << "Rewriting the " << func_name << " to use overlaps join with lhs as "
1013  << rewritten_lhs->toString() << " and rhs as " << rewritten_rhs->toString();
1014  overlaps_oper = makeExpr<Analyzer::BinOper>(
1015  kBOOLEAN, kOVERLAPS, kONE, rewritten_lhs, rewritten_rhs);
1016  needs_to_return_original_expr = true;
1018  func_name)) {
1019  // rest of functions reaching here is poly and point geo join query
1020  // to use overlaps hash join in this case, poly column must have its rte == 1
1021  // lhs is the point col_var
1022  auto lhs = func_oper->getOwnArg(2);
1023  auto rewritten_lhs = deep_copy_visitor.visit(lhs.get());
1024  CHECK(rewritten_lhs);
1025  const auto& lhs_ti = rewritten_lhs->get_type_info();
1026 
1027  if (!lhs_ti.is_geometry() && !is_constructed_point(rewritten_lhs.get())) {
1028  // TODO(adb): If ST_Contains is passed geospatial literals instead of columns,
1029  // the function will be expanded during translation rather than during code
1030  // generation. While this scenario does not make sense for the overlaps join, we
1031  // need to detect and abort the overlaps rewrite. Adding a GeospatialConstant
1032  // dervied class to the Analyzer may prove to be a better way to handle geo
1033  // literals, but for now we ensure the LHS type is a geospatial type, which
1034  // would mean the function has not been expanded to the physical types, yet.
1035  LOG(INFO) << "Unable to rewrite " << func_name
1036  << " to overlaps conjunction. LHS input type is neither a geospatial "
1037  "column nor a constructed point"
1038  << func_oper->toString();
1039  return boost::none;
1040  }
1041 
1042  // rhs is coordinates of the poly col
1043  auto rhs = func_oper->getOwnArg(1);
1044  auto rewritten_rhs = deep_copy_visitor.visit(rhs.get());
1045  CHECK(rewritten_rhs);
1046 
1047  if (has_invalid_join_col_order(lhs.get(), rhs.get()).first) {
1048  LOG(INFO) << "Unable to rewrite " << func_name
1049  << " to overlaps conjunction. Cannot build hash table over LHS type. "
1050  "Check join order."
1051  << func_oper->toString();
1052  return boost::none;
1053  }
1054 
1055  VLOG(1) << "Rewriting " << func_name << " to use overlaps join with lhs as "
1056  << rewritten_lhs->toString() << " and rhs as " << rewritten_rhs->toString();
1057 
1058  overlaps_oper = makeExpr<Analyzer::BinOper>(
1059  kBOOLEAN, kOVERLAPS, kONE, rewritten_lhs, rewritten_rhs);
1060  if (func_name !=
1062  needs_to_return_original_expr = true;
1063  }
1064  }
1065  } else if (rewrite_type == OverlapsJoinRewriteType::RANGE_JOIN) {
1066  auto bin_oper = dynamic_cast<Analyzer::BinOper*>(expr.get());
1067  CHECK(bin_oper);
1068  auto lhs = dynamic_cast<const Analyzer::GeoOperator*>(bin_oper->get_left_operand());
1069  CHECK(lhs);
1070  auto rhs = dynamic_cast<const Analyzer::Constant*>(bin_oper->get_right_operand());
1071  CHECK(rhs);
1072  func_name = lhs->getName();
1073  overlaps_oper =
1074  convert_to_range_join_oper(func_name, expr, bin_oper, lhs, rhs, executor);
1075  needs_to_return_original_expr = true;
1076  }
1077  const auto expr_str = !func_name.empty() ? func_name : expr->toString();
1078  if (overlaps_oper) {
1079  VLOG(1) << "Successfully converted " << expr_str << " to overlaps join";
1080  if (needs_to_return_original_expr) {
1081  return OverlapsJoinConjunction{{expr}, {overlaps_oper}};
1082  } else {
1083  return OverlapsJoinConjunction{{}, {overlaps_oper}};
1084  }
1085  }
1086  VLOG(1) << "Overlaps join not enabled for " << expr_str;
1087  return boost::none;
1088 }
static bool is_poly_mpoly_rewrite_target_func(std::string_view target_func_name)
#define CHECK_EQ(x, y)
Definition: Logger.h:230
std::string cat(Ts &&...args)
#define LOG(tag)
Definition: Logger.h:216
bool is_constructed_point(const Analyzer::Expr *expr)
Definition: Execute.h:1469
Definition: sqldefs.h:34
#define CHECK_GE(x, y)
Definition: Logger.h:235
T visit(const Analyzer::Expr *expr) const
static constexpr std::string_view ST_DWITHIN_POINT_POINT_sv
static constexpr std::string_view ST_OVERLAPS_sv
static constexpr std::string_view ST_DISTANCE_sv
bool g_enable_hashjoin_many_to_many
Definition: Execute.cpp:104
static bool is_many_to_many_func(std::string_view target_func_name)
static bool is_range_join_rewrite_target_func(std::string_view target_func_name)
static bool is_poly_point_rewrite_target_func(std::string_view target_func_name)
static constexpr std::string_view ST_APPROX_OVERLAPS_MULTIPOLYGON_POINT_sv
Definition: sqldefs.h:70
#define CHECK(condition)
Definition: Logger.h:222
boost::optional< OverlapsJoinConjunction > convert_to_range_join_oper(const std::shared_ptr< Analyzer::Expr > expr, const Analyzer::BinOper *range_join_expr, const Analyzer::GeoOperator *lhs, const Analyzer::Constant *rhs)
virtual void collect_rte_idx(std::set< int > &rte_idx_set) const
Definition: Analyzer.h:113
#define VLOG(n)
Definition: Logger.h:316
static bool is_point_poly_rewrite_target_func(std::string_view target_func_name)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool self_join_not_covered_by_left_deep_tree ( const Analyzer::ColumnVar key_side,
const Analyzer::ColumnVar val_side,
const int  max_rte_covered 
)

Definition at line 1189 of file ExpressionRewrite.cpp.

References Analyzer::ColumnVar::get_rte_idx(), and Analyzer::ColumnVar::get_table_id().

Referenced by BaselineJoinHashTable::codegenKey(), PerfectJoinHashTable::codegenMatchingSet(), and PerfectJoinHashTable::codegenSlot().

1191  {
1192  if (key_side->get_table_id() == val_side->get_table_id() &&
1193  key_side->get_rte_idx() == val_side->get_rte_idx() &&
1194  key_side->get_rte_idx() > max_rte_covered) {
1195  return true;
1196  }
1197  return false;
1198 }
int get_table_id() const
Definition: Analyzer.h:201
int get_rte_idx() const
Definition: Analyzer.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::list<std::shared_ptr<Analyzer::Expr> > strip_join_covered_filter_quals ( const std::list< std::shared_ptr< Analyzer::Expr >> &  quals,
const JoinQualsPerNestingLevel join_quals 
)

Definition at line 1131 of file ExpressionRewrite.cpp.

References g_strip_join_covered_quals, and ScalarExprVisitor< T >::visit().

Referenced by RelAlgExecutionUnit::createCountAllExecutionUnit().

1133  {
1135  return quals;
1136  }
1137 
1138  if (join_quals.empty()) {
1139  return quals;
1140  }
1141 
1142  std::list<std::shared_ptr<Analyzer::Expr>> quals_to_return;
1143 
1144  JoinCoveredQualVisitor visitor(join_quals);
1145  for (const auto& qual : quals) {
1146  if (!visitor.visit(qual.get())) {
1147  // Not a covered qual, don't elide it from the filtered count
1148  quals_to_return.push_back(qual);
1149  }
1150  }
1151 
1152  return quals_to_return;
1153 }
bool g_strip_join_covered_quals
Definition: Execute.cpp:107

+ Here is the call graph for this function:

+ Here is the caller graph for this function: