[15721] Implement Sequence in peloton#1292
Conversation
| TableMetricsCatalog::GetInstance(txn); | ||
| IndexMetricsCatalog::GetInstance(txn); | ||
| QueryMetricsCatalog::GetInstance(txn); | ||
| QueryMetricsCatalog::GetInstance(txn); |
There was a problem hiding this comment.
It might be better to keep spaces and lines to be consistent as before.
|
|
||
| SequenceCatalog::~SequenceCatalog() {} | ||
|
|
||
| /* @brief Delete the sequence by name. |
| * limit. | ||
| */ | ||
| int64_t SequenceCatalogObject::get_next_val() { | ||
| int64_t result = seq_curr_val; |
| ResultTypeToString(txn->GetResult()).c_str()); | ||
| } | ||
|
|
||
| return (true); |
| create_type = CreateType::SEQUENCE; | ||
| database_name = std::string(parse_tree->GetDatabaseName()); | ||
|
|
||
| sequence_name = parse_tree->sequence_name; |
There was a problem hiding this comment.
Do you still need to assign default values for fields in createStatement if you always assign values to them explictly here?
There was a problem hiding this comment.
The value could be empty in the postgres, which leave some field undefined.
| parser.BuildParseTree(query).release()); | ||
| EXPECT_TRUE(stmt_list->is_valid); | ||
| if (!stmt_list->is_valid) { | ||
| LOG_ERROR("Message: %s, line: %d, col: %d", stmt_list->parser_msg, |
| bool seq_cycle; // Whether the sequence cycles | ||
| concurrency::TransactionContext *txn_; | ||
|
|
||
| std::mutex sequence_mutex; // mutex for all operations |
There was a problem hiding this comment.
Maybe unnecessary to have mutex for the current implementation.
There was a problem hiding this comment.
Is this mutex being used anywhere? Also, you should use common::synchronization::DirtyMutexLatch
https://github.com/cmu-db/peloton/blob/master/src/include/common/synchronization/mutex_latch.h
| for (auto &child : children_) { | ||
| child_values.push_back(child->Evaluate(tuple1, tuple2, context)); | ||
| } | ||
| uint64_t ctx = (uint64_t)context; |
There was a problem hiding this comment.
Already included in ctx. not necessary to cast and pass.
There was a problem hiding this comment.
Actually not included, so need to pass it explicitly for sequence functions.
yangjuns
left a comment
There was a problem hiding this comment.
Private functions should be CamelCase; Nextval() Currval() should be in a separate files; I think there are fundamental design problems related to default_database_name.
| index_name.c_str(), (int)catalog_table_->GetOid()); | ||
| } | ||
|
|
||
| /*@brief Update specific columns using index scan |
| * @exception throws SequenceException if the sequence exceeds the upper/lower | ||
| * limit. | ||
| */ | ||
| int64_t SequenceCatalogObject::get_next_val() { |
There was a problem hiding this comment.
I think function names should be Camel case, even for private functions.
| explicit ExecutorContext(concurrency::TransactionContext *transaction, | ||
| codegen::QueryParameters parameters = {}); | ||
| codegen::QueryParameters parameters = {}, | ||
| std::string default_database_name = ""); |
There was a problem hiding this comment.
Is this appropriate to add default_database_name here? Even if you want to know the default_database_name when call string_functions, this shouldn't be a separate argument.
There was a problem hiding this comment.
I think we need this but the default value for this parameter should not be an empty string. That's going to cause problems later on.
| static type::Value Lower(const std::vector<type::Value> &args); | ||
|
|
||
| // Sequence-related | ||
| static type::Value Nextval(const std::vector<type::Value> &args); |
There was a problem hiding this comment.
These two functions, Nextval() and Currval() should be put into a new sequence file and update binder to bind the file
There was a problem hiding this comment.
Correct! These are not string functions!
| uint32_t length); | ||
|
|
||
| // Nextval will return the next value of the given sequence | ||
| static uint32_t Nextval(executor::ExecutorContext &ctx, const char *sequence_name); |
There was a problem hiding this comment.
These two functions, Nextval() and Currval() should be put into a new sequence file and update binder to bind the file.
There was a problem hiding this comment.
Andy suggests to merge the two files as other catalogs.
| // transform helper for subquery expressions | ||
| static expression::AbstractExpression *SubqueryExprTransform(SubLink *node); | ||
|
|
||
| static void parse_sequence_params(List *options, |
There was a problem hiding this comment.
Functions names should be Camel case.
| uint32_t length); | ||
|
|
||
| // Nextval will return the next value of the given sequence | ||
| static uint32_t Nextval(executor::ExecutorContext &ctx, const char *sequence_name); |
There was a problem hiding this comment.
These two functions don't seem to be tested.
| #include "catalog/abstract_catalog.h" | ||
| #include "catalog/catalog_defaults.h" | ||
|
|
||
| #define SEQUENCE_CATALOG_NAME "pg_sequence" |
There was a problem hiding this comment.
I think this macro should be declared in catalog_defaults.h.
| const std::string &sequence_name, | ||
| concurrency::TransactionContext *txn) { | ||
| if (txn == nullptr) { | ||
| LOG_TRACE("Do not have transaction to drop sequence: %s", |
There was a problem hiding this comment.
Logging level of LOG_TRACE may be too low here. May consider switching to a higher level, such as LOG_INFO.
There was a problem hiding this comment.
This should throw a CatalogException like the other catalog classes.
| oid_t sequence_oid = SequenceCatalog::GetInstance().GetSequenceOid( | ||
| sequence_name, database_object->GetDatabaseOid(), txn); | ||
| if (sequence_oid == INVALID_OID) { | ||
| LOG_TRACE("Cannot find sequence %s to drop!", sequence_name.c_str()); |
There was a problem hiding this comment.
Logging level of LOG_TRACE may be too low here. May consider switching to a higher level, such as LOG_INFO.
| // 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! |
| // 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! |
| } | ||
|
|
||
| PELOTON_ASSERT(result_tiles->size() == 1); | ||
| oid_t result; |
There was a problem hiding this comment.
Since the variable name "result" does not give any further information, how about compressing lines 293-296 into one line:
return (*result_tiles)[0]->GetValue(0, 0).GetAs<oid_t>();
| std::vector<std::unique_ptr<executor::LogicalTile>> &logical_tile_list) { | ||
| PELOTON_ASSERT(plan != nullptr); | ||
| LOG_TRACE("PlanExecutor Start with transaction"); | ||
| LOG_DEBUG("PlanExecutor 2"); |
There was a problem hiding this comment.
It seems you forgot to delete this line :)
| } | ||
|
|
||
| type::Value OldEngineStringFunctions::Nextval( | ||
| UNUSED_ATTRIBUTE const std::vector<type::Value> &args) { |
| } | ||
|
|
||
| type::Value OldEngineStringFunctions::Currval( | ||
| UNUSED_ATTRIBUTE const std::vector<type::Value> &args) { |
| bool if_not_exists; /* just do nothing if schema already exists? */ | ||
| } CreateSchemaStmt; | ||
|
|
||
| typedef struct CreateSeqStmt |
| void PostgresParser::parse_sequence_params(List *options, | ||
| parser::CreateStatement *result) { | ||
| DefElem *start_value = NULL; | ||
| // DefElem *restart_value = NULL; |
|
Replaced by #1407 |
This pull request contains the implementation of create sequence.
Right now we are treating sequence as normal transaction as Andy suggested in the project status update meeting.
In this pull request, we modified postgresparser.cpp to support CREATE SEQUENCE statement, with options as defined in pg_sequence(10.0). We currently don't support AS(the third-party pg_query table is not updated yet) and OWNED BY(which we plan to discuss with the other team for namespace issue).
We also created a new file in the catalog, called sequence_catalog.cpp , that can deal with insert, get and delete. In the same file, the SequenceCatalogObject class embeds the functionality of the sequence object.