-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
119616: opt: correctly reconcile column definition list with RECORD-returning UDFs r=DrewKimball a=DrewKimball #### sql: remove usages of `types.IsRecordType` Previously, the `types.IsRecordType` function was used in different contexts (with vs without OUT-params, function params vs return type). This made it difficult to determine whether a particular usage was correct, and led to a few bugs in cases where additional checks were necessary. This commit replaces usages of `types.IsRecordType` with either: 1. `typ.Identical(types.AnyTuple)`, or 2. `typ.Oid() == oid.T_record` The former should be used for a RECORD-returning routine with no OUT-parameters, as well as for a RECORD-typed variable. The latter should be used to match either a RECORD-returning routine, or one with multiple OUT-parameters. Informs #114846 Release note: None #### optbuilder: use actual arg types when building routine with wildcard types Previously, we would always pass the static parameter types when building the routine. However, in some cases the static type is a wildcard, so we actually need to use the actual argument type. Note that always using the actual argument type can be incorrect (e.g. we'd lose the tuple labels present in the static type). Release note: None #### opt: refactor optbuild paths for routines and generator functions This commit heavily refactors the type-handling logic for routines and generator functions. The hope is to make the code more readable, and also make the changes in the next commit easier. Informs #114846 Release note: None #### opt: add assignment casts for UDFs used as a data source Previously, attempting to use a RECORD-returning UDF as a data source (e.g. `SELECT * FROM` syntax) would result in an internal error if the column definition list types didn't match the columns of the last statement. This commit fixes that by adding validation that the types are either identical or can be assignment-casted, and adding assignment casts if necessary. Fixes #114846 Fixes #113186 Release note (bug fix): Fixed a bug that could cause an internal error of the form `invalid datum type given: ..., expected ...` when a RECORD-returning UDF used as a data source was supplied a column definition list with mismatched types. This bug has existed since v23.1.0. #### opt/optbuilder: check for coercibility instead of tuple types This commit changes the handling of tuple-returning routines to mirror that of postgres. In particular, when the routine return type is a tuple, postgres first attempts to coerce result columns to the return type of the routine. Only if that attempt fails, postgres wraps the result column in a tuple, and again attempts the coercion. This change affects the handling of routines that return (for example) a single composite-typed column. For example, the following two logic tests should produce the same result: ``` statement ok CREATE TYPE two_typ AS (x INT, y INT); CREATE FUNCTION f() RETURNS two_typ LANGUAGE SQL AS $$ SELECT 1, 2; $$; query T SELECT f(); ---- (1,2) ``` vs ``` statement ok CREATE TYPE two_typ AS (x INT, y INT); CREATE FUNCTION f() RETURNS two_typ LANGUAGE SQL AS $$ SELECT ROW(1, 2); $$; query T SELECT f(); ---- (1,2) ``` There is not release note, since this shouldn't affect versions prior to 24.1. Fixes #120942 Release note: None Co-authored-by: Drew Kimball <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,007 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.