Skip to content

Fix nullable propagation in OR/IS NULL filters#142728

Draft
MattAlp wants to merge 6 commits intoelastic:mainfrom
MattAlp:fix/esql-nullable-propagation
Draft

Fix nullable propagation in OR/IS NULL filters#142728
MattAlp wants to merge 6 commits intoelastic:mainfrom
MattAlp:fix/esql-nullable-propagation

Conversation

@MattAlp
Copy link
Contributor

@MattAlp MattAlp commented Feb 19, 2026

Summary

  • fix PropagateNullable so field IS NULL propagation substitutes null into matching expressions and folds, instead of nullifying entire expression branches
  • preserve correct semantics for predicates like (field IS NOT NULL OR p) AND field IS NULL, which previously could be rewritten to an always-empty filter
  • add regression coverage in local optimizer and PropagateNullable tests to prevent reintroducing the pruning
  • This patch was 'agentically' written based on a spec generated by fuzzing using ternary logic partitioning (TLP) - the fuzzing code is a Spacetime WIP

Preserve IS NULL filter semantics when OR branches reference the same
field by substituting null into expressions and folding, instead of
replacing entire branches with null.

Co-authored-by: Cursor <cursoragent@cursor.com>
elasticsearchmachine and others added 4 commits February 19, 2026 19:18
Use a reduced disjunction/nullability case and assert plan semantics
rather than matching the original fuzz-generated query shape.

Co-authored-by: Cursor <cursoragent@cursor.com>
Align the regression with the optimizer test suite pattern by using
an explicit typed plan chain while still asserting both preserved
conjuncts after optimization.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Contributor

@julian-elastic julian-elastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the change looks good. I left some small suggestions to address before we check in.

@julian-elastic
Copy link
Contributor

Also please add better comments in the PR with explanation.

Let A = field IS NOT NULL and B = p. Then field IS NULL = NOT A.
  The expression is:

  (A OR B) AND (NOT A)

  Distribute AND over OR:

  (A AND NOT A) OR (B AND NOT A)
    = FALSE     OR (B AND NOT A)
    = B AND NOT A

  Substitute back:

  p AND field IS NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments