OmniSciDB  0264ff685a
anonymous_namespace{RelAlgExecutionDescriptor.cpp} Namespace Reference

Functions

std::vector< Vertexmerge_sort_with_input (const std::vector< Vertex > &vertices, const DAG &graph)
 
DAG build_dag (const RelAlgNode *sink)
 
std::unordered_set< Vertexget_join_vertices (const std::vector< Vertex > &vertices, const DAG &graph)
 

Function Documentation

◆ build_dag()

DAG anonymous_namespace{RelAlgExecutionDescriptor.cpp}::build_dag ( const RelAlgNode sink)

Definition at line 126 of file RelAlgExecutionDescriptor.cpp.

References CHECK.

Referenced by RaExecutionSequence::RaExecutionSequence().

126  {
127  DAG graph(1);
128  graph[0] = sink;
129  std::unordered_map<const RelAlgNode*, int> node_ptr_to_vert_idx{
130  std::make_pair(sink, 0)};
131  std::vector<const RelAlgNode*> stack(1, sink);
132  while (!stack.empty()) {
133  const auto node = stack.back();
134  stack.pop_back();
135  if (dynamic_cast<const RelScan*>(node)) {
136  continue;
137  }
138 
139  const auto input_num = node->inputCount();
140  switch (input_num) {
141  case 0:
142  CHECK(dynamic_cast<const RelLogicalValues*>(node));
143  case 1:
144  break;
145  case 2:
146  CHECK(dynamic_cast<const RelJoin*>(node) ||
147  dynamic_cast<const RelLeftDeepInnerJoin*>(node) ||
148  dynamic_cast<const RelLogicalUnion*>(node) ||
149  dynamic_cast<const RelTableFunction*>(node));
150  break;
151  default:
152  CHECK(dynamic_cast<const RelLeftDeepInnerJoin*>(node) ||
153  dynamic_cast<const RelLogicalUnion*>(node) ||
154  dynamic_cast<const RelTableFunction*>(node));
155  }
156  for (size_t i = 0; i < input_num; ++i) {
157  const auto input = node->getInput(i);
158  CHECK(input);
159  const bool visited = node_ptr_to_vert_idx.count(input) > 0;
160  if (!visited) {
161  node_ptr_to_vert_idx.insert(std::make_pair(input, node_ptr_to_vert_idx.size()));
162  }
163  boost::add_edge(node_ptr_to_vert_idx[input], node_ptr_to_vert_idx[node], graph);
164  if (!visited) {
165  graph[node_ptr_to_vert_idx[input]] = input;
166  stack.push_back(input);
167  }
168  }
169  }
170  return graph;
171 }
#define CHECK(condition)
Definition: Logger.h:197
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, const RelAlgNode * > DAG
+ Here is the caller graph for this function:

◆ get_join_vertices()

std::unordered_set<Vertex> anonymous_namespace{RelAlgExecutionDescriptor.cpp}::get_join_vertices ( const std::vector< Vertex > &  vertices,
const DAG graph 
)

Definition at line 173 of file RelAlgExecutionDescriptor.cpp.

References CHECK.

Referenced by RaExecutionSequence::RaExecutionSequence().

174  {
175  std::unordered_set<Vertex> joins;
176  for (const auto vert : vertices) {
177  if (dynamic_cast<const RelLeftDeepInnerJoin*>(graph[vert])) {
178  joins.insert(vert);
179  continue;
180  }
181  if (!dynamic_cast<const RelJoin*>(graph[vert])) {
182  continue;
183  }
184  if (boost::out_degree(vert, graph) > 1) {
185  throw std::runtime_error("Join used more than once not supported yet");
186  }
187  auto [oe_iter, oe_end] = boost::out_edges(vert, graph);
188  CHECK(std::next(oe_iter) == oe_end);
189  const auto out_vert = boost::target(*oe_iter, graph);
190  if (!dynamic_cast<const RelJoin*>(graph[out_vert])) {
191  joins.insert(vert);
192  }
193  }
194  return joins;
195 }
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ merge_sort_with_input()

std::vector<Vertex> anonymous_namespace{RelAlgExecutionDescriptor.cpp}::merge_sort_with_input ( const std::vector< Vertex > &  vertices,
const DAG graph 
)

Definition at line 96 of file RelAlgExecutionDescriptor.cpp.

References CHECK, and gpu_enabled::sort().

Referenced by RaExecutionSequence::RaExecutionSequence().

97  {
98  DAG::in_edge_iterator ie_iter, ie_end;
99  std::unordered_set<Vertex> inputs;
100  for (const auto vert : vertices) {
101  if (const auto sort = dynamic_cast<const RelSort*>(graph[vert])) {
102  boost::tie(ie_iter, ie_end) = boost::in_edges(vert, graph);
103  CHECK(size_t(1) == sort->inputCount() && boost::next(ie_iter) == ie_end);
104  const auto in_vert = boost::source(*ie_iter, graph);
105  const auto input = graph[in_vert];
106  if (dynamic_cast<const RelScan*>(input)) {
107  throw std::runtime_error("Standalone sort not supported yet");
108  }
109  if (boost::out_degree(in_vert, graph) > 1) {
110  throw std::runtime_error("Sort's input node used by others not supported yet");
111  }
112  inputs.insert(in_vert);
113  }
114  }
115 
116  std::vector<Vertex> new_vertices;
117  for (const auto vert : vertices) {
118  if (inputs.count(vert)) {
119  continue;
120  }
121  new_vertices.push_back(vert);
122  }
123  return new_vertices;
124 }
DEVICE void sort(ARGS &&... args)
Definition: gpu_enabled.h:105
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function: