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

expr: compute output type of coalesce function more obviously #2302

Merged
merged 1 commit into from Mar 13, 2020

Conversation

@benesch
Copy link
Member

benesch commented Mar 13, 2020

The output type computation for the coalesce function was previously
quite clever and would mark coalesce as non-nullable if all of its
inputs were non-nullable. It also had an unnecessary check for
ScalarType::Unknown: all inputs to coalesce are made to have the same
type, so there is no need to filter out ScalarType::Unknown when
computing a coalesce invocation's output type.

It is quite a bit clearer if we instead declare the output type of
coalesce to be:

  • unconditionally nullable
  • the same scalar type as its inputs (which are required to all be
    of the same type)

We're not losing an optimization here, either. If a coalesce is indeed
applied to all non-nullable arguments, the new support for reducing
coalesce expressions (see #2298) will remove the coalesce entirely, and
so the non-nullability of the first input will be accessible to the
optimizer in that way.

The output type computation for the coalesce function was previously
quite clever and would mark coalesce as non-nullable if all of its
inputs were non-nullable. It also had an unnecessary check for
ScalarType::Unknown: all inputs to coalesce are made to have the same
type, so there is no need to filter out ScalarType::Unknown when
computing a coalesce invocation's output type.

It is quite a bit clearer if we instead declare the output type of
coalesce to be:

  - unconditionally nullable
  - the same scalar type as its inputs (which are required to all be
    of the same type)

We're not losing an optimization here, either. If a coalesce is indeed
applied to all non-nullable arguments, the new support for reducing
coalesce expressions (see #2298) will remove the coalesce entirely, and
so the non-nullability of the first input will be accessible to the
optimizer in that way.
Copy link
Member

frankmcsherry left a comment

Looks good to me!

@benesch benesch merged commit 438c500 into MaterializeInc:master Mar 13, 2020
14 checks passed
14 checks passed
buildkite/tests Build #5918 passed (14 minutes, 49 seconds)
Details
buildkite/tests/bath-lint-and-rustfmt Passed (1 minute, 7 seconds)
Details
buildkite/tests/bulb-bulb-full-sql-logic-tests Passed (0 seconds)
Details
buildkite/tests/bulb-short-sql-logic-tests Passed (1 minute, 16 seconds)
Details
buildkite/tests/cargo-test Passed (52 seconds)
Details
buildkite/tests/docker-build Passed (11 minutes, 21 seconds)
Details
buildkite/tests/face-with-monocle-miri-test Passed (57 seconds)
Details
buildkite/tests/metabase-demo Passed (55 seconds)
Details
buildkite/tests/paperclip-clippy-and-doctests Passed (1 minute, 40 seconds)
Details
buildkite/tests/pipeline Passed (14 seconds)
Details
buildkite/tests/racing-car-testdrive Passed (3 minutes, 11 seconds)
Details
buildkite/tests/shower-streaming-demo Passed (28 seconds)
Details
license/cla Contributor License Agreement is signed.
Details
netlify/materializeinc/deploy-preview Deploy preview canceled.
Details
@benesch benesch deleted the benesch:coalesce-typing branch Mar 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.