From 2a7d140be857a0fc39b572a732065e3990d91323 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Thu, 17 Oct 2024 17:21:05 -0700 Subject: [PATCH 01/21] feat(p3): introduce external merge sort & remove several executors --- src/execution/CMakeLists.txt | 1 + src/execution/executor_factory.cpp | 3 +- src/execution/mock_scan_executor.cpp | 45 ++++++- src/include/common/bustub_instance.h | 2 +- src/include/common/config.h | 2 +- src/include/storage/table/tuple.h | 3 + src/optimizer/optimizer.cpp | 1 - src/storage/table/tuple.cpp | 7 ++ test/sql/p3.00-primer.slt | 18 ++- test/sql/p3.07-simple-agg.slt | 4 +- test/sql/p3.08-group-agg-1.slt | 5 +- test/sql/p3.10-simple-join.slt | 7 +- test/sql/p3.14-hash-join.slt | 7 +- test/sql/p3.16-sort-limit.slt | 180 +++++++++++++++++++++++---- tools/sqllogictest/sqllogictest.cpp | 59 +++++---- 15 files changed, 268 insertions(+), 76 deletions(-) diff --git a/src/execution/CMakeLists.txt b/src/execution/CMakeLists.txt index cab89f5c0..172744693 100644 --- a/src/execution/CMakeLists.txt +++ b/src/execution/CMakeLists.txt @@ -4,6 +4,7 @@ add_library( aggregation_executor.cpp delete_executor.cpp execution_common.cpp + external_merge_sort_executor.cpp executor_factory.cpp filter_executor.cpp fmt_impl.cpp diff --git a/src/execution/executor_factory.cpp b/src/execution/executor_factory.cpp index dd98b4f09..d83bb085e 100644 --- a/src/execution/executor_factory.cpp +++ b/src/execution/executor_factory.cpp @@ -18,6 +18,7 @@ #include "execution/executors/abstract_executor.h" #include "execution/executors/aggregation_executor.h" #include "execution/executors/delete_executor.h" +#include "execution/executors/external_merge_sort_executor.h" #include "execution/executors/filter_executor.h" #include "execution/executors/hash_join_executor.h" #include "execution/executors/index_scan_executor.h" @@ -166,7 +167,7 @@ auto ExecutorFactory::CreateExecutor(ExecutorContext *exec_ctx, const AbstractPl case PlanType::Sort: { const auto *sort_plan = dynamic_cast(plan.get()); auto child = ExecutorFactory::CreateExecutor(exec_ctx, sort_plan->GetChildPlan()); - return std::make_unique(exec_ctx, sort_plan, std::move(child)); + return std::make_unique>(exec_ctx, sort_plan, std::move(child)); } // Create a new topN executor diff --git a/src/execution/mock_scan_executor.cpp b/src/execution/mock_scan_executor.cpp index 7c3ea3beb..1185d7607 100644 --- a/src/execution/mock_scan_executor.cpp +++ b/src/execution/mock_scan_executor.cpp @@ -36,6 +36,9 @@ static const char *ta_list_2023_fall[] = {"skyzh", "yliang412", "ferna static const char *ta_list_2024[] = {"AlSchlo", "walkingcabbages", "averyqi115", "lanlou1554", "sweetsuro", "ChaosZhai", "SDTheSlayer", "xx01cyx", "yliang412", "thelongmarch-azx"}; +static const char *ta_list_2024_fall[] = {"17zhangw", "connortsui20", "J-HowHuang", "lanlou1554", + "prashanthduvvada", "unw9527", "xx01cyx", "yashkothari42"}; + static const char *ta_oh_2022[] = {"Tuesday", "Wednesday", "Monday", "Wednesday", "Thursday", "Friday", "Wednesday", "Randomly", "Tuesday", "Monday", "Tuesday"}; @@ -48,11 +51,15 @@ static const char *ta_oh_2023_fall[] = {"Randomly", "Tuesday", "Wednesday", "T static const char *ta_oh_2024[] = {"Friday", "Thursday", "Friday", "Wednesday", "Thursday", "Yesterday", "Monday", "Tuesday", "Tuesday", "Monday"}; +static const char *ta_oh_2024_fall[] = {"Wednesday", "Thursday", "Tuesday", "Monday", + "Friday", "Thursday", "Tuesday", "Friday"}; + static const char *course_on_date[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; const char *mock_table_list[] = {"__mock_table_1", "__mock_table_2", "__mock_table_3", "__mock_table_tas_2022", "__mock_table_tas_2023", "__mock_table_tas_2023_fall", "__mock_table_tas_2024", - "__mock_agg_input_small", "__mock_agg_input_big", "__mock_table_schedule_2022", + "__mock_table_tas_2024_fall", "__mock_agg_input_small", "__mock_agg_input_big", + "__mock_external_merge_sort_input", "__mock_table_schedule_2022", "__mock_table_schedule", "__mock_table_123", "__mock_graph", // For leaderboard Q1 "__mock_t1", @@ -94,6 +101,10 @@ auto GetMockTableSchemaOf(const std::string &table) -> Schema { return Schema{std::vector{Column{"github_id", TypeId::VARCHAR, 128}, Column{"office_hour", TypeId::VARCHAR, 128}}}; } + if (table == "__mock_table_tas_2024_fall") { + return Schema{std::vector{Column{"github_id", TypeId::VARCHAR, 128}, Column{"office_hour", TypeId::VARCHAR, 128}}}; + } + if (table == "__mock_table_schedule_2022") { return Schema{std::vector{Column{"day_of_week", TypeId::VARCHAR, 128}, Column{"has_lecture", TypeId::INTEGER}}}; } @@ -108,6 +119,11 @@ auto GetMockTableSchemaOf(const std::string &table) -> Schema { Column{"v5", TypeId::INTEGER}, Column{"v6", TypeId::VARCHAR, 128}}}; } + if (table == "__mock_external_merge_sort_input") { + return Schema{ + std::vector{Column{"v1", TypeId::INTEGER}, Column{"v2", TypeId::INTEGER}, Column{"v3", TypeId::INTEGER}}}; + } + if (table == "__mock_graph") { return Schema{std::vector{Column{"src", TypeId::INTEGER}, Column{"dst", TypeId::INTEGER}, Column{"src_label", TypeId::VARCHAR, 8}, Column{"dst_label", TypeId::VARCHAR, 8}, @@ -182,6 +198,10 @@ auto GetSizeOf(const MockScanPlanNode *plan) -> size_t { return sizeof(ta_list_2024) / sizeof(ta_list_2024[0]); } + if (table == "__mock_table_tas_2024_fall") { + return sizeof(ta_list_2024_fall) / sizeof(ta_list_2024_fall[0]); + } + if (table == "__mock_table_schedule_2022") { return sizeof(course_on_date) / sizeof(course_on_date[0]); } @@ -198,6 +218,10 @@ auto GetSizeOf(const MockScanPlanNode *plan) -> size_t { return 10000; } + if (table == "__mock_external_merge_sort_input") { + return 100000; + } + if (table == "__mock_graph") { return GRAPH_NODE_CNT * GRAPH_NODE_CNT; } @@ -329,6 +353,15 @@ auto GetFunctionOf(const MockScanPlanNode *plan) -> std::function }; } + if (table == "__mock_table_tas_2024_fall") { + return [plan](size_t cursor) { + std::vector values{}; + values.push_back(ValueFactory::GetVarcharValue(ta_list_2024_fall[cursor])); + values.push_back(ValueFactory::GetVarcharValue(ta_oh_2024_fall[cursor])); + return Tuple{values, &plan->OutputSchema()}; + }; + } + if (table == "__mock_table_schedule_2022") { return [plan](size_t cursor) { std::vector values{}; @@ -374,6 +407,16 @@ auto GetFunctionOf(const MockScanPlanNode *plan) -> std::function return Tuple{values, &plan->OutputSchema()}; }; } + // select * from __mock_external_merge_sort_input order by v2 desc, v3 asc limit 100; + if (table == "__mock_external_merge_sort_input") { + return [plan](size_t cursor) { + std::vector values{}; + values.push_back(ValueFactory::GetIntegerValue(cursor)); + values.push_back(ValueFactory::GetIntegerValue((cursor + 1777) % 15000)); + values.push_back(ValueFactory::GetIntegerValue((cursor + 3) % 111)); + return Tuple{values, &plan->OutputSchema()}; + }; + } if (table == "__mock_table_123") { return [plan](size_t cursor) { diff --git a/src/include/common/bustub_instance.h b/src/include/common/bustub_instance.h index f0f9e1617..f1ae30b5d 100644 --- a/src/include/common/bustub_instance.h +++ b/src/include/common/bustub_instance.h @@ -242,7 +242,7 @@ class BusTubInstance { auto MakeExecutorContext(Transaction *txn, bool is_modify) -> std::unique_ptr; public: - explicit BusTubInstance(const std::filesystem::path &db_file_name, size_t bpm_size = 128); + explicit BusTubInstance(const std::filesystem::path &db_file_name, size_t bpm_size = BUFFER_POOL_SIZE); explicit BusTubInstance(size_t bpm_size = 128); diff --git a/src/include/common/config.h b/src/include/common/config.h index 433399ac2..be5a655b4 100644 --- a/src/include/common/config.h +++ b/src/include/common/config.h @@ -36,7 +36,7 @@ static constexpr int INVALID_TXN_ID = -1; // invalid transaction id static constexpr int INVALID_LSN = -1; // invalid log sequence number static constexpr int BUSTUB_PAGE_SIZE = 4096; // size of a data page in byte -static constexpr int BUFFER_POOL_SIZE = 10; // size of buffer pool +static constexpr int BUFFER_POOL_SIZE = 128; // size of buffer pool static constexpr int DEFAULT_DB_IO_SIZE = 16; // starting size of file on disk static constexpr int LOG_BUFFER_SIZE = ((BUFFER_POOL_SIZE + 1) * BUSTUB_PAGE_SIZE); // size of a log buffer in byte static constexpr int BUCKET_SIZE = 50; // size of extendible hash bucket diff --git a/src/include/storage/table/tuple.h b/src/include/storage/table/tuple.h index 2d44cc0bf..4f22d21c1 100644 --- a/src/include/storage/table/tuple.h +++ b/src/include/storage/table/tuple.h @@ -65,6 +65,9 @@ class Tuple { // constructor for creating a new tuple based on input value Tuple(std::vector values, const Schema *schema); + // constructor for creating a new tuple by copying fron existing bytes + Tuple(RID rid, const char *data, uint32_t size); + Tuple(const Tuple &other) = default; // move constructor diff --git a/src/optimizer/optimizer.cpp b/src/optimizer/optimizer.cpp index 7a5a865c7..35f8b92d7 100644 --- a/src/optimizer/optimizer.cpp +++ b/src/optimizer/optimizer.cpp @@ -12,7 +12,6 @@ auto Optimizer::Optimize(const AbstractPlanNodeRef &plan) -> AbstractPlanNodeRef p = OptimizeMergeProjection(p); p = OptimizeMergeFilterNLJ(p); p = OptimizeOrderByAsIndexScan(p); - p = OptimizeSortLimitAsTopN(p); p = OptimizeMergeFilterScan(p); p = OptimizeSeqScanAsIndexScan(p); return p; diff --git a/src/storage/table/tuple.cpp b/src/storage/table/tuple.cpp index e5ea0fa8c..3694847aa 100644 --- a/src/storage/table/tuple.cpp +++ b/src/storage/table/tuple.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,12 @@ Tuple::Tuple(std::vector values, const Schema *schema) { } } +Tuple::Tuple(RID rid, const char *data, uint32_t size) { + rid_ = rid; + data_.resize(size); + memcpy(data_.data(), data, size); +} + auto Tuple::GetValue(const Schema *schema, const uint32_t column_idx) const -> Value { assert(schema); const TypeId column_type = schema->GetColumn(column_idx).GetType(); diff --git a/test/sql/p3.00-primer.slt b/test/sql/p3.00-primer.slt index a46e6f842..063ae6fbc 100644 --- a/test/sql/p3.00-primer.slt +++ b/test/sql/p3.00-primer.slt @@ -1,13 +1,11 @@ query rowsort -select github_id, office_hour from __mock_table_tas_2024; +select github_id, office_hour from __mock_table_tas_2024_fall; ---- -AlSchlo Friday -walkingcabbages Thursday -averyqi115 Friday -lanlou1554 Wednesday -sweetsuro Thursday -ChaosZhai Yesterday -SDTheSlayer Monday +17zhangw Wednesday +connortsui20 Thursday +J-HowHuang Tuesday +lanlou1554 Monday +prashanthduvvada Friday +unw9527 Thursday xx01cyx Tuesday -yliang412 Tuesday -thelongmarch-azx Monday +yashkothari42 Friday \ No newline at end of file diff --git a/test/sql/p3.07-simple-agg.slt b/test/sql/p3.07-simple-agg.slt index 2e3d21f27..e62e7323f 100644 --- a/test/sql/p3.07-simple-agg.slt +++ b/test/sql/p3.07-simple-agg.slt @@ -2,9 +2,9 @@ # How many TAs are there in 2024 Spring? query -select count(*) from __mock_table_tas_2024; +select count(*) from __mock_table_tas_2024_fall; ---- -10 +8 # The real test process begins... diff --git a/test/sql/p3.08-group-agg-1.slt b/test/sql/p3.08-group-agg-1.slt index 15499e5cf..812f19bbd 100644 --- a/test/sql/p3.08-group-agg-1.slt +++ b/test/sql/p3.08-group-agg-1.slt @@ -4,12 +4,11 @@ # "rowsort" means that the order of result doesn't matter. query rowsort -select office_hour, count(*) from __mock_table_tas_2024 group by office_hour; +select office_hour, count(*) from __mock_table_tas_2024_fall group by office_hour; ---- Tuesday 2 Friday 2 -Monday 2 -Yesterday 1 +Monday 1 Wednesday 1 Thursday 2 diff --git a/test/sql/p3.10-simple-join.slt b/test/sql/p3.10-simple-join.slt index 0e9427825..a74d159d1 100644 --- a/test/sql/p3.10-simple-join.slt +++ b/test/sql/p3.10-simple-join.slt @@ -8,13 +8,12 @@ set force_optimizer_starter_rule=yes query rowsort select * from - __mock_table_tas_2024 inner join __mock_table_schedule + __mock_table_tas_2024_fall inner join __mock_table_schedule on office_hour = day_of_week where has_lecture = 1; ---- -lanlou1554 Wednesday Wednesday 1 -SDTheSlayer Monday Monday 1 -thelongmarch-azx Monday Monday 1 +lanlou1554 Monday Monday 1 +17zhangw Wednesday Wednesday 1 # The real test begins... diff --git a/test/sql/p3.14-hash-join.slt b/test/sql/p3.14-hash-join.slt index b3acaaab8..9dfe55e47 100644 --- a/test/sql/p3.14-hash-join.slt +++ b/test/sql/p3.14-hash-join.slt @@ -5,13 +5,12 @@ query rowsort +ensure:hash_join select * from - __mock_table_tas_2024 inner join __mock_table_schedule + __mock_table_tas_2024_fall inner join __mock_table_schedule on office_hour = day_of_week where has_lecture = 1; ---- -SDTheSlayer Monday Monday 1 -thelongmarch-azx Monday Monday 1 -lanlou1554 Wednesday Wednesday 1 +lanlou1554 Monday Monday 1 +17zhangw Wednesday Wednesday 1 # The real test begins... diff --git a/test/sql/p3.16-sort-limit.slt b/test/sql/p3.16-sort-limit.slt index 951853cc5..e113abfdc 100644 --- a/test/sql/p3.16-sort-limit.slt +++ b/test/sql/p3.16-sort-limit.slt @@ -4,34 +4,18 @@ # Default query -select * from __mock_table_tas_2024 order by office_hour, github_id; +select * from __mock_table_1 order by colB desc limit 10; ---- -AlSchlo Friday -averyqi115 Friday -SDTheSlayer Monday -thelongmarch-azx Monday -sweetsuro Thursday -walkingcabbages Thursday -xx01cyx Tuesday -yliang412 Tuesday -lanlou1554 Wednesday -ChaosZhai Yesterday - - -# ASC -query -select * from __mock_table_tas_2024 order by office_hour asc, github_id desc; ----- -averyqi115 Friday -AlSchlo Friday -thelongmarch-azx Monday -SDTheSlayer Monday -walkingcabbages Thursday -sweetsuro Thursday -yliang412 Tuesday -xx01cyx Tuesday -lanlou1554 Wednesday -ChaosZhai Yesterday +99 9900 +98 9800 +97 9700 +96 9600 +95 9500 +94 9400 +93 9300 +92 9200 +91 9100 +90 9000 # Simple limit @@ -65,6 +49,12 @@ select * from test_simple_seq_2 limit 15; statement ok create table temp_1(colA int, colB int, colC int, colD int); +# Select on empty table with sort +query +select * from temp_1 order by colA; +---- + + statement ok insert into temp_1 values (0 , 1, 6113, 48270), @@ -382,3 +372,139 @@ select * from 84 711 4 9 92192 84 4626 69 603 9 8 20385 69 755 33 701 3 8 24527 33 991 + + +# Large amount of data +query +select * from __mock_external_merge_sort_input order by v2 desc, v3 asc limit 100; +---- +13222 14999 16 +28222 14999 31 +43222 14999 46 +58222 14999 61 +73222 14999 76 +88222 14999 91 +13221 14998 15 +28221 14998 30 +43221 14998 45 +58221 14998 60 +73221 14998 75 +88221 14998 90 +13220 14997 14 +28220 14997 29 +43220 14997 44 +58220 14997 59 +73220 14997 74 +88220 14997 89 +13219 14996 13 +28219 14996 28 +43219 14996 43 +58219 14996 58 +73219 14996 73 +88219 14996 88 +13218 14995 12 +28218 14995 27 +43218 14995 42 +58218 14995 57 +73218 14995 72 +88218 14995 87 +13217 14994 11 +28217 14994 26 +43217 14994 41 +58217 14994 56 +73217 14994 71 +88217 14994 86 +13216 14993 10 +28216 14993 25 +43216 14993 40 +58216 14993 55 +73216 14993 70 +88216 14993 85 +13215 14992 9 +28215 14992 24 +43215 14992 39 +58215 14992 54 +73215 14992 69 +88215 14992 84 +13214 14991 8 +28214 14991 23 +43214 14991 38 +58214 14991 53 +73214 14991 68 +88214 14991 83 +13213 14990 7 +28213 14990 22 +43213 14990 37 +58213 14990 52 +73213 14990 67 +88213 14990 82 +13212 14989 6 +28212 14989 21 +43212 14989 36 +58212 14989 51 +73212 14989 66 +88212 14989 81 +13211 14988 5 +28211 14988 20 +43211 14988 35 +58211 14988 50 +73211 14988 65 +88211 14988 80 +13210 14987 4 +28210 14987 19 +43210 14987 34 +58210 14987 49 +73210 14987 64 +88210 14987 79 +13209 14986 3 +28209 14986 18 +43209 14986 33 +58209 14986 48 +73209 14986 63 +88209 14986 78 +13208 14985 2 +28208 14985 17 +43208 14985 32 +58208 14985 47 +73208 14985 62 +88208 14985 77 +13207 14984 1 +28207 14984 16 +43207 14984 31 +58207 14984 46 +73207 14984 61 +88207 14984 76 +13206 14983 0 +28206 14983 15 +43206 14983 30 +58206 14983 45 + + +# remember to enable your hash join optimizer to pass this +# you could disable this ensure if you haven't implemented it yet +query rowsort +ensure:hash_join +select * from + (select * from __mock_external_merge_sort_input order by v1 + v2 limit 2000) t1 + inner join __mock_table_1 + on t1.v2 = __mock_table_1.colB; +---- +23 1800 26 18 1800 +123 1900 15 19 1900 +223 2000 4 20 2000 +323 2100 104 21 2100 +423 2200 93 22 2200 +523 2300 82 23 2300 +623 2400 71 24 2400 +723 2500 60 25 2500 +823 2600 49 26 2600 +923 2700 38 27 2700 +1023 2800 27 28 2800 +1123 2900 16 29 2900 +1223 3000 5 30 3000 +1323 3100 105 31 3100 +1423 3200 94 32 3200 +1523 3300 83 33 3300 +1623 3400 72 34 3400 +1723 3500 61 35 3500 +1823 3600 50 36 3600 +1923 3700 39 37 3700 diff --git a/tools/sqllogictest/sqllogictest.cpp b/tools/sqllogictest/sqllogictest.cpp index 425b7dad0..897b1e937 100644 --- a/tools/sqllogictest/sqllogictest.cpp +++ b/tools/sqllogictest/sqllogictest.cpp @@ -10,6 +10,7 @@ #include "argparse/argparse.hpp" #include "common/bustub_instance.h" +#include "common/config.h" #include "common/exception.h" #include "common/util/string_util.h" #include "execution/check_options.h" @@ -137,30 +138,30 @@ auto ProcessExtraOptions(const std::string &sql, bustub::BusTubInstance &instanc auto expected_cols_proj = std::stoi(args[2]); auto expected_cols_agg = std::stoi(args[3]); // find agg & proj plan and test if the output schema has the expected number of columns - auto lines = bustub::StringUtil::Split(result.str(), "\n"); - for (auto &line : lines) { - bustub::StringUtil::LTrim(&line); - if (bustub::StringUtil::StartsWith(line, "Agg")) { - auto cols = bustub::StringUtil::Split(line, "],"); - if (cols.size() != 3) { - fmt::print("Agg plan wrong formatting!\n"); - return false; - } - for (int i = 0; i < 2; i++) { - if (bustub::StringUtil::Count(cols[i], "\",")+1 > static_cast(expected_cols_agg)) { - fmt::print("Agg wrong column pruning count!\n"); - return false; - } - } - break; + auto lines = bustub::StringUtil::Split(result.str(), "\n"); + for (auto &line : lines) { + bustub::StringUtil::LTrim(&line); + if (bustub::StringUtil::StartsWith(line, "Agg")) { + auto cols = bustub::StringUtil::Split(line, "],"); + if (cols.size() != 3) { + fmt::print("Agg plan wrong formatting!\n"); + return false; } - if (bustub::StringUtil::StartsWith(line, "Projection")) { - if (bustub::StringUtil::Count(line, "\",")+1 > static_cast(expected_cols_proj)) { - fmt::print("Projection wrong column pruning count!\n"); + for (int i = 0; i < 2; i++) { + if (bustub::StringUtil::Count(cols[i], "\",") + 1 > static_cast(expected_cols_agg)) { + fmt::print("Agg wrong column pruning count!\n"); return false; } } + break; + } + if (bustub::StringUtil::StartsWith(line, "Projection")) { + if (bustub::StringUtil::Count(line, "\",") + 1 > static_cast(expected_cols_proj)) { + fmt::print("Projection wrong column pruning count!\n"); + return false; + } } + } } else { throw bustub::NotImplementedException(fmt::format("unsupported extra option: {}", opt)); } @@ -224,6 +225,10 @@ auto main(int argc, char **argv) -> int { // NOLINT program.add_argument("--verbose").help("increase output verbosity").default_value(false).implicit_value(true); program.add_argument("-d", "--diff").help("write diff file").default_value(false).implicit_value(true); program.add_argument("--in-memory").help("use in-memory backend").default_value(false).implicit_value(true); + program.add_argument("--bpm-size") + .help("size of the buffer pool") + .default_value(std::to_string(bustub::BUFFER_POOL_SIZE)); + program.add_argument("--check-min-disk-write").help("the minimum disk write threshold to be checked at the end"); try { program.parse_args(argc, argv); @@ -235,6 +240,8 @@ auto main(int argc, char **argv) -> int { // NOLINT bool verbose = program.get("verbose"); bool diff = program.get("diff"); + auto check_min_disk_write = program.present("check-min-disk-write"); + std::string filename = program.get("file"); std::ifstream t(filename); @@ -253,11 +260,12 @@ auto main(int argc, char **argv) -> int { // NOLINT } std::unique_ptr bustub; + size_t bpm_size = std::stoul(program.get("bpm-size")); if (program.get("--in-memory")) { - bustub = std::make_unique(); + bustub = std::make_unique(bpm_size); } else { - bustub = std::make_unique("test.bustub"); + bustub = std::make_unique("test.bustub", bpm_size); } bustub->GenerateMockTable(); @@ -365,5 +373,14 @@ auto main(int argc, char **argv) -> int { // NOLINT } } + if (program.is_used("--check-min-disk-write")) { + int min_disk_write_num = std::stoi(program.get("--check-min-disk-write")); + int actual_disk_write_num = bustub->disk_manager_->GetNumWrites(); + if (actual_disk_write_num < min_disk_write_num) { + fmt::print("test incurred {} times of disk write, which does not meet the requirement\n", actual_disk_write_num); + return 1; + } + } + return 0; } From b7978563e50fcee4c4c1e1d833483f43951816ac Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Thu, 17 Oct 2024 17:31:26 -0700 Subject: [PATCH 02/21] new line at eof --- test/sql/p3.00-primer.slt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sql/p3.00-primer.slt b/test/sql/p3.00-primer.slt index 063ae6fbc..5cae87931 100644 --- a/test/sql/p3.00-primer.slt +++ b/test/sql/p3.00-primer.slt @@ -8,4 +8,4 @@ lanlou1554 Monday prashanthduvvada Friday unw9527 Thursday xx01cyx Tuesday -yashkothari42 Friday \ No newline at end of file +yashkothari42 Friday From d15e377c510f3a122c2f68d4827cfdd67f8b87fb Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 20 Oct 2024 12:56:56 -0700 Subject: [PATCH 03/21] refactor OrderBy --- src/include/binder/bound_order_by.h | 3 +++ src/include/execution/plans/sort_plan.h | 7 +++---- src/include/execution/plans/topn_per_group_plan.h | 6 +++--- src/include/execution/plans/topn_plan.h | 7 +++---- src/include/execution/plans/window_plan.h | 5 ++--- src/planner/plan_select.cpp | 2 +- src/planner/plan_window_function.cpp | 9 ++++----- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/include/binder/bound_order_by.h b/src/include/binder/bound_order_by.h index ef2614e2c..3cde5c7e5 100644 --- a/src/include/binder/bound_order_by.h +++ b/src/include/binder/bound_order_by.h @@ -14,6 +14,7 @@ #include "binder/bound_expression.h" #include "common/exception.h" +#include "execution/expressions/abstract_expression.h" #include "fmt/format.h" namespace bustub { @@ -28,6 +29,8 @@ enum class OrderByType : uint8_t { DESC = 3, /**< Descending order by type. */ }; +using OrderBy = std::pair; + /** * BoundOrderBy is an item in the ORDER BY clause. */ diff --git a/src/include/execution/plans/sort_plan.h b/src/include/execution/plans/sort_plan.h index fc33053c8..902d00294 100644 --- a/src/include/execution/plans/sort_plan.h +++ b/src/include/execution/plans/sort_plan.h @@ -36,8 +36,7 @@ class SortPlanNode : public AbstractPlanNode { * @param child The child plan node * @param order_bys The sort expressions and their order by types. */ - SortPlanNode(SchemaRef output, AbstractPlanNodeRef child, - std::vector> order_bys) + SortPlanNode(SchemaRef output, AbstractPlanNodeRef child, std::vector order_bys) : AbstractPlanNode(std::move(output), {std::move(child)}), order_bys_(std::move(order_bys)) {} /** @return The type of the plan node */ @@ -50,11 +49,11 @@ class SortPlanNode : public AbstractPlanNode { } /** @return Get sort by expressions */ - auto GetOrderBy() const -> const std::vector> & { return order_bys_; } + auto GetOrderBy() const -> const std::vector & { return order_bys_; } BUSTUB_PLAN_NODE_CLONE_WITH_CHILDREN(SortPlanNode); - std::vector> order_bys_; + std::vector order_bys_; protected: auto PlanNodeToString() const -> std::string override; diff --git a/src/include/execution/plans/topn_per_group_plan.h b/src/include/execution/plans/topn_per_group_plan.h index 29c4c6144..57f543320 100644 --- a/src/include/execution/plans/topn_per_group_plan.h +++ b/src/include/execution/plans/topn_per_group_plan.h @@ -38,7 +38,7 @@ class TopNPerGroupPlanNode : public AbstractPlanNode { * @param n Retain n elements. */ TopNPerGroupPlanNode(SchemaRef output, AbstractPlanNodeRef child, std::vector group_bys, - std::vector> order_bys, std::size_t n) + std::vector order_bys, std::size_t n) : AbstractPlanNode(std::move(output), {std::move(child)}), order_bys_(std::move(order_bys)), group_bys_(std::move(group_bys)), @@ -51,7 +51,7 @@ class TopNPerGroupPlanNode : public AbstractPlanNode { auto GetN() const -> size_t { return n_; } /** @return Get order by expressions */ - auto GetOrderBy() const -> const std::vector> & { return order_bys_; } + auto GetOrderBy() const -> const std::vector & { return order_bys_; } /** @return Get group by expressions */ auto GetGroupBy() const -> const std::vector & { return group_bys_; } @@ -64,7 +64,7 @@ class TopNPerGroupPlanNode : public AbstractPlanNode { BUSTUB_PLAN_NODE_CLONE_WITH_CHILDREN(TopNPerGroupPlanNode); - std::vector> order_bys_; + std::vector order_bys_; std::vector group_bys_; std::size_t n_; diff --git a/src/include/execution/plans/topn_plan.h b/src/include/execution/plans/topn_plan.h index 6adc04248..04a3079a8 100644 --- a/src/include/execution/plans/topn_plan.h +++ b/src/include/execution/plans/topn_plan.h @@ -37,8 +37,7 @@ class TopNPlanNode : public AbstractPlanNode { * @param order_bys The sort expressions and their order by types. * @param n Retain n elements. */ - TopNPlanNode(SchemaRef output, AbstractPlanNodeRef child, - std::vector> order_bys, std::size_t n) + TopNPlanNode(SchemaRef output, AbstractPlanNodeRef child, std::vector order_bys, std::size_t n) : AbstractPlanNode(std::move(output), {std::move(child)}), order_bys_(std::move(order_bys)), n_{n} {} /** @return The type of the plan node */ @@ -48,7 +47,7 @@ class TopNPlanNode : public AbstractPlanNode { auto GetN() const -> size_t { return n_; } /** @return Get order by expressions */ - auto GetOrderBy() const -> const std::vector> & { return order_bys_; } + auto GetOrderBy() const -> const std::vector & { return order_bys_; } /** @return The child plan node */ auto GetChildPlan() const -> AbstractPlanNodeRef { @@ -58,7 +57,7 @@ class TopNPlanNode : public AbstractPlanNode { BUSTUB_PLAN_NODE_CLONE_WITH_CHILDREN(TopNPlanNode); - std::vector> order_bys_; + std::vector order_bys_; std::size_t n_; protected: diff --git a/src/include/execution/plans/window_plan.h b/src/include/execution/plans/window_plan.h index b67cf2380..9790db3cf 100644 --- a/src/include/execution/plans/window_plan.h +++ b/src/include/execution/plans/window_plan.h @@ -61,8 +61,7 @@ class WindowFunctionPlanNode : public AbstractPlanNode { WindowFunctionPlanNode(SchemaRef output_schema, AbstractPlanNodeRef child, std::vector window_func_indexes, std::vector columns, std::vector> partition_bys, - std::vector>> order_bys, - std::vector functions, + std::vector> order_bys, std::vector functions, std::vector window_func_types) : AbstractPlanNode(std::move(output_schema), {std::move(child)}), columns_(std::move(columns)) { for (uint32_t i = 0; i < window_func_indexes.size(); i++) { @@ -88,7 +87,7 @@ class WindowFunctionPlanNode : public AbstractPlanNode { AbstractExpressionRef function_; WindowFunctionType type_; std::vector partition_by_; - std::vector> order_by_; + std::vector order_by_; }; /** all columns expressions */ diff --git a/src/planner/plan_select.cpp b/src/planner/plan_select.cpp index c8829ae94..67c32eec6 100644 --- a/src/planner/plan_select.cpp +++ b/src/planner/plan_select.cpp @@ -117,7 +117,7 @@ auto Planner::PlanSelect(const SelectStatement &statement) -> AbstractPlanNodeRe // Plan ORDER BY if (!statement.sort_.empty()) { - std::vector> order_bys; + std::vector order_bys; for (const auto &order_by : statement.sort_) { auto [_, expr] = PlanExpression(*order_by->expr_, {plan}); auto abstract_expr = std::move(expr); diff --git a/src/planner/plan_window_function.cpp b/src/planner/plan_window_function.cpp index 2b8e866a0..856082077 100644 --- a/src/planner/plan_window_function.cpp +++ b/src/planner/plan_window_function.cpp @@ -28,14 +28,13 @@ namespace bustub { // TODO(chi): clang-tidy on macOS will suggest changing it to const reference. Looks like a bug. -void CheckOrderByCompatible( - const std::vector>> &order_by_exprs) { +void CheckOrderByCompatible(const std::vector> &order_by_exprs) { if (order_by_exprs.empty()) { // either or window functions not having order by clause return; } // or all order by clause are the same - std::vector> first_order_by = order_by_exprs[0]; + std::vector first_order_by = order_by_exprs[0]; for (auto &order_by : order_by_exprs) { if (order_by.size() != first_order_by.size()) { throw Exception("order by clause of window functions are not compatible"); @@ -63,7 +62,7 @@ auto Planner::PlanSelectWindow(const SelectStatement &statement, AbstractPlanNod std::vector window_func_indexes; std::vector window_func_types; std::vector> partition_by_exprs; - std::vector>> order_by_exprs; + std::vector> order_by_exprs; std::vector arg_exprs; for (uint32_t i = 0; i < statement.select_list_.size(); i++) { @@ -111,7 +110,7 @@ auto Planner::PlanSelectWindow(const SelectStatement &statement, AbstractPlanNod throw Exception("order by clause is mandatory for rank function"); } - std::vector> order_by; + std::vector order_by; for (const auto &item : window_call.order_bys_) { auto [_, expr] = PlanExpression(*item->expr_, {child}); auto abstract_expr = std::move(expr); From 89b1d5ab27887a8c394d336d2892fbb0eb4c70b7 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 20 Oct 2024 14:19:26 -0700 Subject: [PATCH 04/21] introduce external merge sort executor --- .../external_merge_sort_executor.cpp | 39 +++++ src/execution/hash_join_executor.cpp | 2 +- .../executors/external_merge_sort_executor.h | 155 ++++++++++++++++++ 3 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 src/execution/external_merge_sort_executor.cpp create mode 100644 src/include/execution/executors/external_merge_sort_executor.h diff --git a/src/execution/external_merge_sort_executor.cpp b/src/execution/external_merge_sort_executor.cpp new file mode 100644 index 000000000..c0eb46a0c --- /dev/null +++ b/src/execution/external_merge_sort_executor.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// BusTub +// +// external_merge_sort_executor.cpp +// +// Identification: src/execution/external_merge_sort_executor.cpp +// +// Copyright (c) 2015-2024, Carnegie Mellon University Database Group +// +//===----------------------------------------------------------------------===// + +#include "execution/executors/external_merge_sort_executor.h" +#include +#include +#include +#include "common/config.h" +#include "execution/plans/sort_plan.h" + +namespace bustub { + +template +ExternalMergeSortExecutor::ExternalMergeSortExecutor(ExecutorContext *exec_ctx, const SortPlanNode *plan, + std::unique_ptr &&child_executor) + : AbstractExecutor(exec_ctx) {} + +template +void ExternalMergeSortExecutor::Init() { + throw NotImplementedException("ExternalMergeSortExecutor is not implemented"); +} + +template +auto ExternalMergeSortExecutor::Next(Tuple *tuple, RID *rid) -> bool { + return false; +} + +template class ExternalMergeSortExecutor<2>; + +} // namespace bustub diff --git a/src/execution/hash_join_executor.cpp b/src/execution/hash_join_executor.cpp index 032bcefe7..469098cde 100644 --- a/src/execution/hash_join_executor.cpp +++ b/src/execution/hash_join_executor.cpp @@ -19,7 +19,7 @@ HashJoinExecutor::HashJoinExecutor(ExecutorContext *exec_ctx, const HashJoinPlan std::unique_ptr &&right_child) : AbstractExecutor(exec_ctx) { if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) { - // Note for 2023 Fall: You ONLY need to implement left join and inner join. + // Note for Fall 2024: You ONLY need to implement left join and inner join. throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType())); } } diff --git a/src/include/execution/executors/external_merge_sort_executor.h b/src/include/execution/executors/external_merge_sort_executor.h new file mode 100644 index 000000000..a999cb57f --- /dev/null +++ b/src/include/execution/executors/external_merge_sort_executor.h @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// BusTub +// +// external_merge_sort_executor.h +// +// Identification: src/include/execution/executors/external_merge_sort_executor.h +// +// Copyright (c) 2015-2024, Carnegie Mellon University Database Group +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include +#include +#include +#include +#include "common/config.h" +#include "common/macros.h" +#include "execution/execution_common.h" +#include "execution/executors/abstract_executor.h" +#include "execution/plans/sort_plan.h" +#include "storage/table/tuple.h" + +namespace bustub { + +/** + * Page to hold the intermediate data for external merge sort. + * Only fixed-length data will be supported in Fall 2024. + */ +class SortPage { + public: + /** TODO: Define your methods for reading data from and writing data to the sort page here. */ + private: + /** + * TODO: Define the private members here. You may want to have some necessary metadata for + * the sort page before the start of the actual data. + */ +}; + +/** + * A data structure that holds the sorted tuples as a run during external merge sort. + * Tuples might be stored in multiple pages, and data are ordered both within one page + * and across pages. + */ +class MergeSortRun { + public: + MergeSortRun() = default; + MergeSortRun(std::vector pages, BufferPoolManager *bpm) : pages_(std::move(pages)), bpm_(bpm) {} + + auto GetPageCount() -> size_t { return pages_.size(); } + + /** Iterator for iterating on the sorted tuples in one run. */ + class Iterator { + friend class MergeSortRun; + + public: + Iterator() = default; + + /** + * Advance the iterator to the next tuple. If the current sort page is exhausted, move to the + * next sort page. + * + * TODO: Implement this method. + */ + auto operator++() -> Iterator & { return *this; } + + /** + * Dereference the iterator to get the current tuple in the sorted run that the iterator is + * pointing to. + * + * TODO: Implement this method. + */ + auto operator*() -> Tuple { return {}; } + + /** + * Checks whether two iterators are pointing to the same tuple in the same sorted run. + * + * TODO: Implement this method. + */ + auto operator==(const Iterator &other) const -> bool { return false; } + + /** + * Checks whether two iterators are pointing to different tuples in a sorted run or iterating + * on different sorted runs. + * + * TODO: Implement this method. + */ + auto operator!=(const Iterator &other) const -> bool { return false; } + + private: + /** TODO: You may want to add additional initilizers to initialize your data members. */ + explicit Iterator(const MergeSortRun *run) : run_(run) {} + + /** The sorted run that the iterator is iterating on. */ + [[maybe_unused]] const MergeSortRun *run_; + + /** + * TODO: Add your own private members here. You may want something to record your current + * position in the sorted run. + */ + }; + + /** + * Get an iterator pointing to the beginning of the sorted run, i.e. the first tuple. + */ + auto Begin() -> Iterator { return {}; } + + /** + * Get an iterator pointing to the end of the sorted run, i.e. the position after the last tuple. + */ + auto End() -> Iterator { return {}; } + + private: + /** The page IDs of the sort pages that store the sorted tuples. */ + std::vector pages_; + /** + * The buffer pool manager used to read sort pages. The buffer pool manager is responsible for + * deleting the sort pages when they are no longer needed. + */ + [[maybe_unused]] BufferPoolManager *bpm_; +}; + +/** + * ExternalMergeSortExecutor executes an external merge sort. + */ +template +class ExternalMergeSortExecutor : public AbstractExecutor { + public: + ExternalMergeSortExecutor(ExecutorContext *exec_ctx, const SortPlanNode *plan, + std::unique_ptr &&child_executor); + + /** Initialize the external merge sort */ + void Init() override; + + /** + * Yield the next tuple from the external merge sort. + * @param[out] tuple The next tuple produced by the external merge sort. + * @param[out] rid The next tuple RID produced by the external merge sort. + * @return `true` if a tuple was produced, `false` if there are no more tuples + */ + auto Next(Tuple *tuple, RID *rid) -> bool override; + + /** @return The output schema for the external merge sort */ + auto GetOutputSchema() const -> const Schema & override { return plan_->OutputSchema(); } + + private: + /** The sort plan node to be executed */ + const SortPlanNode *plan_; + + /** TODO: You may want to add your own data members here. */ +}; + +} // namespace bustub From 3a9a8981319886cc6703178a3813e3c0011915cb Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 20 Oct 2024 14:44:53 -0700 Subject: [PATCH 05/21] introduce tuple comparator --- src/execution/execution_common.cpp | 13 ++++++++ .../external_merge_sort_executor.cpp | 2 +- src/include/execution/execution_common.h | 32 ++++++++++++++++++- .../executors/external_merge_sort_executor.h | 22 +++++++++---- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/execution/execution_common.cpp b/src/execution/execution_common.cpp index 0df9d1a75..617027b3b 100644 --- a/src/execution/execution_common.cpp +++ b/src/execution/execution_common.cpp @@ -10,6 +10,19 @@ namespace bustub { +TupleComparator::TupleComparator(std::vector order_bys) : order_bys_(std::move(order_bys)) {} + +auto TupleComparator::operator()(const SortEntry &entry_a, const SortEntry &entry_b) const -> bool { return false; } + +auto GenerateSortKey(const Tuple &tuple, const std::vector &order_bys, const Schema &schema) -> SortKey { + return {}; +} + +/** + * Above are all you need for P3. + * You can ignore the remaining part of this file until P4. + */ + auto ReconstructTuple(const Schema *schema, const Tuple &base_tuple, const TupleMeta &base_meta, const std::vector &undo_logs) -> std::optional { UNIMPLEMENTED("not implemented"); diff --git a/src/execution/external_merge_sort_executor.cpp b/src/execution/external_merge_sort_executor.cpp index c0eb46a0c..a3c8b6533 100644 --- a/src/execution/external_merge_sort_executor.cpp +++ b/src/execution/external_merge_sort_executor.cpp @@ -22,7 +22,7 @@ namespace bustub { template ExternalMergeSortExecutor::ExternalMergeSortExecutor(ExecutorContext *exec_ctx, const SortPlanNode *plan, std::unique_ptr &&child_executor) - : AbstractExecutor(exec_ctx) {} + : AbstractExecutor(exec_ctx), cmp_(plan->GetOrderBy()) {} template void ExternalMergeSortExecutor::Init() { diff --git a/src/include/execution/execution_common.h b/src/include/execution/execution_common.h index 584f8afdb..ed5b53875 100644 --- a/src/include/execution/execution_common.h +++ b/src/include/execution/execution_common.h @@ -3,6 +3,7 @@ #include #include +#include "binder/bound_order_by.h" #include "catalog/catalog.h" #include "catalog/schema.h" #include "concurrency/transaction.h" @@ -10,13 +11,42 @@ namespace bustub { +/** The SortKey defines a list of values that sort is based on */ +using SortKey = std::vector; +/** The SortEntry defines a key-value pairs for sorting tuples and corresponding RIDs */ +using SortEntry = std::pair; + +/** The Tuple Comparator provides a comparison function for SortEntry */ +class TupleComparator { + public: + explicit TupleComparator(std::vector order_bys); + + /** TODO(P3): Implement the comparison method */ + auto operator()(const SortEntry &entry_a, const SortEntry &entry_b) const -> bool; + + private: + std::vector order_bys_; +}; + +/** + * Generate sort key for a tuple based on the order by expressions. + * + * TODO(P3): Implement this method. + */ +auto GenerateSortKey(const Tuple &tuple, const std::vector &order_bys, const Schema &schema) -> SortKey; + +/** + * Above are all you need for P3. + * You can ignore the remaining part of this file until P4. + */ + auto ReconstructTuple(const Schema *schema, const Tuple &base_tuple, const TupleMeta &base_meta, const std::vector &undo_logs) -> std::optional; void TxnMgrDbg(const std::string &info, TransactionManager *txn_mgr, const TableInfo *table_info, TableHeap *table_heap); -// Add new functions as needed... You are likely need to define some more functions. +// TODO(P4): Add new functions as needed... You are likely need to define some more functions. // // To give you a sense of what can be shared across executors / transaction manager, here are the // list of helper function names that we defined in the reference solution. You should come up with diff --git a/src/include/execution/executors/external_merge_sort_executor.h b/src/include/execution/executors/external_merge_sort_executor.h index a999cb57f..4efeb51ba 100644 --- a/src/include/execution/executors/external_merge_sort_executor.h +++ b/src/include/execution/executors/external_merge_sort_executor.h @@ -31,17 +31,20 @@ namespace bustub { */ class SortPage { public: - /** TODO: Define your methods for reading data from and writing data to the sort page here. */ + /** + * TODO: Define and implement the methods for reading data from and writing data to the sort + * page. Feel free to add other helper methods. + */ private: /** - * TODO: Define the private members here. You may want to have some necessary metadata for + * TODO: Define the private members. You may want to have some necessary metadata for * the sort page before the start of the actual data. */ }; /** * A data structure that holds the sorted tuples as a run during external merge sort. - * Tuples might be stored in multiple pages, and data are ordered both within one page + * Tuples might be stored in multiple pages, and tuples are ordered both within one page * and across pages. */ class MergeSortRun { @@ -90,7 +93,6 @@ class MergeSortRun { auto operator!=(const Iterator &other) const -> bool { return false; } private: - /** TODO: You may want to add additional initilizers to initialize your data members. */ explicit Iterator(const MergeSortRun *run) : run_(run) {} /** The sorted run that the iterator is iterating on. */ @@ -98,17 +100,22 @@ class MergeSortRun { /** * TODO: Add your own private members here. You may want something to record your current - * position in the sorted run. + * position in the sorted run. Also feel free to add additional initializers to initialize + * your private members. */ }; /** * Get an iterator pointing to the beginning of the sorted run, i.e. the first tuple. + * + * TODO: Implement this method. */ auto Begin() -> Iterator { return {}; } /** * Get an iterator pointing to the end of the sorted run, i.e. the position after the last tuple. + * + * TODO: Implement this method. */ auto End() -> Iterator { return {}; } @@ -149,7 +156,10 @@ class ExternalMergeSortExecutor : public AbstractExecutor { /** The sort plan node to be executed */ const SortPlanNode *plan_; - /** TODO: You may want to add your own data members here. */ + /** Compares tuples based on the order-bys */ + TupleComparator cmp_; + + /** TODO: You will want to add your own private members here. */ }; } // namespace bustub From 3f258ad63920108706348a37d43880942a4c7274 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 20 Oct 2024 14:52:08 -0700 Subject: [PATCH 06/21] add comments for 2-way merge sort requirement --- src/include/execution/executors/external_merge_sort_executor.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/include/execution/executors/external_merge_sort_executor.h b/src/include/execution/executors/external_merge_sort_executor.h index 4efeb51ba..17c961f94 100644 --- a/src/include/execution/executors/external_merge_sort_executor.h +++ b/src/include/execution/executors/external_merge_sort_executor.h @@ -27,6 +27,7 @@ namespace bustub { /** * Page to hold the intermediate data for external merge sort. + * * Only fixed-length data will be supported in Fall 2024. */ class SortPage { @@ -131,6 +132,8 @@ class MergeSortRun { /** * ExternalMergeSortExecutor executes an external merge sort. + * + * In Fall 2024, only 2-way external merge sort is required. */ template class ExternalMergeSortExecutor : public AbstractExecutor { From 96d4f4ffcb9714947b1794fdd4ca1c88871c3dc4 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 20 Oct 2024 19:05:29 -0500 Subject: [PATCH 07/21] make sort plan node format as external merge sort --- src/execution/fmt_impl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/execution/fmt_impl.cpp b/src/execution/fmt_impl.cpp index ea3eb0b14..3279118b7 100644 --- a/src/execution/fmt_impl.cpp +++ b/src/execution/fmt_impl.cpp @@ -72,7 +72,9 @@ auto UpdatePlanNode::PlanNodeToString() const -> std::string { } auto SortPlanNode::PlanNodeToString() const -> std::string { - return fmt::format("Sort {{ order_bys={} }}", order_bys_); + // Note(f24): A sort plan node will be converted to an external merge sort executor in + // Fall 2024. So `ExternalMergeSort` is returned instead of `Sort`. + return fmt::format("ExternalMergeSort {{ order_bys={} }}", order_bys_); } auto LimitPlanNode::PlanNodeToString() const -> std::string { return fmt::format("Limit {{ limit={} }}", limit_); } From 9a59379f4a61c5b3828a2280b2c480475dc83239 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 20 Oct 2024 19:14:18 -0500 Subject: [PATCH 08/21] fix lint --- src/include/execution/execution_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/execution/execution_common.h b/src/include/execution/execution_common.h index ed5b53875..d0d0a6c57 100644 --- a/src/include/execution/execution_common.h +++ b/src/include/execution/execution_common.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "binder/bound_order_by.h" From 6825d483fd13348671934d2d8b78ee7a20044a46 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Mon, 21 Oct 2024 15:34:33 -0400 Subject: [PATCH 09/21] sync private for test sort --- src/execution/executor_factory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/execution/executor_factory.cpp b/src/execution/executor_factory.cpp index d83bb085e..18635fdd2 100644 --- a/src/execution/executor_factory.cpp +++ b/src/execution/executor_factory.cpp @@ -167,7 +167,7 @@ auto ExecutorFactory::CreateExecutor(ExecutorContext *exec_ctx, const AbstractPl case PlanType::Sort: { const auto *sort_plan = dynamic_cast(plan.get()); auto child = ExecutorFactory::CreateExecutor(exec_ctx, sort_plan->GetChildPlan()); - return std::make_unique>(exec_ctx, sort_plan, std::move(child)); + return std::make_unique(exec_ctx, sort_plan, std::move(child)); } // Create a new topN executor From 0e16177e3d73ac57e37753124cb48b3d9716070e Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Mon, 21 Oct 2024 21:31:58 -0400 Subject: [PATCH 10/21] sync private --- src/execution/executor_factory.cpp | 2 +- src/execution/mock_scan_executor.cpp | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/execution/executor_factory.cpp b/src/execution/executor_factory.cpp index 18635fdd2..d83bb085e 100644 --- a/src/execution/executor_factory.cpp +++ b/src/execution/executor_factory.cpp @@ -167,7 +167,7 @@ auto ExecutorFactory::CreateExecutor(ExecutorContext *exec_ctx, const AbstractPl case PlanType::Sort: { const auto *sort_plan = dynamic_cast(plan.get()); auto child = ExecutorFactory::CreateExecutor(exec_ctx, sort_plan->GetChildPlan()); - return std::make_unique(exec_ctx, sort_plan, std::move(child)); + return std::make_unique>(exec_ctx, sort_plan, std::move(child)); } // Create a new topN executor diff --git a/src/execution/mock_scan_executor.cpp b/src/execution/mock_scan_executor.cpp index e2d4b9eb3..5cc0946e4 100644 --- a/src/execution/mock_scan_executor.cpp +++ b/src/execution/mock_scan_executor.cpp @@ -407,16 +407,6 @@ auto GetFunctionOf(const MockScanPlanNode *plan) -> std::function return Tuple{values, &plan->OutputSchema()}; }; } - // select * from __mock_external_merge_sort_input order by v2 desc, v3 asc limit 100; - if (table == "__mock_external_merge_sort_input") { - return [plan](size_t cursor) { - std::vector values{}; - values.push_back(ValueFactory::GetIntegerValue(cursor)); - values.push_back(ValueFactory::GetIntegerValue((cursor + 1777) % 15000)); - values.push_back(ValueFactory::GetIntegerValue((cursor + 3) % 111)); - return Tuple{values, &plan->OutputSchema()}; - }; - } if (table == "__mock_external_merge_sort_input") { return [plan](size_t cursor) { From 4d31d3b674bf32714159b674e65b97f7eaf685fe Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Mon, 21 Oct 2024 22:08:10 -0400 Subject: [PATCH 11/21] update submission files --- CMakeLists.txt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87e7bc3c7..97f4b902b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -324,37 +324,33 @@ set(P3_FILES "src/include/execution/executors/index_scan_executor.h" "src/include/execution/executors/insert_executor.h" "src/include/execution/executors/limit_executor.h" + "src/include/execution/executors/nested_index_join_executor.h" "src/include/execution/executors/nested_loop_join_executor.h" "src/include/execution/executors/seq_scan_executor.h" - "src/include/execution/executors/sort_executor.h" - "src/include/execution/executors/topn_executor.h" - "src/include/execution/executors/topn_per_group_executor.h" + "src/include/execution/executors/external_merge_sort_executor.h" "src/include/execution/executors/update_executor.h" - "src/include/execution/executors/window_function_executor.h" "src/execution/aggregation_executor.cpp" - "src/execution/window_function_executor.cpp" "src/execution/delete_executor.cpp" "src/execution/filter_executor.cpp" "src/execution/hash_join_executor.cpp" "src/execution/index_scan_executor.cpp" "src/execution/insert_executor.cpp" "src/execution/limit_executor.cpp" + "src/execution/nested_index_join_executor.cpp" "src/execution/nested_loop_join_executor.cpp" "src/execution/seq_scan_executor.cpp" - "src/execution/sort_executor.cpp" - "src/execution/topn_executor.cpp" - "src/execution/topn_per_group_executor.cpp" + "src/execution/external_merge_sort_executor.cpp" "src/execution/update_executor.cpp" + "src/include/execution/execution_common.h" "src/include/optimizer/optimizer.h" "src/include/optimizer/optimizer_internal.h" + "src/execution/execution_common.cpp" "src/optimizer/nlj_as_hash_join.cpp" "src/optimizer/optimizer_custom_rules.cpp" - "src/optimizer/sort_limit_as_topn.cpp" "src/optimizer/optimizer_internal.cpp" "src/optimizer/seqscan_as_indexscan.cpp" "src/optimizer/column_pruning.cpp" "src/common/bustub_ddl.cpp" - "src/include/execution/plans/topn_per_group_plan.h" ${P2_FILES} ) From ddd9bff2d1518d3e7c23a97a62d5946fb48e00c2 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Mon, 21 Oct 2024 22:17:24 -0400 Subject: [PATCH 12/21] update p4 submission files --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97f4b902b..471135127 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -371,8 +371,6 @@ set(P4_FILES "src/concurrency/transaction_manager.cpp" "src/include/concurrency/watermark.h" "src/concurrency/watermark.cpp" - "src/include/execution/execution_common.h" - "src/execution/execution_common.cpp" ${P3_FILES} ) From c84947c51ce9de913b053e7a0973fc26dc8d0816 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Mon, 21 Oct 2024 23:24:11 -0400 Subject: [PATCH 13/21] initializer -> constructor --- src/include/execution/executors/external_merge_sort_executor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/execution/executors/external_merge_sort_executor.h b/src/include/execution/executors/external_merge_sort_executor.h index 17c961f94..71b94f9fc 100644 --- a/src/include/execution/executors/external_merge_sort_executor.h +++ b/src/include/execution/executors/external_merge_sort_executor.h @@ -101,7 +101,7 @@ class MergeSortRun { /** * TODO: Add your own private members here. You may want something to record your current - * position in the sorted run. Also feel free to add additional initializers to initialize + * position in the sorted run. Also feel free to add additional constructors to initialize * your private members. */ }; From 0b07aabaf1b6e27abbe536398bd74de47ab171e1 Mon Sep 17 00:00:00 2001 From: Yash Kothari Date: Tue, 22 Oct 2024 14:52:41 -0400 Subject: [PATCH 14/21] update tests and shared ptr for IndexInfo and TableInfo --- src/catalog/table_generator.cpp | 2 +- src/common/bustub_ddl.cpp | 4 +- src/common/bustub_instance.cpp | 6 +- src/include/catalog/catalog.h | 81 ++++++++++++--------------- src/include/catalog/table_generator.h | 3 +- src/optimizer/nlj_as_index_join.cpp | 2 +- src/optimizer/optimizer.cpp | 1 + src/optimizer/order_by_index_scan.cpp | 4 +- test/CMakeLists.txt | 2 +- test/sql/p3.13-nested-index-join.slt | 3 - test/sql/p3.19-integration-2.slt | 8 ++- 11 files changed, 54 insertions(+), 62 deletions(-) diff --git a/src/catalog/table_generator.cpp b/src/catalog/table_generator.cpp index 7e6223874..ade9029d6 100644 --- a/src/catalog/table_generator.cpp +++ b/src/catalog/table_generator.cpp @@ -62,7 +62,7 @@ auto TableGenerator::MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> s } } -void TableGenerator::FillTable(TableInfo *info, TableInsertMeta *table_meta) { +void TableGenerator::FillTable(std::shared_ptr info, TableInsertMeta *table_meta) { uint32_t num_inserted = 0; uint32_t batch_size = 128; while (num_inserted < table_meta->num_rows_) { diff --git a/src/common/bustub_ddl.cpp b/src/common/bustub_ddl.cpp index 7cf63c5f0..96e5f3b42 100644 --- a/src/common/bustub_ddl.cpp +++ b/src/common/bustub_ddl.cpp @@ -45,7 +45,7 @@ namespace bustub { void BusTubInstance::HandleCreateStatement(Transaction *txn, const CreateStatement &stmt, ResultWriter &writer) { std::unique_lock l(catalog_lock_); auto info = catalog_->CreateTable(txn, stmt.table_, Schema(stmt.columns_)); - IndexInfo *index = nullptr; + std::shared_ptr index = nullptr; if (!stmt.primary_key_.empty()) { std::vector col_ids; for (const auto &col : stmt.primary_key_) { @@ -106,7 +106,7 @@ void BusTubInstance::HandleIndexStatement(Transaction *txn, const IndexStatement } std::unique_lock l(catalog_lock_); - IndexInfo *info = nullptr; + std::shared_ptr info = nullptr; if (stmt.index_type_.empty()) { info = catalog_->CreateIndex( diff --git a/src/common/bustub_instance.cpp b/src/common/bustub_instance.cpp index 1ec6e9a97..4bd25123b 100644 --- a/src/common/bustub_instance.cpp +++ b/src/common/bustub_instance.cpp @@ -162,7 +162,7 @@ void BusTubInstance::CmdDbgMvcc(const std::vector ¶ms, ResultWr writer.OneCell("table " + table + " not found"); return; } - TxnMgrDbg("\\dbgmvcc", txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("\\dbgmvcc", txn_manager_.get(), table_info.get(), table_info->table_.get()); } void BusTubInstance::CmdDisplayTables(ResultWriter &writer) { @@ -175,7 +175,7 @@ void BusTubInstance::CmdDisplayTables(ResultWriter &writer) { writer.EndHeader(); for (const auto &name : table_names) { writer.BeginRow(); - const auto *table_info = catalog_->GetTable(name); + const auto table_info = catalog_->GetTable(name); writer.WriteCell(fmt::format("{}", table_info->oid_)); writer.WriteCell(table_info->name_); writer.WriteCell(table_info->schema_.ToString()); @@ -194,7 +194,7 @@ void BusTubInstance::CmdDisplayIndices(ResultWriter &writer) { writer.WriteHeaderCell("index_cols"); writer.EndHeader(); for (const auto &table_name : table_names) { - for (const auto *index_info : catalog_->GetTableIndexes(table_name)) { + for (const auto &index_info : catalog_->GetTableIndexes(table_name)) { writer.BeginRow(); writer.WriteCell(table_name); writer.WriteCell(fmt::format("{}", index_info->index_oid_)); diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index 3591356d0..80ff3e984 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -112,11 +112,12 @@ struct IndexInfo { */ class Catalog { public: - /** Indicates that an operation returning a `TableInfo*` failed */ - static constexpr TableInfo *NULL_TABLE_INFO{nullptr}; + /** Indicates that an operation returning a `std::shared_ptr` failed */ + static inline const std::shared_ptr NULL_TABLE_INFO{nullptr}; - /** Indicates that an operation returning a `IndexInfo*` failed */ - static constexpr IndexInfo *NULL_INDEX_INFO{nullptr}; + /** Indicates that an operation returning a `std::shared_ptr` failed */ + // const std::shared_ptr NULL_INDEX_INFO{nullptr}; + static inline const std::shared_ptr NULL_INDEX_INFO{nullptr}; /** * Construct a new Catalog instance. @@ -133,10 +134,10 @@ class Catalog { * @param table_name The name of the new table, note that all tables beginning with `__` are reserved for the system. * @param schema The schema of the new table * @param create_table_heap whether to create a table heap for the new table - * @return A (non-owning) pointer to the metadata for the table + * @return A shared pointer to the metadata for the table */ auto CreateTable(Transaction *txn, const std::string &table_name, const Schema &schema, bool create_table_heap = true) - -> TableInfo * { + -> std::shared_ptr { if (table_names_.count(table_name) != 0) { return NULL_TABLE_INFO; } @@ -157,15 +158,14 @@ class Catalog { const auto table_oid = next_table_oid_.fetch_add(1); // Construct the table information - auto meta = std::make_unique(schema, table_name, std::move(table), table_oid); - auto *tmp = meta.get(); + auto meta = std::make_shared(schema, table_name, std::move(table), table_oid); // Update the internal tracking mechanisms - tables_.emplace(table_oid, std::move(meta)); + tables_.emplace(table_oid, meta); table_names_.emplace(table_name, table_oid); index_names_.emplace(table_name, std::unordered_map{}); - return tmp; + return meta; } /** @@ -173,7 +173,7 @@ class Catalog { * @param table_name The name of the table * @return A (non-owning) pointer to the metadata for the table */ - auto GetTable(const std::string &table_name) const -> TableInfo * { + auto GetTable(const std::string &table_name) const -> std::shared_ptr { auto table_oid = table_names_.find(table_name); if (table_oid == table_names_.end()) { // Table not found @@ -183,21 +183,21 @@ class Catalog { auto meta = tables_.find(table_oid->second); BUSTUB_ASSERT(meta != tables_.end(), "Broken Invariant"); - return (meta->second).get(); + return meta->second; } /** * Query table metadata by OID * @param table_oid The OID of the table to query - * @return A (non-owning) pointer to the metadata for the table + * @return A shared pointer to the metadata for the table */ - auto GetTable(table_oid_t table_oid) const -> TableInfo * { + auto GetTable(table_oid_t table_oid) const -> std::shared_ptr { auto meta = tables_.find(table_oid); if (meta == tables_.end()) { return NULL_TABLE_INFO; } - return (meta->second).get(); + return meta->second; } /** @@ -210,13 +210,13 @@ class Catalog { * @param key_attrs Key attributes * @param keysize Size of the key * @param hash_function The hash function for the index - * @return A (non-owning) pointer to the metadata of the new table + * @return A shared pointer to the metadata of the new table */ template auto CreateIndex(Transaction *txn, const std::string &index_name, const std::string &table_name, const Schema &schema, const Schema &key_schema, const std::vector &key_attrs, std::size_t keysize, HashFunction hash_function, bool is_primary_key = false, - IndexType index_type = IndexType::HashTableIndex) -> IndexInfo * { + IndexType index_type = IndexType::BPlusTreeIndex) -> std::shared_ptr { // Reject the creation request for nonexistent table if (table_names_.find(table_name) == table_names_.end()) { return NULL_INDEX_INFO; @@ -257,7 +257,7 @@ class Catalog { } // Populate the index with all tuples in table heap - auto *table_meta = GetTable(table_name); + auto table_meta = GetTable(table_name); for (auto iter = table_meta->table_->MakeIterator(); !iter.IsEnd(); ++iter) { auto [meta, tuple] = iter.GetTuple(); // we have to silently ignore the error here for a lot of reasons... @@ -268,15 +268,12 @@ class Catalog { const auto index_oid = next_index_oid_.fetch_add(1); // Construct index information; IndexInfo takes ownership of the Index itself - auto index_info = std::make_unique(key_schema, index_name, std::move(index), index_oid, table_name, + auto index_info = std::make_shared(key_schema, index_name, std::move(index), index_oid, table_name, keysize, is_primary_key, index_type); - auto *tmp = index_info.get(); - // Update internal tracking - indexes_.emplace(index_oid, std::move(index_info)); + indexes_.emplace(index_oid, index_info); table_indexes.emplace(index_name, index_oid); - - return tmp; + return index_info; } /** @@ -285,7 +282,7 @@ class Catalog { * @param table_name The name of the table on which to perform query * @return A (non-owning) pointer to the metadata for the index */ - auto GetIndex(const std::string &index_name, const std::string &table_name) -> IndexInfo * { + auto GetIndex(const std::string &index_name, const std::string &table_name) -> std::shared_ptr { auto table = index_names_.find(table_name); if (table == index_names_.end()) { BUSTUB_ASSERT((table_names_.find(table_name) == table_names_.end()), "Broken Invariant"); @@ -302,7 +299,7 @@ class Catalog { auto index = indexes_.find(index_meta->second); BUSTUB_ASSERT((index != indexes_.end()), "Broken Invariant"); - return index->second.get(); + return index->second; } /** @@ -311,7 +308,7 @@ class Catalog { * @param table_oid The OID of the table on which to perform query * @return A (non-owning) pointer to the metadata for the index */ - auto GetIndex(const std::string &index_name, const table_oid_t table_oid) -> IndexInfo * { + auto GetIndex(const std::string &index_name, const table_oid_t table_oid) -> std::shared_ptr { // Locate the table metadata for the specified table OID auto table_meta = tables_.find(table_oid); if (table_meta == tables_.end()) { @@ -327,36 +324,36 @@ class Catalog { * @param index_oid The OID of the index for which to query * @return A (non-owning) pointer to the metadata for the index */ - auto GetIndex(index_oid_t index_oid) -> IndexInfo * { + auto GetIndex(index_oid_t index_oid) -> std::shared_ptr { auto index = indexes_.find(index_oid); if (index == indexes_.end()) { return NULL_INDEX_INFO; } - return index->second.get(); + return index->second; } /** * Get all of the indexes for the table identified by `table_name`. * @param table_name The name of the table for which indexes should be retrieved - * @return A vector of IndexInfo* for each index on the given table, empty vector + * @return A vector of std::shared_ptr for each index on the given table, empty vector * in the event that the table exists but no indexes have been created for it */ - auto GetTableIndexes(const std::string &table_name) const -> std::vector { + auto GetTableIndexes(const std::string &table_name) const -> std::vector> { // Ensure the table exists if (table_names_.find(table_name) == table_names_.end()) { - return std::vector{}; + return std::vector>{}; } auto table_indexes = index_names_.find(table_name); BUSTUB_ASSERT((table_indexes != index_names_.end()), "Broken Invariant"); - std::vector indexes{}; + std::vector> indexes{}; indexes.reserve(table_indexes->second.size()); for (const auto &index_meta : table_indexes->second) { auto index = indexes_.find(index_meta.second); BUSTUB_ASSERT((index != indexes_.end()), "Broken Invariant"); - indexes.push_back(index->second.get()); + indexes.push_back(index->second); } return indexes; @@ -375,12 +372,8 @@ class Catalog { [[maybe_unused]] LockManager *lock_manager_; [[maybe_unused]] LogManager *log_manager_; - /** - * Map table identifier -> table metadata. - * - * NOTE: `tables_` owns all table metadata. - */ - std::unordered_map> tables_; + /** Map table identifier -> table metadata. */ + std::unordered_map> tables_; /** Map table name -> table identifiers. */ std::unordered_map table_names_; @@ -388,12 +381,8 @@ class Catalog { /** The next table identifier to be used. */ std::atomic next_table_oid_{0}; - /** - * Map index identifier -> index metadata. - * - * NOTE: that `indexes_` owns all index metadata. - */ - std::unordered_map> indexes_; + /** Map index identifier -> index metadata. */ + std::unordered_map> indexes_; /** Map table name -> index names -> index identifiers. */ std::unordered_map> index_names_; diff --git a/src/include/catalog/table_generator.h b/src/include/catalog/table_generator.h index dc65acef4..f4b07b784 100644 --- a/src/include/catalog/table_generator.h +++ b/src/include/catalog/table_generator.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -101,7 +102,7 @@ class TableGenerator { : name_(name), num_rows_(num_rows), col_meta_(std::move(col_meta)) {} }; - void FillTable(TableInfo *info, TableInsertMeta *table_meta); + void FillTable(std::shared_ptr info, TableInsertMeta *table_meta); auto MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> std::vector; diff --git a/src/optimizer/nlj_as_index_join.cpp b/src/optimizer/nlj_as_index_join.cpp index b0413ab47..d209deff9 100644 --- a/src/optimizer/nlj_as_index_join.cpp +++ b/src/optimizer/nlj_as_index_join.cpp @@ -24,7 +24,7 @@ namespace bustub { auto Optimizer::MatchIndex(const std::string &table_name, uint32_t index_key_idx) -> std::optional> { const auto key_attrs = std::vector{index_key_idx}; - for (const auto *index_info : catalog_.GetTableIndexes(table_name)) { + for (const auto &index_info : catalog_.GetTableIndexes(table_name)) { if (key_attrs == index_info->index_->GetKeyAttrs()) { return std::make_optional(std::make_tuple(index_info->index_oid_, index_info->name_)); } diff --git a/src/optimizer/optimizer.cpp b/src/optimizer/optimizer.cpp index 35f8b92d7..cc6011401 100644 --- a/src/optimizer/optimizer.cpp +++ b/src/optimizer/optimizer.cpp @@ -11,6 +11,7 @@ auto Optimizer::Optimize(const AbstractPlanNodeRef &plan) -> AbstractPlanNodeRef auto p = plan; p = OptimizeMergeProjection(p); p = OptimizeMergeFilterNLJ(p); + p = OptimizeNLJAsIndexJoin(p); p = OptimizeOrderByAsIndexScan(p); p = OptimizeMergeFilterScan(p); p = OptimizeSeqScanAsIndexScan(p); diff --git a/src/optimizer/order_by_index_scan.cpp b/src/optimizer/order_by_index_scan.cpp index 24d739529..076d0cc46 100644 --- a/src/optimizer/order_by_index_scan.cpp +++ b/src/optimizer/order_by_index_scan.cpp @@ -54,10 +54,10 @@ auto Optimizer::OptimizeOrderByAsIndexScan(const AbstractPlanNodeRef &plan) -> A if (child_plan->GetType() == PlanType::SeqScan) { const auto &seq_scan = dynamic_cast(*child_plan); - const auto *table_info = catalog_.GetTable(seq_scan.GetTableOid()); + const auto table_info = catalog_.GetTable(seq_scan.GetTableOid()); const auto indices = catalog_.GetTableIndexes(table_info->name_); - for (const auto *index : indices) { + for (const auto &index : indices) { const auto &columns = index->index_->GetKeyAttrs(); if (order_by_column_ids == columns) { return std::make_shared(optimized_plan->output_schema_, table_info->oid_, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 72648a9d1..08651f73b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,7 +56,7 @@ set(BUSTUB_SLT_SOURCES "${PROJECT_SOURCE_DIR}/test/sql/p3.02-insert.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.03-update.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.04-delete.slt" - "${PROJECT_SOURCE_DIR}/test/sql/p3.05-index-scan.slt" + "${PROJECT_SOURCE_DIR}/test/sql/p3.05-index-scan-btree.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.06-empty-table.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.07-simple-agg.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.08-group-agg-1.slt" diff --git a/test/sql/p3.13-nested-index-join.slt b/test/sql/p3.13-nested-index-join.slt index 080b8e89a..a8bd12ae2 100644 --- a/test/sql/p3.13-nested-index-join.slt +++ b/test/sql/p3.13-nested-index-join.slt @@ -1,6 +1,3 @@ -# --- NOT TESTED IN Fall 2023 --- -no test - statement ok set force_optimizer_starter_rule=yes diff --git a/test/sql/p3.19-integration-2.slt b/test/sql/p3.19-integration-2.slt index 78ba6b9c8..3840e41c5 100644 --- a/test/sql/p3.19-integration-2.slt +++ b/test/sql/p3.19-integration-2.slt @@ -24,9 +24,11 @@ select count(distance) from __mock_graph; ---- 90 +# Fall 2024: Remove the ORDER BY in the query since it sorts var-length data, which is not supported in the current external merge sort. query -- initialize the result set -INSERT INTO result SELECT src, src as dst, src_label, src_label as dst_label, 0, 0 FROM __mock_graph GROUP BY src, src_label ORDER BY src; +-- INSERT INTO result SELECT src, src as dst, src_label, src_label as dst_label, 0, 0 FROM __mock_graph GROUP BY src, src_label ORDER BY src; +INSERT INTO result SELECT src, src as dst, src_label, src_label as dst_label, 0, 0 FROM __mock_graph GROUP BY src, src_label; ---- 10 @@ -120,8 +122,10 @@ INSERT INTO tmp SELECT * FROM ( statement ok INSERT INTO result SELECT * FROM tmp; DELETE FROM tmp; SELECT count(*) FROM result; +# Fall 2024: Remove the ORDER BY in the query since it sorts var-length data, which is not supported in the current external merge sort. query rowsort +explain:o -SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label ORDER BY dst; +-- SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label ORDER BY dst; +SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label; ---- 1 001 0 000 1000 1 4 1 4 1 001 1 001 1000 0 4 0 4 From 30af3525fc3876c2f3d2ea6def5636d5f788db88 Mon Sep 17 00:00:00 2001 From: Yash Kothari Date: Tue, 22 Oct 2024 16:01:19 -0400 Subject: [PATCH 15/21] update TxnMgrDbg calls --- test/txn/txn_abort_serializable_test.cpp | 12 +- test/txn/txn_executor_test.cpp | 150 +++++++++++------------ test/txn/txn_index_concurrent_test.cpp | 12 +- test/txn/txn_index_test.cpp | 52 ++++---- test/txn/txn_scan_test.cpp | 2 +- 5 files changed, 114 insertions(+), 114 deletions(-) diff --git a/test/txn/txn_abort_serializable_test.cpp b/test/txn/txn_abort_serializable_test.cpp index 7e4325e5a..2969f3159 100644 --- a/test/txn/txn_abort_serializable_test.cpp +++ b/test/txn/txn_abort_serializable_test.cpp @@ -24,7 +24,7 @@ TEST(TxnBonusTest, DISABLED_SerializableTest) { // NOLINT auto txn_read = BeginTxnSerializable(*bustub, "txn_read"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 0 WHERE a = 1")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 1 WHERE a = 0")); - TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_read, ExecuteTxn(*bustub, _var, _txn, "SELECT * FROM maintable WHERE a = 0")); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn3, CommitTxn(*bustub, _var, _txn, EXPECT_FAIL)); @@ -56,7 +56,7 @@ TEST(TxnBonusTest, DISABLED_ConcurrentSerializableTest) { // NOLINT auto txn3 = BeginTxnSerializable(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 1 WHERE a = 0")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 0 WHERE a = 1")); - TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); std::vector commit_threads; const int thread_cnt = 2; @@ -97,7 +97,7 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 233), (2, 2333)")); WithTxn(txn1, AbortTxn(*bustub, _var, _txn)); - TxnMgrDbg("after abort", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after abort", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 2333), (2, 23333), (3, 233)")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", @@ -106,9 +106,9 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT {2, 23333}, {3, 233}, })); - TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", IntResult{ @@ -116,7 +116,7 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT {2, 23333}, {3, 233}, })); - TableHeapEntryNoMoreThan(*bustub, table_info, 3); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); // test continues on Gradescope... } } diff --git a/test/txn/txn_executor_test.cpp b/test/txn/txn_executor_test.cpp index d9f921007..7afe56acb 100644 --- a/test/txn/txn_executor_test.cpp +++ b/test/txn/txn_executor_test.cpp @@ -17,7 +17,7 @@ TEST(TxnExecutorTest, DISABLED_InsertTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); - TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); const std::string query = "SELECT a FROM maintable"; fmt::println(stderr, "A: check scan txn1"); @@ -40,7 +40,7 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); - TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); const std::string query = "SELECT a FROM maintable"; fmt::println(stderr, "A: check scan txn1"); @@ -48,7 +48,7 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit txn1", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit txn1", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn_ref = BeginTxn(*bustub, "txn_ref"); @@ -58,14 +58,14 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT fmt::println(stderr, "D: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); - TxnMgrDbg("after insert into txn3", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert into txn3", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "E: check scan txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {3}})); fmt::println(stderr, "F: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit txn2", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit txn2", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "G: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {3}})); @@ -83,18 +83,18 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 3")); - TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "A: check scan txn1"); const auto query = "SELECT a FROM maintable"; WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn_ref = BeginTxn(*bustub, "txn_ref"); auto txn2 = BeginTxn(*bustub, "txn2"); fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "C: check scan txn4"); @@ -103,7 +103,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (5)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (6)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 6")); - TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "D: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {4}, {5}})); fmt::println(stderr, "E: check scan txn2"); @@ -112,7 +112,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn4, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn5 = BeginTxn(*bustub, "txn5"); fmt::println(stderr, "F: check scan txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {4}, {5}})); @@ -132,24 +132,24 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 3")); - TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "A: check scan txn1"); const auto query = "SELECT a FROM maintable"; WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); auto txn3 = BeginTxn(*bustub, "txn3"); fmt::println(stderr, "C: check scan txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); fmt::println(stderr, "D: taint txn3"); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "E: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); @@ -157,7 +157,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (5)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (6)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 6")); - TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "F: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {4}, {5}})); fmt::println(stderr, "G: check scan txn2"); @@ -166,16 +166,16 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn4, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn5 = BeginTxn(*bustub, "txn5"); fmt::println(stderr, "H: check scan txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {4}, {5}})); fmt::println(stderr, "I: commit txn 6"); auto txn6 = BeginTxn(*bustub, "txn6"); WithTxn(txn6, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 5")); - TxnMgrDbg("after txn6 deletes", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn6 deletes", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn6, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn6 commits", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn6 commits", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "J: taint txn5"); WithTxn(txn5, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 5")); auto txn7 = BeginTxn(*bustub, "txn7"); @@ -195,53 +195,53 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest1) { // NOLINT auto txn_ref = BeginTxn(*bustub, "txn_ref"); auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (1, 1, 1)")); - TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); const std::string query = "SELECT * FROM table1"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); @@ -250,7 +250,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest1) { // NOLINT fmt::println(stderr, "H: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT @@ -262,55 +262,55 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT auto txn0 = BeginTxn(*bustub, "txn0"); WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table2 VALUES (1, 1, 1)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after insert and commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert and commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn_ref = BeginTxn(*bustub, "txn_ref"); const std::string query = "SELECT * FROM table2"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); @@ -322,7 +322,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT WithTxn(txn_ref, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT @@ -338,62 +338,62 @@ TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT auto txn01 = BeginTxn(*bustub, "txn01"); WithTxn(txn01, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1, b = 1, c = 1")); WithTxn(txn01, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after insert, update, and commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert, update, and commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn_ref_1 = BeginTxn(*bustub, "txn_ref_1"); const std::string query = "SELECT * FROM table2"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); @@ -408,7 +408,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT WithTxn(txn_ref_1, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT @@ -421,17 +421,17 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (0, 0, 0)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); auto txn_ref = BeginTxn(*bustub, "txn_ref"); - TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 1")); - TxnMgrDbg("after 1st update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after 1st update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2")); - TxnMgrDbg("after txn tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 0, 0}})); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } { fmt::println(stderr, "--- UpdateConflict2: complex case with version chain ---"); @@ -441,7 +441,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT auto txn0 = BeginTxn(*bustub, "txn0"); WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (0, 0, 0), (1, 1, 1)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn2 = BeginTxn(*bustub, "txn2"); auto txn3 = BeginTxn(*bustub, "txn3"); @@ -450,17 +450,17 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 233 WHERE a = 0")); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 2333 WHERE a = 1")); - TxnMgrDbg("after updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2 WHERE a = 0")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn4, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2 WHERE a = 1")); - TxnMgrDbg("after txn4 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn4 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 0, 0}, {1, 1, 1}})); auto txn5 = BeginTxn(*bustub, "txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 233, 0}, {1, 2333, 1}})); - TableHeapEntryNoMoreThan(*bustub, table_info, 2); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 2); } } @@ -504,7 +504,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT auto txn_watermark_at_3 = BeginTxn(*bustub, "txn_watermark_at_3"); auto txn_watermark_at_3_id = txn_watermark_at_3->GetTransactionId(); BumpCommitTs(*bustub, 2); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_watermark_at_1, @@ -516,11 +516,11 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "A: first GC"); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "B: second GC"); GarbageCollection(*bustub); TxnMgrDbg("after garbage collection (yes, we call it twice without doing anything...)", bustub->txn_manager_.get(), - table_info, table_info->table_.get()); + table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -540,7 +540,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "C: 3rd GC"); WithTxn(txn_watermark_at_0, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -559,7 +559,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "D: 4th GC"); WithTxn(txn_watermark_at_1, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -576,7 +576,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "E: 5th GC"); WithTxn(txn_watermark_at_2, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -591,7 +591,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "F: 6th GC"); WithTxn(txn_watermark_at_3, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -646,7 +646,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT auto txn_watermark_at_3 = BeginTxn(*bustub, "txn_watermark_at_3"); auto txn_watermark_at_3_id = txn_watermark_at_3->GetTransactionId(); BumpCommitTs(*bustub, 2); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_watermark_at_1, @@ -658,11 +658,11 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "A: first GC"); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "B: second GC"); GarbageCollection(*bustub); TxnMgrDbg("after garbage collection (yes, we call it twice without doing anything...)", bustub->txn_manager_.get(), - table_info, table_info->table_.get()); + table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -684,9 +684,9 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT WithTxn(txn5, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 12")); WithTxn(txn5, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 11")); WithTxn(txn6, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 11")); - TxnMgrDbg("after txn5 + txn6 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn5 + txn6 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -708,7 +708,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "D: 4th GC"); WithTxn(txn_watermark_at_0, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -729,7 +729,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "E: 5th GC"); WithTxn(txn_watermark_at_1, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -748,7 +748,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "F: 6th GC"); WithTxn(txn_watermark_at_2, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -765,7 +765,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "G: 7th GC"); WithTxn(txn_watermark_at_3, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); diff --git a/test/txn/txn_index_concurrent_test.cpp b/test/txn/txn_index_concurrent_test.cpp index 90213d2f0..384ad08dc 100644 --- a/test/txn/txn_index_concurrent_test.cpp +++ b/test/txn/txn_index_concurrent_test.cpp @@ -86,7 +86,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentInsertTest) { // NOLINT } auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - auto entry = TableHeapEntry(*bustub, bustub->catalog_->GetTable("maintable")); + auto entry = TableHeapEntry(*bustub, bustub->catalog_->GetTable("maintable").get()); fmt::println(stderr, "{} entries in the table heap", entry); if (n == trials - 1) { SimpleStreamWriter writer(std::cerr); @@ -126,7 +126,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateTest) { // NOLINT const int thread_cnt = 8; const int number_cnt = 20; Execute(*bustub, generate_insert_sql(number_cnt), false); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); update_threads.reserve(thread_cnt); std::map> operation_result; std::mutex result_mutex; @@ -183,7 +183,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateTest) { // NOLINT } auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); if (n == trials - 1 || n == trials - 2) { SimpleStreamWriter writer(std::cerr); fmt::println(stderr, "--- the following data might be manually inspected by TAs ---"); @@ -214,7 +214,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateAbortTest) { // NOLINT Execute(*bustub, "CREATE TABLE maintable(a int primary key, b int)"); std::vector update_threads; Execute(*bustub, generate_insert_sql(number_cnt), false); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); update_threads.reserve(thread_cnt); std::map> operation_result; std::mutex result_mutex; @@ -273,10 +273,10 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateAbortTest) { // NOLINT std::terminate(); } } - auto *table_info = bustub->catalog_->GetTable("maintable"); + auto table_info = bustub->catalog_->GetTable("maintable"); auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - TableHeapEntryNoMoreThan(*bustub, table_info, number_cnt); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), number_cnt); if (n >= trials - 2) { SimpleStreamWriter writer(std::cerr); fmt::println(stderr, "--- the following data might be manually inspected by TAs ---"); diff --git a/test/txn/txn_index_test.cpp b/test/txn/txn_index_test.cpp index b04bf94f6..162685589 100644 --- a/test/txn/txn_index_test.cpp +++ b/test/txn/txn_index_test.cpp @@ -22,37 +22,37 @@ TEST(TxnIndexTest, DISABLED_IndexInsertTest) { // NOLINT auto table_info = bustub->catalog_->GetTable("maintable"); auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 0)")); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {1, 0}, })); WithTxn(txn1, ExecuteTxnTainted(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 1)")); - TxnMgrDbg("after txn1 taint", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TxnMgrDbg("after txn1 taint", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2, 2)")); - TxnMgrDbg("after txn2 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, })); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 2); + TxnMgrDbg("after txn2 commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 2); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3, 3)")); - TxnMgrDbg("after txn3 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, {3, 3}, })); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn3 commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 3); + TxnMgrDbg("after txn3 commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); auto txn4 = BeginTxn(*bustub, "txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, @@ -61,19 +61,19 @@ TEST(TxnIndexTest, DISABLED_IndexInsertTest) { // NOLINT {3, 3}, })); WithTxn(txn4, ExecuteTxnTainted(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3, 4)")); - TxnMgrDbg("after txn4 taint", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 3); + TxnMgrDbg("after txn4 taint", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); auto txn5 = BeginTxn(*bustub, "txn5"); WithTxn(txn5, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 4)")); - TxnMgrDbg("after txn5 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn5 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, {3, 3}, {4, 4}, })); - TableHeapEntryNoMoreThan(*bustub, table_info, 4); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 4); auto txn6 = BeginTxn(*bustub, "txn6"); WithTxn(txn6, QueryShowResult(*bustub, _var, _txn, query, @@ -97,16 +97,16 @@ TEST(TxnIndexTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn1, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4}, IntResult{{1, 0}, {2, 0}, {3, 0}, {4, 0}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1_reverify = BeginTxn(*bustub, "txn1_reverify"); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 4); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 4); // hidden tests in-between @@ -136,7 +136,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 0), (6, 0)")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 5")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 6")); - TxnMgrDbg("after preparation", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after preparation", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); // at this point, we have (4, 0) inserted, (5, 0) deleted, and (6, 0) self inserted and deleted. return {txn1_reverify, txn2_reverify, txn3}; }; @@ -163,9 +163,9 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT IntResult{{1, 0}, {}, {}, {4, 0}, {}, {}})); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2, 1), (5, 1), (3, 1), (6, 1)")); - TxnMgrDbg("after txn3 insert operations", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 insert operations", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col2 = col2 + 10")); - TxnMgrDbg("after txn3 update operations", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 update operations", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {1, 10}, @@ -185,7 +185,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT {6, 11}, })); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, @@ -207,7 +207,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT {6, 11}, })); reverify(bustub, txn1_reverify, txn2_reverify, query); - TableHeapEntryNoMoreThan(*bustub, table_info, 6); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 6); } // hidden tests... } @@ -223,16 +223,16 @@ TEST(GradingTxnIndexTest, DISABLED_IndexUpdateConflictTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 0), (2, 0), (3, 0)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 2")); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 0)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 1")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 3")); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE maintable SET col2 = 2 WHERE col1 = 1")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); // hidden tests... } @@ -249,14 +249,14 @@ TEST(TxnIndexTest, DISABLED_UpdatePrimaryKeyTest) { // NOLINT WithTxn(txn1, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4}, IntResult{{1, 0}, {2, 0}, {3, 0}, {4, 0}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col1 = col1 + 1")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 0}, {3, 0}, {4, 0}, {5, 0}})); WithTxn(txn2, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4, 5}, IntResult{{}, {2, 0}, {3, 0}, {4, 0}, {5, 0}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col1 = col1 - 2")); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0}, {1, 0}, {2, 0}, {3, 0}})); diff --git a/test/txn/txn_scan_test.cpp b/test/txn/txn_scan_test.cpp index 930911a16..adb9ef809 100644 --- a/test/txn/txn_scan_test.cpp +++ b/test/txn/txn_scan_test.cpp @@ -199,7 +199,7 @@ TEST(TxnScanTest, DISABLED_ScanTest) { // NOLINT Tuple{{IntNull(), DoubleNull(), BoolNull()}, schema.get()}); bustub->txn_manager_->UpdateUndoLink(rid4, prev_log_5, nullptr); - TxnMgrDbg("before verify scan", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("before verify scan", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto query = "SELECT * FROM maintable"; fmt::println(stderr, "A: Verify txn0"); From d9d303ceb35ff352f82218f88a9a495d8aad37ef Mon Sep 17 00:00:00 2001 From: Yash Kothari Date: Tue, 22 Oct 2024 17:09:30 -0400 Subject: [PATCH 16/21] fix format errors --- src/catalog/table_generator.cpp | 2 +- src/include/catalog/table_generator.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catalog/table_generator.cpp b/src/catalog/table_generator.cpp index ade9029d6..02c8f860d 100644 --- a/src/catalog/table_generator.cpp +++ b/src/catalog/table_generator.cpp @@ -62,7 +62,7 @@ auto TableGenerator::MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> s } } -void TableGenerator::FillTable(std::shared_ptr info, TableInsertMeta *table_meta) { +void TableGenerator::FillTable(const std::shared_ptr &info, TableInsertMeta *table_meta) { uint32_t num_inserted = 0; uint32_t batch_size = 128; while (num_inserted < table_meta->num_rows_) { diff --git a/src/include/catalog/table_generator.h b/src/include/catalog/table_generator.h index f4b07b784..dc61ea4ad 100644 --- a/src/include/catalog/table_generator.h +++ b/src/include/catalog/table_generator.h @@ -102,7 +102,7 @@ class TableGenerator { : name_(name), num_rows_(num_rows), col_meta_(std::move(col_meta)) {} }; - void FillTable(std::shared_ptr info, TableInsertMeta *table_meta); + void FillTable(const std::shared_ptr &info, TableInsertMeta *table_meta); auto MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> std::vector; From 30bbdd5a557de21e1a22953f1a7c2092a5127328 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Thu, 24 Oct 2024 14:47:21 -0400 Subject: [PATCH 17/21] sync private --- src/catalog/table_generator.cpp | 2 +- src/include/catalog/catalog.h | 21 ++-- src/include/catalog/table_generator.h | 3 +- test/sql/p3.18-integration-1.slt | 26 ++-- test/txn/txn_abort_serializable_test.cpp | 12 +- test/txn/txn_executor_test.cpp | 150 +++++++++++------------ test/txn/txn_index_concurrent_test.cpp | 12 +- test/txn/txn_index_test.cpp | 52 ++++---- test/txn/txn_scan_test.cpp | 2 +- 9 files changed, 145 insertions(+), 135 deletions(-) diff --git a/src/catalog/table_generator.cpp b/src/catalog/table_generator.cpp index 02c8f860d..ade9029d6 100644 --- a/src/catalog/table_generator.cpp +++ b/src/catalog/table_generator.cpp @@ -62,7 +62,7 @@ auto TableGenerator::MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> s } } -void TableGenerator::FillTable(const std::shared_ptr &info, TableInsertMeta *table_meta) { +void TableGenerator::FillTable(std::shared_ptr info, TableInsertMeta *table_meta) { uint32_t num_inserted = 0; uint32_t batch_size = 128; while (num_inserted < table_meta->num_rows_) { diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index 80ff3e984..eaa2d3bc3 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -113,11 +113,10 @@ struct IndexInfo { class Catalog { public: /** Indicates that an operation returning a `std::shared_ptr` failed */ - static inline const std::shared_ptr NULL_TABLE_INFO{nullptr}; + const std::shared_ptr NULL_TABLE_INFO{nullptr}; /** Indicates that an operation returning a `std::shared_ptr` failed */ - // const std::shared_ptr NULL_INDEX_INFO{nullptr}; - static inline const std::shared_ptr NULL_INDEX_INFO{nullptr}; + const std::shared_ptr NULL_INDEX_INFO{nullptr}; /** * Construct a new Catalog instance. @@ -136,8 +135,8 @@ class Catalog { * @param create_table_heap whether to create a table heap for the new table * @return A shared pointer to the metadata for the table */ - auto CreateTable(Transaction *txn, const std::string &table_name, const Schema &schema, bool create_table_heap = true) - -> std::shared_ptr { + auto CreateTable(Transaction *txn, const std::string &table_name, const Schema &schema, + bool create_table_heap = true) -> std::shared_ptr { if (table_names_.count(table_name) != 0) { return NULL_TABLE_INFO; } @@ -372,7 +371,11 @@ class Catalog { [[maybe_unused]] LockManager *lock_manager_; [[maybe_unused]] LogManager *log_manager_; - /** Map table identifier -> table metadata. */ + /** + * Map table identifier -> table metadata. + * + * NOTE: `tables_` owns all table metadata. + */ std::unordered_map> tables_; /** Map table name -> table identifiers. */ @@ -381,7 +384,11 @@ class Catalog { /** The next table identifier to be used. */ std::atomic next_table_oid_{0}; - /** Map index identifier -> index metadata. */ + /** + * Map index identifier -> index metadata. + * + * NOTE: that `indexes_` owns all index metadata. + */ std::unordered_map> indexes_; /** Map table name -> index names -> index identifiers. */ diff --git a/src/include/catalog/table_generator.h b/src/include/catalog/table_generator.h index dc61ea4ad..ad33c1e29 100644 --- a/src/include/catalog/table_generator.h +++ b/src/include/catalog/table_generator.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -102,7 +101,7 @@ class TableGenerator { : name_(name), num_rows_(num_rows), col_meta_(std::move(col_meta)) {} }; - void FillTable(const std::shared_ptr &info, TableInsertMeta *table_meta); + void FillTable(std::shared_ptr info, TableInsertMeta *table_meta); auto MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> std::vector; diff --git a/test/sql/p3.18-integration-1.slt b/test/sql/p3.18-integration-1.slt index 1168cb125..31275afe5 100644 --- a/test/sql/p3.18-integration-1.slt +++ b/test/sql/p3.18-integration-1.slt @@ -5,8 +5,12 @@ # This ultimate goal is to run an extra-complex query to compute the shortest path within x # steps from each of the vertex. We will start from the table scan. +# Note(f24): Make `src_label` and `dst_label` INTEGER because the current external merge sort implementation +# only supports sorting on fixed-length data. Should be VARCHAR(8) if var-length data sorting is supported in +# the future. + statement ok -CREATE TABLE graph(src int, dst int, src_label VARCHAR(8), dst_label VARCHAR(8), distance int); +CREATE TABLE graph(src int, dst int, src_label int, dst_label int, distance int); statement ok INSERT INTO graph SELECT * FROM __mock_graph; @@ -152,16 +156,16 @@ select * from ( ) group by src, dst, src_label, dst_label ) where src = 0 order by dst limit 10; ---- -0 0 000 000 4 -0 1 000 001 4 -0 2 000 002 4 -0 3 000 003 4 -0 4 000 004 4 -0 5 000 005 4 -0 6 000 006 4 -0 7 000 007 4 -0 8 000 008 4 -0 9 000 009 4 +0 0 0 0 4 +0 1 0 100 4 +0 2 0 200 4 +0 3 0 300 4 +0 4 0 400 4 +0 5 0 500 4 +0 6 0 600 4 +0 7 0 700 4 +0 8 0 800 4 +0 9 0 900 4 # In the future, we will construct some custom graphs with different link weight. # But for now, that's the end of the test! diff --git a/test/txn/txn_abort_serializable_test.cpp b/test/txn/txn_abort_serializable_test.cpp index 2969f3159..7e4325e5a 100644 --- a/test/txn/txn_abort_serializable_test.cpp +++ b/test/txn/txn_abort_serializable_test.cpp @@ -24,7 +24,7 @@ TEST(TxnBonusTest, DISABLED_SerializableTest) { // NOLINT auto txn_read = BeginTxnSerializable(*bustub, "txn_read"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 0 WHERE a = 1")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 1 WHERE a = 0")); - TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_read, ExecuteTxn(*bustub, _var, _txn, "SELECT * FROM maintable WHERE a = 0")); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn3, CommitTxn(*bustub, _var, _txn, EXPECT_FAIL)); @@ -56,7 +56,7 @@ TEST(TxnBonusTest, DISABLED_ConcurrentSerializableTest) { // NOLINT auto txn3 = BeginTxnSerializable(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 1 WHERE a = 0")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 0 WHERE a = 1")); - TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); std::vector commit_threads; const int thread_cnt = 2; @@ -97,7 +97,7 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 233), (2, 2333)")); WithTxn(txn1, AbortTxn(*bustub, _var, _txn)); - TxnMgrDbg("after abort", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after abort", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 2333), (2, 23333), (3, 233)")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", @@ -106,9 +106,9 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT {2, 23333}, {3, 233}, })); - TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", IntResult{ @@ -116,7 +116,7 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT {2, 23333}, {3, 233}, })); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); + TableHeapEntryNoMoreThan(*bustub, table_info, 3); // test continues on Gradescope... } } diff --git a/test/txn/txn_executor_test.cpp b/test/txn/txn_executor_test.cpp index 7afe56acb..d9f921007 100644 --- a/test/txn/txn_executor_test.cpp +++ b/test/txn/txn_executor_test.cpp @@ -17,7 +17,7 @@ TEST(TxnExecutorTest, DISABLED_InsertTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); - TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info, table_info->table_.get()); const std::string query = "SELECT a FROM maintable"; fmt::println(stderr, "A: check scan txn1"); @@ -40,7 +40,7 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); - TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info, table_info->table_.get()); const std::string query = "SELECT a FROM maintable"; fmt::println(stderr, "A: check scan txn1"); @@ -48,7 +48,7 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit txn1", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit txn1", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn_ref = BeginTxn(*bustub, "txn_ref"); @@ -58,14 +58,14 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT fmt::println(stderr, "D: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); - TxnMgrDbg("after insert into txn3", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insert into txn3", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "E: check scan txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {3}})); fmt::println(stderr, "F: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit txn2", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit txn2", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "G: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {3}})); @@ -83,18 +83,18 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 3")); - TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "A: check scan txn1"); const auto query = "SELECT a FROM maintable"; WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn_ref = BeginTxn(*bustub, "txn_ref"); auto txn2 = BeginTxn(*bustub, "txn2"); fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "C: check scan txn4"); @@ -103,7 +103,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (5)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (6)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 6")); - TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "D: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {4}, {5}})); fmt::println(stderr, "E: check scan txn2"); @@ -112,7 +112,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn4, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn5 = BeginTxn(*bustub, "txn5"); fmt::println(stderr, "F: check scan txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {4}, {5}})); @@ -132,24 +132,24 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 3")); - TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "A: check scan txn1"); const auto query = "SELECT a FROM maintable"; WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); auto txn3 = BeginTxn(*bustub, "txn3"); fmt::println(stderr, "C: check scan txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); fmt::println(stderr, "D: taint txn3"); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "E: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); @@ -157,7 +157,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (5)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (6)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 6")); - TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "F: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {4}, {5}})); fmt::println(stderr, "G: check scan txn2"); @@ -166,16 +166,16 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn4, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn5 = BeginTxn(*bustub, "txn5"); fmt::println(stderr, "H: check scan txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {4}, {5}})); fmt::println(stderr, "I: commit txn 6"); auto txn6 = BeginTxn(*bustub, "txn6"); WithTxn(txn6, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 5")); - TxnMgrDbg("after txn6 deletes", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn6 deletes", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn6, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn6 commits", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn6 commits", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "J: taint txn5"); WithTxn(txn5, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 5")); auto txn7 = BeginTxn(*bustub, "txn7"); @@ -195,53 +195,53 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest1) { // NOLINT auto txn_ref = BeginTxn(*bustub, "txn_ref"); auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (1, 1, 1)")); - TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); const std::string query = "SELECT * FROM table1"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); @@ -250,7 +250,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest1) { // NOLINT fmt::println(stderr, "H: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); + TableHeapEntryNoMoreThan(*bustub, table_info, 1); } TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT @@ -262,55 +262,55 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT auto txn0 = BeginTxn(*bustub, "txn0"); WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table2 VALUES (1, 1, 1)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after insert and commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insert and commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn_ref = BeginTxn(*bustub, "txn_ref"); const std::string query = "SELECT * FROM table2"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); @@ -322,7 +322,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT WithTxn(txn_ref, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); + TableHeapEntryNoMoreThan(*bustub, table_info, 1); } TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT @@ -338,62 +338,62 @@ TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT auto txn01 = BeginTxn(*bustub, "txn01"); WithTxn(txn01, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1, b = 1, c = 1")); WithTxn(txn01, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after insert, update, and commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after insert, update, and commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn_ref_1 = BeginTxn(*bustub, "txn_ref_1"); const std::string query = "SELECT * FROM table2"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); @@ -408,7 +408,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT WithTxn(txn_ref_1, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); + TableHeapEntryNoMoreThan(*bustub, table_info, 1); } TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT @@ -421,17 +421,17 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (0, 0, 0)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); auto txn_ref = BeginTxn(*bustub, "txn_ref"); - TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 1")); - TxnMgrDbg("after 1st update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after 1st update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn2, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2")); - TxnMgrDbg("after txn tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 0, 0}})); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); + TableHeapEntryNoMoreThan(*bustub, table_info, 1); } { fmt::println(stderr, "--- UpdateConflict2: complex case with version chain ---"); @@ -441,7 +441,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT auto txn0 = BeginTxn(*bustub, "txn0"); WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (0, 0, 0), (1, 1, 1)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn2 = BeginTxn(*bustub, "txn2"); auto txn3 = BeginTxn(*bustub, "txn3"); @@ -450,17 +450,17 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 233 WHERE a = 0")); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 2333 WHERE a = 1")); - TxnMgrDbg("after updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2 WHERE a = 0")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn4, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2 WHERE a = 1")); - TxnMgrDbg("after txn4 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn4 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 0, 0}, {1, 1, 1}})); auto txn5 = BeginTxn(*bustub, "txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 233, 0}, {1, 2333, 1}})); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 2); + TableHeapEntryNoMoreThan(*bustub, table_info, 2); } } @@ -504,7 +504,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT auto txn_watermark_at_3 = BeginTxn(*bustub, "txn_watermark_at_3"); auto txn_watermark_at_3_id = txn_watermark_at_3->GetTransactionId(); BumpCommitTs(*bustub, 2); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_watermark_at_1, @@ -516,11 +516,11 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "A: first GC"); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "B: second GC"); GarbageCollection(*bustub); TxnMgrDbg("after garbage collection (yes, we call it twice without doing anything...)", bustub->txn_manager_.get(), - table_info.get(), table_info->table_.get()); + table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -540,7 +540,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "C: 3rd GC"); WithTxn(txn_watermark_at_0, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -559,7 +559,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "D: 4th GC"); WithTxn(txn_watermark_at_1, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -576,7 +576,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "E: 5th GC"); WithTxn(txn_watermark_at_2, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -591,7 +591,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "F: 6th GC"); WithTxn(txn_watermark_at_3, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -646,7 +646,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT auto txn_watermark_at_3 = BeginTxn(*bustub, "txn_watermark_at_3"); auto txn_watermark_at_3_id = txn_watermark_at_3->GetTransactionId(); BumpCommitTs(*bustub, 2); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_watermark_at_1, @@ -658,11 +658,11 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "A: first GC"); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); fmt::println(stderr, "B: second GC"); GarbageCollection(*bustub); TxnMgrDbg("after garbage collection (yes, we call it twice without doing anything...)", bustub->txn_manager_.get(), - table_info.get(), table_info->table_.get()); + table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -684,9 +684,9 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT WithTxn(txn5, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 12")); WithTxn(txn5, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 11")); WithTxn(txn6, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 11")); - TxnMgrDbg("after txn5 + txn6 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn5 + txn6 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -708,7 +708,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "D: 4th GC"); WithTxn(txn_watermark_at_0, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -729,7 +729,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "E: 5th GC"); WithTxn(txn_watermark_at_1, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -748,7 +748,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "F: 6th GC"); WithTxn(txn_watermark_at_2, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -765,7 +765,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "G: 7th GC"); WithTxn(txn_watermark_at_3, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); diff --git a/test/txn/txn_index_concurrent_test.cpp b/test/txn/txn_index_concurrent_test.cpp index 384ad08dc..90213d2f0 100644 --- a/test/txn/txn_index_concurrent_test.cpp +++ b/test/txn/txn_index_concurrent_test.cpp @@ -86,7 +86,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentInsertTest) { // NOLINT } auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - auto entry = TableHeapEntry(*bustub, bustub->catalog_->GetTable("maintable").get()); + auto entry = TableHeapEntry(*bustub, bustub->catalog_->GetTable("maintable")); fmt::println(stderr, "{} entries in the table heap", entry); if (n == trials - 1) { SimpleStreamWriter writer(std::cerr); @@ -126,7 +126,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateTest) { // NOLINT const int thread_cnt = 8; const int number_cnt = 20; Execute(*bustub, generate_insert_sql(number_cnt), false); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); update_threads.reserve(thread_cnt); std::map> operation_result; std::mutex result_mutex; @@ -183,7 +183,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateTest) { // NOLINT } auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); if (n == trials - 1 || n == trials - 2) { SimpleStreamWriter writer(std::cerr); fmt::println(stderr, "--- the following data might be manually inspected by TAs ---"); @@ -214,7 +214,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateAbortTest) { // NOLINT Execute(*bustub, "CREATE TABLE maintable(a int primary key, b int)"); std::vector update_threads; Execute(*bustub, generate_insert_sql(number_cnt), false); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); update_threads.reserve(thread_cnt); std::map> operation_result; std::mutex result_mutex; @@ -273,10 +273,10 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateAbortTest) { // NOLINT std::terminate(); } } - auto table_info = bustub->catalog_->GetTable("maintable"); + auto *table_info = bustub->catalog_->GetTable("maintable"); auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), number_cnt); + TableHeapEntryNoMoreThan(*bustub, table_info, number_cnt); if (n >= trials - 2) { SimpleStreamWriter writer(std::cerr); fmt::println(stderr, "--- the following data might be manually inspected by TAs ---"); diff --git a/test/txn/txn_index_test.cpp b/test/txn/txn_index_test.cpp index 162685589..b04bf94f6 100644 --- a/test/txn/txn_index_test.cpp +++ b/test/txn/txn_index_test.cpp @@ -22,37 +22,37 @@ TEST(TxnIndexTest, DISABLED_IndexInsertTest) { // NOLINT auto table_info = bustub->catalog_->GetTable("maintable"); auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 0)")); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {1, 0}, })); WithTxn(txn1, ExecuteTxnTainted(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 1)")); - TxnMgrDbg("after txn1 taint", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); + TxnMgrDbg("after txn1 taint", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info, 1); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2, 2)")); - TxnMgrDbg("after txn2 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn2 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, })); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 2); + TxnMgrDbg("after txn2 commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info, 2); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3, 3)")); - TxnMgrDbg("after txn3 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn3 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, {3, 3}, })); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn3 commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); + TxnMgrDbg("after txn3 commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info, 3); auto txn4 = BeginTxn(*bustub, "txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, @@ -61,19 +61,19 @@ TEST(TxnIndexTest, DISABLED_IndexInsertTest) { // NOLINT {3, 3}, })); WithTxn(txn4, ExecuteTxnTainted(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3, 4)")); - TxnMgrDbg("after txn4 taint", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); + TxnMgrDbg("after txn4 taint", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info, 3); auto txn5 = BeginTxn(*bustub, "txn5"); WithTxn(txn5, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 4)")); - TxnMgrDbg("after txn5 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn5 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, {3, 3}, {4, 4}, })); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 4); + TableHeapEntryNoMoreThan(*bustub, table_info, 4); auto txn6 = BeginTxn(*bustub, "txn6"); WithTxn(txn6, QueryShowResult(*bustub, _var, _txn, query, @@ -97,16 +97,16 @@ TEST(TxnIndexTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn1, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4}, IntResult{{1, 0}, {2, 0}, {3, 0}, {4, 0}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn1_reverify = BeginTxn(*bustub, "txn1_reverify"); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 4); + TableHeapEntryNoMoreThan(*bustub, table_info, 4); // hidden tests in-between @@ -136,7 +136,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 0), (6, 0)")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 5")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 6")); - TxnMgrDbg("after preparation", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after preparation", bustub->txn_manager_.get(), table_info, table_info->table_.get()); // at this point, we have (4, 0) inserted, (5, 0) deleted, and (6, 0) self inserted and deleted. return {txn1_reverify, txn2_reverify, txn3}; }; @@ -163,9 +163,9 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT IntResult{{1, 0}, {}, {}, {4, 0}, {}, {}})); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2, 1), (5, 1), (3, 1), (6, 1)")); - TxnMgrDbg("after txn3 insert operations", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn3 insert operations", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col2 = col2 + 10")); - TxnMgrDbg("after txn3 update operations", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn3 update operations", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {1, 10}, @@ -185,7 +185,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT {6, 11}, })); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, @@ -207,7 +207,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT {6, 11}, })); reverify(bustub, txn1_reverify, txn2_reverify, query); - TableHeapEntryNoMoreThan(*bustub, table_info.get(), 6); + TableHeapEntryNoMoreThan(*bustub, table_info, 6); } // hidden tests... } @@ -223,16 +223,16 @@ TEST(GradingTxnIndexTest, DISABLED_IndexUpdateConflictTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 0), (2, 0), (3, 0)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 2")); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 0)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 1")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 3")); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn2 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE maintable SET col2 = 2 WHERE col1 = 1")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); // hidden tests... } @@ -249,14 +249,14 @@ TEST(TxnIndexTest, DISABLED_UpdatePrimaryKeyTest) { // NOLINT WithTxn(txn1, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4}, IntResult{{1, 0}, {2, 0}, {3, 0}, {4, 0}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col1 = col1 + 1")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 0}, {3, 0}, {4, 0}, {5, 0}})); WithTxn(txn2, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4, 5}, IntResult{{}, {2, 0}, {3, 0}, {4, 0}, {5, 0}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("after txn2 update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col1 = col1 - 2")); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0}, {1, 0}, {2, 0}, {3, 0}})); diff --git a/test/txn/txn_scan_test.cpp b/test/txn/txn_scan_test.cpp index adb9ef809..930911a16 100644 --- a/test/txn/txn_scan_test.cpp +++ b/test/txn/txn_scan_test.cpp @@ -199,7 +199,7 @@ TEST(TxnScanTest, DISABLED_ScanTest) { // NOLINT Tuple{{IntNull(), DoubleNull(), BoolNull()}, schema.get()}); bustub->txn_manager_->UpdateUndoLink(rid4, prev_log_5, nullptr); - TxnMgrDbg("before verify scan", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TxnMgrDbg("before verify scan", bustub->txn_manager_.get(), table_info, table_info->table_.get()); auto query = "SELECT * FROM maintable"; fmt::println(stderr, "A: Verify txn0"); From 8b27798b489dde35b6f60ea89a18b39cced2242d Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Thu, 24 Oct 2024 15:16:15 -0400 Subject: [PATCH 18/21] sync private --- src/catalog/table_generator.cpp | 2 +- src/include/catalog/catalog.h | 21 ++-- src/include/catalog/table_generator.h | 3 +- test/txn/txn_abort_serializable_test.cpp | 12 +- test/txn/txn_executor_test.cpp | 150 +++++++++++------------ test/txn/txn_index_concurrent_test.cpp | 12 +- test/txn/txn_index_test.cpp | 52 ++++---- test/txn/txn_scan_test.cpp | 2 +- 8 files changed, 124 insertions(+), 130 deletions(-) diff --git a/src/catalog/table_generator.cpp b/src/catalog/table_generator.cpp index ade9029d6..02c8f860d 100644 --- a/src/catalog/table_generator.cpp +++ b/src/catalog/table_generator.cpp @@ -62,7 +62,7 @@ auto TableGenerator::MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> s } } -void TableGenerator::FillTable(std::shared_ptr info, TableInsertMeta *table_meta) { +void TableGenerator::FillTable(const std::shared_ptr &info, TableInsertMeta *table_meta) { uint32_t num_inserted = 0; uint32_t batch_size = 128; while (num_inserted < table_meta->num_rows_) { diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index eaa2d3bc3..80ff3e984 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -113,10 +113,11 @@ struct IndexInfo { class Catalog { public: /** Indicates that an operation returning a `std::shared_ptr` failed */ - const std::shared_ptr NULL_TABLE_INFO{nullptr}; + static inline const std::shared_ptr NULL_TABLE_INFO{nullptr}; /** Indicates that an operation returning a `std::shared_ptr` failed */ - const std::shared_ptr NULL_INDEX_INFO{nullptr}; + // const std::shared_ptr NULL_INDEX_INFO{nullptr}; + static inline const std::shared_ptr NULL_INDEX_INFO{nullptr}; /** * Construct a new Catalog instance. @@ -135,8 +136,8 @@ class Catalog { * @param create_table_heap whether to create a table heap for the new table * @return A shared pointer to the metadata for the table */ - auto CreateTable(Transaction *txn, const std::string &table_name, const Schema &schema, - bool create_table_heap = true) -> std::shared_ptr { + auto CreateTable(Transaction *txn, const std::string &table_name, const Schema &schema, bool create_table_heap = true) + -> std::shared_ptr { if (table_names_.count(table_name) != 0) { return NULL_TABLE_INFO; } @@ -371,11 +372,7 @@ class Catalog { [[maybe_unused]] LockManager *lock_manager_; [[maybe_unused]] LogManager *log_manager_; - /** - * Map table identifier -> table metadata. - * - * NOTE: `tables_` owns all table metadata. - */ + /** Map table identifier -> table metadata. */ std::unordered_map> tables_; /** Map table name -> table identifiers. */ @@ -384,11 +381,7 @@ class Catalog { /** The next table identifier to be used. */ std::atomic next_table_oid_{0}; - /** - * Map index identifier -> index metadata. - * - * NOTE: that `indexes_` owns all index metadata. - */ + /** Map index identifier -> index metadata. */ std::unordered_map> indexes_; /** Map table name -> index names -> index identifiers. */ diff --git a/src/include/catalog/table_generator.h b/src/include/catalog/table_generator.h index ad33c1e29..dc61ea4ad 100644 --- a/src/include/catalog/table_generator.h +++ b/src/include/catalog/table_generator.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -101,7 +102,7 @@ class TableGenerator { : name_(name), num_rows_(num_rows), col_meta_(std::move(col_meta)) {} }; - void FillTable(std::shared_ptr info, TableInsertMeta *table_meta); + void FillTable(const std::shared_ptr &info, TableInsertMeta *table_meta); auto MakeValues(ColumnInsertMeta *col_meta, uint32_t count) -> std::vector; diff --git a/test/txn/txn_abort_serializable_test.cpp b/test/txn/txn_abort_serializable_test.cpp index 7e4325e5a..2969f3159 100644 --- a/test/txn/txn_abort_serializable_test.cpp +++ b/test/txn/txn_abort_serializable_test.cpp @@ -24,7 +24,7 @@ TEST(TxnBonusTest, DISABLED_SerializableTest) { // NOLINT auto txn_read = BeginTxnSerializable(*bustub, "txn_read"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 0 WHERE a = 1")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 1 WHERE a = 0")); - TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_read, ExecuteTxn(*bustub, _var, _txn, "SELECT * FROM maintable WHERE a = 0")); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn3, CommitTxn(*bustub, _var, _txn, EXPECT_FAIL)); @@ -56,7 +56,7 @@ TEST(TxnBonusTest, DISABLED_ConcurrentSerializableTest) { // NOLINT auto txn3 = BeginTxnSerializable(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 1 WHERE a = 0")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET a = 0 WHERE a = 1")); - TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after two updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); std::vector commit_threads; const int thread_cnt = 2; @@ -97,7 +97,7 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 233), (2, 2333)")); WithTxn(txn1, AbortTxn(*bustub, _var, _txn)); - TxnMgrDbg("after abort", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after abort", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 2333), (2, 23333), (3, 233)")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", @@ -106,9 +106,9 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT {2, 23333}, {3, 233}, })); - TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", IntResult{ @@ -116,7 +116,7 @@ TEST(TxnBonusTest, DISABLED_AbortTest) { // NOLINT {2, 23333}, {3, 233}, })); - TableHeapEntryNoMoreThan(*bustub, table_info, 3); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); // test continues on Gradescope... } } diff --git a/test/txn/txn_executor_test.cpp b/test/txn/txn_executor_test.cpp index d9f921007..7afe56acb 100644 --- a/test/txn/txn_executor_test.cpp +++ b/test/txn/txn_executor_test.cpp @@ -17,7 +17,7 @@ TEST(TxnExecutorTest, DISABLED_InsertTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); - TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); const std::string query = "SELECT a FROM maintable"; fmt::println(stderr, "A: check scan txn1"); @@ -40,7 +40,7 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); - TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insertion", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); const std::string query = "SELECT a FROM maintable"; fmt::println(stderr, "A: check scan txn1"); @@ -48,7 +48,7 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit txn1", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit txn1", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn_ref = BeginTxn(*bustub, "txn_ref"); @@ -58,14 +58,14 @@ TEST(TxnExecutorTest, DISABLED_InsertCommitTest) { // NOLINT fmt::println(stderr, "D: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); - TxnMgrDbg("after insert into txn3", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert into txn3", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "E: check scan txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {3}})); fmt::println(stderr, "F: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2}})); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit txn2", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit txn2", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "G: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {3}})); @@ -83,18 +83,18 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 3")); - TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "A: check scan txn1"); const auto query = "SELECT a FROM maintable"; WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn_ref = BeginTxn(*bustub, "txn_ref"); auto txn2 = BeginTxn(*bustub, "txn2"); fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "C: check scan txn4"); @@ -103,7 +103,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (5)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (6)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 6")); - TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "D: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {4}, {5}})); fmt::println(stderr, "E: check scan txn2"); @@ -112,7 +112,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn4, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn5 = BeginTxn(*bustub, "txn5"); fmt::println(stderr, "F: check scan txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {4}, {5}})); @@ -132,24 +132,24 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 3")); - TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after 3 insert + 1 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "A: check scan txn1"); const auto query = "SELECT a FROM maintable"; WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); fmt::println(stderr, "B: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); auto txn3 = BeginTxn(*bustub, "txn3"); fmt::println(stderr, "C: check scan txn3"); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); fmt::println(stderr, "D: taint txn3"); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 2")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); fmt::println(stderr, "E: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}})); @@ -157,7 +157,7 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (5)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (6)")); WithTxn(txn4, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 6")); - TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn4 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "F: check scan txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {2}, {4}, {5}})); fmt::println(stderr, "G: check scan txn2"); @@ -166,16 +166,16 @@ TEST(TxnExecutorTest, DISABLED_InsertDeleteConflictTest) { // NOLINT WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); WithTxn(txn4, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn5 = BeginTxn(*bustub, "txn5"); fmt::println(stderr, "H: check scan txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1}, {4}, {5}})); fmt::println(stderr, "I: commit txn 6"); auto txn6 = BeginTxn(*bustub, "txn6"); WithTxn(txn6, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 5")); - TxnMgrDbg("after txn6 deletes", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn6 deletes", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn6, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn6 commits", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn6 commits", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "J: taint txn5"); WithTxn(txn5, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM maintable WHERE a = 5")); auto txn7 = BeginTxn(*bustub, "txn7"); @@ -195,53 +195,53 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest1) { // NOLINT auto txn_ref = BeginTxn(*bustub, "txn_ref"); auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (1, 1, 1)")); - TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); const std::string query = "SELECT * FROM table1"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn1, CheckUndoLogNum(*bustub, _var, _txn, 0)); @@ -250,7 +250,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest1) { // NOLINT fmt::println(stderr, "H: check scan txn2"); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT @@ -262,55 +262,55 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT auto txn0 = BeginTxn(*bustub, "txn0"); WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table2 VALUES (1, 1, 1)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after insert and commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert and commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn_ref = BeginTxn(*bustub, "txn_ref"); const std::string query = "SELECT * FROM table2"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); @@ -322,7 +322,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTest2) { // NOLINT WithTxn(txn_ref, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT @@ -338,62 +338,62 @@ TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT auto txn01 = BeginTxn(*bustub, "txn01"); WithTxn(txn01, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1, b = 1, c = 1")); WithTxn(txn01, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after insert, update, and commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after insert, update, and commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn_ref_1 = BeginTxn(*bustub, "txn_ref_1"); const std::string query = "SELECT * FROM table2"; fmt::println(stderr, "A: 1st update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 2, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "B: 2nd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C1: 3rd update, not real update..."); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 1)); fmt::println(stderr, "C2: the real 3rd update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 3, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "D: 4th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET b = 1")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 1, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "E: 5th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 3")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{3, 1, 1}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 2)); fmt::println(stderr, "F: 6th update"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table2 SET a = 4, b = 4, c = 4")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{4, 4, 4}})); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); WithTxn(txn1, CheckUndoLogColumn(*bustub, _var, _txn, 3)); fmt::println(stderr, "G: delete"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE from table2")); - TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_ref_0, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0, 0}})); WithTxn(txn_ref_1, QueryShowResult(*bustub, _var, _txn, query, IntResult{{1, 1, 1}})); @@ -408,7 +408,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateTestWithUndoLog) { // NOLINT WithTxn(txn_ref_1, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT @@ -421,17 +421,17 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (0, 0, 0)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); auto txn_ref = BeginTxn(*bustub, "txn_ref"); - TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET a = 1")); - TxnMgrDbg("after 1st update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after 1st update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2")); - TxnMgrDbg("after txn tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 0, 0}})); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); } { fmt::println(stderr, "--- UpdateConflict2: complex case with version chain ---"); @@ -441,7 +441,7 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT auto txn0 = BeginTxn(*bustub, "txn0"); WithTxn(txn0, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO table1 VALUES (0, 0, 0), (1, 1, 1)")); WithTxn(txn0, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after initialize", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1 = BeginTxn(*bustub, "txn1"); auto txn2 = BeginTxn(*bustub, "txn2"); auto txn3 = BeginTxn(*bustub, "txn3"); @@ -450,17 +450,17 @@ TEST(TxnExecutorTest, DISABLED_UpdateConflict) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 233 WHERE a = 0")); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE table1 SET b = 2333 WHERE a = 1")); - TxnMgrDbg("after updates", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after updates", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2 WHERE a = 0")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn4, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE table1 SET b = 2 WHERE a = 1")); - TxnMgrDbg("after txn4 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn4 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_ref, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 0, 0}, {1, 1, 1}})); auto txn5 = BeginTxn(*bustub, "txn5"); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM table1", IntResult{{0, 233, 0}, {1, 2333, 1}})); - TableHeapEntryNoMoreThan(*bustub, table_info, 2); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 2); } } @@ -504,7 +504,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT auto txn_watermark_at_3 = BeginTxn(*bustub, "txn_watermark_at_3"); auto txn_watermark_at_3_id = txn_watermark_at_3->GetTransactionId(); BumpCommitTs(*bustub, 2); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_watermark_at_1, @@ -516,11 +516,11 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "A: first GC"); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "B: second GC"); GarbageCollection(*bustub); TxnMgrDbg("after garbage collection (yes, we call it twice without doing anything...)", bustub->txn_manager_.get(), - table_info, table_info->table_.get()); + table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -540,7 +540,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "C: 3rd GC"); WithTxn(txn_watermark_at_0, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -559,7 +559,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "D: 4th GC"); WithTxn(txn_watermark_at_1, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -576,7 +576,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "E: 5th GC"); WithTxn(txn_watermark_at_2, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -591,7 +591,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollection) { // NOLINT fmt::println(stderr, "F: 6th GC"); WithTxn(txn_watermark_at_3, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -646,7 +646,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT auto txn_watermark_at_3 = BeginTxn(*bustub, "txn_watermark_at_3"); auto txn_watermark_at_3_id = txn_watermark_at_3->GetTransactionId(); BumpCommitTs(*bustub, 2); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, QueryShowResult(*bustub, _var, _txn, query, empty_table)); WithTxn(txn_watermark_at_1, @@ -658,11 +658,11 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "A: first GC"); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); fmt::println(stderr, "B: second GC"); GarbageCollection(*bustub); TxnMgrDbg("after garbage collection (yes, we call it twice without doing anything...)", bustub->txn_manager_.get(), - table_info, table_info->table_.get()); + table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -684,9 +684,9 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT WithTxn(txn5, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 12")); WithTxn(txn5, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 11")); WithTxn(txn6, ExecuteTxnTainted(*bustub, _var, _txn, "DELETE FROM table1 WHERE a = 11")); - TxnMgrDbg("after txn5 + txn6 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn5 + txn6 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnExists(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -708,7 +708,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "D: 4th GC"); WithTxn(txn_watermark_at_0, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnExists(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -729,7 +729,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "E: 5th GC"); WithTxn(txn_watermark_at_1, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnExists(*bustub, _var, txn_watermark_at_2_id)); @@ -748,7 +748,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "F: 6th GC"); WithTxn(txn_watermark_at_2, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); @@ -765,7 +765,7 @@ TEST(TxnExecutorTest, DISABLED_GarbageCollectionWithTainted) { // NOLINT fmt::println(stderr, "G: 7th GC"); WithTxn(txn_watermark_at_3, CommitTxn(*bustub, _var, _txn)); GarbageCollection(*bustub); - TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after garbage collection", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn_watermark_at_0, EnsureTxnGCed(*bustub, _var, txn_watermark_at_0_id)); WithTxn(txn_watermark_at_1, EnsureTxnGCed(*bustub, _var, txn_watermark_at_1_id)); WithTxn(txn_watermark_at_2, EnsureTxnGCed(*bustub, _var, txn_watermark_at_2_id)); diff --git a/test/txn/txn_index_concurrent_test.cpp b/test/txn/txn_index_concurrent_test.cpp index 90213d2f0..384ad08dc 100644 --- a/test/txn/txn_index_concurrent_test.cpp +++ b/test/txn/txn_index_concurrent_test.cpp @@ -86,7 +86,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentInsertTest) { // NOLINT } auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - auto entry = TableHeapEntry(*bustub, bustub->catalog_->GetTable("maintable")); + auto entry = TableHeapEntry(*bustub, bustub->catalog_->GetTable("maintable").get()); fmt::println(stderr, "{} entries in the table heap", entry); if (n == trials - 1) { SimpleStreamWriter writer(std::cerr); @@ -126,7 +126,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateTest) { // NOLINT const int thread_cnt = 8; const int number_cnt = 20; Execute(*bustub, generate_insert_sql(number_cnt), false); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); update_threads.reserve(thread_cnt); std::map> operation_result; std::mutex result_mutex; @@ -183,7 +183,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateTest) { // NOLINT } auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); if (n == trials - 1 || n == trials - 2) { SimpleStreamWriter writer(std::cerr); fmt::println(stderr, "--- the following data might be manually inspected by TAs ---"); @@ -214,7 +214,7 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateAbortTest) { // NOLINT Execute(*bustub, "CREATE TABLE maintable(a int primary key, b int)"); std::vector update_threads; Execute(*bustub, generate_insert_sql(number_cnt), false); - TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable"), number_cnt); + TableHeapEntryNoMoreThan(*bustub, bustub->catalog_->GetTable("maintable").get(), number_cnt); update_threads.reserve(thread_cnt); std::map> operation_result; std::mutex result_mutex; @@ -273,10 +273,10 @@ TEST(TxnIndexTest, DISABLED_IndexConcurrentUpdateAbortTest) { // NOLINT std::terminate(); } } - auto *table_info = bustub->catalog_->GetTable("maintable"); + auto table_info = bustub->catalog_->GetTable("maintable"); auto query_txn = BeginTxn(*bustub, "query_txn"); WithTxn(query_txn, QueryShowResult(*bustub, _var, _txn, "SELECT * FROM maintable", expected_rows)); - TableHeapEntryNoMoreThan(*bustub, table_info, number_cnt); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), number_cnt); if (n >= trials - 2) { SimpleStreamWriter writer(std::cerr); fmt::println(stderr, "--- the following data might be manually inspected by TAs ---"); diff --git a/test/txn/txn_index_test.cpp b/test/txn/txn_index_test.cpp index b04bf94f6..162685589 100644 --- a/test/txn/txn_index_test.cpp +++ b/test/txn/txn_index_test.cpp @@ -22,37 +22,37 @@ TEST(TxnIndexTest, DISABLED_IndexInsertTest) { // NOLINT auto table_info = bustub->catalog_->GetTable("maintable"); auto txn1 = BeginTxn(*bustub, "txn1"); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 0)")); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn1, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {1, 0}, })); WithTxn(txn1, ExecuteTxnTainted(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 1)")); - TxnMgrDbg("after txn1 taint", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 1); + TxnMgrDbg("after txn1 taint", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 1); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2, 2)")); - TxnMgrDbg("after txn2 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, })); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 2); + TxnMgrDbg("after txn2 commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 2); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3, 3)")); - TxnMgrDbg("after txn3 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, {3, 3}, })); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn3 commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 3); + TxnMgrDbg("after txn3 commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); auto txn4 = BeginTxn(*bustub, "txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, @@ -61,19 +61,19 @@ TEST(TxnIndexTest, DISABLED_IndexInsertTest) { // NOLINT {3, 3}, })); WithTxn(txn4, ExecuteTxnTainted(*bustub, _var, _txn, "INSERT INTO maintable VALUES (3, 4)")); - TxnMgrDbg("after txn4 taint", bustub->txn_manager_.get(), table_info, table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 3); + TxnMgrDbg("after txn4 taint", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 3); auto txn5 = BeginTxn(*bustub, "txn5"); WithTxn(txn5, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 4)")); - TxnMgrDbg("after txn5 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn5 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn5, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {2, 2}, {3, 3}, {4, 4}, })); - TableHeapEntryNoMoreThan(*bustub, table_info, 4); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 4); auto txn6 = BeginTxn(*bustub, "txn6"); WithTxn(txn6, QueryShowResult(*bustub, _var, _txn, query, @@ -97,16 +97,16 @@ TEST(TxnIndexTest, DISABLED_InsertDeleteTest) { // NOLINT WithTxn(txn1, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4}, IntResult{{1, 0}, {2, 0}, {3, 0}, {4, 0}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn1_reverify = BeginTxn(*bustub, "txn1_reverify"); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 delete", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); - TableHeapEntryNoMoreThan(*bustub, table_info, 4); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 4); // hidden tests in-between @@ -136,7 +136,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 0), (6, 0)")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 5")); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 6")); - TxnMgrDbg("after preparation", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after preparation", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); // at this point, we have (4, 0) inserted, (5, 0) deleted, and (6, 0) self inserted and deleted. return {txn1_reverify, txn2_reverify, txn3}; }; @@ -163,9 +163,9 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT IntResult{{1, 0}, {}, {}, {4, 0}, {}, {}})); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (2, 1), (5, 1), (3, 1), (6, 1)")); - TxnMgrDbg("after txn3 insert operations", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 insert operations", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col2 = col2 + 10")); - TxnMgrDbg("after txn3 update operations", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 update operations", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{ {1, 10}, @@ -185,7 +185,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT {6, 11}, })); WithTxn(txn3, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after commit", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn4 = BeginTxn(*bustub, "txn4"); WithTxn(txn4, QueryShowResult(*bustub, _var, _txn, query, @@ -207,7 +207,7 @@ TEST(TxnIndexTest, DISABLED_UpdateTest) { // NOLINT {6, 11}, })); reverify(bustub, txn1_reverify, txn2_reverify, query); - TableHeapEntryNoMoreThan(*bustub, table_info, 6); + TableHeapEntryNoMoreThan(*bustub, table_info.get(), 6); } // hidden tests... } @@ -223,16 +223,16 @@ TEST(GradingTxnIndexTest, DISABLED_IndexUpdateConflictTest) { // NOLINT WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (1, 0), (2, 0), (3, 0)")); WithTxn(txn1, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 2")); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "INSERT INTO maintable VALUES (4, 0)")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 1")); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "DELETE FROM maintable WHERE col1 = 3")); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 modification", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 modification", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); WithTxn(txn3, ExecuteTxnTainted(*bustub, _var, _txn, "UPDATE maintable SET col2 = 2 WHERE col1 = 1")); - TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn3 tainted", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); // hidden tests... } @@ -249,14 +249,14 @@ TEST(TxnIndexTest, DISABLED_UpdatePrimaryKeyTest) { // NOLINT WithTxn(txn1, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4}, IntResult{{1, 0}, {2, 0}, {3, 0}, {4, 0}})); WithTxn(txn1, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn1 insert", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn2 = BeginTxn(*bustub, "txn2"); WithTxn(txn2, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col1 = col1 + 1")); WithTxn(txn2, QueryShowResult(*bustub, _var, _txn, query, IntResult{{2, 0}, {3, 0}, {4, 0}, {5, 0}})); WithTxn(txn2, QueryIndex(*bustub, _var, _txn, query, "col1", std::vector{1, 2, 3, 4, 5}, IntResult{{}, {2, 0}, {3, 0}, {4, 0}, {5, 0}})); WithTxn(txn2, CommitTxn(*bustub, _var, _txn)); - TxnMgrDbg("after txn2 update", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("after txn2 update", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto txn3 = BeginTxn(*bustub, "txn3"); WithTxn(txn3, ExecuteTxn(*bustub, _var, _txn, "UPDATE maintable SET col1 = col1 - 2")); WithTxn(txn3, QueryShowResult(*bustub, _var, _txn, query, IntResult{{0, 0}, {1, 0}, {2, 0}, {3, 0}})); diff --git a/test/txn/txn_scan_test.cpp b/test/txn/txn_scan_test.cpp index 930911a16..adb9ef809 100644 --- a/test/txn/txn_scan_test.cpp +++ b/test/txn/txn_scan_test.cpp @@ -199,7 +199,7 @@ TEST(TxnScanTest, DISABLED_ScanTest) { // NOLINT Tuple{{IntNull(), DoubleNull(), BoolNull()}, schema.get()}); bustub->txn_manager_->UpdateUndoLink(rid4, prev_log_5, nullptr); - TxnMgrDbg("before verify scan", bustub->txn_manager_.get(), table_info, table_info->table_.get()); + TxnMgrDbg("before verify scan", bustub->txn_manager_.get(), table_info.get(), table_info->table_.get()); auto query = "SELECT * FROM maintable"; fmt::println(stderr, "A: Verify txn0"); From a855696214e803dc63e0cb168f4fe71dd3ef83e0 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 27 Oct 2024 13:08:36 -0400 Subject: [PATCH 19/21] sync private --- test/CMakeLists.txt | 2 +- test/sql/p3.16-sort-limit.slt | 485 +++++++++++++++++++++------------ test/sql/p3.leaderboard-q1.slt | 42 ++- test/sql/p3.leaderboard-q2.slt | 51 ++-- test/sql/p3.leaderboard-q3.slt | 39 +-- test/sql/p3.leaderboard-q4.slt | 3 - 6 files changed, 370 insertions(+), 252 deletions(-) delete mode 100644 test/sql/p3.leaderboard-q4.slt diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 08651f73b..81609100d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -72,7 +72,7 @@ set(BUSTUB_SLT_SOURCES "${PROJECT_SOURCE_DIR}/test/sql/p3.18-integration-1.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.19-integration-2.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.20-window-function.slt" - "${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q1-window.slt" + "${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q1.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q2.slt" "${PROJECT_SOURCE_DIR}/test/sql/p3.leaderboard-q3.slt" ) diff --git a/test/sql/p3.16-sort-limit.slt b/test/sql/p3.16-sort-limit.slt index e113abfdc..f20801a34 100644 --- a/test/sql/p3.16-sort-limit.slt +++ b/test/sql/p3.16-sort-limit.slt @@ -1,4 +1,4 @@ -# 4 pts +# 10 pts # Simple sort @@ -47,120 +47,220 @@ select * from test_simple_seq_2 limit 15; # Harder Test with sort and limit statement ok -create table temp_1(colA int, colB int, colC int, colD int); +create table temp_1(col1 int, col2 int, col3 int, col4 int, col5 int, col6 int, col7 int, col8 int); # Select on empty table with sort query -select * from temp_1 order by colA; +select * from temp_1 order by col1; ---- statement ok insert into temp_1 values - (0 , 1, 6113, 48270), - (1 , 5, 8005, 22497), - (2 , 0, 4476, 73541), - (9 , 2, 2600, 32938), - (10, 8, 398 , 60977), - (11, 1, 5472, 33166), - (12, 3, 1107, 94947), - (13, 0, 4153, 54624), - (14, 3, 1907, 48515), - (15, 6, 9754, 95830), - (16, 8, 5252, 96696), - (3 , 2, 290 , 20860), - (4 , 0, 3362, 47696), - (5 , 8, 7022, 59586), - (6 , 2, 170 , 92798), - (7 , 2, 8524, 19746), - (8 , 8, 3074, 56174), - (17, 3, 4819, 99411), - (18, 9, 666 , 86073), - (19, 3, 701 , 34675), - (20, 2, 2307, 97170), - (28, 5, 8710, 194 ), - (29, 5, 5519, 4256 ), - (30, 0, 3803, 18357), - (31, 6, 219 , 2090 ), - (32, 2, 3842, 38160), - (33, 8, 991 , 24527), - (34, 4, 1443, 41478), - (35, 2, 7564, 14242), - (21, 4, 194 , 42522), - (22, 3, 4256, 54404), - (23, 7, 6037, 70355), - (24, 6, 1973, 98970), - (25, 3, 2090, 701 ), - (26, 2, 5392, 94519), - (27, 0, 8143, 47916), - (36, 6, 2269, 54671), - (37, 3, 3582, 77724), - (38, 2, 5267, 69339), - (39, 0, 1180, 94216), - (40, 6, 3158, 16603), - (41, 3, 4878, 85762), - (42, 1, 34 , 95622), - (43, 6, 9359, 1443 ), - (44, 0, 2173, 31618), - (45, 3, 9616, 67805), - (46, 2, 2006, 92368), - (47, 0, 6785, 75686), - (48, 6, 2696, 19966), - (49, 1, 3313, 70803), - (50, 7, 4001, 99484), - (51, 8, 9106, 28177), - (52, 1, 8312, 52310), - (58, 8, 483 , 86798), - (59, 6, 9742, 59516), - (60, 5, 4347, 34 ), - (61, 2, 9484, 25743), - (53, 1, 9567, 10624), - (54, 2, 6866, 15963), - (55, 1, 4956, 27755), - (56, 1, 4060, 16227), - (57, 9, 3683, 78077), - (62, 2, 9506, 13806), - (63, 2, 7758, 44219), - (64, 2, 1999, 83926), - (65, 3, 3886, 72321), - (66, 3, 8020, 97035), - (67, 0, 4633, 68232), - (68, 4, 2699, 52465), - (69, 8, 755 , 20385), - (70, 2, 8311, 59841), - (71, 4, 7826, 97071), - (72, 7, 7027, 29049), - (73, 9, 499 , 73848), - (74, 1, 9088, 12950), - (75, 3, 3517, 94485), - (76, 7, 4339, 25951), - (77, 2, 5801, 59170), - (85, 9, 849 , 11512), - (86, 3, 2697, 9484 ), - (87, 2, 3060, 25890), - (88, 2, 7329, 40526), - (89, 1, 9418, 34767), - (90, 9, 6826, 69422), - (91, 1, 1411, 8020 ), - (92, 9, 2110, 28695), - (78, 3, 5737, 59426), - (79, 3, 4299, 97298), - (80, 3, 7683, 21340), - (81, 0, 2045, 3683 ), - (82, 8, 5290, 98787), - (96, 1, 4733, 2699 ), - (97, 1, 2273, 63790), - (98, 3, 1394, 17139), - (99, 6, 4482, 57463), - (83, 3, 2914, 91662), - (84, 9, 4626, 92192), - (93, 4, 2758, 27498), - (94, 5, 8802, 70169), - (95, 9, 5706, 15441); + (196, 9, 79, 147, 766, 65018, 580420, 3460119), + (96, 9, 73, 674, 5266, 132, 141779, 9085955), + (5, 3, 21, 251, 2419, 4040, 454689, 8904729), + (87, 7, 29, 129, 5132, 30303, 378736, 2741233), + (18, 8, 10, 508, 1933, 54020, 125384, 813451), + (75, 2, 41, 901, 593, 14227, 586302, 462945), + (111, 3, 44, 700, 2024, 61402, 787437, 3015027), + (39, 9, 84, 243, 4208, 14273, 384043, 1263705), + (128, 6, 93, 735, 3749, 87702, 353590, 4995735), + (41, 7, 67, 859, 1630, 8890, 346654, 2642419), + (33, 2, 95, 120, 2284, 20382, 656992, 8703768), + (124, 8, 69, 351, 4670, 77529, 139759, 8776939), + (183, 5, 32, 390, 8718, 36152, 686749, 8919342), + (91, 3, 1, 613, 2964, 87648, 509069, 7536978), + (166, 8, 47, 552, 6515, 66148, 324278, 1957978), + (107, 3, 1, 594, 267, 7803, 11909, 366568), + (31, 0, 51, 921, 5840, 48429, 328862, 5960441), + (148, 0, 66, 139, 2130, 78439, 204429, 1286350), + (185, 9, 84, 831, 7327, 14708, 5597, 5096306), + (100, 3, 56, 856, 1409, 5704, 921859, 8296737), + (97, 1, 97, 644, 9674, 48009, 704186, 3668180), + (160, 8, 70, 571, 7936, 22902, 603269, 8680300), + (32, 9, 13, 285, 3097, 3996, 395731, 7687792), + (48, 8, 58, 516, 1321, 9104, 689086, 7547836), + (13, 7, 37, 597, 9695, 79132, 5913, 2729103), + (51, 2, 85, 748, 2277, 90946, 543930, 5704145), + (16, 7, 75, 814, 6433, 96606, 487369, 179266), + (131, 0, 95, 665, 6705, 68624, 389457, 1055001), + (110, 7, 94, 979, 7019, 26419, 268566, 9668807), + (108, 3, 1, 410, 6820, 33364, 580756, 1818944), + (156, 3, 48, 886, 4471, 7582, 242036, 5518578), + (14, 7, 84, 815, 9372, 76305, 936436, 5246864), + (168, 8, 7, 851, 2023, 46784, 687310, 4103789), + (158, 4, 58, 294, 2711, 93255, 610740, 3917117), + (176, 8, 34, 636, 7301, 47976, 569899, 9218292), + (189, 7, 13, 452, 8596, 94212, 682893, 9647479), + (151, 7, 94, 410, 6233, 91520, 940819, 7230491), + (102, 2, 72, 523, 4379, 94749, 544165, 348734), + (147, 6, 67, 708, 8020, 54656, 211346, 5425761), + (146, 6, 4, 393, 6835, 88911, 568402, 4590957), + (95, 0, 92, 180, 2635, 80737, 619176, 4947590), + (98, 2, 84, 36, 5383, 54686, 90558, 3135289), + (43, 2, 88, 577, 7009, 64800, 507828, 5295211), + (191, 3, 51, 117, 3103, 67268, 135031, 8950927), + (187, 1, 93, 803, 6104, 99815, 684391, 5519665), + (12, 5, 43, 767, 7501, 9636, 83576, 5070120), + (58, 4, 89, 871, 5347, 63473, 89035, 2890030), + (49, 1, 46, 286, 9426, 40720, 93086, 9399852), + (171, 1, 61, 381, 3526, 41471, 34075, 9185441), + (71, 0, 29, 448, 3800, 82369, 975429, 3874917), + (188, 1, 61, 916, 4058, 39604, 405586, 891694), + (133, 9, 66, 345, 4546, 17571, 408146, 8155891), + (80, 5, 48, 401, 6773, 66298, 835516, 5003483), + (65, 7, 46, 226, 4705, 84312, 973089, 4319545), + (132, 0, 44, 923, 7435, 1345, 783426, 5120786), + (55, 3, 99, 134, 63, 13196, 284220, 1931990), + (21, 3, 67, 366, 5218, 35569, 603781, 7963823), + (64, 3, 18, 562, 124, 82284, 413419, 7469541), + (115, 2, 57, 1, 2533, 10526, 806424, 6735507), + (86, 1, 72, 47, 1864, 37709, 250122, 7133555), + (165, 4, 80, 442, 2490, 73021, 924437, 7821936), + (59, 5, 90, 876, 4518, 71072, 16420, 6697862), + (123, 3, 92, 951, 9769, 96069, 331647, 2019560), + (19, 7, 8, 866, 3594, 59865, 860895, 1147124), + (37, 9, 44, 896, 6733, 59844, 347449, 4470115), + (145, 3, 21, 711, 223, 65113, 247776, 6286926), + (109, 5, 74, 631, 1617, 52223, 48765, 6012052), + (89, 2, 31, 525, 9975, 21923, 618183, 3074793), + (30, 8, 54, 165, 8934, 10717, 200689, 8326241), + (135, 0, 31, 533, 4479, 43225, 675685, 4584830), + (142, 8, 97, 665, 9823, 46844, 383619, 6444628), + (159, 5, 10, 347, 4333, 81149, 467131, 3495302), + (93, 4, 45, 49, 4327, 54773, 50210, 4033852), + (52, 6, 91, 411, 3138, 55061, 585468, 5056821), + (154, 6, 81, 983, 4486, 77159, 833103, 4968465), + (67, 3, 70, 226, 2823, 80004, 895654, 437490), + (60, 3, 61, 587, 3633, 53753, 972672, 9199994), + (155, 4, 62, 858, 1135, 34382, 494514, 2959301), + (61, 0, 21, 22, 5642, 21864, 313078, 9305193), + (24, 3, 74, 425, 117, 3468, 896998, 9109877), + (140, 1, 71, 21, 2828, 94610, 12838, 1212582), + (57, 5, 7, 617, 2743, 70578, 773995, 2744737), + (112, 8, 60, 77, 6057, 41809, 524022, 7077061), + (105, 5, 54, 290, 2563, 96935, 232157, 4499459), + (179, 7, 36, 79, 9115, 60534, 741330, 5927650), + (82, 4, 91, 302, 1292, 75026, 888084, 8742272), + (35, 3, 95, 13, 8753, 92210, 671499, 5205336), + (172, 9, 22, 546, 8088, 89284, 964185, 39966), + (198, 0, 99, 778, 1528, 52316, 726477, 8219397), + (121, 7, 81, 746, 3116, 71628, 235086, 5966098), + (77, 7, 89, 732, 5803, 94659, 898745, 7829986), + (73, 1, 27, 586, 1410, 43828, 466258, 1943103), + (0, 8, 5, 561, 9989, 87361, 494821, 5840702), + (162, 1, 42, 929, 9622, 39856, 518843, 9852745), + (116, 8, 77, 963, 5488, 30956, 928245, 7855578), + (68, 5, 52, 373, 1322, 7952, 755240, 4880763), + (120, 7, 16, 168, 6744, 9691, 204061, 4253805), + (23, 4, 5, 322, 7775, 4410, 961809, 3225009), + (1, 2, 31, 422, 4453, 7210, 206335, 2045026), + (137, 5, 1, 930, 6654, 83304, 304305, 9773858), + (186, 9, 78, 888, 7407, 52027, 924097, 8606329), + (53, 9, 42, 211, 9846, 61097, 684453, 4213854), + (169, 3, 81, 659, 3459, 2353, 207646, 9481338), + (9, 5, 93, 106, 5472, 88331, 755124, 9894953), + (177, 3, 37, 238, 8807, 29443, 358235, 7280614), + (7, 8, 11, 154, 8374, 74676, 497239, 7923921), + (27, 7, 8, 887, 4592, 68130, 997285, 8035102), + (193, 8, 65, 708, 9371, 99964, 37220, 3893300), + (126, 0, 98, 644, 8145, 5131, 900228, 86417), + (79, 9, 28, 823, 8590, 23300, 806801, 9298308), + (180, 4, 69, 230, 9161, 43700, 738588, 1671536), + (136, 9, 75, 565, 8630, 41623, 545551, 2020603), + (101, 5, 6, 338, 8983, 58203, 57330, 5788803), + (182, 6, 82, 244, 9558, 66182, 418917, 2008979), + (40, 4, 34, 178, 825, 60242, 621162, 8616326), + (84, 4, 47, 877, 3953, 83544, 622038, 4004697), + (106, 2, 40, 476, 1509, 76746, 787497, 5191618), + (90, 2, 96, 640, 8200, 91418, 944866, 8362182), + (143, 5, 34, 710, 1025, 13597, 292787, 1136995), + (10, 0, 97, 333, 1746, 98384, 770109, 7276590), + (22, 9, 4, 171, 8343, 36077, 87048, 4103074), + (125, 8, 37, 430, 8820, 88328, 137510, 2536831), + (167, 8, 36, 72, 6461, 4563, 892235, 4323669), + (88, 5, 21, 684, 6242, 16628, 688491, 2852785), + (127, 6, 94, 235, 9482, 23290, 494525, 32445), + (42, 6, 39, 379, 5631, 51474, 506563, 4082086), + (144, 5, 92, 158, 1891, 4846, 127501, 5091868), + (66, 8, 59, 388, 2509, 7229, 450773, 4992666), + (34, 7, 79, 669, 902, 89891, 435911, 1840339), + (81, 4, 4, 967, 1170, 92808, 244868, 6029276), + (25, 8, 35, 868, 8059, 52702, 124611, 2869517), + (175, 6, 71, 776, 4998, 92846, 340124, 915006), + (36, 1, 7, 485, 7138, 35984, 339740, 4215732), + (74, 7, 64, 386, 121, 77691, 547614, 3943836), + (3, 7, 23, 305, 3878, 93485, 43156, 3921438), + (129, 7, 59, 139, 2438, 98470, 904917, 7754852), + (149, 0, 52, 326, 7765, 24531, 959352, 7732143), + (163, 1, 68, 950, 8610, 35696, 579122, 3084354), + (153, 3, 68, 463, 5311, 94011, 82294, 1015581), + (11, 2, 76, 69, 8076, 81619, 312257, 1930656), + (46, 6, 9, 116, 5967, 41769, 283685, 4522930), + (161, 0, 63, 491, 2590, 14553, 151667, 1239028), + (152, 7, 66, 282, 4766, 22709, 526711, 7306101), + (170, 8, 55, 672, 3974, 45487, 823761, 428878), + (72, 2, 70, 903, 1712, 21708, 203630, 8093216), + (85, 4, 80, 75, 2539, 68936, 828987, 2365244), + (141, 6, 22, 289, 627, 56493, 111716, 2475428), + (99, 7, 11, 724, 3662, 46405, 260985, 6094229), + (17, 3, 8, 218, 7079, 29335, 522580, 1393348), + (138, 7, 44, 600, 8991, 26953, 187679, 2491217), + (114, 8, 32, 275, 6183, 44193, 380432, 1910962), + (173, 0, 83, 100, 3367, 16621, 640206, 2773136), + (50, 3, 46, 494, 6676, 50513, 230812, 8717166), + (139, 4, 84, 497, 7487, 66828, 809011, 3037040), + (150, 2, 98, 560, 6491, 73299, 766200, 2561789), + (54, 1, 92, 136, 7375, 1615, 874417, 8532832), + (62, 1, 52, 175, 7240, 70387, 28071, 3546585), + (92, 2, 86, 754, 8935, 77526, 810276, 1884535), + (194, 9, 84, 887, 8293, 57428, 13305, 4166625), + (117, 6, 55, 784, 4148, 32330, 182024, 9606542), + (104, 4, 74, 29, 8701, 73679, 99074, 6267512), + (63, 4, 4, 198, 9352, 99004, 734374, 7638195), + (118, 5, 61, 18, 6558, 77494, 823400, 7540500), + (83, 1, 1, 314, 128, 50974, 855262, 5617222), + (70, 9, 7, 631, 2287, 35350, 4649, 1123333), + (130, 3, 92, 678, 4290, 33394, 223241, 3461293), + (199, 9, 11, 91, 6896, 94319, 527602, 8222281), + (26, 1, 37, 126, 7323, 60028, 910446, 8299621), + (184, 1, 27, 665, 2372, 30282, 203725, 5814793), + (122, 9, 77, 585, 7558, 32215, 911472, 837405), + (44, 9, 19, 200, 2545, 70842, 89745, 3435765), + (103, 7, 93, 707, 2350, 18066, 780695, 5926799), + (78, 2, 36, 499, 7838, 6035, 419854, 6093766), + (94, 8, 58, 110, 4757, 42114, 598073, 9891358), + (134, 2, 25, 346, 9990, 97041, 996353, 6604388), + (195, 2, 47, 637, 2139, 66667, 317043, 4354233), + (56, 4, 8, 440, 7097, 29112, 428581, 405846), + (157, 6, 67, 789, 572, 52215, 294088, 3587193), + (20, 6, 88, 209, 7012, 96205, 849891, 8671682), + (28, 8, 92, 585, 2310, 41334, 545418, 1334792), + (4, 5, 2, 755, 2853, 34184, 414444, 171994), + (181, 3, 85, 915, 8122, 62571, 639142, 8752584), + (119, 5, 14, 618, 8072, 40581, 76034, 7244977), + (197, 9, 99, 623, 6246, 23617, 514078, 8376894), + (8, 0, 99, 699, 3253, 88194, 522672, 7341468), + (2, 9, 39, 499, 7022, 86936, 848301, 746939), + (192, 6, 74, 653, 2599, 52200, 760612, 7420299), + (190, 6, 44, 51, 184, 43594, 329767, 9381954), + (178, 0, 33, 773, 5278, 44429, 452382, 7142150), + (164, 5, 80, 615, 4826, 89334, 216827, 6267318), + (15, 4, 99, 43, 7336, 18702, 932476, 4751240), + (76, 3, 27, 181, 1112, 30392, 427843, 6401112), + (47, 7, 78, 119, 9233, 17182, 72665, 1921751), + (6, 8, 91, 259, 9318, 22573, 724639, 9856469), + (174, 7, 38, 163, 6614, 6389, 215981, 5410513), + (113, 5, 70, 719, 9300, 57448, 47709, 9456206), + (69, 7, 21, 434, 5673, 85399, 354546, 2362967), + (45, 4, 71, 397, 3677, 2556, 316835, 5636529), + (38, 1, 93, 307, 8805, 38987, 956976, 7329265), + (29, 1, 73, 173, 3972, 18059, 968740, 9895271); statement ok -create table temp_2(colA int, colB int, colC int); +create table temp_2(col1 int, col2 int, col3 int); statement ok insert into temp_2 values @@ -266,57 +366,97 @@ insert into temp_2 values (99, 722, 9); query -select colB, colD, colA, colC from temp_1 order by colB desc, colD, colA desc limit 20; +select col2, col4, col1, col3, col5, col6, col7, col8 from temp_1 order by col2 desc, col4, col1 desc limit 50; ---- -9 11512 85 849 -9 15441 95 5706 -9 28695 92 2110 -9 69422 90 6826 -9 73848 73 499 -9 78077 57 3683 -9 86073 18 666 -9 92192 84 4626 -8 20385 69 755 -8 24527 33 991 -8 28177 51 9106 -8 56174 8 3074 -8 59586 5 7022 -8 60977 10 398 -8 86798 58 483 -8 96696 16 5252 -8 98787 82 5290 -7 25951 76 4339 -7 29049 72 7027 -7 70355 23 6037 +9 91 199 11 6896 94319 527602 8222281 +9 147 196 79 766 65018 580420 3460119 +9 171 22 4 8343 36077 87048 4103074 +9 200 44 19 2545 70842 89745 3435765 +9 211 53 42 9846 61097 684453 4213854 +9 243 39 84 4208 14273 384043 1263705 +9 285 32 13 3097 3996 395731 7687792 +9 345 133 66 4546 17571 408146 8155891 +9 499 2 39 7022 86936 848301 746939 +9 546 172 22 8088 89284 964185 39966 +9 565 136 75 8630 41623 545551 2020603 +9 585 122 77 7558 32215 911472 837405 +9 623 197 99 6246 23617 514078 8376894 +9 631 70 7 2287 35350 4649 1123333 +9 674 96 73 5266 132 141779 9085955 +9 823 79 28 8590 23300 806801 9298308 +9 831 185 84 7327 14708 5597 5096306 +9 887 194 84 8293 57428 13305 4166625 +9 888 186 78 7407 52027 924097 8606329 +9 896 37 44 6733 59844 347449 4470115 +8 72 167 36 6461 4563 892235 4323669 +8 77 112 60 6057 41809 524022 7077061 +8 110 94 58 4757 42114 598073 9891358 +8 154 7 11 8374 74676 497239 7923921 +8 165 30 54 8934 10717 200689 8326241 +8 259 6 91 9318 22573 724639 9856469 +8 275 114 32 6183 44193 380432 1910962 +8 351 124 69 4670 77529 139759 8776939 +8 388 66 59 2509 7229 450773 4992666 +8 430 125 37 8820 88328 137510 2536831 +8 508 18 10 1933 54020 125384 813451 +8 516 48 58 1321 9104 689086 7547836 +8 552 166 47 6515 66148 324278 1957978 +8 561 0 5 9989 87361 494821 5840702 +8 571 160 70 7936 22902 603269 8680300 +8 585 28 92 2310 41334 545418 1334792 +8 636 176 34 7301 47976 569899 9218292 +8 665 142 97 9823 46844 383619 6444628 +8 672 170 55 3974 45487 823761 428878 +8 708 193 65 9371 99964 37220 3893300 +8 851 168 7 2023 46784 687310 4103789 +8 868 25 35 8059 52702 124611 2869517 +8 963 116 77 5488 30956 928245 7855578 +7 79 179 36 9115 60534 741330 5927650 +7 119 47 78 9233 17182 72665 1921751 +7 129 87 29 5132 30303 378736 2741233 +7 139 129 59 2438 98470 904917 7754852 +7 163 174 38 6614 6389 215981 5410513 +7 168 120 16 6744 9691 204061 4253805 +7 226 65 46 4705 84312 973089 4319545 query -select * from temp_1 order by colB desc, colA + colD - colA desc, colA asc limit 20; +select * from temp_1 order by col2 desc, col1 + col4 - col1 desc, col1 asc limit 30; ---- -84 9 4626 92192 -18 9 666 86073 -57 9 3683 78077 -73 9 499 73848 -90 9 6826 69422 -92 9 2110 28695 -95 9 5706 15441 -85 9 849 11512 -82 8 5290 98787 -16 8 5252 96696 -58 8 483 86798 -10 8 398 60977 -5 8 7022 59586 -8 8 3074 56174 -51 8 9106 28177 -33 8 991 24527 -69 8 755 20385 -50 7 4001 99484 -23 7 6037 70355 -72 7 7027 29049 +37 9 44 896 6733 59844 347449 4470115 +186 9 78 888 7407 52027 924097 8606329 +194 9 84 887 8293 57428 13305 4166625 +185 9 84 831 7327 14708 5597 5096306 +79 9 28 823 8590 23300 806801 9298308 +96 9 73 674 5266 132 141779 9085955 +70 9 7 631 2287 35350 4649 1123333 +197 9 99 623 6246 23617 514078 8376894 +122 9 77 585 7558 32215 911472 837405 +136 9 75 565 8630 41623 545551 2020603 +172 9 22 546 8088 89284 964185 39966 +2 9 39 499 7022 86936 848301 746939 +133 9 66 345 4546 17571 408146 8155891 +32 9 13 285 3097 3996 395731 7687792 +39 9 84 243 4208 14273 384043 1263705 +53 9 42 211 9846 61097 684453 4213854 +44 9 19 200 2545 70842 89745 3435765 +22 9 4 171 8343 36077 87048 4103074 +196 9 79 147 766 65018 580420 3460119 +199 9 11 91 6896 94319 527602 8222281 +116 8 77 963 5488 30956 928245 7855578 +25 8 35 868 8059 52702 124611 2869517 +168 8 7 851 2023 46784 687310 4103789 +193 8 65 708 9371 99964 37220 3893300 +170 8 55 672 3974 45487 823761 428878 +142 8 97 665 9823 46844 383619 6444628 +176 8 34 636 7301 47976 569899 9218292 +28 8 92 585 2310 41334 545418 1334792 +160 8 70 571 7936 22902 603269 8680300 +0 8 5 561 9989 87361 494821 5840702 query -select colA from (select colC, colA, colB, from temp_2 order by colC - colB + colA, colA limit 20); +select col1 from (select col3, col1, col2, from temp_2 order by col3 - col2 + col1, col1 limit 20); ---- 1 19 @@ -342,39 +482,44 @@ select colA from (select colC, colA, colB, from temp_2 order by colC - colB + co # Repeat query rowsort -select * from __mock_table_123, (select * from temp_1 order by colA desc limit 3); +select * from __mock_table_123, (select * from temp_1 order by col1 desc limit 3); ---- -1 99 6 4482 57463 -1 98 3 1394 17139 -1 97 1 2273 63790 -2 99 6 4482 57463 -2 98 3 1394 17139 -2 97 1 2273 63790 -3 99 6 4482 57463 -3 98 3 1394 17139 -3 97 1 2273 63790 +1 199 9 11 91 6896 94319 527602 8222281 +1 198 0 99 778 1528 52316 726477 8219397 +1 197 9 99 623 6246 23617 514078 8376894 +2 199 9 11 91 6896 94319 527602 8222281 +2 198 0 99 778 1528 52316 726477 8219397 +2 197 9 99 623 6246 23617 514078 8376894 +3 199 9 11 91 6896 94319 527602 8222281 +3 198 0 99 778 1528 52316 726477 8219397 +3 197 9 99 623 6246 23617 514078 8376894 # remember to enable your hash join optimizer to pass this # you could disable this ensure if you haven't implemented it yet query rowsort +ensure:hash_join select * from temp_2 t2 inner join - (select colB, colD, colA, colC from temp_1 order by colB desc, colD, colA desc limit 10 ) t1 - on t1.colA = t2.colA; + (select col2, col4, col1, col3 from temp_1 order by col2 desc, col4, col1 desc limit 30 ) t1 + on t1.col1 = t2.col1; ---- -85 779 5 9 11512 85 849 -95 120 5 9 15441 95 5706 -92 815 2 9 28695 92 2110 -90 914 0 9 69422 90 6826 -73 782 3 9 73848 73 499 -57 346 7 9 78077 57 3683 -18 398 8 9 86073 18 666 -84 711 4 9 92192 84 4626 -69 603 9 8 20385 69 755 -33 701 3 8 24527 33 991 +22 387 2 9 171 22 4 +44 975 4 9 200 44 19 +53 770 3 9 211 53 42 +39 160 9 9 243 39 84 +32 666 2 9 285 32 13 +2 837 2 9 499 2 39 +70 107 0 9 631 70 7 +96 662 6 9 674 96 73 +79 125 9 9 823 79 28 +37 812 7 9 896 37 44 +94 377 4 8 110 94 58 +7 88 7 8 154 7 11 +30 132 0 8 165 30 54 +6 592 6 8 259 6 91 +66 529 6 8 388 66 59 -# Large amount of data +# Very large amount of data, spanning multiple sort pages in external merge sort query select * from __mock_external_merge_sort_input order by v2 desc, v3 asc limit 100; ---- diff --git a/test/sql/p3.leaderboard-q1.slt b/test/sql/p3.leaderboard-q1.slt index df4455d98..6981725fd 100644 --- a/test/sql/p3.leaderboard-q1.slt +++ b/test/sql/p3.leaderboard-q1.slt @@ -1,27 +1,21 @@ statement ok -create table t1(x int, y int, z int); +explain (o) select count(*), max(__mock_t4_1m.x), max(__mock_t4_1m.y), max(__mock_t5_1m.x), max(__mock_t5_1m.y), max(__mock_t6_1m.x), max(__mock_t6_1m.y) + from __mock_t4_1m, __mock_t5_1m, __mock_t6_1m + where (__mock_t4_1m.x = __mock_t5_1m.x) + and (__mock_t6_1m.y = __mock_t5_1m.y) + and (__mock_t4_1m.y >= 1000000) + and (__mock_t4_1m.y < 1500000) + and (__mock_t6_1m.x < 150000) + and (__mock_t6_1m.x >= 100000); -statement ok -create index t1xy on t1(x, y); - -query -INSERT INTO t1 SELECT * FROM __mock_t1; ----- -1000000 - -statement ok -explain (o) select * from t1 where x >= 90 and y = 10; - -query rowsort +timing:x10:.q1 -select * from t1 where x >= 90 and y = 10; +query +timing:x10:.q2 +select count(*), max(__mock_t4_1m.x), max(__mock_t4_1m.y), max(__mock_t5_1m.x), max(__mock_t5_1m.y), max(__mock_t6_1m.x), max(__mock_t6_1m.y) + from __mock_t4_1m, __mock_t5_1m, __mock_t6_1m + where (__mock_t4_1m.x = __mock_t5_1m.x) + and (__mock_t6_1m.y = __mock_t5_1m.y) + and (__mock_t4_1m.y >= 1000000) + and (__mock_t4_1m.y < 1500000) + and (__mock_t6_1m.x < 150000) + and (__mock_t6_1m.x >= 100000); ---- -91 10 910010 -92 10 920010 -95 10 950010 -93 10 930010 -98 10 980010 -96 10 960010 -90 10 900010 -99 10 990010 -97 10 970010 -94 10 940010 +400000 149999 1499990 149999 1499990 149999 1499990 diff --git a/test/sql/p3.leaderboard-q2.slt b/test/sql/p3.leaderboard-q2.slt index 6981725fd..07867767f 100644 --- a/test/sql/p3.leaderboard-q2.slt +++ b/test/sql/p3.leaderboard-q2.slt @@ -1,21 +1,36 @@ statement ok -explain (o) select count(*), max(__mock_t4_1m.x), max(__mock_t4_1m.y), max(__mock_t5_1m.x), max(__mock_t5_1m.y), max(__mock_t6_1m.x), max(__mock_t6_1m.y) - from __mock_t4_1m, __mock_t5_1m, __mock_t6_1m - where (__mock_t4_1m.x = __mock_t5_1m.x) - and (__mock_t6_1m.y = __mock_t5_1m.y) - and (__mock_t4_1m.y >= 1000000) - and (__mock_t4_1m.y < 1500000) - and (__mock_t6_1m.x < 150000) - and (__mock_t6_1m.x >= 100000); +explain (o) select v, d1, d2 from ( + select + v, max(v1) as d1, max(v1) + max(v1) + max(v2) as d2, + min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2) + from __mock_t7 left join (select v4 from __mock_t8 where 1 == 2) on v < v4 group by v +) -query +timing:x10:.q2 -select count(*), max(__mock_t4_1m.x), max(__mock_t4_1m.y), max(__mock_t5_1m.x), max(__mock_t5_1m.y), max(__mock_t6_1m.x), max(__mock_t6_1m.y) - from __mock_t4_1m, __mock_t5_1m, __mock_t6_1m - where (__mock_t4_1m.x = __mock_t5_1m.x) - and (__mock_t6_1m.y = __mock_t5_1m.y) - and (__mock_t4_1m.y >= 1000000) - and (__mock_t4_1m.y < 1500000) - and (__mock_t6_1m.x < 150000) - and (__mock_t6_1m.x >= 100000); +query rowsort ok +timing:x10:.q3 +select v, d1, d2 from ( + select + v, max(v1) as d1, max(v1) + max(v1) + max(v2) as d2, + min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2) + from __mock_t7 left join (select v4 from __mock_t8 where 1 == 2) on v < v4 group by v +) ---- -400000 149999 1499990 149999 1499990 149999 1499990 +19 999999 2999997 +15 999995 2999985 +16 999996 2999988 +14 999994 2999982 +17 999997 2999991 +13 999993 2999979 +18 999998 2999994 +12 999992 2999976 +11 999991 2999973 +10 999990 2999970 +9 999989 2999967 +7 999987 2999961 +8 999988 2999964 +6 999986 2999958 +5 999985 2999955 +3 999983 2999949 +4 999984 2999952 +2 999982 2999946 +1 999981 2999943 +0 999980 2999940 diff --git a/test/sql/p3.leaderboard-q3.slt b/test/sql/p3.leaderboard-q3.slt index 07867767f..86933563c 100644 --- a/test/sql/p3.leaderboard-q3.slt +++ b/test/sql/p3.leaderboard-q3.slt @@ -1,36 +1,3 @@ -statement ok -explain (o) select v, d1, d2 from ( - select - v, max(v1) as d1, max(v1) + max(v1) + max(v2) as d2, - min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2) - from __mock_t7 left join (select v4 from __mock_t8 where 1 == 2) on v < v4 group by v -) - -query rowsort ok +timing:x10:.q3 -select v, d1, d2 from ( - select - v, max(v1) as d1, max(v1) + max(v1) + max(v2) as d2, - min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2), min(v1), max(v2), min(v2), max(v1) + min(v1), max(v2) + min(v2) - from __mock_t7 left join (select v4 from __mock_t8 where 1 == 2) on v < v4 group by v -) ----- -19 999999 2999997 -15 999995 2999985 -16 999996 2999988 -14 999994 2999982 -17 999997 2999991 -13 999993 2999979 -18 999998 2999994 -12 999992 2999976 -11 999991 2999973 -10 999990 2999970 -9 999989 2999967 -7 999987 2999961 -8 999988 2999964 -6 999986 2999958 -5 999985 2999955 -3 999983 2999949 -4 999984 2999952 -2 999982 2999946 -1 999981 2999943 -0 999980 2999940 +query rowsort +timing:x20:.q1 +select * from __mock_t10 a join __mock_t11 b on a.x = b.x; +---- \ No newline at end of file diff --git a/test/sql/p3.leaderboard-q4.slt b/test/sql/p3.leaderboard-q4.slt deleted file mode 100644 index 86933563c..000000000 --- a/test/sql/p3.leaderboard-q4.slt +++ /dev/null @@ -1,3 +0,0 @@ -query rowsort +timing:x20:.q1 -select * from __mock_t10 a join __mock_t11 b on a.x = b.x; ----- \ No newline at end of file From c254996d624eb4a4620483eb121c7680bb88e2a7 Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 27 Oct 2024 13:08:58 -0400 Subject: [PATCH 20/21] redistribute points --- test/sql/p3.12-repeat-execute.slt | 2 +- test/sql/p3.13-nested-index-join.slt | 2 + test/sql/p3.14-hash-join.slt | 2 +- test/sql/p3.18-integration-1.slt | 2 +- test/sql/p3.19-integration-2.slt | 58 ++++++++++++++-------------- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/test/sql/p3.12-repeat-execute.slt b/test/sql/p3.12-repeat-execute.slt index 861973296..9528301a1 100644 --- a/test/sql/p3.12-repeat-execute.slt +++ b/test/sql/p3.12-repeat-execute.slt @@ -1,4 +1,4 @@ -# 5 pts +# 4 pts # Put everything on the right side of NLJ statement ok diff --git a/test/sql/p3.13-nested-index-join.slt b/test/sql/p3.13-nested-index-join.slt index a8bd12ae2..79681f6f5 100644 --- a/test/sql/p3.13-nested-index-join.slt +++ b/test/sql/p3.13-nested-index-join.slt @@ -1,3 +1,5 @@ +# 6 pts + statement ok set force_optimizer_starter_rule=yes diff --git a/test/sql/p3.14-hash-join.slt b/test/sql/p3.14-hash-join.slt index 9dfe55e47..d7af39b4f 100644 --- a/test/sql/p3.14-hash-join.slt +++ b/test/sql/p3.14-hash-join.slt @@ -1,4 +1,4 @@ -# 5 pts +# 4 pts # Show office hours on lecture days # "rowsort" means that the order of result doesn't matter. diff --git a/test/sql/p3.18-integration-1.slt b/test/sql/p3.18-integration-1.slt index 31275afe5..db4fa7f64 100644 --- a/test/sql/p3.18-integration-1.slt +++ b/test/sql/p3.18-integration-1.slt @@ -1,4 +1,4 @@ -# 10 pts +# 8 pts # This is something done by some TAs in some start-ups before. Once they got a wrong result # in a query, they split the query into parts so as to find which one goes wrong... # diff --git a/test/sql/p3.19-integration-2.slt b/test/sql/p3.19-integration-2.slt index 3840e41c5..0388e5a67 100644 --- a/test/sql/p3.19-integration-2.slt +++ b/test/sql/p3.19-integration-2.slt @@ -4,17 +4,21 @@ # This test is like how a data engineer works towards their goal. They query some data, # store it (materialize it), and query some more data again, until they reach their goal. +# Note(f24): Make `src_label` and `dst_label` INTEGER because the current external merge sort implementation +# only supports sorting on fixed-length data. Should be VARCHAR(8) if var-length data sorting is supported in +# the future. + statement ok -- still the graph :) -CREATE TABLE graph(src int, dst int, src_label VARCHAR(8), dst_label VARCHAR(8), distance int); +CREATE TABLE graph(src int, dst int, src_label int, dst_label int, distance int); statement ok -- and we materialize the result -CREATE TABLE result(src int, dst int, src_label VARCHAR(8), dst_label VARCHAR(8), distance int, steps int); +CREATE TABLE result(src int, dst int, src_label int, dst_label int, distance int, steps int); statement ok -- temp table (as we don't support union and insert into the table selected from) -CREATE TABLE tmp(src int, dst int, src_label VARCHAR(8), dst_label VARCHAR(8), distance int, steps int); +CREATE TABLE tmp(src int, dst int, src_label int, dst_label int, distance int, steps int); statement ok INSERT INTO graph SELECT * FROM __mock_graph; @@ -24,27 +28,25 @@ select count(distance) from __mock_graph; ---- 90 -# Fall 2024: Remove the ORDER BY in the query since it sorts var-length data, which is not supported in the current external merge sort. query -- initialize the result set --- INSERT INTO result SELECT src, src as dst, src_label, src_label as dst_label, 0, 0 FROM __mock_graph GROUP BY src, src_label ORDER BY src; -INSERT INTO result SELECT src, src as dst, src_label, src_label as dst_label, 0, 0 FROM __mock_graph GROUP BY src, src_label; +INSERT INTO result SELECT src, src as dst, src_label, src_label as dst_label, 0, 0 FROM __mock_graph GROUP BY src, src_label ORDER BY src; ---- 10 query rowsort SELECT * FROM result; ---- -0 0 000 000 0 0 -1 1 001 001 0 0 -2 2 002 002 0 0 -3 3 003 003 0 0 -4 4 004 004 0 0 -5 5 005 005 0 0 -6 6 006 006 0 0 -7 7 007 007 0 0 -8 8 008 008 0 0 -9 9 009 009 0 0 +0 0 0 0 0 0 +1 1 100 100 0 0 +2 2 200 200 0 0 +3 3 300 300 0 0 +4 4 400 400 0 0 +5 5 500 500 0 0 +6 6 600 600 0 0 +7 7 700 700 0 0 +8 8 800 800 0 0 +9 9 900 900 0 0 query rowsort +explain:o -- 1st neighbor @@ -122,18 +124,16 @@ INSERT INTO tmp SELECT * FROM ( statement ok INSERT INTO result SELECT * FROM tmp; DELETE FROM tmp; SELECT count(*) FROM result; -# Fall 2024: Remove the ORDER BY in the query since it sorts var-length data, which is not supported in the current external merge sort. query rowsort +explain:o --- SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label ORDER BY dst; -SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label; +SELECT src, src_label, dst, dst_label, count(*), min(distance), max(distance), min(steps), max(steps) FROM result WHERE src = 1 GROUP BY src, src_label, dst, dst_label ORDER BY dst; ---- -1 001 0 000 1000 1 4 1 4 -1 001 1 001 1000 0 4 0 4 -1 001 2 002 1000 1 4 1 4 -1 001 3 003 1000 1 4 1 4 -1 001 4 004 1000 1 4 1 4 -1 001 5 005 1000 1 4 1 4 -1 001 6 006 1000 1 4 1 4 -1 001 7 007 1000 1 4 1 4 -1 001 8 008 1000 1 4 1 4 -1 001 9 009 1000 1 4 1 4 +1 100 0 0 1000 1 4 1 4 +1 100 1 100 1000 0 4 0 4 +1 100 2 200 1000 1 4 1 4 +1 100 3 300 1000 1 4 1 4 +1 100 4 400 1000 1 4 1 4 +1 100 5 500 1000 1 4 1 4 +1 100 6 600 1000 1 4 1 4 +1 100 7 700 1000 1 4 1 4 +1 100 8 800 1000 1 4 1 4 +1 100 9 900 1000 1 4 1 4 From 7903d280a318852bc2fb149cb266229eb36599ec Mon Sep 17 00:00:00 2001 From: Yuanxin Cao Date: Sun, 27 Oct 2024 13:09:24 -0400 Subject: [PATCH 21/21] rename leaderboard test file --- test/sql/p3.leaderboard-q1-index.slt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/sql/p3.leaderboard-q1-index.slt diff --git a/test/sql/p3.leaderboard-q1-index.slt b/test/sql/p3.leaderboard-q1-index.slt new file mode 100644 index 000000000..df4455d98 --- /dev/null +++ b/test/sql/p3.leaderboard-q1-index.slt @@ -0,0 +1,27 @@ +statement ok +create table t1(x int, y int, z int); + +statement ok +create index t1xy on t1(x, y); + +query +INSERT INTO t1 SELECT * FROM __mock_t1; +---- +1000000 + +statement ok +explain (o) select * from t1 where x >= 90 and y = 10; + +query rowsort +timing:x10:.q1 +select * from t1 where x >= 90 and y = 10; +---- +91 10 910010 +92 10 920010 +95 10 950010 +93 10 930010 +98 10 980010 +96 10 960010 +90 10 900010 +99 10 990010 +97 10 970010 +94 10 940010