OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExpressionRewrite.h File Reference
#include <llvm/IR/Value.h>
#include <boost/optional.hpp>
#include <list>
#include <memory>
#include <vector>
#include "Analyzer/Analyzer.h"
#include "RelAlgExecutionUnit.h"
+ Include dependency graph for ExpressionRewrite.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  OverlapsJoinConjunction
 
struct  OverlapsJoinSupportedFunction
 

Namespaces

 Analyzer
 

Enumerations

enum  OverlapsJoinRewriteType { OverlapsJoinRewriteType::OVERLAPS_JOIN, OverlapsJoinRewriteType::RANGE_JOIN, OverlapsJoinRewriteType::UNKNOWN }
 

Functions

Analyzer::ExpressionPtr rewrite_expr (const Analyzer::Expr *)
 
Analyzer::ExpressionPtr rewrite_array_elements (const Analyzer::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)
 
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)
 
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 *)
 
bool self_join_not_covered_by_left_deep_tree (const Analyzer::ColumnVar *lhs, const Analyzer::ColumnVar *rhs, const int max_rte_covered)
 
const int get_max_rte_scan_table (std::unordered_map< int, llvm::Value * > &scan_idx_to_hash_pos)
 

Enumeration Type Documentation

Function Documentation

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 
)

Referenced by rewrite_overlaps_conjunction().

+ Here is the caller graph for this function:

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

Definition at line 1143 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().

1143  {
1144  if (!expr) {
1145  return nullptr;
1146  }
1147  const auto expr_no_likelihood = strip_likelihood(expr);
1148  ConstantFoldingVisitor visitor;
1149  auto rewritten_expr = visitor.visit(expr_no_likelihood);
1150  if (visitor.get_num_overflows() > 0 && rewritten_expr->get_type_info().is_integer() &&
1151  rewritten_expr->get_type_info().get_type() != kBIGINT) {
1152  auto rewritten_expr_const =
1153  std::dynamic_pointer_cast<const Analyzer::Constant>(rewritten_expr);
1154  if (!rewritten_expr_const) {
1155  // Integer expression didn't fold completely the first time due to
1156  // overflows in smaller type subexpressions, trying again with a cast
1157  const auto& ti = SQLTypeInfo(kBIGINT, false);
1158  auto bigint_expr_no_likelihood = expr_no_likelihood->deep_copy()->add_cast(ti);
1159  auto rewritten_expr_take2 = visitor.visit(bigint_expr_no_likelihood.get());
1160  auto rewritten_expr_take2_const =
1161  std::dynamic_pointer_cast<Analyzer::Constant>(rewritten_expr_take2);
1162  if (rewritten_expr_take2_const) {
1163  // Managed to fold, switch to the new constant
1164  rewritten_expr = rewritten_expr_take2_const;
1165  }
1166  }
1167  }
1168  const auto expr_with_likelihood = dynamic_cast<const Analyzer::LikelihoodExpr*>(expr);
1169  if (expr_with_likelihood) {
1170  // Add back likelihood
1171  return std::make_shared<Analyzer::LikelihoodExpr>(
1172  rewritten_expr, expr_with_likelihood->get_likelihood());
1173  }
1174  return rewritten_expr;
1175 }
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 1188 of file ExpressionRewrite.cpp.

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

1189  {
1190  int ret = INT32_MIN;
1191  for (auto& kv : scan_idx_to_hash_pos) {
1192  if (kv.first > ret) {
1193  ret = kv.first;
1194  }
1195  }
1196  return ret;
1197 }

+ Here is the caller graph for this function:

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

Definition at line 757 of file ExpressionRewrite.cpp.

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

757  {
758  return ArrayElementStringLiteralEncodingVisitor().visit(expr);
759 }

+ Here is the caller graph for this function:

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

Definition at line 761 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().

761  {
762  const auto sum_window = rewrite_sum_window(expr);
763  if (sum_window) {
764  return sum_window;
765  }
766  const auto avg_window = rewrite_avg_window(expr);
767  if (avg_window) {
768  return avg_window;
769  }
770  const auto expr_no_likelihood = strip_likelihood(expr);
771  // The following check is not strictly needed, but seems silly to transform a
772  // simple string comparison to an IN just to codegen the same thing anyway.
773 
774  RecursiveOrToInVisitor visitor;
775  auto rewritten_expr = visitor.visit(expr_no_likelihood);
776  const auto expr_with_likelihood =
777  std::dynamic_pointer_cast<const Analyzer::LikelihoodExpr>(rewritten_expr);
778  if (expr_with_likelihood) {
779  // Add back likelihood
780  return std::make_shared<Analyzer::LikelihoodExpr>(
781  rewritten_expr, expr_with_likelihood->get_likelihood());
782  }
783  return rewritten_expr;
784 }
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 786 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().

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

Definition at line 1177 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().

1179  {
1180  if (key_side->get_table_id() == val_side->get_table_id() &&
1181  key_side->get_rte_idx() == val_side->get_rte_idx() &&
1182  key_side->get_rte_idx() > max_rte_covered) {
1183  return true;
1184  }
1185  return false;
1186 }

+ 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 1119 of file ExpressionRewrite.cpp.

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

Referenced by RelAlgExecutionUnit::createCountAllExecutionUnit().

1121  {
1123  return quals;
1124  }
1125 
1126  if (join_quals.empty()) {
1127  return quals;
1128  }
1129 
1130  std::list<std::shared_ptr<Analyzer::Expr>> quals_to_return;
1131 
1132  JoinCoveredQualVisitor visitor(join_quals);
1133  for (const auto& qual : quals) {
1134  if (!visitor.visit(qual.get())) {
1135  // Not a covered qual, don't elide it from the filtered count
1136  quals_to_return.push_back(qual);
1137  }
1138  }
1139 
1140  return quals_to_return;
1141 }
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: