-
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/opt: add index on pg_proc(oid) and support regproc/procedure in foldOIDFamilyCast #92590
Conversation
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 reword the commit/PR title so it's clear that there is more to this change than just the foldOIDFamilyCast
function. The index added to the table was a surprise after reading the commit title.
query T | ||
select '12345'::regprocedure::string | ||
---- | ||
12345 |
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.
The tests in this file are verifying query plans to test that we can correctly build query plans, so I don't think these two tests should live here too. Perhaps pkg/sql/logictest/testdata/logic_test/cast
would be a better place?
@@ -408,6 +408,34 @@ func (c *CustomFuncs) foldOIDFamilyCast( | |||
default: | |||
return nil, false, nil | |||
} | |||
case oid.T_regproc: | |||
cDatum, err := eval.PerformCast(c.f.ctx, c.f.evalCtx, datum, typ) |
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.
I'm not convinced we need to use PerformCast
here. If we use it, we'll need some more checks to ensure that the cast is valid, e.g. use cast.ValidCast
, otherwise we'll be attempting to fold expressions like 12.3::FLOAT::REGPROC
which I think would fail.
Can we instead use similar logic as in the case oid.T_oid:
at the top of the switch?
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.
i think we should be able to use PerformCast
as long as we add similar cases like the ones we have in the Regtype case
da12760
to
a82a4cf
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 @mgartner and @rafiss)
pkg/sql/opt/exec/execbuilder/testdata/scalar
line 1055 at r1 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
The tests in this file are verifying query plans to test that we can correctly build query plans, so I don't think these two tests should live here too. Perhaps
pkg/sql/logictest/testdata/logic_test/cast
would be a better place?
A test like this exists in pkg/sql/logictest/testdata/logic_test/pgoidtype
so i'll remove them.
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.
looks close!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @e-mbrown and @mgartner)
pkg/sql/opt/norm/fold_constants_funcs.go
line 418 at r3 (raw file):
return nil, false, err } dOid = tree.NewDOidWithType(tree.MustBeDOid(cDatum).Oid, types.RegProc)
we should be able to replace all of this:
dOid = tree.NewDOidWithType(tree.MustBeDOid(cDatum).Oid, types.RegProcedure)
procName, overload, err := c.f.catalog.ResolveFunctionByOID(c.f.ctx, dOid.Oid)
if err != nil {
return nil, false, err
}
dOid = tree.NewDOidWithTypeAndName(overload.Oid, types.RegProcedure, procName)
with this:
dOid = tree.MustBeDOid(cDatum)
(The PerformCast
call already takes care of resolving the function, so no need to do it again)
pkg/sql/opt/norm/fold_constants_funcs.go
line 434 at r3 (raw file):
return nil, false, err } dOid = tree.NewDOidWithType(tree.MustBeDOid(cDatum).Oid, types.RegProcedure)
ditto, replace with dOid = tree.MustBeDOid(cDatum)
994a57f
to
c214e7e
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 @mgartner and @rafiss)
pkg/sql/opt/norm/fold_constants_funcs.go
line 418 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
we should be able to replace all of this:
dOid = tree.NewDOidWithType(tree.MustBeDOid(cDatum).Oid, types.RegProcedure) procName, overload, err := c.f.catalog.ResolveFunctionByOID(c.f.ctx, dOid.Oid) if err != nil { return nil, false, err } dOid = tree.NewDOidWithTypeAndName(overload.Oid, types.RegProcedure, procName)
with this:
dOid = tree.MustBeDOid(cDatum)
(The
PerformCast
call already takes care of resolving the function, so no need to do it again)
Done.
pkg/sql/opt/norm/fold_constants_funcs.go
line 434 at r3 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
ditto, replace with
dOid = tree.MustBeDOid(cDatum)
Done.
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! you just need to rewrite the create_statements
logic test to account for the index you added
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.
It looks like some unintended changes made it into the create_statements
file.
@e-mbrown you can use this command to rewrite the file:
|
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.
When I rewrite the test, tables other thanpg_proc
change in the output. Not sure why.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mgartner and @rafiss)
this is also failing a benchmark test, probably due to #90842. i will look into this
as far as the create_statements diff, maybe it's expected after #91702 ... but i'm not sure |
5ab105f
to
0142df1
Compare
i think this query will work. the issue is with the newlines in the result
|
in foldOIDFamilyCast Add index on pgproc(oid). Type cast to regproc and regprocedure can use the index on pgproc(oid). Release note: None
Thanks for all the help! bors r=rafiss |
Build succeeded: |
Informs: #91022
Add index on pgproc(oc).
Typecast to regproc and regprocedure can use the
index on pgproc(oid).
Release note: None