OmniSciDB  a47db9e897
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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

Definition at line 120 of file RelAlgExecutionDescriptor.cpp.

References CHECK().

Referenced by RaExecutionSequence::RaExecutionSequence().

120  {
121  DAG graph(1);
122  graph[0] = sink;
123  std::unordered_map<const RelAlgNode*, int> node_ptr_to_vert_idx{
124  std::make_pair(sink, 0)};
125  std::vector<const RelAlgNode*> stack(1, sink);
126  while (!stack.empty()) {
127  const auto node = stack.back();
128  stack.pop_back();
129  if (dynamic_cast<const RelScan*>(node)) {
130  continue;
131  }
132 
133  const auto input_num = node->inputCount();
134  CHECK(input_num == 1 ||
135  (dynamic_cast<const RelLogicalValues*>(node) && input_num == 0) ||
136  (dynamic_cast<const RelModify*>(node) && input_num == 1) ||
137  (input_num == 2 && (dynamic_cast<const RelJoin*>(node) ||
138  dynamic_cast<const RelLeftDeepInnerJoin*>(node))) ||
139  (input_num > 2 && (dynamic_cast<const RelLeftDeepInnerJoin*>(node))));
140  for (size_t i = 0; i < input_num; ++i) {
141  const auto input = node->getInput(i);
142  CHECK(input);
143  const bool visited = node_ptr_to_vert_idx.count(input) > 0;
144  if (!visited) {
145  node_ptr_to_vert_idx.insert(std::make_pair(input, node_ptr_to_vert_idx.size()));
146  }
147  boost::add_edge(node_ptr_to_vert_idx[input], node_ptr_to_vert_idx[node], graph);
148  if (!visited) {
149  graph[node_ptr_to_vert_idx[input]] = input;
150  stack.push_back(input);
151  }
152  }
153  }
154  return graph;
155 }
CHECK(cgen_state)
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, const RelAlgNode * > DAG

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 157 of file RelAlgExecutionDescriptor.cpp.

References CHECK().

Referenced by RaExecutionSequence::RaExecutionSequence().

158  {
159  std::unordered_set<Vertex> joins;
160  for (const auto vert : vertices) {
161  if (dynamic_cast<const RelLeftDeepInnerJoin*>(graph[vert])) {
162  joins.insert(vert);
163  continue;
164  }
165  if (!dynamic_cast<const RelJoin*>(graph[vert])) {
166  continue;
167  }
168  if (boost::out_degree(vert, graph) > 1) {
169  throw std::runtime_error("Join used more than once not supported yet");
170  }
171  auto [oe_iter, oe_end] = boost::out_edges(vert, graph);
172  CHECK(std::next(oe_iter) == oe_end);
173  const auto out_vert = boost::target(*oe_iter, graph);
174  if (!dynamic_cast<const RelJoin*>(graph[out_vert])) {
175  joins.insert(vert);
176  }
177  }
178  return joins;
179 }
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 90 of file RelAlgExecutionDescriptor.cpp.

References CHECK().

Referenced by RaExecutionSequence::RaExecutionSequence().

91  {
92  DAG::in_edge_iterator ie_iter, ie_end;
93  std::unordered_set<Vertex> inputs;
94  for (const auto vert : vertices) {
95  if (const auto sort = dynamic_cast<const RelSort*>(graph[vert])) {
96  boost::tie(ie_iter, ie_end) = boost::in_edges(vert, graph);
97  CHECK(size_t(1) == sort->inputCount() && boost::next(ie_iter) == ie_end);
98  const auto in_vert = boost::source(*ie_iter, graph);
99  const auto input = graph[in_vert];
100  if (dynamic_cast<const RelScan*>(input)) {
101  throw std::runtime_error("Standalone sort not supported yet");
102  }
103  if (boost::out_degree(in_vert, graph) > 1) {
104  throw std::runtime_error("Sort's input node used by others not supported yet");
105  }
106  inputs.insert(in_vert);
107  }
108  }
109 
110  std::vector<Vertex> new_vertices;
111  for (const auto vert : vertices) {
112  if (inputs.count(vert)) {
113  continue;
114  }
115  new_vertices.push_back(vert);
116  }
117  return new_vertices;
118 }
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: