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

schemachanger: support partition zone config #130422

Merged
merged 5 commits into from
Oct 10, 2024

Conversation

annrpom
Copy link
Contributor

@annrpom annrpom commented Sep 10, 2024

schemachanger: add PartitionZoneConfig element

This patch adds a new element, PartitionZoneConfig,
that will become relevant for supporting ALTER PARTITION ... CONFIGURE ZONE in the DSC.

Release note: None


schemachanger: add opgen rule for partition zc

This patch adds an opgen rule to support our PartitionZoneConfig
element.

Release note: None


schemachanger: panic if partition does not exist on index

This patch ensures that we panic if a partition does not
exist on the specified index in a ALTER TABLE ... OF INDEX.

Release note: None


schemachanger: add support for ALTER PARTITION ... OF TABLE

This patch adds support for ALTER PARTITION ... OF TABLE in
the form of zone_config_helpers.

Release note: None


schemachanger: support partition zone config

This patch adds the functionality to configure
a zone configuration on a partition.

Fixes: #129889
Release note: None

Epic: CRDB-31473

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@annrpom annrpom force-pushed the dsc-partitions-zc branch 6 times, most recently from 96b61fa to 7041bb6 Compare September 12, 2024 22:14
@annrpom annrpom force-pushed the dsc-partitions-zc branch 6 times, most recently from f4d835e to c4bd018 Compare September 17, 2024 18:59
Copy link

blathers-crl bot commented Sep 17, 2024

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
Copy link
Contributor Author

annrpom commented Sep 17, 2024

argh -- i think i need to review over the test_deps code to get the transactional partition zone configs working; RFAL. i'll batch the first 2 commits in a separate PR and write some tests with them

@annrpom annrpom marked this pull request as ready for review September 17, 2024 19:01
@annrpom annrpom requested a review from a team as a code owner September 17, 2024 19:01
Copy link
Contributor

@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.

The changes look okay to me. I just had a few questions in the code.

Reviewed 2 of 4 files at r1, 24 of 24 files at r5, 2 of 2 files at r6, 10 of 10 files at r7, 5 of 5 files at r8, 5 of 5 files at r9, 3 of 3 files at r10, 17 of 17 files at r11, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @annrpom)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go line 80 at r10 (raw file):

		partitionName := string(zs.Partition)

		// TODO(before merge): [reviewer callout] can we guarantee that this will

Would it be safer to check both cases by calling isCorrespondingTemporaryIndex twice—once assuming the temporary index is indexes[0] and again assuming it’s indexes[1]?


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go line 1171 at r10 (raw file):

	maybeCorresponding := b.QueryByID(tableID).FilterTemporaryIndex().
		Filter(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.TemporaryIndex) bool {
			return idx+1 == e.IndexID && e.IndexID == otherIdx

Isn’t idx the ID of the temporary index? Since e is a temporary index based on the filter, shouldn’t the check be:

return idx == e.IndexID && e.IndexID == otherIdx+1

pkg/sql/schemachanger/scop/immediate_mutation.go line 936 at r8 (raw file):

	TableID       descpb.ID
	IndexID       descpb.IndexID
	PartitionName string

I didn’t see this field being used. Do we need to pass it down when calling UpdateSubzoneConfig?


pkg/ccl/logictestccl/testdata/logic_test/zone line 1308 at r9 (raw file):

statement ok
CREATE TABLE fooba(pk INT PRIMARY KEY, i INT);
ALTER TABLE fooba PARTITION BY LIST (pk) (PARTITION "one" VALUES IN (1), PARTITION "rest" VALUES IN (DEFAULT));

Should we separate this into a new statement so that we run this through the DSC?

@annrpom annrpom force-pushed the dsc-partitions-zc branch from c4bd018 to a9669ff Compare October 9, 2024 15:26
Copy link
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 @fqazi and @spilchen)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go line 80 at r10 (raw file):

Previously, spilchen wrote…

Would it be safer to check both cases by calling isCorrespondingTemporaryIndex twice—once assuming the temporary index is indexes[0] and again assuming it’s indexes[1]?

ah i think this would also work; i think the logic would look a bit messier -- i'm thinking something like:

		case 2:
			// Perhaps our target index is a part of a backfill. In this case,
			// temporary indexes created during backfill should always share the
			// same zone configs as the corresponding new index.
			idx1 := indexes[0]
			idx2 := indexes[1]
			hasIdx2AsTemp := isCorrespondingTemporaryIndex(b, pzo.tableID, idx2.IndexID, idx1.IndexID)
			hasIdx1AsTemp := isCorrespondingTemporaryIndex(b, pzo.tableID, idx1.IndexID, idx2.IndexID)
			if hasIdx2AsTemp || hasIdx1AsTemp {
				idx := idx1
				if hasIdx1AsTemp {
					idx = idx2
				}
				idxName := mustRetrieveIndexNameElem(b, pzo.tableID, idx.IndexID)
				zs.TableOrIndex.Index = tree.UnrestrictedName(idxName.Name)
				// Our index name has changed -- find the corresponding indexID
				// and fill that out.
				pzo.fillIndexFromZoneSpecifier(b, n.ZoneSpecifier)
				break
			}

since the array len will always be 2, i think i'll sort our indexes by ID before calling isCorrespondingTemporaryIndex, but i'm open to further discussion


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go line 334 at r11 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

I think in for most cases this would be true, but I don't think its guaranteed it would be true in more complex cases. I think to be safer we can gather all the partitions and sort them by IndexID, the iteration order matches the the order things are added in the builder.

ah right; ty


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go line 339 at r11 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

Do we need to look at the current status or target here? This will include dropping objects as well right now.

done


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go line 1171 at r10 (raw file):

Previously, spilchen wrote…

Isn’t idx the ID of the temporary index? Since e is a temporary index based on the filter, shouldn’t the check be:

return idx == e.IndexID && e.IndexID == otherIdx+1

done -- ty!


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go line 1175 at r11 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

Think you need to use the TemporaryIndexID field here

done -- ty!


pkg/sql/schemachanger/scop/immediate_mutation.go line 936 at r8 (raw file):

Previously, spilchen wrote…

I didn’t see this field being used. Do we need to pass it down when calling UpdateSubzoneConfig?

no we do not -- we don't need to pass down indexID either technically (same for AddIndexZoneConfig); let me fix the partitions one in this pr

Copy link
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 @fqazi and @spilchen)


pkg/ccl/logictestccl/testdata/logic_test/zone line 1308 at r9 (raw file):

Previously, spilchen wrote…

Should we separate this into a new statement so that we run this through the DSC?

oki done

This patch adds a new element, `PartitionZoneConfig`,
that will become relevant for supporting `ALTER PARTITION
... CONFIGURE ZONE` in the DSC.

Release note: None
@annrpom annrpom force-pushed the dsc-partitions-zc branch from a9669ff to 4d1cd3f Compare October 9, 2024 15:44
This patch adds an opgen rule to support our PartitionZoneConfig
element.

Release note: None
This patch ensures that we panic if a partition does not
exist on the specified index in a `ALTER TABLE ... OF INDEX`.

Release note: None
This patch adds support for ALTER PARTITION ... OF TABLE in
the form of zone_config_helpers.

Release note: None
@annrpom annrpom force-pushed the dsc-partitions-zc branch from 4d1cd3f to 866d217 Compare October 9, 2024 17:14
@fqazi fqazi requested a review from spilchen October 9, 2024 18:55
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 3 of 10 files at r7, 16 of 31 files at r12, 32 of 32 files at r17, 5 of 5 files at r18, 1 of 3 files at r20, 26 of 28 files at r21, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @annrpom and @spilchen)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go line 1164 at r21 (raw file):

	b BuildCtx, tableID catid.DescID, idx catid.IndexID, otherIdx catid.IndexID,
) bool {
	maybeCorresponding := b.QueryByID(tableID).FilterTemporaryIndex().

Think we can check TemporaryIndexID in here too

Copy link
Contributor

@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.

:lgtm:

Reviewed 5 of 31 files at r12, 2 of 29 files at r16, 32 of 32 files at r17, 1 of 5 files at r19, 2 of 28 files at r21, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @annrpom and @fqazi)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go line 80 at r10 (raw file):

Previously, annrpom (annie pompa) wrote…

ah i think this would also work; i think the logic would look a bit messier -- i'm thinking something like:

		case 2:
			// Perhaps our target index is a part of a backfill. In this case,
			// temporary indexes created during backfill should always share the
			// same zone configs as the corresponding new index.
			idx1 := indexes[0]
			idx2 := indexes[1]
			hasIdx2AsTemp := isCorrespondingTemporaryIndex(b, pzo.tableID, idx2.IndexID, idx1.IndexID)
			hasIdx1AsTemp := isCorrespondingTemporaryIndex(b, pzo.tableID, idx1.IndexID, idx2.IndexID)
			if hasIdx2AsTemp || hasIdx1AsTemp {
				idx := idx1
				if hasIdx1AsTemp {
					idx = idx2
				}
				idxName := mustRetrieveIndexNameElem(b, pzo.tableID, idx.IndexID)
				zs.TableOrIndex.Index = tree.UnrestrictedName(idxName.Name)
				// Our index name has changed -- find the corresponding indexID
				// and fill that out.
				pzo.fillIndexFromZoneSpecifier(b, n.ZoneSpecifier)
				break
			}

since the array len will always be 2, i think i'll sort our indexes by ID before calling isCorrespondingTemporaryIndex, but i'm open to further discussion

Yeah, I'm okay with sorting. It keeps the code clean.

This patch adds the functionality to configure
a zone configuration on a partition.

Fixes: cockroachdb#129889

Release note: None
@annrpom annrpom force-pushed the dsc-partitions-zc branch from 866d217 to f2f059d Compare October 9, 2024 20:57
@annrpom
Copy link
Contributor Author

annrpom commented Oct 10, 2024

TFTR! ('-')7

bors r+

@craig craig bot merged commit fd4b146 into cockroachdb:master Oct 10, 2024
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.

Implement ALTER PARTITION ... CONFIGURE ZONE USING ... in declarative schema changer
4 participants