Skip to content

schemachanger: remove RBR fallback for add column#140617

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
annrpom:add-column-rbr
Mar 13, 2025
Merged

schemachanger: remove RBR fallback for add column#140617
craig[bot] merged 1 commit intocockroachdb:masterfrom
annrpom:add-column-rbr

Conversation

@annrpom
Copy link
Copy Markdown
Contributor

@annrpom annrpom commented Feb 6, 2025

This patch removes the regional by row fallback for ADD COLUMN
in the declarative schema changer.

Epic: CRDB-31282
Fixes: #80545

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Feb 10, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@annrpom annrpom force-pushed the add-column-rbr branch 3 times, most recently from f288f4b to 5f1e89e Compare February 18, 2025 18:28
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Feb 18, 2025

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@annrpom annrpom force-pushed the add-column-rbr branch 3 times, most recently from afe63bb to da29679 Compare February 19, 2025 18:25
@annrpom annrpom marked this pull request as ready for review February 19, 2025 18:25
@annrpom annrpom requested a review from a team as a code owner February 19, 2025 18:25
@annrpom annrpom force-pushed the add-column-rbr branch 3 times, most recently from 71b2ee9 to d13d41f Compare March 12, 2025 17:06
@annrpom annrpom requested a review from rafiss March 12, 2025 17:07
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.

this is super exciting!! great work.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained


pkg/ccl/schemachangerccl/testdata/end_to_end/add_column_regional_by_row/add_column_regional_by_row.definition line 2 at r1 (raw file):

setup
CREATE DATABASE multiregion_db PRIMARY REGION "us-east1" REGIONS "us-east2", "us-east3" SURVIVE REGION FAILURE;

should we also have a test with SURVIVE ZONE FAILURE, or do you feel like this is sufficient?


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go line 128 at r1 (raw file):

	if idx != nil {
		if isRBR {
			panicIfRegionChangeUnderwayOnRBRTable(b, "add a UNIQUE COLUMN", tbl.TableID)

nit: let's remove the if isRBR check here. panicIfRegionChangeUnderwayOnRBRTable already has that check in it.

also is the idx != nil check too broad? previously, we'd only call panicIfRegionChangeUnderwayOnRBRTable if a UNIQUE column was being added.

Copy link
Copy Markdown
Contributor Author

@annrpom annrpom 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)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go line 128 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

nit: let's remove the if isRBR check here. panicIfRegionChangeUnderwayOnRBRTable already has that check in it.

also is the idx != nil check too broad? previously, we'd only call panicIfRegionChangeUnderwayOnRBRTable if a UNIQUE column was being added.

re:nit -- ah oki right

re: broadness of idx != nil check -- i aligned this with legacy's implementation

idx := cdd.PrimaryKeyOrUniqueIndexDescriptor
incTelemetryForNewColumn(d, col)
// Ensure all new indexes are partitioned appropriately.
if idx != nil {
if n.tableDesc.IsLocalityRegionalByRow() {
if err := params.p.checkNoRegionChangeUnderway(
params.ctx,
n.tableDesc.GetParentID(),
"add a UNIQUE COLUMN on a REGIONAL BY ROW table",
); err != nil {
return err
}
}
; iiuc this should still be equivalent since primary keys are also unique, but lmk if that's not what it going on here
// PrimaryKeyOrUniqueIndexDescriptor is the index descriptor for the index implied by a
// PRIMARY KEY or UNIQUE column.
PrimaryKeyOrUniqueIndexDescriptor *descpb.IndexDescriptor


pkg/ccl/schemachangerccl/testdata/end_to_end/add_column_regional_by_row/add_column_regional_by_row.definition line 2 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

should we also have a test with SURVIVE ZONE FAILURE, or do you feel like this is sufficient?

i feel like this is sufficient -- at least for a DSC end_to_end test, but what were you thinking about testing? the zone config generated from a SURVIVE ZONE FAILURE (which is code i touched, but by porting it over to a new pkg) exists:

SHOW ZONE CONFIGURATION FOR DATABASE multi_region_test_survive_zone_failure_db
----
DATABASE multi_region_test_survive_zone_failure_db ALTER DATABASE multi_region_test_survive_zone_failure_db CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 14400,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=us-east-1]',
lease_preferences = '[[+region=us-east-1]]'

if this was what you were thinking about

This patch removes the regional by row fallback for `ADD COLUMN`
in the declarative schema changer.

Epic: CRDB-31282
Fixes: cockroachdb#80545

Release note: None
@annrpom annrpom requested a review from rafiss March 12, 2025 21:41
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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @annrpom)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_column.go line 128 at r1 (raw file):

Previously, annrpom (annie pompa) wrote…

re:nit -- ah oki right

re: broadness of idx != nil check -- i aligned this with legacy's implementation

idx := cdd.PrimaryKeyOrUniqueIndexDescriptor
incTelemetryForNewColumn(d, col)
// Ensure all new indexes are partitioned appropriately.
if idx != nil {
if n.tableDesc.IsLocalityRegionalByRow() {
if err := params.p.checkNoRegionChangeUnderway(
params.ctx,
n.tableDesc.GetParentID(),
"add a UNIQUE COLUMN on a REGIONAL BY ROW table",
); err != nil {
return err
}
}
; iiuc this should still be equivalent since primary keys are also unique, but lmk if that's not what it going on here
// PrimaryKeyOrUniqueIndexDescriptor is the index descriptor for the index implied by a
// PRIMARY KEY or UNIQUE column.
PrimaryKeyOrUniqueIndexDescriptor *descpb.IndexDescriptor

that makes sense to me! thanks


pkg/ccl/schemachangerccl/testdata/end_to_end/add_column_regional_by_row/add_column_regional_by_row.definition line 2 at r1 (raw file):

Previously, annrpom (annie pompa) wrote…

i feel like this is sufficient -- at least for a DSC end_to_end test, but what were you thinking about testing? the zone config generated from a SURVIVE ZONE FAILURE (which is code i touched, but by porting it over to a new pkg) exists:

SHOW ZONE CONFIGURATION FOR DATABASE multi_region_test_survive_zone_failure_db
----
DATABASE multi_region_test_survive_zone_failure_db ALTER DATABASE multi_region_test_survive_zone_failure_db CONFIGURE ZONE USING
range_min_bytes = 134217728,
range_max_bytes = 536870912,
gc.ttlseconds = 14400,
num_replicas = 5,
num_voters = 3,
constraints = '{+region=ap-southeast-2: 1, +region=ca-central-1: 1, +region=us-east-1: 1}',
voter_constraints = '[+region=us-east-1]',
lease_preferences = '[[+region=us-east-1]]'

if this was what you were thinking about

that is basically all i had in mind. i'm guessing the schema change plan isn't that different whether the database has REGION FAILURE or ZONE FAILURE then?

Copy link
Copy Markdown
Contributor Author

@annrpom annrpom 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)


pkg/ccl/schemachangerccl/testdata/end_to_end/add_column_regional_by_row/add_column_regional_by_row.definition line 2 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

that is basically all i had in mind. i'm guessing the schema change plan isn't that different whether the database has REGION FAILURE or ZONE FAILURE then?

nod nod (i verified this by rewriting the tests after modifying REGION FAILURE to ZONE FAILURE and looking at the diff as well -- the plan was the same)

@annrpom
Copy link
Copy Markdown
Contributor Author

annrpom commented Mar 13, 2025

test failure is unrelated to these changes:

    explain_test.go:207: pq: internal error: argument expression has type RECORD, need type USER DEFINED RECORD: public.seed, assignment cast isn't possible: WITH        	with_27 (col_270)

TFTR! ('-')7

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 13, 2025

@craig craig bot merged commit 6f4f374 into cockroachdb:master Mar 13, 2025
23 of 24 checks passed
annrpom added a commit to annrpom/cockroach that referenced this pull request Mar 26, 2025
The end to end tests with DML injections we added
in cockroachdb#140617, cockroachdb#139622, cockroachdb#142921 are sufficient.

Epic: none
Fixes: cockroachdb#136846

Release note: None
craig bot pushed a commit that referenced this pull request Mar 27, 2025
143545: testutilsccl: only test legacy in AlterPrimaryKeyCorrectZoneConfigTest r=annrpom a=annrpom

The end to end tests with DML injections we added
in #140617, #139622, #142921 are sufficient.

Epic: none
Fixes: #136846

Release note: None

Co-authored-by: Annie Pompa <annie@cockroachlabs.com>
spilchen pushed a commit to spilchen/cockroach that referenced this pull request Mar 27, 2025
The end to end tests with DML injections we added
in cockroachdb#140617, cockroachdb#139622, cockroachdb#142921 are sufficient.

Epic: none
Fixes: cockroachdb#136846

Release note: None
@annrpom annrpom deleted the add-column-rbr branch September 15, 2025 21:13
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.

sql/schemachanger: remove regional-by-row fallback from add column in declarative schema changer

3 participants