Styxis
Company
Knowledge

Check NaN constants before treating negated DuckDB comparisons as algebra

Reconcile row-selection flags for the original negated comparison and its optimized path when NaN is present. Quarantining every non-finite value does not establish that the original predicate was preserved.

Establish NaN comparison semantics

Moving unary minus across a comparison is not automatically equivalent for a NaN constant. Truthound Core can compare prepared row-selection Booleans with a reference based on DuckDB semantics rather than a universal floating-point ordering assumption. [1, 2, 3]

A reported rewrite difference

DuckDB issue #28052 reports comparison results changing with expression_rewriter in the 2.0 family. A follow-up expands the observed forms to FLOAT, DOUBLE, ordered operators, and projection or FILTER contexts. The reporter separates tested comparisons from the proposed unary-minus rewrite mechanism. [1]

Keep values and expression context

Build a selection table for negative, positive, infinite, and NaN inputs. Compare the original -d predicate with the rewritten path and preserve the engine version and optimizer setting. Check the declared DuckDB NaN ordering instead of borrowing another engine’s rules. [1, 3]

The finite 1.5 witness

Adopt the report’s rule that NaN sorts above other DOUBLE values. With d=1.5, -d=-1.5 cannot exceed NaN, so keep=false passes. keep=true fails because it changes the selected set. NaN-versus-NaN cases require their own expected Boolean and must not inherit this finite-input result. [1, 3]

Compare prepared selection flags

ColumnPairValidator in Truthound Core Python SDK 3.3.2 can compare non-null keep columns with ==. The operator supplies the predicate reference and special-value classification. It does not rewrite the optimizer or turn a suspected mechanism into an independently established cause. [1, 2, 3]

Use a controlled rewrite comparison

An expression_rewriter-disabled run is a useful control on the same data, subject to other semantic and performance effects. Preserve both query text and setting so a result is not attributed merely to a version label. [1, 3]

Quarantine differs from equivalence

This is a selection contract, not a rule to reject every NaN. A policy that isolates all nonfinite values may be appropriate elsewhere, but it does not prove the original comparison retained its meaning. [1, 3]

Application conditions

Prepare selection flags with DuckDB NaN semantics and optimizer settings retained.

Alternatives

Use an expression_rewriter-disabled path as a controlled same-data comparison.

Limitations

  • Do not generalize DuckDB NaN ordering to every engine.

Evidence

Event checked
Subject checked
Modified