* Be careful, after we create a sub_plan, some nodes in the original plan have been deleted and deconstructed. * More precisely, nodes that moved to sub_plan are deleted. */
| 238 | * More precisely, nodes that moved to sub_plan are deleted. |
| 239 | */ |
| 240 | QueryPlan QueryPlan::getSubPlan(QueryPlan::Node * node_) |
| 241 | { |
| 242 | QueryPlan sub_plan; |
| 243 | |
| 244 | std::stack<QueryPlan::Node *> plan_nodes; |
| 245 | sub_plan.addRoot(Node{.step = node_->step, .children = node_->children, .id = node_->id}); |
| 246 | plan_nodes.push(sub_plan.getRoot()); |
| 247 | sub_plan.setResetStepId(reset_step_id); |
| 248 | |
| 249 | while (!plan_nodes.empty()) |
| 250 | { |
| 251 | auto current = plan_nodes.top(); |
| 252 | plan_nodes.pop(); |
| 253 | |
| 254 | std::vector<Node *> result_children; |
| 255 | for (auto & child : current->children) |
| 256 | { |
| 257 | sub_plan.addNode(Node{.step = child->step, .children = child->children, .id = child->id}); |
| 258 | result_children.push_back(sub_plan.getLastNode()); |
| 259 | plan_nodes.push(sub_plan.getLastNode()); |
| 260 | } |
| 261 | current->children.swap(result_children); |
| 262 | } |
| 263 | |
| 264 | freshPlan(); |
| 265 | |
| 266 | return sub_plan; |
| 267 | } |
| 268 | |
| 269 | QueryPipelinePtr QueryPlan::buildQueryPipeline( |
| 270 | const QueryPlanOptimizationSettings & optimization_settings, const BuildQueryPipelineSettings & build_pipeline_settings) |
no test coverage detected