-
Notifications
You must be signed in to change notification settings - Fork 215
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
catalog: support composite primary key #625
Comments
... may also be done together with #590 |
assigned to @shmiwy |
@skyzh create table t (a int not null, b int not null, c int, d int, primary key(a, b)); the physicalCreateTable says that neither a nor b is primary key🤣 |
Then our binder doesn't support such syntax now 🤣 Please also help refactor the binder to support primary key (a, b) syntax. risinglight/src/binder/statement/create_table.rs Lines 20 to 22 in a5644b1
For example, the first statement produces AST like:
We can read the |
By the way, currently the binder only supports primary key at this location 🤣 |
Can we add a field called risinglight/src/catalog/table.rs Lines 43 to 46 in a5644b1
add a judgment about col_catalog.is_primary() before line 44. If it is true , we can record the corresponding col_id in somewhere (maybe a vector). When we end up the for loop, we can change the primary_key_indices .
After we have created the a table, it seems that subsequent queries will not modify the catalog data like primary keys' id of the table. So it seems acceptable that we store redundant data about primary keys.🤣 |
By the way, changing the binder to supports this kind of sql query seems easy. create table t(a int not null, b int not null, c int, d int, primary key(a, b)); (emmm, also I still have one weird mistake I haven't figured out, one sql logic test falled????)🤪 |
You may send a draft PR and we can investigate it...
Of course we can :) But from my perspective, |
I think it just make some thing like |
Or we need to refactor everything that uses the function (more bugs can emerge hhhh🤩) |
Exactly. If you want to refactor, we can do this. But storing
For most of the places using |
still not tell difference between primary key(a, b) and primary key(b, a), i will do this int the not-too-distant future. |
on the first step, I'm going to add two filed in for example, if we have a sql like create table t (a int primary key, b int not null, c int not null, d int , primary key(b, c)); the I'm trying to maintain the data of the two filed without using any of the To achieve this goal, I will refactor some codes when creating a table, add two filed in |
I think we should forbid this in binder. We should only allow single primary key if |
So, if
We should have hashset to set b -> true, c -> true, and If
We should set a -> true, while ordered_pk_ids only contain id of a. I believe in the future, the HashSet won't be used, as all inquiries about pks will consider order. But we can keep it for now, to refactor everything little by little. |
This plan looks great! We can proceed on this. |
Sounds good to me. |
ok🥳 |
Currently, our catalog cannot handle the case for composite primary key. For example,
These two tables will have exactly the same catalog entry, despite that the first one should have (x, y) as composite sort key, and the second one have (y, x). The order is different!
Therefore, we will need to refactor the catalog to correctly record such information. For
TableCatalog
, we should have a fieldprimary_key_indices
, and remove theis_primary
field fromColumnDesc
.This task might involve some refactors and some regressions in functionalities. Need plan first.
The text was updated successfully, but these errors were encountered: