Skip to content

release-20.2: opt: cast to identical types for set operations#61086

Merged
RaduBerinde merged 1 commit intocockroachdb:release-20.2from
RaduBerinde:backport20.2-60560
Feb 25, 2021
Merged

release-20.2: opt: cast to identical types for set operations#61086
RaduBerinde merged 1 commit intocockroachdb:release-20.2from
RaduBerinde:backport20.2-60560

Conversation

@RaduBerinde
Copy link
Copy Markdown
Member

Backport 1/1 commits from #60560.

/cc @cockroachdb/release


This change makes the optbuilder more strict when building set
operations. Previously, it could build expressions which have
corresponding left/right types which are Equivalent(), but not
Identical(). This leads to errors in vectorized execution, when we
e.g. try to union a INT8 with an INT4.

We now make the types on both sides Identical(), adding casts as
necessary. We try to do a best-effort attempt to use the larger
numeric type when possible (e.g. int4->int8, int->float, float->decimal).

Fixes #59148.

Release note (bug fix): fixed execution errors for some queries that
use set operations (UNION / EXCEPT / INTERSECT) where a column has
types of different widths on the two sides (e.g. INT4 vs INT8).

This change makes the optbuilder more strict when building set
operations. Previously, it could build expressions which have
corresponding left/right types which are `Equivalent()`, but not
`Identical()`. This leads to errors in vectorized execution, when we
e.g. try to union a INT8 with an INT4.

We now make the types on both sides `Identical()`, adding casts as
necessary. We try to do a best-effort attempt to use the larger
numeric type when possible (e.g. int4->int8, int->float, float->decimal).

Fixes cockroachdb#59148.

Release note (bug fix): fixed execution errors for some queries that
use set operations (UNION / EXCEPT / INTERSECT) where a column has
types of different widths on the two sides (e.g. INT4 vs INT8).
@RaduBerinde RaduBerinde requested a review from a team as a code owner February 24, 2021 20:19
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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.

Reviewed 6 of 6 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

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.

3 participants