Skip to content

Commit

Permalink
Merge #115848
Browse files Browse the repository at this point in the history
115848: sql: allow dropping routines with UDT-typed parameters r=DrewKimball a=DrewKimball

Previously, it was not possible to specify UDT parameters when dropping a routine. This is because of an oversight in `MatchAtIdentical`, which was likely copied from `MatchAt`. Specifically, `MatchAt` has special handling for tuple types that take advantage of the fact that `types.Equivalent` allows `types.AnyTuple` to match with any other tuple. `MatchAtIdentical, on the other hand, uses `types.Identical`, which does not make the same allowance. This meant that overload resolution would always fail for UDT parameters in code paths that use `MatchAtIdentical`, such as DROP FUNCTION.

This patch removes the replacement logic for tuple types in `MatchAtIdentical`, so that `types.Identical` is always called with the original type. This allows statements like the following to succeed:
```
DROP PROCEDURE foo(x udt);
```

Fixes #114677

Release note (bug fix): Fixed a bug existing since v23.1 that prevented naming UDT parameters when dropping a user-defined function (or procedure).

Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
  • Loading branch information
craig[bot] and DrewKimball committed Dec 9, 2023
2 parents 75e7cf9 + defd746 commit 22d9482
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
63 changes: 63 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/drop_function
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,66 @@ SET search_path = public

statement ok
DROP SCHEMA sc1;

# Regression test for #114677 - it should be possible to drop a function with
# a UDT parameter
subtest udt_parameter

statement ok
CREATE TYPE t114677 AS (x INT, y INT);
CREATE TYPE t114677_2 AS (a INT, b INT);

# Create an overload with a composite type that has the same signature to verify
# that the correct overload is dropped.
statement ok
CREATE FUNCTION f114677(v t114677) RETURNS INT LANGUAGE SQL AS $$ SELECT 0; $$;
CREATE FUNCTION f114677(v t114677_2) RETURNS INT LANGUAGE SQL AS $$ SELECT 1; $$;

query T nosort
SELECT create_statement FROM [SHOW CREATE FUNCTION f114677] ORDER BY create_statement;
----
CREATE FUNCTION public.f114677(IN v T114677)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 0;
$$
CREATE FUNCTION public.f114677(IN v T114677_2)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$

statement error pgcode 42725 pq: function name \"f114677\" is not unique
DROP FUNCTION f114677;

statement ok
DROP FUNCTION f114677(t114677);

query T
SELECT create_statement FROM [SHOW CREATE FUNCTION f114677];
----
CREATE FUNCTION public.f114677(IN v T114677_2)
RETURNS INT8
VOLATILE
NOT LEAKPROOF
CALLED ON NULL INPUT
LANGUAGE SQL
AS $$
SELECT 1;
$$

statement ok
DROP FUNCTION f114677;

statement error pgcode 42883 unknown function: f114677\(\)
SHOW CREATE FUNCTION f114677;

subtest end
15 changes: 15 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/drop_procedure
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,18 @@ SET search_path = public

statement ok
DROP SCHEMA sc1

# Regression test for #114677 - it should be possible to drop a procedure with
# a UDT parameter
subtest udt_parameter

statement ok
CREATE TYPE t114677 AS (x INT, y INT);

statement ok
CREATE PROCEDURE p114677(v t114677) LANGUAGE SQL AS $$ SELECT 0; $$;

statement ok
DROP PROCEDURE p114677(t114677);

subtest end
3 changes: 0 additions & 3 deletions pkg/sql/sem/tree/overload.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,6 @@ func (p ParamTypes) MatchAt(typ *types.T, i int) bool {

// MatchAtIdentical is part of the TypeList interface.
func (p ParamTypes) MatchAtIdentical(typ *types.T, i int) bool {
if typ.Family() == types.TupleFamily {
typ = types.AnyTuple
}
return i < len(p) && (typ.Family() == types.UnknownFamily || p[i].Typ.Identical(typ))
}

Expand Down

0 comments on commit 22d9482

Please sign in to comment.