Skip to content
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

feat: support multi ordered primary key #633

Merged
merged 3 commits into from
Apr 21, 2022
Merged

feat: support multi ordered primary key #633

merged 3 commits into from
Apr 21, 2022

Conversation

shmiwy
Copy link
Contributor

@shmiwy shmiwy commented Apr 19, 2022

Signed-off-by: Shmiwy wyf000219@126.com

try to implementation #625

at this moment, I just append ordered_pk_ids to tableCatalog withoud using is_primary filed in ColumnDesc. It will make removing is_primary in the future easier.

Signed-off-by: Shmiwy <wyf000219@126.com>
@skyzh skyzh self-requested a review April 19, 2022 16:51
Copy link
Member

@skyzh skyzh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, good work!

For the bind_create_table part, I suggest to reorganize the code, so that it can be much clearer to readers.

  • Firstly, get the pk constraints ident vec from get_extra_pks, like vec!["a"]
  • Then, replace vec of ident to vec of column id, e.g., vec![ColumnId(1)]. May use hashmap in the process to accelerate lookups. We call this ordered_pks_from_constraint.
  • After that, iterate all columns, and generate a new set of ordered_pks_from_columns from is_primary property.
  • If both ordered_pks_from_constraint and ordered_pks_from_columns are not empty, return error. If ordered_pks_from_columns has more than 1 elements, return error (if you want).
  • Then we can get the final ordered_pks from either ordered_pks_from_constraint or ordered_pks_from_columns.

src/binder/statement/create_table.rs Outdated Show resolved Hide resolved
@@ -124,10 +140,14 @@ mod tests {
let catalog = Arc::new(RootCatalog::new());
let mut binder = Binder::new(catalog.clone());
let sql = "
create table t1 (v1 int not null, v2 int);
create table t1 (v1 int not null, v2 int);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have planner test in the future 🤣 I guess writing this test case must be painful.

FYI, https://github.com/singularity-data/risingwave/blob/main/src/frontend/test_runner/tests/testdata/tpch.yaml

src/binder/statement/create_table.rs Outdated Show resolved Hide resolved
src/binder/statement/create_table.rs Outdated Show resolved Hide resolved
src/binder/statement/create_table.rs Outdated Show resolved Hide resolved
src/storage/mod.rs Outdated Show resolved Hide resolved
table_name.clone(),
column_descs.to_vec(),
false,
ordered_pk_ids,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ordered_pk_ids also needs to be persisted to disk in manifest.rs CreateTableEntry. We can do this in later PRs.

Signed-off-by: Shmiwy <wyf000219@126.com>
Copy link
Member

@skyzh skyzh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM, good work!

src/binder/statement/create_table.rs Outdated Show resolved Hide resolved
Signed-off-by: Shmiwy <wyf000219@126.com>
@skyzh skyzh enabled auto-merge (squash) April 21, 2022 02:46
@skyzh skyzh merged commit fc5a837 into risinglightdb:main Apr 21, 2022
@shmiwy shmiwy deleted the support_multi_pk branch April 21, 2022 02:59
@shmiwy shmiwy restored the support_multi_pk branch April 21, 2022 02:59
@shmiwy shmiwy deleted the support_multi_pk branch April 21, 2022 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants