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

release-19.1: opt, sql: fix type inference of TypeCheck for subqueries #37598

Merged
merged 1 commit into from
May 20, 2019

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented May 20, 2019

Backport 1/1 commits from #37578.

/cc @cockroachdb/release


Prior to this commit, the optimizer was not correctly inferring the types of
columns in subqueries for expressions of the form scalar IN (subquery).
This was due to two problems which have now been fixed:

  1. The subquery was built as a relational expression before the desired types
    were known. Now the subquery build is delayed until TypeCheck is called for
    the first time.

  2. For subqueries on the right side of an IN expression, the desired type
    passed into TypeCheck was AnyTuple. This resulted in an error later on in
    typeCheckSubqueryWithIn, which checks to make sure the type of the subquery
    is tuple{T} where T is the type of the left expression. Now the desired
    type passed into TypeCheck is tuple{T}.

Note that this commit only fixes type inference for the optimizer. It is still
broken in the heuristic planner.

Fixes #37263
Fixes #14554

Release note (bug fix): Fixed type inference of columns in subqueries for
some expressions of the form scalar IN (subquery).

@rytaft rytaft requested a review from a team as a code owner May 20, 2019 16:11
@rytaft rytaft requested a review from a team May 20, 2019 16:11
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jordanlewis, @justinj, and @RaduBerinde)

Prior to this commit, the optimizer was not correctly inferring the types of
columns in subqueries for expressions of the form `scalar IN (subquery)`.
This was due to two problems which have now been fixed:

1. The subquery was built as a relational expression before the desired types
   were known. Now the subquery build is delayed until TypeCheck is called for
   the first time.

2. For subqueries on the right side of an IN expression, the desired type
   passed into TypeCheck was FamTuple. This resulted in an error later on in
   typeCheckSubqueryWithIn, which checks to make sure the type of the subquery
   is tuple{T} where T is the type of the left expression. Now the desired
   type passed into TypeCheck is tuple{T}.

Note that this commit only fixes type inference for the optimizer. It is still
broken in the heuristic planner.

Fixes cockroachdb#37263
Fixes cockroachdb#14554

Release note (bug fix): Fixed type inference of columns in subqueries for
some expressions of the form `scalar IN (subquery)`.
@rytaft rytaft merged commit 9671342 into cockroachdb:release-19.1 May 20, 2019
@rytaft rytaft deleted the backport19.1-37578 branch May 20, 2019 19:23
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.

None yet

3 participants