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

Conversation

@bdengNE
Copy link

@bdengNE bdengNE commented May 5, 2018

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)

Kangyan-Zhou and others added 30 commits March 22, 2018 16:07
}

/*@brief evict sequence catalog object from cache
* @param sequence_name, database_oid
Copy link

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
Copy link

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
Copy link

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
Copy link

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!
Copy link

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>();
Copy link

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
Copy link

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));
Copy link

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="");
Copy link

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;
Copy link

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()) {
Copy link

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) ||
Copy link

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());
Copy link

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,
Copy link

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);
Copy link

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 {
Copy link

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.

Copy link

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 {
Copy link

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

Copy link

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;
Copy link

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)

Copy link

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
Copy link

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
Copy link

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

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;

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.

Copy link

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,

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();

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());

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?

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;

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) {

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.

Copy link

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.

apavlo added a commit to apavlo/peloton that referenced this pull request Jun 10, 2018
apavlo added a commit to apavlo/peloton that referenced this pull request Jun 11, 2018
apavlo added a commit to apavlo/peloton that referenced this pull request Jun 11, 2018
@apavlo
Copy link
Member

apavlo commented Jun 11, 2018

I am closing this PR. I will merge the sequence code manually without the temporary table patches.

@apavlo apavlo closed this Jun 11, 2018
@apavlo apavlo mentioned this pull request Jun 14, 2018
apavlo added a commit to apavlo/peloton that referenced this pull request Jun 19, 2018
…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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants