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
Fix some bugs involving union and coalescing of optional values #6590
Conversation
There are a number of places that improperly handle a set that has multiple NULL values in it: * INSERT on single values * UPDATE on single values * assert_single The assert_single case is a long standing bug that can be triggered without much trouble. The INSERT/UPDATE bugs are new, and stem from the new ?? on DML, since I think it that was the first thing in the compiler backend where extra NULLS might be produced for something with single cardinality. Fix this by adding null checks at the consumer sites. One of the consumer sites is set_as_subquery, and I modified update to always use that. I also added a helper function to add the null checks, and I'll be going back and changing lots of other code to use the helper. We could also flip this around a bit and try saying that we shouldn't ever produce extra NULLs in a single set, and try to stamp it out on the producer side, though that seems a little less consistent to me? Fixes #6438.
Why? I have the opposite feeling that stamping out all callers could be a more error-prone whack-a-mole? |
There is sort of a general question of "when is having NULLs output by a producer permitted" that needs to be answered. The answer can't be "never", because at the very least we have our optional wrappers, but more generally we want some operations to always produce NULL and for us to be able to elide the optional wrapper in that case. (Object property references, parameters, json casts are current operations where this happens).
Alright I have convinced myself that option 2 is the best. |
this will make it easier to inject the filter on the backend
There are a number of places that improperly handle a set that has multiple NULL values in it: * INSERT on single values produced by ?? * UPDATE on single values produced by ?? * assert_single * limit/offset The assert_single and limit case is a long standing bug that can be triggered without much trouble. The INSERT/UPDATE bugs are new, and stem from the new ?? on DML, since I think it that was the first thing in the compiler backend where extra NULLS might be produced for something with single cardinality. Fix the long-standing cases by adding null checks, but fix the coalesce cases by adding a null check at the producer side. The rule then, is that there can be NULLs in any produced set that can be empty, but a single set has to return at most one row (so it can't have extra NULLs). Fixes #6438.
…#6590) The original 4.x/5.x version had a lot to do with DML coalescing. There are a number of places that improperly handle a set that has multiple NULL values in it: * assert_single * limit/offset The assert_single and limit case is a long standing bug that can be triggered without much trouble. Fix the long-standing cases by adding null checks, but fix the coalesce cases by adding a null check at the producer side. The rule then, is that there can be NULLs in any produced set that can be empty, but a single set has to return at most one row (so it can't have extra NULLs).
…#6590) The original 4.x/5.x version had a lot to do with DML coalescing. There are a number of places that improperly handle a set that has multiple NULL values in it: * assert_single * limit/offset The assert_single and limit case is a long standing bug that can be triggered without much trouble. Fix the long-standing cases by adding null checks, but fix the coalesce cases by adding a null check at the producer side. The rule then, is that there can be NULLs in any produced set that can be empty, but a single set has to return at most one row (so it can't have extra NULLs).
There are a number of places that improperly handle a set that has multiple NULL values in it: * INSERT on single values produced by ?? * UPDATE on single values produced by ?? * assert_single * limit/offset The assert_single and limit case is a long standing bug that can be triggered without much trouble. The INSERT/UPDATE bugs are new, and stem from the new ?? on DML, since I think it that was the first thing in the compiler backend where extra NULLS might be produced for something with single cardinality. Fix the long-standing cases by adding null checks, but fix the coalesce cases by adding a null check at the producer side. The rule then, is that there can be NULLs in any produced set that can be empty, but a single set has to return at most one row (so it can't have extra NULLs). Fixes #6438.
There are a number of places that improperly handle a set that has
multiple NULL values in it:
The assert_single case is a long standing bug that can be triggered
without much trouble. The INSERT/UPDATE bugs are new, and stem from
the new ?? on DML, since I think it that was the first thing in the
compiler backend where extra NULLS might be produced for something
with single cardinality.
Fix this by adding null checks at the consumer sites. One of the
consumer sites is set_as_subquery, and I modified update to always use
that.
I also added a helper function to add the null checks, and I'll be
going back and changing lots of other code to use the helper.
We could also flip this around a bit and try saying that we shouldn't
ever produce extra NULLs in a single set, and try to stamp it out on
the producer side, though that seems a little less consistent to me?
Fixes #6438.