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