@@ -106,8 +106,8 @@ std::unique_ptr<RmRecord> mvcc_get_record(const Rid &rid, Context *context_, RmF
106106 return rec;
107107}
108108
109- bool mvcc_insert_index (const TabMeta &tab_, RmRecord &rec, Rid rid, Context *context_, TransactionManager *txn_mgr ,
110- SmManager *sm_manager) {
109+ bool mvcc_insert_index (const TabMeta &tab_, std::unique_ptr< RmRecord> &rec, Rid rid, Context *context_,
110+ TransactionManager *txn_mgr, SmManager *sm_manager) {
111111 RmFileHandle *fh_ = sm_manager->fhs_ .at (tab_.name ).get ();
112112 std::vector<std::unique_ptr<char []>> inserted_keys; // 记录已插入的键值
113113 inserted_keys.reserve (tab_.indexes .size ()); // 预分配空间以提高性能
@@ -118,7 +118,7 @@ bool mvcc_insert_index(const TabMeta &tab_, RmRecord &rec, Rid rid, Context *con
118118 auto key = std::make_unique<char []>(index.col_tot_len );
119119 int offset = 0 ;
120120 for (size_t j = 0 ; j < static_cast <size_t >(index.col_num ); ++j) {
121- memcpy (key.get () + offset, rec. data + index.cols [j].offset , index.cols [j].len );
121+ memcpy (key.get () + offset, rec-> data + index.cols [j].offset , index.cols [j].len );
122122 offset += index.cols [j].len ;
123123 }
124124 // 检查索引项是否已存在
@@ -165,13 +165,13 @@ bool mvcc_insert_index(const TabMeta &tab_, RmRecord &rec, Rid rid, Context *con
165165 * @param col 列元数据
166166 * @return 提取出的 Value
167167 */
168- Value GetColumnValue (const RmRecord &record, const ColMeta &col) {
168+ Value GetColumnValue (const std::unique_ptr< RmRecord> &record, const ColMeta &col) {
169169 Value val;
170- val.set_col_data (col.type , record. data + col.offset , col.len );
170+ val.set_col_data (col.type , record-> data + col.offset , col.len );
171171 return val;
172172}
173173
174- Value EvaluateExpr (const ExprTerm &term, const RmRecord &record, const std::vector<ColMeta> &cols) {
174+ Value EvaluateExpr (const ExprTerm &term, const std::unique_ptr< RmRecord> &record, const std::vector<ColMeta> &cols) {
175175 TRACE_FUNCTION
176176 switch (term.term_type ) {
177177 case TermType::VALUE : {
@@ -180,11 +180,16 @@ Value EvaluateExpr(const ExprTerm &term, const RmRecord &record, const std::vect
180180 }
181181 case TermType::COLUMN : {
182182 // 查找列并返回值
183+ if (record == nullptr ) {
184+ throw InternalError (" Record is null in record evaluation for column: " + term.col .to_string ());
185+ }
183186 for (const auto &col_meta : cols) {
184187 if (col_meta.name == term.col .col_name && col_meta.tab_name == term.col .tab_name ) {
185188 return GetColumnValue (record, col_meta);
186189 }
187190 }
191+ // 如果没有找到对应的列,抛出异常
192+ throw InternalError (" Column not found: " + term.col .to_string () + " in record evaluation" );
188193 }
189194 case TermType::EXPR : {
190195 // 递归计算左右操作数
0 commit comments