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

Support ALTER TABLE ADD PRIMARY KEY statements #11895

Draft
wants to merge 24 commits into
base: feature
Choose a base branch
from

Conversation

frapa
Copy link

@frapa frapa commented May 1, 2024

This PR implements ALTER TABLE table ADD PRIMARY KEY (col1, ...); statements, as per #57.

I suggest reviewing by commit, as I tried to make them thematic and self-contained. However, the first commits basically do changes needed for the last 2-3 commits, so please have a look at the final ones if something's unclear.

Let me know if there is anything I can improve.

@Tishj
Copy link
Contributor

Tishj commented May 1, 2024

I'm not sure this is the best time to add this feature, as there is a pending PR to rework binding of Indexes (#11867)

src/storage/data_table.cpp Outdated Show resolved Hide resolved
src/storage/data_table.cpp Outdated Show resolved Hide resolved
src/storage/data_table.cpp Outdated Show resolved Hide resolved
@frapa
Copy link
Author

frapa commented May 1, 2024

Thanks for the quick review!

Regarding #11867, I guess that would affect the part about indexes, which should affect only small part of the code from this PR (the DataTable constructor). Review of the rest should be safe.

@frapa
Copy link
Author

frapa commented May 5, 2024

I fixed all comments, let me know if there is anything else I can change!

@frapa frapa force-pushed the support_alter_table_add_primary_key branch from f14b1f4 to e05ed09 Compare May 5, 2024 19:16
@duckdb-draftbot duckdb-draftbot marked this pull request as draft May 5, 2024 19:16
@frapa frapa force-pushed the support_alter_table_add_primary_key branch from e05ed09 to e7d1570 Compare May 5, 2024 19:20
@frapa frapa marked this pull request as ready for review May 5, 2024 19:20
@frapa frapa force-pushed the support_alter_table_add_primary_key branch from e7d1570 to ce62349 Compare May 5, 2024 19:27
@duckdb-draftbot duckdb-draftbot marked this pull request as draft May 5, 2024 19:28
@frapa frapa marked this pull request as ready for review May 5, 2024 19:28
@frapa frapa force-pushed the support_alter_table_add_primary_key branch from ce62349 to 70b552a Compare May 5, 2024 19:35
@duckdb-draftbot duckdb-draftbot marked this pull request as draft May 5, 2024 19:35
@Tishj
Copy link
Contributor

Tishj commented May 26, 2024

Thank you for the changes!
You should target the branch to feature as well so only your changes show up in the "files changed", this can be done at the top of the page 👍

@frapa frapa changed the base branch from main to feature May 28, 2024 16:25
@frapa frapa force-pushed the support_alter_table_add_primary_key branch 2 times, most recently from b7d693b to 1d11f30 Compare June 2, 2024 09:42
@duckdb-draftbot duckdb-draftbot marked this pull request as draft June 2, 2024 09:42
frapa added 24 commits June 9, 2024 12:28
…se it.

Taking advantage of polymorphism to replace
switch statements in a couple places.

I also had to refactor UniqueBoundConstraint
to use PhysicalIndexes instead of LogicalIndexes,
in a similar way to all other BoundConstraints.
I renamed it AddConstraintIndex.

By the name, this method belongs there,
and I need it later in the DataTable class
constructor to handle addition of unique indices.
Now, when a new unique index is created and a modified
instance of the storage is made, the DataTable will
automatically add an ART index and index existing
rows, throwing an error if the uniqueness is not
satisfied.
This makes code that needs to access the index
after the addition to the table simpler.
This is not necessary because
creating a unique index
automatically checks the uniqueness.
@frapa frapa force-pushed the support_alter_table_add_primary_key branch from 851a466 to ca4137e Compare June 9, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants