@@ -212,6 +212,24 @@ storage::DataTable *TestingTransactionUtil::CreateTable(
212
212
return table;
213
213
}
214
214
215
+ void TestingTransactionUtil::AddSecondaryIndex (storage::DataTable *table) {
216
+ // Create unique index on the value column
217
+ std::vector<oid_t > key_attrs = {1 };
218
+ auto tuple_schema = table->GetSchema ();
219
+ bool unique = false ;
220
+ auto key_schema = catalog::Schema::CopySchema (tuple_schema, key_attrs);
221
+ key_schema->SetIndexedColumns (key_attrs);
222
+ auto index_metadata2 = new index ::IndexMetadata (
223
+ " unique_btree_index" , 1235 , TEST_TABLE_OID, CATALOG_DATABASE_OID,
224
+ IndexType::BWTREE, IndexConstraintType::UNIQUE, tuple_schema, key_schema,
225
+ key_attrs, unique);
226
+
227
+ std::shared_ptr<index ::Index> secondary_key_index (
228
+ index ::IndexFactory::GetIndex (index_metadata2));
229
+
230
+ table->AddIndex (secondary_key_index);
231
+ }
232
+
215
233
std::unique_ptr<const planner::ProjectInfo>
216
234
TestingTransactionUtil::MakeProjectInfoFromTuple (const storage::Tuple *tuple) {
217
235
TargetList target_list;
@@ -456,5 +474,83 @@ bool TestingTransactionUtil::ExecuteScan(
456
474
}
457
475
return true ;
458
476
}
477
+
478
+ ResultType TestingTransactionUtil::UpdateTuple (storage::DataTable *table,
479
+ const int key) {
480
+ srand (15721 );
481
+
482
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
483
+ TransactionScheduler scheduler (1 , table, &txn_manager);
484
+ scheduler.Txn (0 ).Update (key, rand () % 15721 );
485
+ scheduler.Txn (0 ).Commit ();
486
+ scheduler.Run ();
487
+
488
+ return scheduler.schedules [0 ].txn_result ;
489
+ }
490
+
491
+ ResultType TestingTransactionUtil::InsertTuple (storage::DataTable *table,
492
+ const int key) {
493
+ srand (15721 );
494
+
495
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
496
+ TransactionScheduler scheduler (1 , table, &txn_manager);
497
+ scheduler.Txn (0 ).Insert (key, rand () % 15721 );
498
+ scheduler.Txn (0 ).Commit ();
499
+ scheduler.Run ();
500
+
501
+ return scheduler.schedules [0 ].txn_result ;
502
+ }
503
+
504
+ ResultType TestingTransactionUtil::BulkInsertTuples (storage::DataTable *table,
505
+ const size_t num_tuples) {
506
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
507
+ TransactionScheduler scheduler (1 , table, &txn_manager);
508
+ for (size_t i = 0 ; i < num_tuples; i++) {
509
+ scheduler.Txn (0 ).Insert (i, i);
510
+ }
511
+ scheduler.Txn (0 ).Commit ();
512
+ scheduler.Run ();
513
+
514
+ return scheduler.schedules [0 ].txn_result ;
515
+ }
516
+
517
+ ResultType TestingTransactionUtil::BulkDeleteTuples (storage::DataTable *table,
518
+ const size_t num_tuples) {
519
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
520
+ TransactionScheduler scheduler (1 , table, &txn_manager);
521
+ for (size_t i = 0 ; i < num_tuples; i++) {
522
+ scheduler.Txn (0 ).Delete (i, false );
523
+ }
524
+ scheduler.Txn (0 ).Commit ();
525
+ scheduler.Run ();
526
+
527
+ return scheduler.schedules [0 ].txn_result ;
528
+ }
529
+
530
+ ResultType TestingTransactionUtil::DeleteTuple (storage::DataTable *table,
531
+ const int key) {
532
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
533
+ TransactionScheduler scheduler (1 , table, &txn_manager);
534
+ scheduler.Txn (0 ).Delete (key);
535
+ scheduler.Txn (0 ).Commit ();
536
+ scheduler.Run ();
537
+
538
+ return scheduler.schedules [0 ].txn_result ;
459
539
}
540
+
541
+ ResultType TestingTransactionUtil::SelectTuple (storage::DataTable *table,
542
+ const int key,
543
+ std::vector<int > &results) {
544
+ auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
545
+ TransactionScheduler scheduler (1 , table, &txn_manager);
546
+ scheduler.Txn (0 ).Read (key);
547
+ scheduler.Txn (0 ).Commit ();
548
+ scheduler.Run ();
549
+
550
+ results = scheduler.schedules [0 ].results ;
551
+
552
+ return scheduler.schedules [0 ].txn_result ;
460
553
}
554
+
555
+ } // namespace test
556
+ } // namespace peloton
0 commit comments