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

sql/schemachanger: Preserving column family order for complex column type changes #133845

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

spilchen
Copy link
Contributor

When altering a column’s type in a way that requires a backfill, we drop the old column and add a new one. Previously, the new column was always added to the end of the column family. This change ensures the column family order is preserved.

In the DSC, the column family is updated when a new ColumnType element is added. I introduced a new field to this element to control the order, which requires specifying the column ID that the new column should follow.

Epic: CRDB-25314
Closes #133040
Release note: none

@spilchen spilchen self-assigned this Oct 30, 2024
@spilchen spilchen requested a review from a team as a code owner October 30, 2024 14:57
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 14 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @spilchen)


-- commits line 5 at r1:
Trying to understand the rationale for why we need this? From a SQL viewpoint nothing changes based on the order (maybe the DDL from SHOW CREATE only). I think a hazard is that rows could become unreadable if we aren't careful about how this is ordered

Copy link
Contributor Author

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi and @spilchen)


-- commits line 5 at r1:

Previously, fqazi (Faizan Qazi) wrote…

Trying to understand the rationale for why we need this? From a SQL viewpoint nothing changes based on the order (maybe the DDL from SHOW CREATE only). I think a hazard is that rows could become unreadable if we aren't careful about how this is ordered

The reasons were:

  • To ensure consistent output in commands like SHOW CREATE after the alteration.
  • The legacy schema changer also preserved the order.

I admit these aren’t strong reasons, so I’m okay with deferring this work.

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

Reviewed 13 of 14 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @spilchen)


-- commits line 5 at r1:

Previously, spilchen wrote…

The reasons were:

  • To ensure consistent output in commands like SHOW CREATE after the alteration.
  • The legacy schema changer also preserved the order.

I admit these aren’t strong reasons, so I’m okay with deferring this work.

Just as sanity lets confirm this with a DML injection test to confirm that everything stays readable. The changes themselves look fine, but it would just add piece of mind.

…type changes

When altering a column’s type in a way that requires a backfill, we drop
the old column and add a new one. Previously, the new column was always
added to the end of the column family. This change ensures the column
family order is preserved.

In the DSC, the column family is updated when a new ColumnType element
is added. I introduced a new field to this element to control the order,
which requires specifying the column ID that the new column should
follow.

Epic: CRDB-25314
Closes cockroachdb#133040
Release note: none
@spilchen spilchen force-pushed the issue-133040/preserve-order branch from 53de17e to 5059f89 Compare November 1, 2024 15:05
Copy link
Contributor Author

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @fqazi and @spilchen)


-- commits line 5 at r1:

Previously, fqazi (Faizan Qazi) wrote…

Just as sanity lets confirm this with a DML injection test to confirm that everything stays readable. The changes themselves look fine, but it would just add piece of mind.

I added a DML injection test. But there is a known problem where the column we are altering can become invisible for a couple of stages. I have issue #133996 opened to investigate that.

@spilchen
Copy link
Contributor Author

spilchen commented Nov 1, 2024

TFTR @fqazi

bors r+

@craig craig bot merged commit d04294b into cockroachdb:master Nov 1, 2024
22 of 23 checks passed
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.

sql/schemachanger: Preserve column family ordering during ALTER COLUMN TYPE
3 participants