Skip to content

fix: keep volatile predicates in place when simplifying filters - #27742

Open
vishalkotak wants to merge 1 commit into
apache:mainfrom
vishalkotak:fix-volatile-predicate-order
Open

vishalkotak wants to merge 1 commit into
apache:mainfrom
vishalkotak:fix-volatile-predicate-order

Conversation

@vishalkotak

@vishalkotak vishalkotak commented Nov 25, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

Adding a redundant comparison to a filter could change how often a volatile function like random() runs. When the optimizer merged the comparisons, it moved the volatile call to the front, so it ran on every row instead of only the rows the earlier comparisons kept.

What changes are included in this PR?

Merged comparisons now stay where the first of them was written, and every other predicate keeps its place. A merged comparison is at least
as strict as the ones it replaces, so nothing after it sees more rows than before.

What is the testing strategy for this PR?

Added the example from the issue, which counts how often the volatile function runs, and plan tests for the other cases the issue lists. Two existing plan tests change order: predicates now follow the query instead of being grouped by column.

Are there any user-facing changes?

No.

Removing a redundant comparison could move a volatile call like random()
in front of the comparisons written before it, so it ran on more rows.
Simplified comparisons now stay where the first one was written, and
everything else keeps its place.

Closes apache#27683
@github-actions github-actions Bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PushDownFilter moves volatile conjuncts ahead of the comparisons it simplifies

1 participant