OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelAlgExecutionUnit.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 
24 #ifndef QUERYENGINE_RELALGEXECUTIONUNIT_H
25 #define QUERYENGINE_RELALGEXECUTIONUNIT_H
26 
28 #include "QueryHint.h"
29 #include "RelAlgDag.h"
30 #include "Shared/sqldefs.h"
31 #include "Shared/toString.h"
35 
36 #include <boost/graph/adjacency_list.hpp>
37 
38 #include <list>
39 #include <memory>
40 #include <optional>
41 #include <vector>
42 
43 using AdjacentList = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS>;
44 // node ID used when extracting query plan DAG
45 // note this ID is different from RelNode's id since query plan DAG extractor assigns an
46 // unique node ID only to a rel node which is included in extracted DAG (if we cannot
47 // extract a DAG from the query plan DAG extractor skips to assign unique IDs to rel nodes
48 // in that query plan
49 using RelNodeId = size_t;
50 // hash value of explained rel node
51 using RelNodeExplainedHash = size_t;
52 // a string representation of a query plan that is collected by visiting query plan DAG
53 // starting from root to leaf and concatenate each rel node's id
54 // where two adjacent rel nodes in a QueryPlanDAG are connected via '|' delimiter
55 // i.e., 1|2|3|4|
56 using QueryPlanDAG = std::string;
57 // hashed value of QueryPlanNodeIds
58 using QueryPlanHash = size_t;
59 // hold query plan dag and column info of join columns
60 // used to detect a correct cached hashtable
62  public:
63  HashTableBuildDag(size_t in_inner_cols_info,
64  size_t in_outer_cols_info,
65  QueryPlanHash in_inner_cols_access_path,
66  QueryPlanHash in_outer_cols_access_path,
67  std::unordered_set<size_t>&& inputTableKeys)
68  : inner_cols_info(in_inner_cols_info)
69  , outer_cols_info(in_outer_cols_info)
70  , inner_cols_access_path(in_inner_cols_access_path)
71  , outer_cols_access_path(in_outer_cols_access_path)
72  , inputTableKeys(std::move(inputTableKeys)) {}
77  std::unordered_set<size_t>
78  inputTableKeys; // table keys of input(s), e.g., scan node or subquery's DAG
79 };
80 // A map btw. join qual's column info and its corresponding hashtable access path as query
81 // plan DAG i.e., A.a = B.b and build hashtable on B.b? <(A.a = B.b) --> query plan DAG of
82 // projecting B.b> here, this two-level mapping (join qual -> inner join col -> hashtable
83 // access plan DAG) is required since we have to extract query plan before deciding which
84 // join col becomes inner since rel alg related metadata is required to extract query
85 // plan, and the actual decision happens at the time of building hashtable
86 using HashTableBuildDagMap = std::unordered_map<size_t, HashTableBuildDag>;
87 // A map btw. join column's input table id to its corresponding rel node
88 // for each hash join operation, we can determine whether its input source
89 // has inconsistency in its source data, e.g., row ordering
90 // by seeing a type of input node, e.g., RelSort
91 // note that disabling DAG extraction when we find sort node from join's input
92 // is too restrict when a query becomes complex (and so have multiple joins)
93 // since it eliminates a change of data recycling
94 using TableIdToNodeMap = std::unordered_map<int, const RelAlgNode*>;
95 
99  kQual, // INNER + OUTER
100  kDirect // set target directly (i.e., put Analyzer::Expr* instead of
101  // Analyzer::BinOper*)
102 };
103 constexpr char const* EMPTY_QUERY_PLAN = "";
105 
107 
108 namespace Analyzer {
109 class Expr;
110 class ColumnVar;
111 class Estimator;
112 struct OrderEntry;
113 
114 } // namespace Analyzer
115 
116 struct SortInfo {
117  const std::list<Analyzer::OrderEntry> order_entries;
119  const size_t limit;
120  const size_t offset;
121  bool limit_delivered{false};
122 };
123 
125  std::list<std::shared_ptr<Analyzer::Expr>> quals;
127 };
128 
129 using JoinQualsPerNestingLevel = std::vector<JoinCondition>;
130 
132  std::vector<InputDescriptor> input_descs;
133  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
134  std::list<std::shared_ptr<Analyzer::Expr>> simple_quals;
135  std::list<std::shared_ptr<Analyzer::Expr>> quals;
137  const std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
138  std::vector<Analyzer::Expr*> target_exprs;
139  const std::shared_ptr<Analyzer::Estimator> estimator;
141  size_t scan_limit;
146  bool use_bump_allocator{false};
147  // empty if not a UNION, true if UNION ALL, false if regular UNION
148  const std::optional<bool> union_all;
149  std::shared_ptr<const query_state::QueryState> query_state;
150  std::vector<Analyzer::Expr*> target_exprs_union; // targets in second subquery of UNION
151 
152  RelAlgExecutionUnit createNdvExecutionUnit(const int64_t range) const;
154  Analyzer::Expr* replacement_target) const;
155 };
156 
157 std::ostream& operator<<(std::ostream& os, const RelAlgExecutionUnit& ra_exe_unit);
158 std::string ra_exec_unit_desc_for_caching(const RelAlgExecutionUnit& ra_exe_unit);
159 
161  const std::vector<InputDescriptor> input_descs;
162  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
163  std::vector<Analyzer::Expr*> input_exprs;
164  std::vector<Analyzer::ColumnVar*> table_func_inputs;
165  std::vector<Analyzer::Expr*> target_exprs;
166  mutable size_t output_buffer_size_param;
169 
170  public:
171  std::string toString() const {
172  return typeName(this) + "(" + "input_exprs=" + ::toString(input_exprs) +
173  ", table_func_inputs=" + ::toString(table_func_inputs) +
174  ", target_exprs=" + ::toString(target_exprs) +
175  ", output_buffer_size_param=" + ::toString(output_buffer_size_param) +
176  ", table_func=" + ::toString(table_func) +
177  ", query_plan_dag=" + ::toString(query_plan_dag_hash) + ")";
178  }
179 };
180 
181 class ResultSet;
182 using ResultSetPtr = std::shared_ptr<ResultSet>;
183 
184 #endif // QUERYENGINE_RELALGEXECUTIONUNIT_H
std::vector< Analyzer::Expr * > target_exprs
JoinType
Definition: sqldefs.h:151
std::string ra_exec_unit_desc_for_caching(const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:1607
std::vector< Analyzer::Expr * > input_exprs
std::vector< Analyzer::ColumnVar * > table_func_inputs
QueryPlanHash query_plan_dag_hash
const std::optional< bool > union_all
const table_functions::TableFunction table_func
std::string QueryPlanDAG
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
const std::list< Analyzer::OrderEntry > order_entries
QueryPlanHash outer_cols_access_path
JoinColumnSide
const std::vector< InputDescriptor > input_descs
ResultSet(const std::vector< TargetInfo > &targets, const ExecutorDeviceType device_type, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Catalog_Namespace::Catalog *catalog, const unsigned block_size, const unsigned grid_size)
Definition: ResultSet.cpp:62
std::vector< InputDescriptor > input_descs
const SortAlgorithm algorithm
boost::adjacency_list< boost::setS, boost::vecS, boost::directedS > AdjacentList
std::vector< JoinCondition > JoinQualsPerNestingLevel
std::shared_ptr< ResultSet > ResultSetPtr
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
std::unordered_set< size_t > inputTableKeys
std::vector< Analyzer::Expr * > target_exprs_union
const size_t limit
std::unordered_map< size_t, HashTableBuildDag > HashTableBuildDagMap
const JoinQualsPerNestingLevel join_quals
std::unordered_map< int, const RelAlgNode * > TableIdToNodeMap
TableIdToNodeMap table_id_to_node_map
RelAlgExecutionUnit createCountAllExecutionUnit(Analyzer::Expr *replacement_target) const
const std::shared_ptr< Analyzer::Estimator > estimator
std::string toString() const
HashTableBuildDag(size_t in_inner_cols_info, size_t in_outer_cols_info, QueryPlanHash in_inner_cols_access_path, QueryPlanHash in_outer_cols_access_path, std::unordered_set< size_t > &&inputTableKeys)
QueryPlanHash inner_cols_access_path
size_t RelNodeExplainedHash
RelAlgExecutionUnit createNdvExecutionUnit(const int64_t range) const
size_t QueryPlanHash
std::string typeName(const T *v)
Definition: toString.h:102
std::list< std::shared_ptr< Analyzer::Expr > > quals
std::list< std::shared_ptr< Analyzer::Expr > > quals
RegisteredQueryHint query_hint
constexpr char const * EMPTY_QUERY_PLAN
std::list< std::shared_ptr< const InputColDescriptor > > input_col_descs
std::shared_ptr< const query_state::QueryState > query_state
Common Enum definitions for SQL processing.
std::vector< Analyzer::Expr * > target_exprs
std::list< std::shared_ptr< const InputColDescriptor > > input_col_descs
const size_t offset
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
size_t RelNodeId
HashTableBuildDagMap hash_table_build_plan_dag