-
Notifications
You must be signed in to change notification settings - Fork 473
Remove error promotion from COALESCE
#33103
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
Remove error promotion from COALESCE
#33103
Conversation
A point worth discussing: this breaks PostgreSQL compatibility for a query like Postgres
Materialize
The only way I can square this is that PostgreSQL replaces queries with errors if literal errors can occur in the query text, but then turns off that part of its brain in the course of query optimization. If we really want to respect this form of compatibility, it feels like a pass before any query transformations have occured. |
d2da4e7
to
c6997e9
Compare
The Postgres docs say I did some more tests:
I'll add these in an slt and push to the PR. Unfortunately, I can still make
We'd need to add a similar exception in MFP CSE for materialize/src/expr/src/linear.rs Lines 1488 to 1492 in 98cf9ae
|
This sounds worth doing and I'll take a look. I don't think we need extensive testing done yet though, in the absence of clear semantics (we had two tests for the previous version; the bug was that we didn't know what was supposed to happen). No harm, but it's more stuff we'll have to review once we do have an opinion on the error semantics (which @mgree is peeking at, so it's not wildly far-fetched). |
Maybe said differently: I think the tests for "postgres compat" make sense, but we should keep them apart from "intended behavior". Having just deleted some of the "intended behavior" tests for not actually being the intended behavior, but rather inspired by postgres compat. :D |
I think it's good to add tests, so that we at least know about it when the behavior changes. We'll need these tests anyway later when we do more comprehensive work on error semantics. Also, this is input to @mgree's work: These are some specific example queries that he can look at to see what his formal semantics say on them. I've pushed the tests here: Could you please cherry-pick that commit? ggevay@0d2b6ae Edit: Could you also add a comment above the new tests that we haven't totally decided yet whether this is the intended behavior? |
So, we don't agree on this. Let's discuss async. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Observed in #33103 (comment), and an easy fix. ### Motivation <!-- Which of the following best describes the motivation behind this PR? * This PR fixes a recognized bug. [Ensure issue is linked somewhere.] * This PR adds a known-desirable feature. [Ensure issue is linked somewhere.] * This PR fixes a previously unreported bug. [Describe the bug in detail, as if you were filing a bug report.] * This PR adds a feature that has not yet been specified. [Write a brief specification for the feature, including justification for its inclusion in Materialize, as if you were writing the original feature specification.] * This PR refactors existing code. [Describe what was wrong with the existing code, if it is not obvious.] --> ### Tips for reviewer <!-- Leave some tips for your reviewer, like: * The diff is much smaller if viewed with whitespace hidden. * [Some function/module/file] deserves extra attention. * [Some function/module/file] is pure code movement and only needs a skim. Delete this section if no tips. --> ### Checklist - [ ] This PR has adequate test coverage / QA involvement has been duly considered. ([trigger-ci for additional test/nightly runs](https://trigger-ci.dev.materialize.com/)) - [ ] This PR has an associated up-to-date [design doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md), is a design doc ([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)), or is sufficiently small to not require a design. <!-- Reference the design in the description. --> - [ ] If this PR evolves [an existing `$T ⇔ Proto$T` mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md) (possibly in a backwards-incompatible way), then it is tagged with a `T-proto` label. - [ ] If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label ([example](MaterializeInc/cloud#5021)). <!-- Ask in #team-cloud on Slack if you need help preparing the cloud PR. --> - [ ] If this PR includes major [user-facing behavior changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note), I have pinged the relevant PM to schedule a changelog post.
We have an expression optimization that promotes literal errors around the documented evaluation order guards of
COALESCE
. It seems like this may be for "postgres compatibility", as postgres does a similar thing of erroring even when there are non-null values before the error (but only observed when the error is present in the query text, rather than as a result of data). We have situations where literal errors result from data, and need to guard the promotion of the error in the way thatCOALESCE
is documented to do.Seems hard to imagine fall-out from this, as we believe we are optimizing the performance of an error-producing case. We'll see what tests say!
Motivation
Tips for reviewer
Checklist
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way), then it is tagged with aT-proto
label.