Skip to content

Commit 36f623e

Browse files
committed
fix index key
1 parent 4ff771f commit 36f623e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/include/execution/executors/update_executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class UpdateExecutor : public AbstractExecutor {
8080
const UpdatePlanNode *plan_;
8181
/** Metadata identifying the table that should be updated. */
8282
const TableMetadata *table_info_;
83-
/** The child executor to obtain value from, can be nullptr. */
83+
/** The child executor to obtain value from. */
8484
std::unique_ptr<AbstractExecutor> child_executor_;
8585
};
8686
} // namespace bustub

test/execution/executor_test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "execution/plans/seq_scan_plan.h"
3636
#include "gtest/gtest.h"
3737
#include "storage/b_plus_tree_test_util.h" // NOLINT
38+
#include "storage/table/tuple.h"
3839
#include "type/value_factory.h"
3940

4041
namespace bustub {
@@ -312,16 +313,18 @@ TEST_F(ExecutorTest, DISABLED_SimpleRawInsertWithIndexTest) {
312313
std::vector<RID> rids;
313314

314315
// Get RID from index, fetch tuple and then compare
315-
for (size_t i = 0; i < result_set.size(); ++i) {
316-
index_info->index_->ScanKey(result_set[i], &rids, GetTxn());
316+
for (auto &table_tuple : result_set) {
317+
rids.clear();
318+
auto index_key = table_tuple.KeyFromTuple(schema, index_info->key_schema_, index_info->index_->GetKeyAttrs());
319+
index_info->index_->ScanKey(index_key, &rids, GetTxn());
317320
Tuple indexed_tuple;
318-
auto fetch_tuple = table_info->table_->GetTuple(rids[i], &indexed_tuple, GetTxn());
321+
auto fetch_tuple = table_info->table_->GetTuple(rids[0], &indexed_tuple, GetTxn());
319322

320323
ASSERT_TRUE(fetch_tuple);
321324
ASSERT_EQ(indexed_tuple.GetValue(out_schema, out_schema->GetColIdx("colA")).GetAs<int32_t>(),
322-
result_set[i].GetValue(out_schema, out_schema->GetColIdx("colA")).GetAs<int32_t>());
325+
table_tuple.GetValue(out_schema, out_schema->GetColIdx("colA")).GetAs<int32_t>());
323326
ASSERT_EQ(indexed_tuple.GetValue(out_schema, out_schema->GetColIdx("colB")).GetAs<int32_t>(),
324-
result_set[i].GetValue(out_schema, out_schema->GetColIdx("colB")).GetAs<int32_t>());
327+
table_tuple.GetValue(out_schema, out_schema->GetColIdx("colB")).GetAs<int32_t>());
325328

326329
std::cout << indexed_tuple.GetValue(out_schema, out_schema->GetColIdx("colA")).GetAs<int32_t>() << ", "
327330
<< indexed_tuple.GetValue(out_schema, out_schema->GetColIdx("colB")).GetAs<int32_t>() << std::endl;

0 commit comments

Comments
 (0)