OmniSciDB  21ac014ffc
 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 "Shared/sqldefs.h"
32 #include "Shared/toString.h"
36 
37 #include <boost/graph/adjacency_list.hpp>
38 
39 #include <list>
40 #include <memory>
41 #include <optional>
42 #include <vector>
43 
44 using AdjacentList = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS>;
45 // node ID used when extracting query plan DAG
46 // note this ID is different from RelNode's id since query plan DAG extractor assigns an
47 // unique node ID only to a rel node which is included in extracted DAG (if we cannot
48 // extract a DAG from the query plan DAG extractor skips to assign unique IDs to rel nodes
49 // in that query plan
50 using RelNodeId = size_t;
51 // toString content of each extracted rel node
52 using RelNodeExplained = std::string;
53 // hash value of explained rel node
54 using RelNodeExplainedHash = size_t;
55 // a string representation of a query plan that is collected by visiting query plan DAG
56 // starting from root to leaf and concatenate each rel node's id
57 // where two adjacent rel nodes in a QueryPlan are connected via '|' delimiter
58 // i.e., 1|2|3|4|
59 using QueryPlan = std::string;
60 // join column's column id info
61 using JoinColumnsInfo = std::string;
62 // hashed value of QueryPlanNodeIds
63 using QueryPlanHash = size_t;
64 // a map btw. a join column and its access path, i.e., a query plan DAG to project B.b
65 // here this join column is used to build a hashtable
66 using HashTableBuildDag = std::pair<JoinColumnsInfo, QueryPlan>;
67 // A map btw. join qual's column info and its corresponding hashtable access path as query
68 // plan DAG i.e., A.a = B.b and build hashtable on B.b? <(A.a = B.b) --> query plan DAG of
69 // projecting B.b> here, this two-level mapping (join qual -> inner join col -> hashtable
70 // access plan DAG) is required since we have to extract query plan before deciding which
71 // join col becomes inner since rel alg related metadata is required to extract query
72 // plan, and the actual decision happens at the time of building hashtable
73 using HashTableBuildDagMap = std::unordered_map<JoinColumnsInfo, HashTableBuildDag>;
74 
78  kQual, // INNER + OUTER
79  kDirect // set target directly (i.e., put Analyzer::Expr* instead of
80  // Analyzer::BinOper*)
81 };
82 constexpr char const* EMPTY_QUERY_PLAN = "";
83 
85 
86 namespace Analyzer {
87 class Expr;
88 class ColumnVar;
89 class Estimator;
90 struct OrderEntry;
91 
92 } // namespace Analyzer
93 
94 struct SortInfo {
95  const std::list<Analyzer::OrderEntry> order_entries;
97  const size_t limit;
98  const size_t offset;
99 };
100 
102  std::list<std::shared_ptr<Analyzer::Expr>> quals;
104 };
105 
106 using JoinQualsPerNestingLevel = std::vector<JoinCondition>;
107 
109  std::vector<InputDescriptor> input_descs;
110  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
111  std::list<std::shared_ptr<Analyzer::Expr>> simple_quals;
112  std::list<std::shared_ptr<Analyzer::Expr>> quals;
114  const std::list<std::shared_ptr<Analyzer::Expr>> groupby_exprs;
115  std::vector<Analyzer::Expr*> target_exprs;
116  const std::shared_ptr<Analyzer::Estimator> estimator;
118  size_t scan_limit;
122  bool use_bump_allocator{false};
123  // empty if not a UNION, true if UNION ALL, false if regular UNION
124  const std::optional<bool> union_all;
125  std::shared_ptr<const query_state::QueryState> query_state;
126 };
127 
128 std::ostream& operator<<(std::ostream& os, const RelAlgExecutionUnit& ra_exe_unit);
129 std::string ra_exec_unit_desc_for_caching(const RelAlgExecutionUnit& ra_exe_unit);
130 
132  const std::vector<InputDescriptor> input_descs;
133  std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs;
134  std::vector<Analyzer::Expr*> input_exprs;
135  std::vector<Analyzer::ColumnVar*> table_func_inputs;
136  std::vector<Analyzer::Expr*> target_exprs;
139 
140  public:
141  std::string toString() const {
142  return typeName(this) + "(" + "input_exprs=" + ::toString(input_exprs) +
143  ", table_func_inputs=" + ::toString(table_func_inputs) +
144  ", target_exprs=" + ::toString(target_exprs) +
145  ", output_buffer_size_param=" + ::toString(output_buffer_size_param) +
146  ", table_func=" + ::toString(table_func) + ")";
147  }
148 };
149 
150 class ResultSet;
151 using ResultSetPtr = std::shared_ptr<ResultSet>;
152 
153 #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:1223
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:53
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:60
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
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:85
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