OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RelAlgExecutionDescriptor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, 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 <boost/graph/adjacency_list.hpp>
20 
23 #include "QueryEngine/ResultSet.h"
24 #include "Shared/TargetInfo.h"
25 #include "Shared/toString.h"
26 
27 class ResultSet;
28 
30  public:
32 
33  ExecutionResult(const std::shared_ptr<ResultSet>& rows,
34  const std::vector<TargetMetaInfo>& targets_meta);
35 
36  ExecutionResult(ResultSetPtr&& result, const std::vector<TargetMetaInfo>& targets_meta);
37 
38  ExecutionResult(const ExecutionResult& that);
39 
41 
42  ExecutionResult(const std::vector<PushedDownFilterInfo>& pushed_down_filter_info,
43  bool filter_push_down_enabled);
44 
46 
47  const std::shared_ptr<ResultSet>& getRows() const { return result_; }
48 
49  bool empty() const { return !result_; }
50 
51  const ResultSetPtr& getDataPtr() const { return result_; }
52 
53  const std::vector<TargetMetaInfo>& getTargetsMeta() const { return targets_meta_; }
54 
55  const std::vector<PushedDownFilterInfo>& getPushedDownFilterInfo() const;
56 
57  const bool isFilterPushDownEnabled() const { return filter_push_down_enabled_; }
58 
59  void setQueueTime(const int64_t queue_time_ms) {
60  CHECK(result_);
61  result_->setQueueTime(queue_time_ms);
62  }
63 
64  std::string toString() const {
65  return ::typeName(this) + "(" + ::toString(result_) + ", " +
67  }
68 
70 
71  std::string getExplanation();
72  void updateResultSet(const std::string& query_ra, RType type, bool success = true);
73  RType getResultType() const { return type_; }
75  int64_t getExecutionTime() const { return execution_time_ms_; }
76  void setExecutionTime(int64_t execution_time_ms) {
77  execution_time_ms_ = execution_time_ms;
78  }
79  void addExecutionTime(int64_t execution_time_ms) {
80  execution_time_ms_ += execution_time_ms;
81  }
82 
83  private:
85  std::vector<TargetMetaInfo> targets_meta_;
86  // filters chosen to be pushed down
87  std::vector<PushedDownFilterInfo> pushed_down_filter_info_;
88  // whether or not it was allowed to look for filters to push down
90 
91  bool success_;
94 };
95 
96 class RelAlgNode;
97 
99  public:
101  : body_(body)
102  , result_(std::make_shared<ResultSet>(std::vector<TargetInfo>{},
105  nullptr,
106  nullptr,
107  0,
108  0),
109  {}) {}
110 
111  const ExecutionResult& getResult() const { return result_; }
112 
113  void setResult(const ExecutionResult& result);
114 
115  const RelAlgNode* getBody() const;
116 
117  private:
120 };
121 
122 using DAG = boost::
123  adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, const RelAlgNode*>;
124 using Vertex = DAG::vertex_descriptor;
125 
135  public:
136  RaExecutionSequence(const RelAlgNode*, const bool build_sequence = true);
137  RaExecutionSequence(std::unique_ptr<RaExecutionDesc> exec_desc);
138 
144 
150 
156  std::optional<size_t> nextStepId(const bool after_broadcast) const;
157 
158  bool executionFinished() const;
159 
160  RaExecutionDesc* getDescriptor(size_t idx) const {
161  CHECK_LT(idx, descs_.size());
162  return descs_[idx].get();
163  }
164 
165  size_t size() const { return descs_.size(); }
166  bool empty() const { return descs_.empty(); }
167 
168  size_t totalDescriptorsCount() const;
169 
170  private:
172 
173  std::unordered_set<Vertex> joins_;
174  std::vector<Vertex> ordering_; // reverse order topological sort of graph_
175  size_t current_vertex_ = 0;
176  size_t scan_count_ = 0;
177 
186  size_t stepsToNextBroadcast() const;
187 
188  // The execution descriptors hold the pointers to their results. We need to push them
189  // back into this vector as they are created, so we don't lose the intermediate results
190  // later.
191  std::vector<std::unique_ptr<RaExecutionDesc>> descs_;
192 };
RType getResultType() const
RaExecutionDesc * getDescriptor(size_t idx) const
ExecutionResult & operator=(const ExecutionResult &that)
void setQueueTime(const int64_t queue_time_ms)
const RelAlgNode * body_
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
const ResultSetPtr & getDataPtr() const
std::shared_ptr< ResultSet > ResultSetPtr
std::unordered_set< Vertex > joins_
void addExecutionTime(int64_t execution_time_ms)
RaExecutionSequence(const RelAlgNode *, const bool build_sequence=true)
std::vector< std::unique_ptr< RaExecutionDesc > > descs_
A container for relational algebra descriptors defining the execution order for a relational algebra ...
const std::vector< TargetMetaInfo > & getTargetsMeta() const
const std::shared_ptr< ResultSet > & getRows() const
void updateResultSet(const std::string &query_ra, RType type, bool success=true)
RaExecutionDesc(const RelAlgNode *body)
std::string toString() const
std::vector< PushedDownFilterInfo > pushed_down_filter_info_
void setResultType(RType type)
#define CHECK_LT(x, y)
Definition: Logger.h:207
const std::vector< PushedDownFilterInfo > & getPushedDownFilterInfo() const
std::vector< Vertex > ordering_
Descriptor for the result set buffer layout.
std::string typeName(const T *v)
Definition: toString.h:81
const bool isFilterPushDownEnabled() const
#define CHECK(condition)
Definition: Logger.h:197
void setExecutionTime(int64_t execution_time_ms)
const RelAlgNode * getBody() const
Basic constructors and methods of the row set interface.
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, const RelAlgNode * > DAG
DAG::vertex_descriptor Vertex
std::vector< TargetMetaInfo > targets_meta_
int64_t getExecutionTime() const
std::optional< size_t > nextStepId(const bool after_broadcast) const