OmniSciDB  6686921089
 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 // toString content of each extracted rel node
53 using RelNodeExplained = std::string;
54 // hash value of explained rel node
55 using RelNodeExplainedHash = size_t;
56 // a string representation of a query plan that is collected by visiting query plan DAG
57 // starting from root to leaf and concatenate each rel node's id
58 // where two adjacent rel nodes in a QueryPlan are connected via '|' delimiter
59 // i.e., 1|2|3|4|
60 using QueryPlan = std::string;
61 // join column's column id info
62 using JoinColumnsInfo = std::string;
63 // hashed value of QueryPlanNodeIds
64 using QueryPlanHash = size_t;
65 // a map btw. a join column and its access path, i.e., a query plan DAG to project B.b
66 // here this join column is used to build a hashtable
67 using HashTableBuildDag = std::pair<JoinColumnsInfo, QueryPlan>;
68 // A map btw. join qual's column info and its corresponding hashtable access path as query
69 // plan DAG i.e., A.a = B.b and build hashtable on B.b? <(A.a = B.b) --> query plan DAG of
70 // projecting B.b> here, this two-level mapping (join qual -> inner join col -> hashtable
71 // access plan DAG) is required since we have to extract query plan before deciding which
72 // join col becomes inner since rel alg related metadata is required to extract query
73 // plan, and the actual decision happens at the time of building hashtable
74 using HashTableBuildDagMap = std::unordered_map<JoinColumnsInfo, HashTableBuildDag>;
75 // A map btw. join column's input table id to its corresponding rel node
76 // for each hash join operation, we can determine whether its input source
77 // has inconsistency in its source data, e.g., row ordering
78 // by seeing a type of input node, e.g., RelSort
79 // note that disabling DAG extraction when we find sort node from join's input
80 // is too restrict when a query becomes complex (and so have multiple joins)
81 // since it eliminates a change of data recycling
82 using TableIdToNodeMap = std::unordered_map<int, const RelAlgNode*>;
83 
87  kQual, // INNER + OUTER
88  kDirect // set target directly (i.e., put Analyzer::Expr* instead of
89  // Analyzer::BinOper*)
90 };
91 constexpr char const* EMPTY_QUERY_PLAN = "";
93 
95 
96 namespace Analyzer {
97 class Expr;
98 class ColumnVar;
99 class Estimator;
100 struct OrderEntry;
101 
102 } // namespace Analyzer
103 
104 struct SortInfo {
105  const std::list<Analyzer::OrderEntry> order_entries;
107  const size_t limit;
108  const size_t offset;
109 };
110 
112  std::list<std::shared_ptr<Analyzer::Expr>> quals;
114 };
115 
116 using JoinQualsPerNestingLevel = std::vector<JoinCondition>;
117 
119  std::vector<InputDescriptor> input_descs;
120  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
121  std::list<std::shared_ptr<Analyzer::Expr>> simple_quals;
122  std::list<std::shared_ptr<Analyzer::Expr>> quals;
124  const std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
125  std::vector<Analyzer::Expr*> target_exprs;
126  const std::shared_ptr<Analyzer::Estimator> estimator;
128  size_t scan_limit;
133  bool use_bump_allocator{false};
134  // empty if not a UNION, true if UNION ALL, false if regular UNION
135  const std::optional<bool> union_all;
136  std::shared_ptr<const query_state::QueryState> query_state;
137 };
138 
139 std::ostream& operator<<(std::ostream& os, const RelAlgExecutionUnit& ra_exe_unit);
140 std::string ra_exec_unit_desc_for_caching(const RelAlgExecutionUnit& ra_exe_unit);
141 
143  const std::vector<InputDescriptor> input_descs;
144  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
145  std::vector<Analyzer::Expr*> input_exprs;
146  std::vector<Analyzer::ColumnVar*> table_func_inputs;
147  std::vector<Analyzer::Expr*> target_exprs;
150 
151  public:
152  std::string toString() const {
153  return typeName(this) + "(" + "input_exprs=" + ::toString(input_exprs) +
154  ", table_func_inputs=" + ::toString(table_func_inputs) +
155  ", target_exprs=" + ::toString(target_exprs) +
156  ", output_buffer_size_param=" + ::toString(output_buffer_size_param) +
157  ", table_func=" + ::toString(table_func) + ")";
158  }
159 };
160 
161 class ResultSet;
162 using ResultSetPtr = std::shared_ptr<ResultSet>;
163 
164 #endif // QUERYENGINE_RELALGEXECUTIONUNIT_H
std::vector< Analyzer::Expr * > target_exprs
std::string JoinColumnsInfo
JoinType
Definition: sqldefs.h:108
std::string ra_exec_unit_desc_for_caching(const RelAlgExecutionUnit &ra_exe_unit)
Definition: Execute.cpp:1244
std::vector< Analyzer::Expr * > input_exprs
std::vector< Analyzer::ColumnVar * > table_func_inputs
const std::optional< bool > union_all
const table_functions::TableFunction table_func
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
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:57
std::vector< InputDescriptor > input_descs
const SortAlgorithm algorithm
boost::adjacency_list< boost::setS, boost::vecS, boost::directedS > AdjacentList
std::pair< JoinColumnsInfo, QueryPlan > HashTableBuildDag
std::vector< JoinCondition > JoinQualsPerNestingLevel
std::shared_ptr< ResultSet > ResultSetPtr
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
const size_t limit
const JoinQualsPerNestingLevel join_quals
SortAlgorithm
std::unordered_map< int, const RelAlgNode * > TableIdToNodeMap
TableIdToNodeMap table_id_to_node_map
const std::shared_ptr< Analyzer::Estimator > estimator
std::string toString() const
size_t RelNodeExplainedHash
size_t QueryPlanHash
std::string RelNodeExplained
std::string typeName(const T *v)
Definition: toString.h:88
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::string QueryPlan
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
size_t RelNodeId
HashTableBuildDagMap hash_table_build_plan_dag
std::unordered_map< JoinColumnsInfo, HashTableBuildDag > HashTableBuildDagMap