sql: implement REPLACE FUNCTION#85900
Conversation
7e578e0 to
64f3051
Compare
64f3051 to
9e2970b
Compare
|
I'll move this into (and the one in Code quote: if udfDesc.LeakProof && udfDesc.Volatility != catpb.Function_IMMUTABLE {
return pgerror.Newf(
pgcode.InvalidFunctionDefinition,
"cannot create leakproof function with non-immutable volatility: %s",
udfDesc.Volatility.String(),
)
} |
ajwerner
left a comment
There was a problem hiding this comment.
Reviewed 2 of 6 files at r1, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @ajwerner and @chengxiong-ruan)
pkg/sql/crdb_internal.go line 2594 at r1 (raw file):
`, populate: func(ctx context.Context, p *planner, db catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error { flags := tree.ObjectLookupFlags{CommonLookupFlags: tree.CommonLookupFlags{AvoidLeased: true}}
I think this is only reasonable to do because of the work @jasonmchan did such that by the time we're here, we have every descriptor 🎉 . I also think it means that you'd end up using a read descriptor rather than a leased one anyway. I guess one thing that might be cool would be to add an rttyanalysis test for a query against this table.
pkg/sql/create_function.go line 195 at r1 (raw file):
} udfMutableDesc.DependsOnTypes = append(udfMutableDesc.DependsOnTypes, id) }
Use catalog.DescIDSet and build the first set and difference the second and then call Ordered?
Code quote:
udfDesc.DependsOnTypes = []descpb.ID{}
for id := range n.typeDeps {
if implicitTypeTblIDs.Contains(int(id)) {
continue
}
udfDesc.DependsOnTypes = append(udfDesc.DependsOnTypes, id)pkg/sql/create_function.go line 299 at r1 (raw file):
// tables used directly in function body or as implicit types. backrefTblIDs := util.MakeFastIntSet() implicitTypeTblIDs := util.MakeFastIntSet()
catalog.DescIDSet?
Code quote:
backrefTblIDs := util.MakeFastIntSet()
implicitTypeTblIDs := util.MakeFastIntSet()pkg/sql/create_function.go line 376 at r1 (raw file):
// Add forward references to UDF descriptor. udfDesc.DependsOn = make([]descpb.ID, 0, backrefTblIDs.Len())
udfDesc.DependsOn = backrefTblIDs.Ordered()?
Code quote:
udfDesc.DependsOn = make([]descpb.ID, 0, backrefTblIDs.Len())
backrefTblIDs.ForEach(func(id int) {
udfDesc.DependsOn = append(udfDesc.DependsOn, descpb.ID(id))
})9e2970b to
6fd956e
Compare
chengxiong-ruan
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ajwerner and @jasonmchan)
pkg/sql/crdb_internal.go line 2594 at r1 (raw file):
Previously, ajwerner wrote…
I think this is only reasonable to do because of the work @jasonmchan did such that by the time we're here, we have every descriptor 🎉 . I also think it means that you'd end up using a read descriptor rather than a leased one anyway. I guess one thing that might be cool would be to add an
rttyanalysistest for a query against this table.
Oh yeah, that's awesome work! Though I didn't do ReadAllDescriptors() here, should I do that? Do you think it's an overkill here given the number of schema and function could be low?
pkg/sql/create_function.go line 195 at r1 (raw file):
Previously, ajwerner wrote…
Use
catalog.DescIDSetand build the first set and difference the second and then callOrdered?
that saved my life, fixed, thanks!
pkg/sql/create_function.go line 299 at r1 (raw file):
Previously, ajwerner wrote…
catalog.DescIDSet?
ah, thanks, I kept forgetting this. fixed
pkg/sql/create_function.go line 376 at r1 (raw file):
Previously, ajwerner wrote…
udfDesc.DependsOn = backrefTblIDs.Ordered()?
yes, with ID set, this is much nicer. fixed
ajwerner
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner and @jasonmchan)
pkg/sql/crdb_internal.go line 2594 at r1 (raw file):
Previously, chengxiong-ruan (Chengxiong Ruan) wrote…
Oh yeah, that's awesome work! Though I didn't do
ReadAllDescriptors()here, should I do that? Do you think it's an overkill here given the number of schema and function could be low?
Oh, I suppose that that's right. I don't know. It's one of those things where it's really painful if the nodes are far apart. I'm hopeful in 23.1 to adopt global tables, but for now it's going to be O(functions) round-trips which might be very slow. One approach might be to collect the IDs in one pass and then fetch them as a batch and then iterate separately.
7db9f60 to
120fe55
Compare
|
Previously, ajwerner wrote…
I see, thanks for the background info. And thanks for the batching idea, I changed it that way |
|
TFTR! |
|
Build failed (retrying...): |
|
Build failed (retrying...): |
|
Build failed (retrying...): |
|
Build failed: |
|
hmm bizarre timeout on some backup tests |
This commit adds to the `REPLACE` path to the
`CREATE OR REPLACE FUNCTION` statement. Major changes are
(1) fetch function with same signature if exists, and validate
(2) remove refereces before replacing the function, and then
add new references.
Release note: None
120fe55 to
d71f834
Compare
|
Looks like the time out was fixed overnight maybe by #86191 |
|
I'm worried there's still a flake in there somewhere. If you see one, let me know. |
|
🙏 |
|
Build succeeded: |
This commit adds to the
REPLACEpath to theCREATE OR REPLACE FUNCTIONstatement. Major changes are(1) fetch function with same signature if exists, and validate
(2) remove refereces before replacing the function, and then
add new references.
Fixes #83236
Release note: None
Release justification: This commit includes a fix to avoid duplicate functions.