constant or null can be replaced when argument is a bound column reg #18018
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes https://github.com/duckdblabs/duckdb-internal/issues/5141
#17425 introduced an optimization to replace
constant_or_null(true, X)with anis_not_null(X)filter. This was not tested well and assumes thatXis just a BOUND_COLUMN_REF. IfXis a function (for examplecoalesce(X, 'value')) then this optimization does not produce the same results.In the coalesce example, the column X may only contain
NULLS, but since it is coalesced with a constant value, theIS NOT NULLfilter will produce a different result.I thought about adding an
IsNotNull()filter on top of the ExpressionFilter when propagating the statistics (@propagate_get.cpp:104). This turns the optimization into aconstant_or_nullintoIs not NULL (Coalesce('X', 'value')). The problem there is thatconstant_or_nullcan have multiple children, so it would turn into a conjunction and with all of the children.There is definitely still room to optimize the
constant_or_nullfunction, but since this is a bug fix, I tried to keep the diff small.