/
executor_context.h
115 lines (96 loc) · 3.99 KB
/
executor_context.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//===----------------------------------------------------------------------===//
//
// BusTub
//
// executor_context.h
//
// Identification: src/include/execution/executor_context.h
//
// Copyright (c) 2015-2021, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#pragma once
#include <deque>
#include <memory>
#include <unordered_set>
#include <utility>
#include <vector>
#include "catalog/catalog.h"
#include "concurrency/transaction.h"
#include "execution/check_options.h"
#include "execution/executors/abstract_executor.h"
#include "storage/page/tmp_tuple_page.h"
namespace bustub {
class AbstractExecutor;
/**
* ExecutorContext stores all the context necessary to run an executor.
*/
class ExecutorContext {
public:
/**
* Creates an ExecutorContext for the transaction that is executing the query.
* @param transaction The transaction executing the query
* @param catalog The catalog that the executor uses
* @param bpm The buffer pool manager that the executor uses
* @param txn_mgr The transaction manager that the executor uses
* @param lock_mgr The lock manager that the executor uses
*/
ExecutorContext(Transaction *transaction, Catalog *catalog, BufferPoolManager *bpm, TransactionManager *txn_mgr,
LockManager *lock_mgr, bool is_delete)
: transaction_(transaction),
catalog_{catalog},
bpm_{bpm},
txn_mgr_(txn_mgr),
lock_mgr_(lock_mgr),
is_delete_(is_delete) {
nlj_check_exec_set_ = std::deque<std::pair<AbstractExecutor *, AbstractExecutor *>>(
std::deque<std::pair<AbstractExecutor *, AbstractExecutor *>>{});
check_options_ = std::make_shared<CheckOptions>();
}
~ExecutorContext() = default;
DISALLOW_COPY_AND_MOVE(ExecutorContext);
/** @return the running transaction */
auto GetTransaction() const -> Transaction * { return transaction_; }
/** @return the catalog */
auto GetCatalog() -> Catalog * { return catalog_; }
/** @return the buffer pool manager */
auto GetBufferPoolManager() -> BufferPoolManager * { return bpm_; }
/** @return the log manager - don't worry about it for now */
auto GetLogManager() -> LogManager * { return nullptr; }
/** @return the lock manager */
auto GetLockManager() -> LockManager * { return lock_mgr_; }
/** @return the transaction manager */
auto GetTransactionManager() -> TransactionManager * { return txn_mgr_; }
/** @return the set of nlj check executors */
auto GetNLJCheckExecutorSet() -> std::deque<std::pair<AbstractExecutor *, AbstractExecutor *>> & {
return nlj_check_exec_set_;
}
/** @return the check options */
auto GetCheckOptions() -> std::shared_ptr<CheckOptions> { return check_options_; }
void AddCheckExecutor(AbstractExecutor *left_exec, AbstractExecutor *right_exec) {
nlj_check_exec_set_.emplace_back(left_exec, right_exec);
}
void InitCheckOptions(std::shared_ptr<CheckOptions> &&check_options) {
BUSTUB_ASSERT(check_options, "nullptr");
check_options_ = std::move(check_options);
}
/** As of Fall 2023, this function should not be used. */
auto IsDelete() const -> bool { return is_delete_; }
private:
/** The transaction context associated with this executor context */
Transaction *transaction_;
/** The database 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_;
/** The set of NLJ check executors associated with this executor context */
std::deque<std::pair<AbstractExecutor *, AbstractExecutor *>> nlj_check_exec_set_;
/** The set of check options associated with this executor context */
std::shared_ptr<CheckOptions> check_options_;
bool is_delete_;
};
} // namespace bustub