OmniSciDB  ca0c39ec8f
 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 overlaps joins
47  std::list<std::shared_ptr<Analyzer::Expr>> quals;
48  std::list<std::shared_ptr<Analyzer::Expr>> join_quals;
49 };
50 
52 
54  static constexpr std::string_view ST_CONTAINS_POLYGON_POINT_sv{
55  "ST_Contains_Polygon_Point"};
56  static constexpr std::string_view ST_CONTAINS_POLYGON_POLYGON_sv{
57  "ST_Contains_Polygon_Polygon"};
58  static constexpr std::string_view ST_CONTAINS_MULTIPOLYGON_POINT_sv{
59  "ST_Contains_MultiPolygon_Point"};
60  static constexpr std::string_view ST_INTERSECTS_POINT_POLYGON_sv{
61  "ST_Intersects_Point_Polygon"};
62  static constexpr std::string_view ST_INTERSECTS_POINT_MULTIPOLYGON_sv{
63  "ST_Intersects_Point_MultiPolygon"};
64  static constexpr std::string_view ST_INTERSECTS_POLYGON_POINT_sv{
65  "ST_Intersects_Polygon_Point"};
66  static constexpr std::string_view ST_INTERSECTS_POLYGON_POLYGON_sv{
67  "ST_Intersects_Polygon_Polygon"};
68  static constexpr std::string_view ST_INTERSECTS_POLYGON_MULTIPOLYGON_sv{
69  "ST_Intersects_Polygon_MultiPolygon"};
70  static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_MULTIPOLYGON_sv{
71  "ST_Intersects_MultiPolygon_MultiPolygon"};
72  static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POLYGON_sv{
73  "ST_Intersects_MultiPolygon_Polygon"};
74  static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POINT_sv{
75  "ST_Intersects_MultiPolygon_Point"};
76  static constexpr std::string_view ST_APPROX_OVERLAPS_MULTIPOLYGON_POINT_sv{
77  "ST_Approx_Overlaps_MultiPolygon_Point"};
78  static constexpr std::string_view ST_OVERLAPS_sv{"ST_Overlaps"};
79  static constexpr std::string_view ST_DISTANCE_sv{"ST_Distance"};
80  // compressed coords version
81  static constexpr std::string_view ST_CCONTAINS_MULTIPOLYGON_POINT_sv{
82  "ST_cContains_MultiPolygon_Point"};
83  static constexpr std::string_view ST_CCONTAINS_POLYGON_POINT_sv{
84  "ST_cContains_Polygon_Point"};
85  static constexpr std::string_view ST_CINTERSECTS_POLYGON_POINT_sv{
86  "ST_cIntersects_Polygon_Point"};
87  static constexpr std::string_view ST_CINTERSECTS_MULTIPOLYGON_POINT_sv{
88  "ST_cIntersects_MultiPolygon_Point"};
89  static constexpr std::string_view ST_DWITHIN_POINT_POINT_sv{"ST_DWithin_Point_Point"};
90 
91  static constexpr std::array<std::string_view, 18> OVERLAPS_SUPPORTED_FUNC{
110 
111  static constexpr std::array<std::string_view, 5> MANY_TO_MANY_OVERLAPS_FUNC{
117 
118  static constexpr std::array<std::string_view, 5> POLY_MPOLY_REWRITE_TARGET_FUNC{
124 
125  static constexpr std::array<std::string_view, 9> POLY_POINT_REWRITE_TARGET_FUNC{
135 
136  static constexpr std::array<std::string_view, 2> POINT_POLY_REWRITE_TARGET_FUNC{
139 
140  static constexpr std::array<std::string_view, 2> RANGE_JOIN_REWRITE_TARGET_FUNC{
143 
144  static bool is_overlaps_supported_func(std::string_view target_func_name) {
147  [target_func_name](std::string_view func_name) {
148  return target_func_name == func_name;
149  });
150  }
151 
152  static bool is_many_to_many_func(std::string_view target_func_name) {
155  [target_func_name](std::string_view func_name) {
156  return target_func_name == func_name;
157  });
158  }
159 
160  static bool is_poly_mpoly_rewrite_target_func(std::string_view target_func_name) {
161  return std::any_of(
164  [target_func_name](std::string_view func_name) {
165  return target_func_name == func_name;
166  });
167  }
168 
169  static bool is_point_poly_rewrite_target_func(std::string_view target_func_name) {
170  return std::any_of(
173  [target_func_name](std::string_view func_name) {
174  return target_func_name == func_name;
175  });
176  }
177 
178  static bool is_poly_point_rewrite_target_func(std::string_view target_func_name) {
179  return std::any_of(
182  [target_func_name](std::string_view func_name) {
183  return target_func_name == func_name;
184  });
185  }
186 
187  static bool is_range_join_rewrite_target_func(std::string_view target_func_name) {
188  return std::any_of(
191  [target_func_name](std::string_view func_name) {
192  return target_func_name == func_name;
193  });
194  }
195 };
196 
197 boost::optional<OverlapsJoinConjunction> rewrite_overlaps_conjunction(
198  const std::shared_ptr<Analyzer::Expr> expr,
199  const std::vector<InputDescriptor>& input_table_info,
200  const OverlapsJoinRewriteType rewrite_type,
201  const Executor* executor);
202 
203 boost::optional<OverlapsJoinConjunction> convert_to_range_join_oper(
204  const std::shared_ptr<Analyzer::Expr> expr,
205  const Analyzer::BinOper* range_join_expr,
206  const Analyzer::GeoOperator* lhs,
207  const Analyzer::Constant* rhs);
208 
209 std::list<std::shared_ptr<Analyzer::Expr>> strip_join_covered_filter_quals(
210  const std::list<std::shared_ptr<Analyzer::Expr>>& quals,
211  const JoinQualsPerNestingLevel& join_quals);
212 
213 std::shared_ptr<Analyzer::Expr> fold_expr(const Analyzer::Expr*);
214 
216  const Analyzer::ColumnVar* rhs,
217  const int max_rte_covered);
218 
219 const int get_max_rte_scan_table(
220  std::unordered_map<int, llvm::Value*>& scan_idx_to_hash_pos);
Defines data structures for the semantic analysis phase of query processing.
Analyzer::ExpressionPtr rewrite_array_elements(Analyzer::Expr const *expr)
static bool is_poly_mpoly_rewrite_target_func(std::string_view target_func_name)
static constexpr std::string_view ST_INTERSECTS_POINT_POLYGON_sv
static constexpr std::array< std::string_view, 2 > POINT_POLY_REWRITE_TARGET_FUNC
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::array< std::string_view, 9 > POLY_POINT_REWRITE_TARGET_FUNC
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)
static bool is_overlaps_supported_func(std::string_view target_func_name)
std::list< std::shared_ptr< Analyzer::Expr > > quals
static constexpr std::string_view ST_INTERSECTS_POINT_MULTIPOLYGON_sv
static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_MULTIPOLYGON_sv
std::shared_ptr< Analyzer::Expr > ExpressionPtr
Definition: Analyzer.h:187
std::list< std::shared_ptr< Analyzer::Expr > > join_quals
std::vector< JoinCondition > JoinQualsPerNestingLevel
Analyzer::ExpressionPtr rewrite_expr(const Analyzer::Expr *expr)
static constexpr std::string_view ST_DWITHIN_POINT_POINT_sv
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::string_view ST_OVERLAPS_sv
static constexpr std::string_view ST_DISTANCE_sv
static constexpr std::string_view ST_CONTAINS_POLYGON_POLYGON_sv
static constexpr std::string_view ST_INTERSECTS_POLYGON_POLYGON_sv
static constexpr std::array< std::string_view, 2 > RANGE_JOIN_REWRITE_TARGET_FUNC
static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POINT_sv
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 constexpr std::string_view ST_CINTERSECTS_POLYGON_POINT_sv
static constexpr std::array< std::string_view, 5 > MANY_TO_MANY_OVERLAPS_FUNC
static bool is_poly_point_rewrite_target_func(std::string_view target_func_name)
static constexpr std::string_view ST_CONTAINS_POLYGON_POINT_sv
static constexpr std::string_view ST_APPROX_OVERLAPS_MULTIPOLYGON_POINT_sv
static constexpr std::array< std::string_view, 18 > OVERLAPS_SUPPORTED_FUNC
static constexpr std::string_view ST_INTERSECTS_POLYGON_POINT_sv
static constexpr std::string_view ST_INTERSECTS_MULTIPOLYGON_POLYGON_sv
static constexpr std::string_view ST_INTERSECTS_POLYGON_MULTIPOLYGON_sv
static constexpr std::string_view ST_CONTAINS_MULTIPOLYGON_POINT_sv
OverlapsJoinRewriteType
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)
Execution unit for relational algebra. It&#39;s a low-level description of any relational algebra operati...
static constexpr std::string_view ST_CCONTAINS_POLYGON_POINT_sv
static constexpr std::string_view ST_CINTERSECTS_MULTIPOLYGON_POINT_sv
static constexpr std::array< std::string_view, 5 > POLY_MPOLY_REWRITE_TARGET_FUNC
std::shared_ptr< Analyzer::Expr > fold_expr(const Analyzer::Expr *expr)
static bool is_point_poly_rewrite_target_func(std::string_view target_func_name)
static constexpr std::string_view ST_CCONTAINS_MULTIPOLYGON_POINT_sv