classExecutorContext { private: /** The transaction context associated with this executor context */ Transaction *transaction_; /** The datbase catalog associated with this executor context */ Catalog *catalog_; /** The buffer pool manager associated with this executor context */ BufferPoolManager *bpm_; /** The transaction manager associated with this executor context */ TransactionManager *txn_mgr_; /** The lock manager associated with this executor context */ LockManager *lock_mgr_; };
classAbstractExecutor { public: /** * Construct a new AbstractExecutor instance. * @param exec_ctx the executor context that the executor runs with */ explicitAbstractExecutor(ExecutorContext *exec_ctx) : exec_ctx_{exec_ctx} {}
/** * Initialize the executor. * @warning This function must be called before Next() is called! */ virtualvoidInit()= 0;
/** * Yield the next tuple from this executor. * @param[out] tuple The next tuple produced by this executor * @param[out] rid The next tuple RID produced by this executor * @return `true` if a tuple was produced, `false` if there are no more tuples */ virtualboolNext(Tuple *tuple, RID *rid)= 0;
/** @return The schema of the tuples that this executor produces */ virtualconst Schema *GetOutputSchema()= 0;
protected: /** The executor context in which the executor runs */ ExecutorContext *exec_ctx_; };
classAbstractPlanNode { private: /** * The schema for the output of this plan node. In the volcano model, every plan node will spit out tuples, * and this tells you what schema this plan node's tuples will have. */ const Schema *output_schema_; /** The children of this plan node. */ std::vector<const AbstractPlanNode *> children_; }; } // namespace bustub
boolExecute(const AbstractPlanNode *plan, std::vector<Tuple> *result_set, Transaction *txn, ExecutorContext *exec_ctx){ // Construct and executor for the plan auto executor = ExecutorFactory::CreateExecutor(exec_ctx, plan);
// Prepare the root executor executor->Init();
// Execute the query plan try { Tuple tuple; RID rid; while (executor->Next(&tuple, &rid)) { if (result_set != nullptr) { result_set->push_back(tuple); } } } catch (Exception &e) { // TODO(student): handle exceptions LOG_DEBUG("%s", e.what()); }