OmniSciDB  a5dc49c757
 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 constexpr std::array<std::string_view, 4>
169 
170  static constexpr std::array<std::string_view, 6>
178 
179  static bool is_bbox_intersect_supported_func(std::string_view target_func_name) {
180  return std::any_of(
183  [target_func_name](std::string_view func_name) {
184  return target_func_name == func_name;
185  });
186  }
187 
188  static bool is_many_to_many_func(std::string_view target_func_name) {
189  return std::any_of(
191  .begin(),
193  [target_func_name](std::string_view func_name) {
194  return target_func_name == func_name;
195  });
196  }
197 
198  static bool is_poly_mpoly_rewrite_target_func(std::string_view target_func_name) {
199  return std::any_of(
202  [target_func_name](std::string_view func_name) {
203  return target_func_name == func_name;
204  });
205  }
206 
207  static bool is_point_poly_rewrite_target_func(std::string_view target_func_name) {
208  return std::any_of(
211  [target_func_name](std::string_view func_name) {
212  return target_func_name == func_name;
213  });
214  }
215 
216  static bool is_poly_point_rewrite_target_func(std::string_view target_func_name) {
217  return std::any_of(
220  [target_func_name](std::string_view func_name) {
221  return target_func_name == func_name;
222  });
223  }
224 
225  static bool is_range_join_rewrite_target_func(std::string_view target_func_name) {
226  return std::any_of(
229  [target_func_name](std::string_view func_name) {
230  return target_func_name == func_name;
231  });
232  }
233 };
234 
236  const std::shared_ptr<Analyzer::Expr> expr,
237  std::vector<InputDescriptor> const& input_descs,
238  std::unordered_map<const RelAlgNode*, int> const& input_to_nest_level,
239  std::vector<size_t> const& input_permutation,
240  std::list<std::shared_ptr<const InputColDescriptor>>& input_col_desc,
241  const BoundingBoxIntersectJoinRewriteType rewrite_type,
242  Executor const* executor);
243 
245  JoinQualsPerNestingLevel const& join_quals,
246  std::vector<InputDescriptor>& input_descs,
247  std::unordered_map<const RelAlgNode*, int>& input_to_nest_level,
248  std::vector<size_t>& input_permutation,
249  std::list<std::shared_ptr<const InputColDescriptor>>& input_col_desc,
250  Executor const* executor);
251 
252 std::list<std::shared_ptr<Analyzer::Expr>> strip_join_covered_filter_quals(
253  const std::list<std::shared_ptr<Analyzer::Expr>>& quals,
254  const JoinQualsPerNestingLevel& join_quals);
255 
256 std::shared_ptr<Analyzer::Expr> fold_expr(const Analyzer::Expr*);
257 
259  const Analyzer::ColumnVar* rhs,
260  const int max_rte_covered);
261 
262 const int get_max_rte_scan_table(
263  std::unordered_map<int, llvm::Value*>& scan_idx_to_hash_pos);
264 
265 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::array< std::string_view, 6 > ST_INTERSECTS_FORCE_TABLE_REORDERING_TARGET_FUNC
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, 4 > ST_CONTAIN_FORCE_TABLE_REORDERING_TARGET_FUNC
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