-
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
sql: add drop type to the prepared statement generator #61394
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. I have added a few people who may be able to assist in reviewing: 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
@rafiss, can you help by re-triggering the ci ?. thanks in advance. |
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 this fix!
this needs a test. can you add one in pkg/sql/logictest/testdata/logic_test/drop_type
the change looks fine, but since it's optimizer-related and we're in stability period, @RaduBerinde can you please sign off?
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @tharun208)
pkg/sql/plan_opt.go, line 64 at r1 (raw file):
*tree.CreateStats, *tree.Deallocate, *tree.Discard, *tree.DropDatabase, *tree.DropIndex, *tree.DropTable, *tree.DropView, *tree.DropSequence,
could you add DropType here, closer to the other drop statements?
@rafiss, I think the test should need to be a part of |
1c0ec3b
to
b8394e7
Compare
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
fb9f20f
to
bd61249
Compare
e87836a
to
726ca2b
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.
Can you also add DROP TYPE to TestStatementReuses
? This tests that all those statements work with PREPARE and EXPLAIN.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @rafiss and @tharun208)
726ca2b
to
8a3cdce
Compare
@RaduBerinde done with the changes. To pass the |
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 (and 1 stale) (waiting on @rafiss and @tharun208)
pkg/sql/plan_opt.go, line 65 at r2 (raw file):
*tree.Deallocate, *tree.Discard, *tree.DropDatabase, *tree.DropIndex, *tree.DropTable, *tree.DropView, *tree.DropSequence, *tree.DropType, *tree.Execute, *tree.Explain,
Adding Explain here is not correct, Explain has result columns and is supported by the optimizer.
I assume you added it because some PREPARE EXPLAIN case was failing?
yes, just now checked |
pkg/sql/plan_opt.go, line 65 at r2 (raw file): Previously, tharun208 (Tharun Rajendran) wrote…
What was the failure? |
The same stack trace error we got for |
I think the right fix here is to move the part that uses |
8a3cdce
to
aa022d0
Compare
yes, I am able to achieve it, without adding |
aa022d0
to
fa553b7
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 (and 1 stale) (waiting on @RaduBerinde and @tharun208)
pkg/sql/drop_type.go, line 33 at r3 (raw file):
type typeToDrop struct { desc *typedesc.Mutable fqName string
i believe fqName should be removed now
pkg/sql/drop_type.go, line 111 at r3 (raw file):
// Record these descriptors for deletion. node.td[typeDesc.ID] = typeToDrop{ desc: typeDesc,
instead of removing fqName here, does it work with:
fqName, err := getTypeNameFromTypeDescriptor(
oneAtATimeSchemaResolver{ctx, p},
typeDesc,
)
if err != nil {
return nil, err
}
node.td[typeDesc.ID] = typeToDrop{
desc: typeDesc,
fqName: fqName.FQString(),
}
pkg/sql/drop_type.go, line 151 at r3 (raw file):
func (n *dropTypeNode) startExec(params runParams) error { for _, toDrop := range n.td { typ, fqName := toDrop.desc, toDrop.fqName
and now this can be changed to
fqName := tree.AsStringWithFQNames(n.n, params.Ann())
pkg/sql/drop_type.go, line 152 at r3 (raw file):
for _, toDrop := range n.td { typ, fqName := toDrop.desc, toDrop.fqName if err := params.p.dropTypeImpl(params.ctx, typ, tree.AsStringWithFQNames(n.n, params.Ann()), true /* queueJob */); err != nil {
use fqName as the 3rd argument here
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 (and 1 stale) (waiting on @RaduBerinde and @tharun208)
pkg/sql/drop_type.go, line 33 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
i believe fqName should be removed now
sorry, i didn't mean to publish this comment.
pkg/sql/drop_type.go, line 151 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
and now this can be changed to
fqName := tree.AsStringWithFQNames(n.n, params.Ann())
i didn't mean to publish this comment
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 (and 1 stale) (waiting on @tharun208)
pkg/sql/drop_type.go, line 112 at r3 (raw file):
node.td[typeDesc.ID] = typeToDrop{ desc: typeDesc, fqName: tree.AsStringWithFQNames(name, p.Ann()),
I don't get it, now fqName
is not set in half the cases, but we are using it in startExec.
Why don't we remove the field altogether and just do getTypeNameFromTypeDescriptor()
in all cases instartExec
and use FQString()
pkg/sql/drop_type.go, line 152 at r3 (raw file): Previously, rafiss (Rafi Shamim) wrote…
Noete that the third argument is the entire statement, not just the type name. I would move it out of the loop and assign to an aptly named variable, it's silly to reformat for each type. |
fa553b7
to
3432a33
Compare
3432a33
to
daff007
Compare
this will change the |
daff007
to
82230d8
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 (and 1 stale) (waiting on @rafiss and @tharun208)
pkg/sql/drop_type.go, line 112 at r3 (raw file):
Previously, tharun208 (Tharun Rajendran) wrote…
this will change the
TypeName
in theevent log
. Current changes will not alter the event log` and all necessary cases got passed.
I don't understand.. what I'm suggesting should be equivalent to the latest revision, we would just call getTypeNameFromTypeDescriptor
from startExec
instead. Here's a diff (it passes the sql package tests and the drop_type logictest):
https://gist.github.com/RaduBerinde/f78a2b2c17f22cc429734b366f53edc5
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 (and 1 stale) (waiting on @RaduBerinde and @tharun208)
pkg/sql/drop_type.go, line 152 at r3 (raw file):
Previously, RaduBerinde wrote…
Noete that the third argument is the entire statement, not just the type name. I would move it out of the loop and assign to an aptly named variable, it's silly to reformat for each type.
oh good call. hmm well also this parameter is the job description, which is used in the db console as a display name. so perhaps it would be better for them to have different names anyway.
maybe change to
params.p.dropTypeImpl(params.ctx, typ, "dropping type " + fqName, true /* queueJob */)
pkg/sql/drop_type.go, line 152 at r3 (raw file): Previously, rafiss (Rafi Shamim) wrote…
Yeah that's probably better |
82230d8
to
ad4fbad
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 (and 1 stale) (waiting on @RaduBerinde, @rafiss, and @tharun208)
pkg/sql/drop_type.go, line 135 at r4 (raw file):
statementStr := tree.AsStringWithFQNames(n.n, params.Ann()) for _, typeDesc := range n.toDrop { err := params.p.dropTypeImpl(params.ctx, typeDesc, "dropping type "+statementStr, true /* queueJob */)
please change "dropping type "+statementStr
to dropping type "+typeFQName
and remove the statementStr
variable entirely
so, this |
Release justification: fixes for high-priority or high-severity bugs in existing functionality Previously, prepare statement doesnt have support for drop type in optimizer, so it panic during execution as no flags are generated. This patch fixes this by adding dropType to the optimizer. Resolves cockroachdb#61226 Release note: none Signed-off-by: Tharun <[email protected]>
ad4fbad
to
556ea20
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.
thank you! this was a nice cleanup
bors r+ |
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! 1 of 0 LGTMs obtained (waiting on @rafiss and @tharun208)
Build succeeded: |
Release justification: fixes for high-priority or high-severity bugs in existing functionality
Previously, prepare statement doesn't have support for drop type
in the optimizer, so it panics during execution as no flags are generated.
This patch fixes this by adding
dropType
to the optimizer.Resolves #61226
Release note: none
Signed-off-by: Tharun [email protected]