-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: Implement ADD UNIQUE WITHOUT INDEX
#93824
schemachanger: Implement ADD UNIQUE WITHOUT INDEX
#93824
Conversation
be03a59
to
41327b8
Compare
This is ready for a round of looks! |
ADD UNIQUE WITHOUT INDEX
ADD UNIQUE WITHOUT INDEX
This looks good, I did a first pass and have no comments besides what I already shared in the PR this is based on, which might apply here also. |
41327b8
to
2ff8573
Compare
2ff8573
to
03d3059
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Most of this code is out of my area of expertise, but from what I can tell it looks good!
With this PR have you added support for all aspects of UNIQUE WITHOUT INDEX
or just some? e.g., does this cover adding NOT VALID
constraints and/or running VALIDATE
on an existing constraint? How about adding them as part of a CREATE TABLE
statement or dropping them?
Also seems like the change to include indexIDForValidation
is mixed in with this change but should probably be its own separate change. It doesn't seem related to this.
I left a bunch of nits about long comment lines. Comments should be <= 80 characters wide.
Reviewed 5 of 5 files at r18, 9 of 9 files at r19, 3 of 3 files at r20, 3 of 3 files at r21, 17 of 17 files at r22, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Xiang-Gu)
pkg/sql/catalog/rewrite/rewrite.go
line 176 at r21 (raw file):
} // Rewrite unique_without_index in both `UniqueWithoutIndexConstraints` and `Mutations` slice.
nit: long line
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_constraint.go
line 439 at r20 (raw file):
} // getIndexIDForValidationForConstraint returns the index ID this check constraint is supposed to
nit: long line
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 346 at r19 (raw file):
} if op.ConstraintID >= tbl.NextConstraintID { tbl.NextConstraintID = op.ConstraintID + 1
why are you doing this in this function but not the others?
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 352 at r19 (raw file):
TableID: op.TableID, ColumnIDs: op.ColumnIDs, Name: tabledesc.ConstraintNamePlaceholder(op.ConstraintID),
why not use the constraint name?
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 385 at r19 (raw file):
// Remove the mutation from the mutation slice. The `MakeMutationComplete` // call will also mark the above added unique_without_index as VALIDATED. // If this is a rollback of a drop, we are trying to add the unique_without_index constraint
nit: long line
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 410 at r19 (raw file):
} func (m *visitor) MakePublicUniqueWithoutIndexConstraintValidated(
The name of this function doesn't seem to match what it's doing
pkg/sql/schemachanger/scop/mutation.go
line 369 at r19 (raw file):
} // MakeAbsentUniqueWithoutIndexConstraintWriteOnly adds a non-existent unique_without_index constraint
nit: long line
pkg/sql/schemachanger/scpb/elements.proto
line 325 at r19 (raw file):
// Predicate, if non-nil, means a partial uniqueness constraint. Expression predicate = 4 [(gogoproto.customname) = "Predicate"]; // IndexIDForValidation is the index id to hint to the unique_without_index constraint validation SQL query about which index
nit: long line
pkg/sql/schemachanger/scplan/internal/opgen/opgen_unique_without_index_constraint.go
line 19 at r19 (raw file):
func init() { opRegistry.register((*scpb.UniqueWithoutIndexConstraint)(nil),
I'm not familiar enough with how this works to review this part
pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules
line 1447 at r22 (raw file):
- $next-node[CurrentStatus] = TRANSIENT_DELETE_ONLY - descriptorIsNotBeingDropped($prev) - joinTargetNode($prev, $prev-target, $prev-node)
I don't know enough about this to review
@rytaft Thank you first of all for taking a look at this PR. To answer your question:
I will address your code review feedback shortly! |
03d3059
to
2c68210
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rytaft)
pkg/sql/catalog/rewrite/rewrite.go
line 176 at r21 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
nit: long line
done
Code quote:
WithoutIndexConstraints` and `Mutations` slice.
pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_add_constraint.go
line 439 at r20 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
nit: long line
done
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 346 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
why are you doing this in this function but not the others?
I in fact did: This is only required in the "first" operation, which usually has the name of MakeAbsentXxxWriteOnly
. I confirmed that we did this for all three constraints we currently support: check, fk, and uwi
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 352 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
why not use the constraint name?
The constraint name itself is modeled as a separate "element" and we will update the name to the right on during the lifecycle of that name element.
Code quote:
uwi := &descpb.UniqueWithoutIndexConstraint{
TableID: op.TableID,
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 385 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
nit: long line
done
Code quote:
drop, we are trying to add the unique_without_inde
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 410 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
The name of this function doesn't seem to match what it's doing
You are right. We used to have a more-free-formed naming for those operations/functions. We (the schema team) then decided to make them conform to a certain naming convention. We chose the convention that makes it clear of the affected element's before and after status -- the element status as shown in a new schema changer plan. This operation, in the new schema changer plan's worlds and terminologies, transitioned the UniqueWIthoutIndex element from Public status to Validated status, so I gave this function this name.
What the function actually does, i.e. what a transition in the new schema changer plan's world translates to modifications to the descriptor, is considered a layer below and thus we don't want it to show in the function/operation names. That's my understanding of the rationale behind such a naming convention.
pkg/sql/schemachanger/scop/mutation.go
line 369 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
nit: long line
done
Code quote:
ds a non-existent unique_without_index constraint
pkg/sql/schemachanger/scpb/elements.proto
line 325 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
nit: long line
done
Code quote:
index id to hint to the unique_without_index cons
pkg/sql/schemachanger/scplan/internal/opgen/opgen_unique_without_index_constraint.go
line 19 at r19 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
I'm not familiar enough with how this works to review this part
ack
pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules
line 1447 at r22 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
I don't know enough about this to review
ack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info! I will let someone from the schema team sign off on this since I'm not familiar with most of this code.
Reviewed 2 of 7 files at r30, 1 of 1 files at r31, 1 of 1 files at r32.
Reviewable status: complete! 0 of 0 LGTMs obtained
pkg/sql/schemachanger/scexec/scmutationexec/constraint.go
line 410 at r19 (raw file):
Previously, Xiang-Gu (Xiang Gu) wrote…
You are right. We used to have a more-free-formed naming for those operations/functions. We (the schema team) then decided to make them conform to a certain naming convention. We chose the convention that makes it clear of the affected element's before and after status -- the element status as shown in a new schema changer plan. This operation, in the new schema changer plan's worlds and terminologies, transitioned the UniqueWIthoutIndex element from Public status to Validated status, so I gave this function this name.
What the function actually does, i.e. what a transition in the new schema changer plan's world translates to modifications to the descriptor, is considered a layer below and thus we don't want it to show in the function/operation names. That's my understanding of the rationale behind such a naming convention.
Thanks for the explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please address my comments in #93068 first before merging. Nicely done!
925cb01
to
f354bd5
Compare
f354bd5
to
edad297
Compare
bors r+ |
Build succeeded: |
This PR implements
ADD UNIQUE WITHOUT INDEX
in the declarative schema changer.In general, it follows the same recipe for
ADD CHECK
.Epic: None