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

tree: don't resolve expressions with wildcard types #108892

Merged
merged 1 commit into from Oct 27, 2023

Conversation

DrewKimball
Copy link
Collaborator

There are various wildcard types that are used during type-checking, but which are not valid during execution. Previously, we only checked for types.Any in several places, but there are other wildcard types like types.AnyEnum with similar properties. This could lead to an internal panic during execution when this invalid type was resolved. This patch adds a new method types.T.IsWildcardType() that checks for all wildcard types, to be used during type-checking.

Fixes #83496

Release note (bug fix): Fixed a bug that has existed since before v22.2 which could cause an internal error during distributed execution for an expression like CASE that requires its inputs to be the same type with all NULL inputs.

@DrewKimball DrewKimball requested a review from a team August 17, 2023 07:07
@DrewKimball DrewKimball requested a review from a team as a code owner August 17, 2023 07:07
@DrewKimball DrewKimball removed the request for review from a team August 17, 2023 07:07
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

:lgtm: Thanks for this! Probably worth backporting.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@yuzefovich yuzefovich added backport-22.2.x Flags PRs that need to be backported to 22.2. backport-23.1.x Flags PRs that need to be backported to 23.1 labels Sep 8, 2023
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm:

I agree that it seems worth it to backport, so I added the corresponding labels, but it might be good to give it some baking time on master (the automatic backports should fail anyway).

bors r=rharding6373,yuzefovich

Reviewed 3 of 3 files at r1, 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @DrewKimball)

@craig
Copy link
Contributor

craig bot commented Sep 9, 2023

Build failed:

@yuzefovich
Copy link
Member

Looks like CI is red, perhaps #108387 changed something related.

@mgartner
Copy link
Collaborator

Looks like this fixes some tests which didn't match Postgres behavior (the tests I changed in the added commit), while it broke others (the tests I commented-out in the added commit).

There are various wildcard types that are used during type-checking,
but which are not valid during execution. Previously, we only checked
for `types.Any` in several places, but there are other wildcard types
like `types.AnyEnum` with similar properties. This could lead to an
internal panic during execution when this invalid type was resolved.
This patch adds a new method `types.T.IsWildcardType()` that checks
for all wildcard types, to be used during type-checking.

Fixes cockroachdb#83496

Release note (bug fix): Fixed a bug that has existed since before v22.2
which could cause an internal error during distributed execution for an
expression like `CASE` that requires its inputs to be the same type
with all `NULL` inputs.
Copy link
Collaborator Author

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, PTAL.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @yuzefovich)


pkg/sql/sem/tree/type_check.go line 1712 at r3 (raw file):

	if len(expr.Exprs) == 0 {
		if desiredParam.IsWildcardType() {

The change I made to ArrayExpr type checking was an oversight - only types.Any is used as a wildcard there.

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

:lgtm:

nit: I'd remove backport 22.2 and 23.1 labels and maybe would add 23.2.

Reviewed 3 of 3 files at r5, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale)

@DrewKimball DrewKimball removed backport-22.2.x Flags PRs that need to be backported to 22.2. backport-23.1.x Flags PRs that need to be backported to 23.1 labels Oct 27, 2023
@DrewKimball
Copy link
Collaborator Author

nit: I'd remove backport 22.2 and 23.1 labels and maybe would add 23.2.

Sure. I'll give it some time to bake before thinking about backporting, since it seems low-priority.

@DrewKimball
Copy link
Collaborator Author

TRTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 27, 2023

Build succeeded:

@craig craig bot merged commit 9b7662e into cockroachdb:master Oct 27, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

roachtest/sqlsmith: cannot resolve types in DistSQL by name with fakedist config
5 participants