Do not consider non-deterministic expressions as invariants in pre-filters #7853
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.
Related to my prior commit for #1708. Even if the boolean does not access table fields it may still be non-deterministic, in this case it should not be treated as invariant and evaluated just once.
Example:
select count(*) from employee where rand() > 0.5
The condition is not correlated with any data but still produces a different result per every invocation. Prior to v5, it returned (approximately) half rows of the result set. In v5, it returns either zero rows or a half of them, depending on what was the result of
RAND()
during its first invocation.Tested with constant expressions,
RAND()
and SQL functions defined as deterministic and non-deterministic. This patch does not detect determinism too deeply (e.g. whether a field references stream from the current scope or the outer one), only to the level currently needed for the optimizer.