OmniSciDB  0264ff685a
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 
69  private:
71  std::vector<TargetMetaInfo> targets_meta_;
72  // filters chosen to be pushed down
73  std::vector<PushedDownFilterInfo> pushed_down_filter_info_;
74  // whether or not it was allowed to look for filters to push down
76 };
77 
78 class RelAlgNode;
79 
81  public:
83  : body_(body)
84  , result_(std::make_shared<ResultSet>(std::vector<TargetInfo>{},
87  nullptr,
88  nullptr,
89  0,
90  0),
91  {}) {}
92 
93  const ExecutionResult& getResult() const { return result_; }
94 
95  void setResult(const ExecutionResult& result);
96 
97  const RelAlgNode* getBody() const;
98 
99  private:
102 };
103 
104 using DAG = boost::
105  adjacency_list<boost::setS, boost::vecS, boost::bidirectionalS, const RelAlgNode*>;
106 using Vertex = DAG::vertex_descriptor;
107 
117  public:
118  RaExecutionSequence(const RelAlgNode*, const bool build_sequence = true);
119  RaExecutionSequence(std::unique_ptr<RaExecutionDesc> exec_desc);
120 
125  RaExecutionDesc* next();
126 
132  std::optional<size_t> nextStepId(const bool after_broadcast) const;
133 
134  bool executionFinished() const;
135 
136  RaExecutionDesc* getDescriptor(size_t idx) const {
137  CHECK_LT(idx, descs_.size());
138  return descs_[idx].get();
139  }
140 
141  size_t size() const { return descs_.size(); }
142  bool empty() const { return descs_.empty(); }
143 
144  size_t totalDescriptorsCount() const;
145 
146  private:
148 
149  std::unordered_set<Vertex> joins_;
150  std::vector<Vertex> ordering_; // reverse order topological sort of graph_
151  size_t current_vertex_ = 0;
152  size_t scan_count_ = 0;
153 
162  size_t stepsToNextBroadcast() const;
163 
164  // The execution descriptors hold the pointers to their results. We need to push them
165  // back into this vector as they are created, so we don't lose the intermediate results
166  // later.
167  std::vector<std::unique_ptr<RaExecutionDesc>> descs_;
168 };
const ExecutionResult & getResult() const
ExecutionResult & operator=(const ExecutionResult &that)
void setQueueTime(const int64_t queue_time_ms)
const std::vector< PushedDownFilterInfo > & getPushedDownFilterInfo() const
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:56
std::shared_ptr< ResultSet > ResultSetPtr
std::unordered_set< Vertex > joins_
std::string toString() const
std::vector< std::unique_ptr< RaExecutionDesc > > descs_
A container for relational algebra descriptors defining the execution order for a relational algebra ...
RaExecutionDesc(const RelAlgNode *body)
const ResultSetPtr & getDataPtr() const
std::vector< PushedDownFilterInfo > pushed_down_filter_info_
#define CHECK_LT(x, y)
Definition: Logger.h:207
const std::shared_ptr< ResultSet > & getRows() const
std::vector< Vertex > ordering_
Descriptor for the result set buffer layout.
const std::vector< TargetMetaInfo > & getTargetsMeta() const
RaExecutionDesc * getDescriptor(size_t idx) const
#define CHECK(condition)
Definition: Logger.h:197
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_
const bool isFilterPushDownEnabled() const