-
Notifications
You must be signed in to change notification settings - Fork 619
[15721] Sequence second PR #1345
Conversation
# Conflicts: # src/function/old_engine_string_functions.cpp
| } | ||
|
|
||
| /*@brief evict sequence catalog object from cache | ||
| * @param sequence_name, database_oid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each parameter should be put on a separate line.
| } | ||
|
|
||
| /*@brief get sequence catalog object from cache | ||
| * @param sequence_name, database_oid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each parameter should be put on a separate line.
| } | ||
|
|
||
| /*@brief get the hash key given the sequence information | ||
| * @param sequence_name, database_oid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each parameter should be put on a separate line.
| } | ||
|
|
||
| /* @brief Delete the sequence by name. | ||
| * @param database_oid the databse_oid associated with the sequence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong parameter in doc
| // the result is a vector of executor::LogicalTile | ||
| auto result_tiles = | ||
| GetResultWithIndexScan(column_ids, index_offset, values, txn); | ||
| // carefull! the result tile could be null! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: carefull
| * @return the result of executing CurrVal | ||
| */ | ||
| type::Value SequenceFunctions::_Currval(const std::vector<type::Value> &args) { | ||
| executor::ExecutorContext* ctx=(executor::ExecutorContext*)args[1].GetAs<uint64_t>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not formatted
| } | ||
|
|
||
| /*@brief The wrapper function to get the current value for the specified sequence | ||
| * @param sequence name, executor context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
| if (seq_min > seq_max) { | ||
| throw SequenceException( | ||
| StringUtil::Format( | ||
| "MINVALUE (%d) must be less than MAXVALUE (%d)", seq_min, seq_max)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
less than -> less than or equal to
or: cannot be greater than
| std::function<void(executor::ExecutionResult, | ||
| std::vector<ResultValue> &&)> on_complete); | ||
| std::vector<ResultValue> &&)> on_complete, | ||
| std::string default_database_name=""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not formatted
|
|
||
| typedef struct CreateSeqStmt | ||
| { | ||
| NodeTag type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not formatted
|
|
||
| // check if already in cache | ||
| if (sequence_objects_cache.find(hash_key) != | ||
| sequence_objects_cache.end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to throw an exception for this case?
| int64_t result = seq_curr_val; | ||
| seq_prev_val = result; | ||
| if (seq_increment > 0) { | ||
| if ((seq_max >= 0 && seq_curr_val > seq_max - seq_increment) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some comments to explain the logic?
| std::unique_ptr<storage::Tuple> tuple( | ||
| new storage::Tuple(catalog_table_->GetSchema(), true)); | ||
|
|
||
| auto val0 = type::ValueFactory::GetIntegerValue(GetNextOid()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More meaningful variable names here
| return new_sequence; | ||
| } | ||
|
|
||
| bool SequenceCatalog::UpdateNextVal(oid_t sequence_oid, int64_t nextval, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing doc here
| LOG_INFO("sequence %d will be deleted!", sequence_oid); | ||
|
|
||
| oid_t database_oid = database_object->GetDatabaseOid(); | ||
| DeleteSequenceByName(sequence_name, database_oid, txn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to get the return value of this function and return fail sometimes?
| return pool_.get(); | ||
| } | ||
|
|
||
| std::string ExecutorContext::GetDatabaseName() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually this function is set in header file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what other functions in the same file do, so gonna keep it like this.
| ret = txn_manager.CommitTransaction(mini_txn); | ||
| } | ||
| return val; | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, for the case when no such sequence exists at all.
|
|
||
| type::EphemeralPool *GetPool(); | ||
|
|
||
| std::string GetDatabaseName() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like previous comment, you can make this function inline to return the database name (like what other files do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what other functions in the same file do, so gonna keep it like this.
| CONSTRAINT = 4, // constraint create type | ||
| TRIGGER = 5, // trigger create type | ||
| SCHEMA = 6, // schema create type | ||
| SEQUENCE = 7 // sequencce create type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in comment
|
|
||
| /* @brief get sequence oid from pg_sequence table given sequence_name and | ||
| * database_oid | ||
| * @param database_oid the databse_oid associated with the sequence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong param order
| bool CatalogCache::InsertSequenceObject( | ||
| std::shared_ptr<SequenceCatalogObject> sequence_object) { | ||
| if (!sequence_object || sequence_object->seq_oid == INVALID_OID) { | ||
| return false; // invalid object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, false doesn't indicate the sequence exists in the cache. Probably need to change the @return spec or requires the sequence_object to be valid.
| std::size_t hash_key = GetHashKey(sequence_name, database_oid); | ||
| auto it = sequence_objects_cache.find(hash_key); | ||
| if (it == sequence_objects_cache.end()) { | ||
| return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It said it return object with invalid oid if not found. To make things consistent, instead of returning nullptr, we should probably return an SequenceCatalogObject with seq_oid = INVALID_OID. Or another easier way is to change the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a consistent behavior with the existing methods (like GetTableObejct, etc.) in catalog_cache.cpp so I would like to keep it.
| * @param sequence_name, database_oid | ||
| * @return hash key | ||
| */ | ||
| std::size_t CatalogCache::GetHashKey(const std::string sequence_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but wouldn't using reference, const std::string &, avoid unnecessary copies of strings?
|
|
||
| LOG_INFO("sequence %d will be deleted!", sequence_oid); | ||
|
|
||
| oid_t database_oid = database_object->GetDatabaseOid(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you called GetDataBaseOid() three times. You could instead store it.
| concurrency::TransactionContext *txn) { | ||
| oid_t index_offset = IndexId::DBOID_SEQNAME_KEY; | ||
| std::vector<type::Value> values; | ||
| values.push_back(type::ValueFactory::GetIntegerValue(database_oid).Copy()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need Copy() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just following conventions from other files.
| child_values.push_back(child->Evaluate(tuple1, tuple2, context)); | ||
| } | ||
| if (func_name_ == "nextval" || func_name_ == "currval") { | ||
| uint64_t ctx = (uint64_t)context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting a pointer to a 64bit integer and passing as an BigIntValue doesn't look like a good design for me.
| ->GetSystemCatalogs(database_oid) | ||
| ->GetSequenceCatalog() | ||
| ->GetSequence(database_oid, sequence_name, mini_txn); | ||
| if (sequence_object != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function EvictSequenceObject() grantees to evict the given database_oid. So I think you don't need to search for sequence_object and double check again. Or, since EvictSequenceObject() will return false and true, you can use this information for help you make decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sequence may exist in the catalog but not exist in the cache. In this case, EvictSequenceObject() will return false but we want to call nextval on the sequence.
…g the temp table components...
|
I am closing this PR. I will merge the sequence code manually without the temporary table patches. |
…cmu-db#1345 Checking in the testing files from cmu-db#1345 These should be the last files that we need from from cmu-db#1345 This compiles and passes all the tests except for the sequence test (obviously)
In the second PR, we have fixed the problems found in first PR and modified codes based on the updates in the master branch. In addition, we are currently adding features such as drop sequence and currency control, etc (still implementing them and you will see more commits to the PR very soon)