Skip to content

sql/schemachanger: block data type alter of col used in computed cols#125870

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
spilchen:issue-72457-block-alter-type-computed-col
Jun 21, 2024
Merged

sql/schemachanger: block data type alter of col used in computed cols#125870
craig[bot] merged 1 commit intocockroachdb:masterfrom
spilchen:issue-72457-block-alter-type-computed-col

Conversation

@spilchen
Copy link
Copy Markdown
Contributor

Previously, altering the data type of a column used in a generated column was allowed, causing downstream issues when querying the generated column.

To be consistent with postgres, we will now block any attempt to alter the data type of a column used in a computed column.

Epic: CRDB-25314
Closes: #72457
Release note (bug fix): Attempts to alter the data type of a column used in a computed column expression are now blocked.

@spilchen spilchen requested a review from rafiss June 18, 2024 18:56
@spilchen spilchen self-assigned this Jun 18, 2024
@spilchen spilchen requested a review from a team as a code owner June 18, 2024 18:56
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@spilchen spilchen force-pushed the issue-72457-block-alter-type-computed-col branch from f94cca5 to 9a921b7 Compare June 19, 2024 13:13
@spilchen spilchen requested a review from a team as a code owner June 19, 2024 13:13
@spilchen spilchen requested review from wenyihu6 and removed request for a team June 19, 2024 13:13
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

i just had one optional suggestion to possible make the function simpler

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


pkg/sql/catalog/schemaexpr/expr.go line 644 at r1 (raw file):

	}
	if referencedCols.Contains(dependentColID) {
		return errCallback()

i think we could keep this simpler by having this function return a (bool, error) pair. then rather than calling the error callback here, we just leave it to the caller to return the error it wants to.

Previously, altering the data type of a column used in a generated
column was allowed, causing downstream issues when querying the
generated column.

To be consistent with postgres, we will now block any attempt to alter
the data type of a column used in a computed column.

The update to event_test.go was needed because it was doing an ALTER
that is now blocked. The test was changed to not reference a column in
the computed expression that we intend to change the data type on.

Epic: CRDB-25314
Closes: cockroachdb#72457
Release note (bug fix): Attempts to alter the data type of a column used
in a computed column expression are now blocked.

Signed-off-by: Matt Spilchen <matt.spilchen@cockroachlabs.com>
@spilchen spilchen force-pushed the issue-72457-block-alter-type-computed-col branch from 9a921b7 to c0a3044 Compare June 21, 2024 13:02
Copy link
Copy Markdown
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 @rafiss and @wenyihu6)


pkg/sql/catalog/schemaexpr/expr.go line 644 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i think we could keep this simpler by having this function return a (bool, error) pair. then rather than calling the error callback here, we just leave it to the caller to return the error it wants to.

Good suggestion, this is much simpler.

@spilchen
Copy link
Copy Markdown
Contributor Author

tftr!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jun 21, 2024

@craig craig bot merged commit 47e3c39 into cockroachdb:master Jun 21, 2024
@spilchen spilchen deleted the issue-72457-block-alter-type-computed-col branch June 21, 2024 16:25
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: ALTER COLUMN TYPE does not check computed column definitions

3 participants