OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExpressionRewrite.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <llvm/IR/Value.h>
20 #include <boost/optional.hpp>
21 #include <list>
22 #include <memory>
23 #include <vector>
24 
25 #include "Analyzer/Analyzer.h"
26 #include "RelAlgExecutionUnit.h"
27 
28 namespace Analyzer {
29 
30 class Expr;
31 
32 class InValues;
33 
34 } // namespace Analyzer
35 
36 class InputColDescriptor;
37 
38 // Rewrites an OR tree where leaves are equality compare against literals.
40 
41 // Rewrites array elements that are strings to be dict encoded transient literals
43 
44 // Rewrite a FunctionOper to an AND between a BinOper and the FunctionOper if the
45 // FunctionOper is supported for bounding box intersect hash joins
47  std::list<std::shared_ptr<Analyzer::Expr>> quals;
48  std::list<std::shared_ptr<Analyzer::Expr>> join_quals;
49 };
50 
54  bool is_reordered{false};
55 };
56 
58  bool swap_arguments{false};
59  std::optional<BoundingBoxIntersectJoinConjunction> converted_bbox_intersect_join_info{
60  std::nullopt};
61 
63  return {false, std::nullopt};
64  }
65 };
66 
69  RANGE_JOIN,
70  UNKNOWN
71 };
72 
74  static constexpr std::string_view ST_CONTAINS_POLYGON_POINT_sv{
75  "ST_Contains_Polygon_Point"};
76  static constexpr std::string_view ST_CONTAINS_POLYGON_POLYGON_sv{
77  "ST_Contains_Polygon_Polygon"};
78  static constexpr std::string_view ST_CONTAINS_MULTIPOLYGON_POINT_sv{
79  "ST_Contains_MultiPolygon_Point"};
80  static constexpr std::string_view ST_INTERSECTS_POINT_POLYGON_sv{
81  "ST_Intersects_Point_Polygon"};
82  static constexpr std::string_view ST_INTERSECTS_POINT_MULTIPOLYGON_sv{
83  "ST_Intersects_Point_MultiPolygon"};
84  static constexpr std::string_view ST_INTERSECTS_POLYGON_POINT_sv{
85  "ST_Intersects_Polygon_Point"};
86  static constexpr std::string_view ST_INTERSECTS_POLYGON_POLYGON_sv{
87  "ST_Intersects_Polygon_Polygon"};
88  static constexpr std::string_view ST_INTERSECTS_POLYGON_MULTIPOLYGON_sv{
89  "ST_Intersects_Polygon_MultiPolygon"};
90  static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_MULTIPOLYGON_sv{
91  "ST_Intersects_MultiPolygon_MultiPolygon"};
92  static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POLYGON_sv{
93  "ST_Intersects_MultiPolygon_Polygon"};
94  static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POINT_sv{
95  "ST_Intersects_MultiPolygon_Point"};
96  static constexpr std::string_view ST_APPROX_OVERLAPS_MULTIPOLYGON_POINT_sv{
97  "ST_Approx_Overlaps_MultiPolygon_Point"};
98  static constexpr std::string_view ST_INTERSECTSBOX_sv{"ST_IntersectsBox"};
99  static constexpr std::string_view ST_DISTANCE_sv{"ST_Distance"};
100  // compressed coords version
101  static constexpr std::string_view ST_CCONTAINS_MULTIPOLYGON_POINT_sv{
102  "ST_cContains_MultiPolygon_Point"};
103  static constexpr std::string_view ST_CCONTAINS_POLYGON_POINT_sv{
104  "ST_cContains_Polygon_Point"};
105  static constexpr std::string_view ST_CINTERSECTS_POLYGON_POINT_sv{
106  "ST_cIntersects_Polygon_Point"};
107  static constexpr std::string_view ST_CINTERSECTS_MULTIPOLYGON_POINT_sv{
108  "ST_cIntersects_MultiPolygon_Point"};
109  static constexpr std::string_view ST_DWITHIN_POINT_POINT_sv{"ST_DWithin_Point_Point"};
110 
111  static constexpr std::array<std::string_view, 18> BBOX_INTERSECT_SUPPORTED_FUNC{
130 
131  static constexpr std::array<std::string_view, 5> MANY_TO_MANY_BBOX_INTERSECT_FUNC{
137 
138  static constexpr std::array<std::string_view, 5> POLY_MPOLY_REWRITE_TARGET_FUNC{
144 
145  static constexpr std::array<std::string_view, 9> POLY_POINT_REWRITE_TARGET_FUNC{
155 
156  static constexpr std::array<std::string_view, 2> POINT_POLY_REWRITE_TARGET_FUNC{
159 
160  static constexpr std::array<std::string_view, 2> RANGE_JOIN_REWRITE_TARGET_FUNC{
163 
164  static bool is_bbox_intersect_supported_func(std::string_view target_func_name) {
165  return std::any_of(
168  [target_func_name](std::string_view func_name) {
169  return target_func_name == func_name;
170  });
171  }
172 
173  static bool is_many_to_many_func(std::string_view target_func_name) {
174  return std::any_of(
176  .begin(),
178  [target_func_name](std::string_view func_name) {
179  return target_func_name == func_name;
180  });
181  }
182 
183  static bool is_poly_mpoly_rewrite_target_func(std::string_view target_func_name) {
184  return std::any_of(
187  [target_func_name](std::string_view func_name) {
188  return target_func_name == func_name;
189  });
190  }
191 
192  static bool is_point_poly_rewrite_target_func(std::string_view target_func_name) {
193  return std::any_of(
196  [target_func_name](std::string_view func_name) {
197  return target_func_name == func_name;
198  });
199  }
200 
201  static bool is_poly_point_rewrite_target_func(std::string_view target_func_name) {
202  return std::any_of(
205  [target_func_name](std::string_view func_name) {
206  return target_func_name == func_name;
207  });
208  }
209 
210  static bool is_range_join_rewrite_target_func(std::string_view target_func_name) {
211  return std::any_of(
214  [target_func_name](std::string_view func_name) {
215  return target_func_name == func_name;
216  });
217  }
218 };
219 
221  const std::shared_ptr<Analyzer::Expr> expr,
222  std::vector<InputDescriptor> const& input_descs,
223  std::unordered_map<const RelAlgNode*, int> const& input_to_nest_level,
224  std::vector<size_t> const& input_permutation,
225  std::list<std::shared_ptr<const InputColDescriptor>>& input_col_desc,
226  const BoundingBoxIntersectJoinRewriteType rewrite_type,
227  Executor const* executor);
228 
230  JoinQualsPerNestingLevel const& join_quals,
231  std::vector<InputDescriptor>& input_descs,
232  std::unordered_map<const RelAlgNode*, int>& input_to_nest_level,
233  std::vector<size_t>& input_permutation,
234  std::list<std::shared_ptr<const InputColDescriptor>>& input_col_desc,
235  Executor const* executor);
236 
237 std::list<std::shared_ptr<Analyzer::Expr>> strip_join_covered_filter_quals(
238  const std::list<std::shared_ptr<Analyzer::Expr>>& quals,
239  const JoinQualsPerNestingLevel& join_quals);
240 
241 std::shared_ptr<Analyzer::Expr> fold_expr(const Analyzer::Expr*);
242 
244  const Analyzer::ColumnVar* rhs,
245  const int max_rte_covered);
246 
247 const int get_max_rte_scan_table(
248  std::unordered_map<int, llvm::Value*>& scan_idx_to_hash_pos);
249 
250 size_t get_table_cardinality(shared::TableKey const& table_key, Executor const* executor);
Defines data structures for the semantic analysis phase of query processing.
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
static constexpr std::array< std::string_view, 9 > POLY_POINT_REWRITE_TARGET_FUNC
static bool is_point_poly_rewrite_target_func(std::string_view target_func_name)
static constexpr std::string_view ST_INTERSECTS_POLYGON_POINT_sv
std::optional< BoundingBoxIntersectJoinConjunction > converted_bbox_intersect_join_info
std::list< std::shared_ptr< Analyzer::Expr > > join_quals
static constexpr std::string_view ST_INTERSECTS_POINT_POLYGON_sv
bool self_join_not_covered_by_left_deep_tree(const Analyzer::ColumnVar *key_side, const Analyzer::ColumnVar *val_side, const int max_rte_covered)
static constexpr std::string_view ST_CONTAINS_POLYGON_POINT_sv
static constexpr std::array< std::string_view, 18 > BBOX_INTERSECT_SUPPORTED_FUNC
static constexpr std::string_view ST_CINTERSECTS_POLYGON_POINT_sv
static constexpr std::string_view ST_DISTANCE_sv
size_t get_table_cardinality(shared::TableKey const &table_key, Executor const *executor)
static bool is_range_join_rewrite_target_func(std::string_view target_func_name)
std::shared_ptr< Analyzer::Expr > ExpressionPtr
Definition: Analyzer.h:184
std::vector< JoinCondition > JoinQualsPerNestingLevel
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
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)
const int get_max_rte_scan_table(std::unordered_map< int, llvm::Value * > &scan_idx_to_hash_pos)
static constexpr std::array< std::string_view, 2 > POINT_POLY_REWRITE_TARGET_FUNC
static BoundingBoxIntersectJoinTranslationResult createEmptyResult()
std::list< std::shared_ptr< Analyzer::Expr > > quals
static constexpr std::string_view ST_APPROX_OVERLAPS_MULTIPOLYGON_POINT_sv
static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_MULTIPOLYGON_sv
static constexpr std::string_view ST_INTERSECTS_POINT_MULTIPOLYGON_sv
static constexpr std::string_view ST_INTERSECTSBOX_sv
static constexpr std::string_view ST_CCONTAINS_MULTIPOLYGON_POINT_sv
static constexpr std::string_view ST_CINTERSECTS_MULTIPOLYGON_POINT_sv
BoundingBoxIntersectJoinTranslationInfo convert_bbox_intersect_join(JoinQualsPerNestingLevel const &join_quals, std::vector< InputDescriptor > &input_descs, std::unordered_map< const RelAlgNode *, int > &input_to_nest_level, std::vector< size_t > &input_permutation, std::list< std::shared_ptr< const InputColDescriptor >> &input_col_desc, Executor const *executor)
static bool is_bbox_intersect_supported_func(std::string_view target_func_name)
static constexpr std::array< std::string_view, 5 > POLY_MPOLY_REWRITE_TARGET_FUNC
BoundingBoxIntersectJoinTranslationResult translate_bbox_intersect_with_reordering(const std::shared_ptr< Analyzer::Expr > expr, std::vector< InputDescriptor > const &input_descs, std::unordered_map< const RelAlgNode *, int > const &input_to_nest_level, std::vector< size_t > const &input_permutation, std::list< std::shared_ptr< const InputColDescriptor >> &input_col_desc, const BoundingBoxIntersectJoinRewriteType rewrite_type, Executor const *executor)
static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POLYGON_sv
static constexpr std::array< std::string_view, 5 > MANY_TO_MANY_BBOX_INTERSECT_FUNC
static constexpr std::string_view ST_INTERSECTS_POLYGON_POLYGON_sv
static constexpr std::string_view ST_DWITHIN_POINT_POINT_sv
static bool is_poly_point_rewrite_target_func(std::string_view target_func_name)
static bool is_poly_mpoly_rewrite_target_func(std::string_view target_func_name)
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)
static constexpr std::string_view ST_CONTAINS_MULTIPOLYGON_POINT_sv
BoundingBoxIntersectJoinRewriteType
Execution unit for relational algebra. It&#39;s a low-level description of any relational algebra operati...
static constexpr std::string_view ST_CONTAINS_POLYGON_POLYGON_sv
static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POINT_sv
static bool is_many_to_many_func(std::string_view target_func_name)
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)
static constexpr std::string_view ST_CCONTAINS_POLYGON_POINT_sv
static constexpr std::string_view ST_INTERSECTS_POLYGON_MULTIPOLYGON_sv
static constexpr std::array< std::string_view, 2 > RANGE_JOIN_REWRITE_TARGET_FUNC