Skip to content
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: only re-use resolved routine type when flag is set #143170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DrewKimball
Copy link
Collaborator

This commit adds a RoutineUseResolvedType flag to the SemaContext properties to indicate that type-checking for a routine that has already been resolved to a concrete type should short-circuit. This is used to determine the column type for a Values operator which depends on a RECORD-returning routine, which only determines its type after the body is built. This will prevent regressions in other code paths that do not desire this short-circuiting behavior.

Fixes #142615

Release note (bug fix): Fixed a bug in v24.1.14, v24.3.7, v24.3.8, and v25.1 which could cause a nil-pointer error when a column's default expression contained a volatile expression (like nextval) as a UDF argument.

@DrewKimball DrewKimball added backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.1.x Flags PRs that need to be backported to 25.1 labels Mar 19, 2025
@DrewKimball DrewKimball requested a review from mgartner March 19, 2025 22:58
@DrewKimball DrewKimball requested review from a team as code owners March 19, 2025 22:58
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich added backport-24.3.9-rc Monday, 03/31: release-24.3.9-rc will be frozen backport-24.1.15-rc Monday, 03/31: release-24.1.15-rc will be frozen backport-25.1.3-rc Monday, 03/31: release-25.1.3-rc will be frozen labels Mar 20, 2025
// should reuse the already resolved type, if any. This is used to handle
// "re-type-checking" that occurs for a RECORD-returning routine, for which
// the return type is not known until the routine body is built.
RoutineUseResolvedType bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to use ScalarAncestors here? The special case is a bit confusing to me - it only applies to routines within a VALUES expression?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can use ScalarAncestors, or at least it would potentially be more confusing. We apply the special case to expressions within a VALUES operator, but only on the second type-checking pass which happens when the VALUES column type depends on a record-returning routine. Using ScalarAncestors here would cause us to to also use this special behavior on the first type-checking pass.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This commit adds a `RoutineUseResolvedType` flag to the `SemaContext`
properties to indicate that type-checking for a routine that has already
been resolved to a concrete type should short-circuit. This is used to
determine the column type for a `Values` operator which depends on a
RECORD-returning routine, which only determines its type after the
body is built. This will prevent regressions in other code paths that
do not desire this short-circuiting behavior.

Fixes cockroachdb#142615

Release note (bug fix): Fixed a bug in `v24.1.14`, `v24.3.7`, `v24.3.8`,
and `v25.1` which could cause a nil-pointer error when a column's default
expression contained a volatile expression (like `nextval`) as a UDF
argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.1.15-rc Monday, 03/31: release-24.1.15-rc will be frozen backport-24.3.x Flags PRs that need to be backported to 24.3 backport-24.3.9-rc Monday, 03/31: release-24.3.9-rc will be frozen backport-25.1.x Flags PRs that need to be backported to 25.1 backport-25.1.3-rc Monday, 03/31: release-25.1.3-rc will be frozen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: v24.1.14: nil pointer regression due to a type-checking logic change
4 participants