-
Notifications
You must be signed in to change notification settings - Fork 623
[15721] Implement Sequence in peloton #1292
Conversation
@@ -148,12 +150,13 @@ void Catalog::Bootstrap() { | |||
DatabaseMetricsCatalog::GetInstance(txn); | |||
TableMetricsCatalog::GetInstance(txn); | |||
IndexMetricsCatalog::GetInstance(txn); | |||
QueryMetricsCatalog::GetInstance(txn); | |||
QueryMetricsCatalog::GetInstance(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.
It might be better to keep spaces and lines to be consistent as before.
|
||
SequenceCatalog::~SequenceCatalog() {} | ||
|
||
/* @brief Delete the sequence by 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.
Inconsistent brief here.
* limit. | ||
*/ | ||
int64_t SequenceCatalogObject::get_next_val() { | ||
int64_t result = seq_curr_val; |
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 more comments here?
ResultTypeToString(txn->GetResult()).c_str()); | ||
} | ||
|
||
return (true); |
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 it always returns true here?
create_type = CreateType::SEQUENCE; | ||
database_name = std::string(parse_tree->GetDatabaseName()); | ||
|
||
sequence_name = parse_tree->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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
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 seems to be dead code.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe unnecessary to have mutex for the current implementation.
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.
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
std::vector<type::Value> child_values; | ||
|
||
PELOTON_ASSERT(func_.impl != nullptr); | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already included in ctx. not necessary to cast and pass.
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.
Actually not included, so need to pass it explicitly for sequence functions.
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.
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.
@@ -272,5 +274,69 @@ void AbstractCatalog::AddIndex(const std::vector<oid_t> &key_attrs, | |||
index_name.c_str(), (int)catalog_table_->GetOid()); | |||
} | |||
|
|||
/*@brief Update specific columns using index scan |
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.
/*(space)brief
is probably better
* @exception throws SequenceException if the sequence exceeds the upper/lower | ||
* limit. | ||
*/ | ||
int64_t SequenceCatalogObject::get_next_val() { |
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.
I think function names should be Camel case, even for private functions.
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.
Yes! Please fix!
@@ -30,7 +30,8 @@ namespace executor { | |||
class ExecutorContext { | |||
public: | |||
explicit ExecutorContext(concurrency::TransactionContext *transaction, | |||
codegen::QueryParameters parameters = {}); | |||
codegen::QueryParameters parameters = {}, | |||
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -68,6 +68,10 @@ class OldEngineStringFunctions { | |||
// Upper, Lower | |||
static type::Value Upper(const std::vector<type::Value> &args); | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! These are not string functions!
@@ -74,6 +74,12 @@ class StringFunctions { | |||
// Length will return the number of characters in the given string | |||
static uint32_t Length(executor::ExecutorContext &ctx, const char *str, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions names should be Camel case.
@@ -74,6 +74,12 @@ class StringFunctions { | |||
// Length will return the number of characters in the given string | |||
static uint32_t Length(executor::ExecutorContext &ctx, const char *str, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throw an exception.
// 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"
// 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"
} | ||
|
||
PELOTON_ASSERT(result_tiles->size() == 1); | ||
oid_t result; |
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.
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>();
@@ -181,6 +186,7 @@ int PlanExecutor::ExecutePlan( | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you forgot to delete this line :)
@@ -235,5 +235,18 @@ type::Value OldEngineStringFunctions::Lower( | |||
throw Exception{"Lower not implemented in old engine"}; | |||
} | |||
|
|||
type::Value OldEngineStringFunctions::Nextval( | |||
UNUSED_ATTRIBUTE const std::vector<type::Value> &args) { |
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.
"UNUSED_ATTRIBUTE" may be removed.
} | ||
|
||
type::Value OldEngineStringFunctions::Currval( | ||
UNUSED_ATTRIBUTE const std::vector<type::Value> &args) { |
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.
"UNUSED_ATTRIBUTE" may be removed.
@@ -730,6 +730,16 @@ typedef struct CreateSchemaStmt | |||
bool if_not_exists; /* just do nothing if schema already exists? */ | |||
} CreateSchemaStmt; | |||
|
|||
typedef struct CreateSeqStmt |
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 properly formatted
void PostgresParser::parse_sequence_params(List *options, | ||
parser::CreateStatement *result) { | ||
DefElem *start_value = NULL; | ||
// DefElem *restart_value = 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.
Dead code
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.