Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 3e6348c

Browse files
Added more tests.
1 parent b5c2780 commit 3e6348c

File tree

2 files changed

+121
-12
lines changed

2 files changed

+121
-12
lines changed

src/executor/update_executor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ bool UpdateExecutor::PerformUpdatePrimaryKey(
6363
storage::TileGroupHeader *tile_group_header, oid_t physical_tuple_id,
6464
ItemPointer &old_location) {
6565

66-
/* if (statement_write_set_.find(old_location) != statement_write_set_.end()) {
67-
return true;
68-
} */
69-
7066
auto &transaction_manager =
7167
concurrency::TransactionManagerFactory::GetInstance();
7268

test/sql/update_sql_test.cpp

Lines changed: 121 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ TEST_F(UpdateSQLTests, UpdateSQLCastTest) {
278278
txn_manager.CommitTransaction(txn);
279279
}
280280

281-
TEST_F(UpdateSQLTests, HalloweenTest) {
281+
TEST_F(UpdateSQLTests, HalloweenProblemTest) {
282+
// This SQL Test verifies that executor does not cause the Halloween Problem
283+
// This test checks for tables without Primary Keys
284+
282285
LOG_DEBUG("Bootstrapping...");
283286

284287
auto catalog = catalog::Catalog::GetInstance();
@@ -289,6 +292,12 @@ TEST_F(UpdateSQLTests, HalloweenTest) {
289292

290293
LOG_DEBUG("Bootstrapping completed!");
291294

295+
// Setting ActiveTileGroupCount to 3 in order to trigger the case where
296+
// the executor scans TileGroup 0, inserts an empty version in TileGroup 1.
297+
// It then inserts the updated version of the tuple in TileGroup 2.
298+
// When it scans TileGroup 2, without the statement level WriteSet,
299+
// it would have caused a second update on an already updated Tuple.
300+
292301
size_t active_tilegroup_count = 3;
293302
storage::DataTable::SetActiveTileGroupCount(active_tilegroup_count);
294303

@@ -310,9 +319,80 @@ TEST_F(UpdateSQLTests, HalloweenTest) {
310319
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO test VALUES (10, 1000);");
311320
LOG_DEBUG("Tuple inserted!");
312321

322+
// Update a tuple in the table
323+
LOG_DEBUG("Updating a tuple...");
324+
LOG_DEBUG("Query: UPDATE test SET a = a/2");
325+
326+
std::vector<ResultValue> result;
327+
std::vector<FieldInfo> tuple_descriptor;
328+
std::string error_message;
329+
int rows_affected;
330+
331+
TestingSQLUtil::ExecuteSQLQuery("UPDATE test SET a = a/2;", result,
332+
tuple_descriptor, rows_affected,
333+
error_message);
334+
335+
// Check the return value
336+
EXPECT_EQ(1, rows_affected);
337+
LOG_DEBUG("Tuple Updated!");
313338
txn_manager.CommitTransaction(txn);
314339

315-
// Update a tuple into table
340+
LOG_DEBUG("Selecting updated value.");
341+
txn = txn_manager.BeginTransaction();
342+
// Check value of column a after updating
343+
TestingSQLUtil::ExecuteSQLQuery("SELECT a from test", result,
344+
tuple_descriptor, rows_affected,
345+
error_message);
346+
// Check the return value
347+
txn_manager.CommitTransaction(txn);
348+
349+
EXPECT_EQ(TestingSQLUtil::GetResultValueAsString(result, 0), "5");
350+
LOG_DEBUG("Successfully updated tuple.");
351+
352+
// free the database just created
353+
txn = txn_manager.BeginTransaction();
354+
catalog::Catalog::GetInstance()->DropDatabaseWithName(DEFAULT_DB_NAME, txn);
355+
txn_manager.CommitTransaction(txn);
356+
}
357+
358+
TEST_F(UpdateSQLTests, HalloweenProblemTestWithPK) {
359+
// This SQL Test verifies that executor does not cause the Halloween Problem
360+
// This test checks for tables with Primary Keys
361+
// It checks for updates on both Non-Primary Key column & Primary Key column
362+
363+
LOG_DEBUG("Bootstrapping...");
364+
365+
auto catalog = catalog::Catalog::GetInstance();
366+
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
367+
auto txn = txn_manager.BeginTransaction();
368+
catalog->CreateDatabase(DEFAULT_DB_NAME, txn);
369+
txn_manager.CommitTransaction(txn);
370+
371+
LOG_DEBUG("Bootstrapping completed!");
372+
373+
// active_tilegroup_count set to 3, [Reason: Refer to HalloweenProblemTest]
374+
size_t active_tilegroup_count = 3;
375+
storage::DataTable::SetActiveTileGroupCount(active_tilegroup_count);
376+
377+
LOG_DEBUG("Active tile group count = %zu",
378+
storage::DataTable::GetActiveTileGroupCount());
379+
// Create a table first
380+
LOG_DEBUG("Creating a table...");
381+
LOG_DEBUG("Query: CREATE TABLE test(a INT PRIMARY KEY, b INT)");
382+
383+
TestingSQLUtil::ExecuteSQLQuery("CREATE TABLE test(a INT PRIMARY KEY, b INT);");
384+
385+
LOG_DEBUG("Table created!");
386+
387+
txn = txn_manager.BeginTransaction();
388+
// Insert a tuple into table
389+
LOG_DEBUG("Inserting a tuple...");
390+
391+
LOG_DEBUG("Query: INSERT INTO test VALUES (10, 100)");
392+
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO test VALUES (10, 1000);");
393+
LOG_DEBUG("Tuple inserted!");
394+
395+
// Update a tuple in table
316396
LOG_DEBUG("Updating a tuple...");
317397
LOG_DEBUG("Query: UPDATE test SET a = a/2");
318398

@@ -321,19 +401,18 @@ TEST_F(UpdateSQLTests, HalloweenTest) {
321401
std::string error_message;
322402
int rows_affected;
323403

324-
txn = txn_manager.BeginTransaction();
325404
TestingSQLUtil::ExecuteSQLQuery("UPDATE test SET a = a/2;", result,
326405
tuple_descriptor, rows_affected,
327406
error_message);
328407

329408
// Check the return value
330409
EXPECT_EQ(1, rows_affected);
331-
LOG_DEBUG("Tuple Updated!");
410+
LOG_DEBUG("Tuple Primary Key column Updated!");
332411
txn_manager.CommitTransaction(txn);
333412

334413
LOG_DEBUG("Selecting updated value.");
335414
txn = txn_manager.BeginTransaction();
336-
// Check value of column salary after updating
415+
// Check value of column a after updating
337416
TestingSQLUtil::ExecuteSQLQuery("SELECT a from test", result,
338417
tuple_descriptor, rows_affected,
339418
error_message);
@@ -343,6 +422,34 @@ TEST_F(UpdateSQLTests, HalloweenTest) {
343422
EXPECT_EQ(TestingSQLUtil::GetResultValueAsString(result, 0), "5");
344423
LOG_DEBUG("Successfully updated tuple.");
345424

425+
txn = txn_manager.BeginTransaction();
426+
427+
LOG_DEBUG("Updating a tuple...");
428+
LOG_DEBUG("Query: UPDATE test SET b = b/2");
429+
430+
TestingSQLUtil::ExecuteSQLQuery("UPDATE test SET b = b/2;", result,
431+
tuple_descriptor, rows_affected,
432+
error_message);
433+
434+
EXPECT_EQ(1, rows_affected);
435+
LOG_DEBUG("Tuple Non-Primary Key column Updated!");
436+
txn_manager.CommitTransaction(txn);
437+
438+
LOG_DEBUG("Selecting updated value.");
439+
txn = txn_manager.BeginTransaction();
440+
// Check value of column b after updating
441+
TestingSQLUtil::ExecuteSQLQuery("SELECT b from test", result,
442+
tuple_descriptor, rows_affected,
443+
error_message);
444+
// Check the return value
445+
txn_manager.CommitTransaction(txn);
446+
447+
EXPECT_EQ(TestingSQLUtil::GetResultValueAsString(result, 0), "500");
448+
LOG_DEBUG("Successfully updated tuple.");
449+
450+
451+
452+
346453
// free the database just created
347454
txn = txn_manager.BeginTransaction();
348455
catalog::Catalog::GetInstance()->DropDatabaseWithName(DEFAULT_DB_NAME, txn);
@@ -360,6 +467,7 @@ TEST_F(UpdateSQLTests, MultiTileGroupUpdateSQLTest) {
360467

361468
LOG_DEBUG("Bootstrapping completed!");
362469

470+
// active_tilegroup_count set to 3, [Reason: Refer to HalloweenProblemTest]
363471
size_t active_tilegroup_count = 3;
364472
storage::DataTable::SetActiveTileGroupCount(active_tilegroup_count);
365473

@@ -382,7 +490,7 @@ TEST_F(UpdateSQLTests, MultiTileGroupUpdateSQLTest) {
382490

383491
LOG_DEBUG("Tuple inserted!");
384492

385-
// Update a tuple into table
493+
// Update a tuple in the table
386494
LOG_DEBUG("Updating a tuple...");
387495
LOG_DEBUG("Query: UPDATE test SET a = 10 WHERE b = 100");
388496

@@ -398,15 +506,20 @@ TEST_F(UpdateSQLTests, MultiTileGroupUpdateSQLTest) {
398506
LOG_DEBUG("Query: UPDATE test SET a = 1 WHERE b = 100");
399507
// Check the return value
400508
EXPECT_EQ(1, rows_affected);
401-
LOG_DEBUG("Tuple Updated!");
509+
LOG_DEBUG("Tuple Update successful!");
402510

403511
TestingSQLUtil::ExecuteSQLQuery("UPDATE test SET a = 1 WHERE b = 100;",
404512
result, tuple_descriptor, rows_affected,
405513
error_message);
406514

407515
// Check the return value
516+
// Updating the tuple the second time casued the assertion failure
517+
// on line 641 of timestamp_ordering_transaction_manager.cpp
518+
// This was because it tried to update an already updated version
519+
// of the tuple. This was fixed by the statement level WriteSet.
408520
EXPECT_EQ(1, rows_affected);
409-
LOG_DEBUG("Tuple Updated!");
521+
LOG_DEBUG("Tuple Update successful, again!");
522+
410523

411524
// free the database just created
412525
txn = txn_manager.BeginTransaction();

0 commit comments

Comments
 (0)