src/backend/bridge/dml/executor/plan_executor.cpp
/**
 * @brief Build the executor tree.
 * @param The current executor tree
 * @param The plan tree
 * @param Transation context
 * @return The updated executor tree.
 */
@brief Build the executor tree.
@param The current executor tree
@param The plan tree
@param Transation context
@return The updated executor tree.
@brief Build the executor tree . @param The current executor tree @param The plan tree @param Transation context @return The updated executor tree .
executor::AbstractExecutor *BuildExecutorTree(
    executor::AbstractExecutor *root, const planner::AbstractPlan *plan,
    executor::ExecutorContext *executor_context) {
  if (plan == nullptr) return root;
  executor::AbstractExecutor *child_executor = nullptr;
  auto plan_node_type = plan->GetPlanNodeType();
  switch (plan_node_type) {
    case PLAN_NODE_TYPE_INVALID:
      LOG_ERROR("Invalid plan node type ");
      break;
    case PLAN_NODE_TYPE_SEQSCAN:
      child_executor = new executor::SeqScanExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_INDEXSCAN:
      child_executor = new executor::IndexScanExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_INSERT:
      child_executor = new executor::InsertExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_DELETE:
      child_executor = new executor::DeleteExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_UPDATE:
      child_executor = new executor::UpdateExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_LIMIT:
      child_executor = new executor::LimitExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_NESTLOOP:
      child_executor =
          new executor::NestedLoopJoinExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_MERGEJOIN:
      child_executor = new executor::MergeJoinExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_HASH:
      child_executor = new executor::HashExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_HASHJOIN:
      child_executor = new executor::HashJoinExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_PROJECTION:
      child_executor = new executor::ProjectionExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_MATERIALIZE:
      child_executor =
          new executor::MaterializationExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_AGGREGATE_V2:
      child_executor = new executor::AggregateExecutor(plan, executor_context);
      break;
    case PLAN_NODE_TYPE_ORDERBY:
      child_executor = new executor::OrderByExecutor(plan, executor_context);
      break;
    default:
      LOG_ERROR("Unsupported plan node type : %d ", plan_node_type);
      break;
  }
  if (child_executor != nullptr) {
    if (root != nullptr)
      root->AddChild(child_executor);
    else
      root = child_executor;
  }
  auto &children = plan->GetChildren();
  for (auto &child : children) {
    child_executor = BuildExecutorTree(child_executor, child.get(), executor_context);
  }
  return root;
}
executor :: AbstractExecutor * BuildExecutorTree ( executor :: AbstractExecutor * root , const planner :: AbstractPlan * plan , executor :: ExecutorContext * executor_context ) { if ( plan == nullptr ) return root ; executor :: AbstractExecutor * child_executor = nullptr ; auto plan_node_type = plan -> GetPlanNodeType ( ) ; switch ( plan_node_type ) { case PLAN_NODE_TYPE_INVALID : LOG_ERROR ( " " ) ; break ; case PLAN_NODE_TYPE_SEQSCAN : child_executor = new executor :: SeqScanExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_INDEXSCAN : child_executor = new executor :: IndexScanExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_INSERT : child_executor = new executor :: InsertExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_DELETE : child_executor = new executor :: DeleteExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_UPDATE : child_executor = new executor :: UpdateExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_LIMIT : child_executor = new executor :: LimitExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_NESTLOOP : child_executor = new executor :: NestedLoopJoinExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_MERGEJOIN : child_executor = new executor :: MergeJoinExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_HASH : child_executor = new executor :: HashExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_HASHJOIN : child_executor = new executor :: HashJoinExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_PROJECTION : child_executor = new executor :: ProjectionExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_MATERIALIZE : child_executor = new executor :: MaterializationExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_AGGREGATE_V2 : child_executor = new executor :: AggregateExecutor ( plan , executor_context ) ; break ; case PLAN_NODE_TYPE_ORDERBY : child_executor = new executor :: OrderByExecutor ( plan , executor_context ) ; break ; default : LOG_ERROR ( " " , plan_node_type ) ; break ; } if ( child_executor != nullptr ) { if ( root != nullptr ) root -> AddChild ( child_executor ) ; else root = child_executor ; } auto & children = plan -> GetChildren ( ) ; for ( auto & child : children ) { child_executor = BuildExecutorTree ( child_executor , child . get ( ) , executor_context ) ; } return root ; }
@brief Build the executor tree.
@brief Build the executor tree .
// Base case // Base case // Recurse