@@ -35,28 +35,32 @@ uint32_t SequenceFunctions::Nextval(executor::ExecutorContext &ctx,
35
35
const char *sequence_name) {
36
36
PELOTON_ASSERT (sequence_name != nullptr );
37
37
concurrency::TransactionContext* txn = ctx.GetTransaction ();
38
- // get the database oid for this transaction
39
- oid_t database_oid = catalog::Catalog::GetInstance ()
40
- ->GetDatabaseObject (ctx.GetDatabaseName (), txn)->GetDatabaseOid ();
41
- LOG_DEBUG (" Get database oid: %u" , database_oid);
38
+
39
+ // HACK: Assume that there is only one database in our cache
40
+ auto all_databases = txn->GetCatalogCache ()->GetAllDatabaseObjects ();
41
+ PELOTON_ASSERT (all_databases.empty () == false );
42
+ auto database_catalog = all_databases[0 ];
43
+ LOG_DEBUG (" Get database oid: %u" , database_catalog->GetDatabaseOid ());
42
44
43
45
// initialize a new transaction for incrementing sequence value
44
46
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance ();
45
47
auto mini_txn = txn_manager.BeginTransaction ();
46
48
47
49
// evict the old cached copy of sequence
48
- txn->catalog_cache .EvictSequenceObject (sequence_name,database_oid);
50
+ txn->GetCatalogCache ()->EvictSequenceObject (sequence_name,
51
+ database_catalog->GetDatabaseOid ());
49
52
auto sequence_object =
50
53
catalog::Catalog::GetInstance ()
51
- ->GetSystemCatalogs (database_oid )
54
+ ->GetSystemCatalogs (database_catalog-> GetDatabaseOid () )
52
55
->GetSequenceCatalog ()
53
- ->GetSequence (database_oid, sequence_name, mini_txn);
56
+ ->GetSequence (database_catalog->GetDatabaseOid (),
57
+ sequence_name, mini_txn);
54
58
55
59
if (sequence_object != nullptr ) {
56
60
uint32_t val = sequence_object->GetNextVal ();
57
61
int64_t curr_val = sequence_object->GetCurrVal ();
58
62
// insert the new copy of sequence into cache for future currval
59
- txn->catalog_cache . InsertSequenceObject (sequence_object);
63
+ txn->GetCatalogCache ()-> InsertSequenceObject (sequence_object);
60
64
61
65
auto ret = txn_manager.CommitTransaction (mini_txn);
62
66
if (ret != ResultType::SUCCESS) {
@@ -65,9 +69,9 @@ uint32_t SequenceFunctions::Nextval(executor::ExecutorContext &ctx,
65
69
}
66
70
67
71
catalog::Catalog::GetInstance ()
68
- ->GetSystemCatalogs (database_oid )
72
+ ->GetSystemCatalogs (database_catalog-> GetDatabaseOid () )
69
73
->GetSequenceCatalog ()
70
- ->InsertCurrValCache (txn-> GetTemporarySchemaName () ,
74
+ ->InsertCurrValCache (" FIXME_SCHEMA " ,
71
75
sequence_name, curr_val);
72
76
return val;
73
77
} else {
@@ -88,23 +92,24 @@ uint32_t SequenceFunctions::Currval(executor::ExecutorContext &ctx,
88
92
PELOTON_ASSERT (sequence_name != nullptr );
89
93
concurrency::TransactionContext* txn = ctx.GetTransaction ();
90
94
// get the database oid for this transaction
91
- oid_t database_oid = catalog::Catalog::GetInstance ()
92
- ->GetDatabaseObject (ctx.GetDatabaseName (), txn)->GetDatabaseOid ();
93
- LOG_DEBUG (" Get database oid: %u" , database_oid);
95
+ // HACK: Assume that there is only one database in our cache
96
+ auto all_databases = txn->GetCatalogCache ()->GetAllDatabaseObjects ();
97
+ PELOTON_ASSERT (all_databases.empty () == false );
98
+ auto database_catalog = all_databases[0 ];
94
99
95
100
// get the sequence copy from cache
96
101
auto sequence_catalog = catalog::Catalog::GetInstance ()
97
- ->GetSystemCatalogs (database_oid )
102
+ ->GetSystemCatalogs (database_catalog-> GetDatabaseOid () )
98
103
->GetSequenceCatalog ();
99
104
100
105
if (sequence_catalog->CheckCachedCurrValExistence (
101
- txn-> GetTemporarySchemaName () , std::string (sequence_name))) {
106
+ " FIXME_SCHEMA " , std::string (sequence_name))) {
102
107
return sequence_catalog->GetCachedCurrVal (
103
- txn-> GetTemporarySchemaName () , std::string (sequence_name));
108
+ " FIXME_SCHEMA " , std::string (sequence_name));
104
109
} else {
105
110
// get sequence from catalog
106
111
auto sequence_object = sequence_catalog
107
- ->GetSequence (database_oid , sequence_name, txn);
112
+ ->GetSequence (database_catalog-> GetDatabaseOid () , sequence_name, txn);
108
113
if (sequence_object != nullptr ) {
109
114
throw SequenceException (
110
115
StringUtil::Format (" currval for sequence \" %s\" is undefined for this session" ,
0 commit comments