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

Open
wants to merge 25 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
@frapa frapa force-pushed the support_alter_table_add_primary_key branch from c09ce34 to ab5a5fc Compare June 9, 2024 14:31
@frapa frapa marked this pull request as ready for review June 9, 2024 18:57
frapa added 25 commits June 12, 2024 20:17
…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 ab5a5fc to 8b87ebc Compare June 12, 2024 18:17
@duckdb-draftbot duckdb-draftbot marked this pull request as draft June 12, 2024 18:18
@frapa frapa marked this pull request as ready for review June 12, 2024 18:19
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