cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

opt: type check VALUES rows after building them

Open DrewKimball opened this issue 1 year ago • 1 comments

The type of a RECORD-returning UDF is not fully resolved until after it is fully built within the optbuilder. Therefore, a VALUES expression with a UDF can only determine its column types after building its rows. We accounted for this in #103078, but that fix was incomplete - building the row resolves the type of the UDF, but does not update the type annotation for any expressions that wrap it (for example, a COALESCE).

This commit fully fixes the type resolution bug by type checking the row once again after it is built. This ensures that the UDF's resolved type is correctly propagated to parent expressions.

Fixes #117101

Release note (bug fix): Fixed a bug that would cause an internal error when the result of a RECORD-returning UDF was wrapped by another expression (such as COALESCE) within a VALUES clause.

DrewKimball avatar Aug 27 '24 04:08 DrewKimball

This change is Reviewable

cockroach-teamcity avatar Aug 27 '24 04:08 cockroach-teamcity

@DrewKimball Can we merge this?

mgartner avatar Oct 31 '24 15:10 mgartner

I updated the re-typing logic to use the previously resolved type rather than the desired type. This is necessary because type annotations in the AST could have been removed by the time we re-type.

DrewKimball avatar Dec 18 '24 07:12 DrewKimball

TFTRs!

bors r+

DrewKimball avatar Dec 18 '24 21:12 DrewKimball

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #117101: branch-release-23.2, branch-release-24.1, branch-release-24.2, branch-release-24.3.


:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] avatar Dec 18 '24 22:12 blathers-crl[bot]

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from aa866dfcab593aac5f97d9359e495059e300c96c to blathers/backport-release-23.2-129706: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.2.x failed. See errors above.


error creating merge commit from aa866dfcab593aac5f97d9359e495059e300c96c to blathers/backport-release-24.1-129706: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.1.x failed. See errors above.


:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] avatar Dec 18 '24 22:12 blathers-crl[bot]