Skip to content

Commit 078c09b

Browse files
authored
Merge pull request #29 from poyrazK/test/raft-group-coverage
fix(heap_table): TupleId sentinel bug and 28 unit tests
2 parents ceaae2e + 615fa1c commit 078c09b

5 files changed

Lines changed: 386 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CMakeFiles/
1010
cmake_install.cmake
1111
Makefile
1212
*.cmake
13+
_deps/
1314

1415
# Compiled binaries
1516
sqlEngine

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ if(BUILD_TESTS)
137137
add_cloudsql_test(raft_group_tests tests/raft_group_tests.cpp)
138138
add_cloudsql_test(raft_protocol_tests tests/raft_protocol_tests.cpp)
139139
add_cloudsql_test(columnar_table_tests tests/columnar_table_tests.cpp)
140+
add_cloudsql_test(heap_table_tests tests/heap_table_tests.cpp)
140141
add_cloudsql_test(storage_manager_tests tests/storage_manager_tests.cpp)
141142
add_cloudsql_test(rpc_server_tests tests/rpc_server_tests.cpp)
142143
add_cloudsql_test(operator_tests tests/operator_tests.cpp)

include/storage/heap_table.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class HeapTable {
3737
uint32_t page_num; /**< Physical page index in the file */
3838
uint16_t slot_num; /**< Logical slot index within the page */
3939

40-
TupleId() : page_num(0), slot_num(0) {}
40+
TupleId() : page_num(UINT32_MAX), slot_num(0) {}
4141
TupleId(uint32_t page, uint16_t slot) : page_num(page), slot_num(slot) {}
4242

4343
/** @return true if the ID represents a null/invalid record */
44-
[[nodiscard]] bool is_null() const { return page_num == 0 && slot_num == 0; }
44+
[[nodiscard]] bool is_null() const { return page_num == UINT32_MAX && slot_num == 0; }
4545

4646
/** @return Human-readable string representation */
4747
[[nodiscard]] std::string to_string() const {

src/storage/heap_table.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,12 @@ bool HeapTable::get_meta(const TupleId& tuple_id, TupleMeta& out_meta) const {
543543
std::memcpy(&out_meta.xmin, data + 2, 8);
544544
std::memcpy(&out_meta.xmax, data + 10, 8);
545545

546+
/* Skip tuples that have been logically deleted */
547+
if (out_meta.xmax != 0) {
548+
bpm_.unpin_page_by_id(file_id_, tuple_id.page_num, false);
549+
return false;
550+
}
551+
546552
size_t cursor = 18;
547553
std::vector<common::Value> values;
548554
values.reserve(schema_.column_count());

0 commit comments

Comments
 (0)