-
Notifications
You must be signed in to change notification settings - Fork 819
feat: impl Keyword AUTOINCREMENT
#18715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
In main branch Sequence already support to support and start, step. And now sequence in Databend only support order. |
|
tests/sqllogictests/suites/base/05_ddl/05_0000_ddl_create_tables.test
Outdated
Show resolved
Hide resolved
https://docs.snowflake.com/en/sql-reference/sql/create-table Snowflake use autoincrement as the keyword. Maybe Databend can also follow this approach. |
AUTO INCREMENT
AUTOINCREMENT
a30f025
to
b2cf7cf
Compare
ci test_ut error |
src/query/ee/src/storages/fuse/operations/vacuum_drop_tables.rs
Outdated
Show resolved
Hide resolved
src/query/service/src/interpreters/interpreter_table_add_column.rs
Outdated
Show resolved
Hide resolved
src/query/service/src/interpreters/interpreter_table_drop_column.rs
Outdated
Show resolved
Hide resolved
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.
@drmingdrmer reviewed 4 of 25 files at r1, 3 of 35 files at r3, 3 of 12 files at r5, all commit messages.
Reviewable status: 10 of 50 files reviewed, 12 unresolved discussions (waiting on @dantengsky, @KKould, and @TCeason)
src/query/ast/src/ast/statements/auto_increment.rs
line 25 at r5 (raw file):
pub start: u64, pub step: u64, pub is_order: bool,
this field is not that obvious about the purpose. please add doc comment to explain it.
does it mean is_ordered
or something else?
src/query/ast/src/ast/statements/auto_increment.rs
line 43 at r5 (raw file):
} Ok(()) }
is this Display used to print out a runnable SQL? if it is, use another function or implement another trait for such purpose. Display may not provide any grammar correctness guarantee and further refactoring may break it.
Code quote:
impl Display for AutoIncrement {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "AUTOINCREMENT ({}, {})", self.start, self.step)?;
if self.is_order {
write!(f, " ORDER")?;
} else {
write!(f, " NOORDER")?;
}
Ok(())
}
src/query/sql/src/planner/binder/default_expr.rs
line 57 at r5 (raw file):
/// Helper for binding scalar expression with `BindContext`. pub struct DefaultExprBinder { auto_increment_table_id: Option<MetaId>,
what does this field mean? add doc comment to explain please
src/query/service/src/interpreters/interpreter_table_add_column.rs
Outdated
Show resolved
Hide resolved
src/query/service/src/interpreters/interpreter_table_drop_column.rs
Outdated
Show resolved
Hide resolved
@drmingdrmer the current review comment has been completed, and the auto increment sequence is also completed in the same transaction when the table is created. |
d427567
to
b1b37b1
Compare
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.
@drmingdrmer reviewed 9 of 58 files at r22, 4 of 14 files at r24, 6 of 11 files at r25, all commit messages.
Reviewable status: 24 of 98 files reviewed, 29 unresolved discussions (waiting on @dantengsky, @KKould, and @TCeason)
src/meta/app/src/principal/auto_increment.rs
line 37 at r25 (raw file):
impl Display for AutoIncrementKey { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}/{}", self.table_id, self.column_id)
it would be much better to be with text AutoIncrement
, for example, AutoIncrement({table_id}/{column_id})
src/meta/app/src/schema/auto_increment.rs
line 25 at r25 (raw file):
pub expr: AutoIncrementExpr, pub key: AutoIncrementKey, pub count: u64,
add doc comment to struct and field. explain the purposes. In this case, the purpose of expr
is not very obvious.
Code quote:
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GetAutoIncrementNextValueReq {
pub tenant: Tenant,
pub expr: AutoIncrementExpr,
pub key: AutoIncrementKey,
pub count: u64,
src/meta/api/src/table_api.rs
line 465 at r25 (raw file):
txn.if_then .extend(vec![txn_put_pb(&storage_ident, &storage_value)?]); }
There is a question. Suppose there is a table with two versions, v1 and v2, in the meta - service. In v1, there is an auto - increment column with id = 3. In v2, there are two auto - increment columns with id = 3 and id = 4. At this time, if we perform garbage collection (GC) on v1, we cannot delete the auto - increment with id = 3. At this moment, we must compare the two versions before and after to check whether the later version uses the auto - increment in the current version. Where is this mechanism processed?
Code quote:
.push(txn_op_put(&key_dbid_tbname, serialize_u64(table_id)?))
}
for table_field in req.table_meta.schema.fields() {
let Some(auto_increment_expr) = table_field.auto_increment_expr() else {
continue;
};
let auto_increment_key =
AutoIncrementKey::new(table_id, table_field.column_id());
let storage_ident =
AutoIncrementStorageIdent::new_generic(req.tenant(), auto_increment_key);
let storage_value =
Id::new_typed(AutoIncrementStorageValue(auto_increment_expr.start));
txn.if_then
.extend(vec![txn_put_pb(&storage_ident, &storage_value)?]);
}
src/meta/protos/proto/metadata.proto
line 51 at r25 (raw file):
uint64 min_reader_ver = 101; uint64 start = 1;
start
should be stored in the auto increment storage, does it need to be stored here?
src/meta/protos/proto/metadata.proto
line 54 at r25 (raw file):
int64 step = 2; bool is_ordered = 3; uint32 column_id = 4;
why does it need to store column_id
?
src/meta/api/src/schema_api_test_suite.rs
line 5043 at r25 (raw file):
step: 1, is_ordered: true, }))]))
the new AutoIncrementApi should be tested too.
0b7f6a6
to
e4ccfb6
Compare
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.
@drmingdrmer reviewed 1 of 10 files at r12, 10 of 58 files at r22, 1 of 23 files at r23, 15 of 17 files at r26, all commit messages.
Reviewable status: 41 of 101 files reviewed, 26 unresolved discussions (waiting on @dantengsky, @KKould, and @TCeason)
src/query/service/src/catalogs/default/database_catalog.rs
line 892 at r26 (raw file):
req: GetAutoIncrementNextValueReq, ) -> Result<GetAutoIncrementNextValueReply> { self.mutable_catalog.get_autoincrement_next_value(req).await
Why does auto-increment need to be accessed via CatalogAPI? AFAIK, it only needs to be used when writing data.
Code quote:
async fn get_autoincrement_next_value(
&self,
req: GetAutoIncrementNextValueReq,
) -> Result<GetAutoIncrementNextValueReply> {
self.mutable_catalog.get_autoincrement_next_value(req).await
@drmingdrmer When inserting data, if a column is defined as AUTOINCREMENT and no explicit value is provided, the DefaultExprBinder generates an AsyncFunction. This function is then evaluated in TransformAsyncFunction, where the catalog is used to perform the necessary metadata operations. This constitutes the current end-to-end process for filling unspecified values during insertion. |
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.
@drmingdrmer reviewed 2 of 58 files at r22, 2 of 23 files at r23.
Reviewable status: 45 of 101 files reviewed, 26 unresolved discussions (waiting on @dantengsky, @KKould, and @TCeason)
CI error |
…tch_add` and enable AutoIncrement to work
…tch_add` and enable AutoIncrement to work
… add auto increment check of add column
ffa7c0c
to
90a70ff
Compare
815550f
to
90b5b97
Compare
src/query/service/src/pipelines/processors/transforms/transform_async_function.rs
Show resolved
Hide resolved
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.
@drmingdrmer reviewed 1 of 10 files at r12, 1 of 58 files at r22, 2 of 14 files at r24, 1 of 11 files at r25, 1 of 15 files at r28, 8 of 11 files at r29, all commit messages.
Reviewable status: 51 of 102 files reviewed, 27 unresolved discussions (waiting on @dantengsky, @KKould, and @TCeason)
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
when creating a table or adding a column, the column can be set to Auto Increment.
AUTOINCREMENT will generate a sequence bound to the column and will be deleted when the column is deleted.
Tips:
currently, AutoIncrementStorageIdent is used to implement next_val_v1 for AutoIncrementIdent, but since the result of next_val_v1 is incorrect, it now defaults to using next_val_v0 for AutoIncrement, which will cause AutoIncrementStorageIdent to be dead code for the time being.
Tests
Type of change
This change is