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

scbuild, rules: rewrite index handling in scbuild, fix bugs #86571

Merged
merged 1 commit into from
Aug 27, 2022

Conversation

postamar
Copy link

This commit fixes bugs related to constraints and comments in the
declarative schema changer. This commit also rewrites how index targets
are manipulated inside the builder, but otherwise does not change its
output.

This commit is a spin-off from work performed on adding secondary index
support in the ALTER PRIMARY KEY implementation. That work is not going
to be included in the 22.2 release, unlike this.

Relates to #83932.

Release justification: bug fixes with otherwise no functional changes
Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@postamar postamar marked this pull request as ready for review August 22, 2022 17:04
@postamar postamar requested a review from a team August 22, 2022 17:04
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Good stuff, the bug fixes around naming in particular. Just minor stuff.

Comment on lines 539 to 548
// recreateAllSecondaryIndexes recreates all secondary indexes. While the key
// columns remain the same in the face of a primary key change, the key suffix
// columns or the stored columns may not.
func recreateAllSecondaryIndexes(
b BuildCtx, tbl *scpb.Table, newPrimaryIndex, sourcePrimaryIndex *scpb.PrimaryIndex,
) {
// TODO(postamar): implement in 23.1
}
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this need to return a not implemented error?

Copy link
Author

Choose a reason for hiding this comment

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

No. I added a comment to clarify.

Comment on lines +489 to +490
// makeIndexSpec constructs an indexSpec based on an existing index element.
func makeIndexSpec(b BuildCtx, tableID catid.DescID, indexID catid.IndexID) (s indexSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this panic an error if it can't find the index? right now it'll just return an empty spec, no?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +536 to +547
// makeSwapIndexSpec constructs a pair of indexSpec for the new index and the
// accompanying temporary index to swap out an existing index with.
func makeSwapIndexSpec(
Copy link
Contributor

Choose a reason for hiding this comment

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

this code implicitly assumes that the spec is either primary or secondary, but I don't see code anywhere to assert that that's true. I'm fine with having this code assume out is well-formed, but something above it needs to assert that

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

if err != nil {
return nil, err
var constraintName string
if constraint, err := tbl.FindConstraintWithID(e.ConstraintID); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Xiang-Gu were you doing something about this?

@postamar postamar force-pushed the fix-constraint-and-comment-bugs branch from 06fdc67 to e0df27d Compare August 24, 2022 00:49
@postamar
Copy link
Author

Ready for another look.

Copy link
Contributor

@ajwerner ajwerner 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 4 of 25 files at r1, 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner and @postamar)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_primary_key.go line 354 at r2 (raw file):

	// if we drop the sharding on the primary, we need to maintain it on the
	// secondaries if they exist.
	if !hasSecondary {

Just for my own understanding, this too will always be true because of fallBackIfSecondaryIndexExists, right?

@postamar postamar force-pushed the fix-constraint-and-comment-bugs branch from e0df27d to 11e3a71 Compare August 25, 2022 13:03
This commit fixes bugs related to constraints and comments in the
declarative schema changer. This commit also rewrites how index targets
are manipulated inside the builder, but otherwise does not change its
output.

This commit is a spin-off from work performed on adding secondary index
support in the ALTER PRIMARY KEY implementation. That work is not going
to be included in the 22.2 release, unlike this.

Relates to cockroachdb#83932.

Release justification: bug fixes with otherwise no functional changes
Release note: None
@postamar postamar force-pushed the fix-constraint-and-comment-bugs branch from 11e3a71 to b88b0a5 Compare August 26, 2022 14:48
@postamar
Copy link
Author

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 26, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 26, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 27, 2022

Build succeeded:

@craig craig bot merged commit 92b550b into cockroachdb:master Aug 27, 2022
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.

3 participants