Preserve NaN semantics for floating-point array_position pushdown - #341
Open
fallintoplace wants to merge 5 commits into
Open
Preserve NaN semantics for floating-point array_position pushdown#341fallintoplace wants to merge 5 commits into
fallintoplace wants to merge 5 commits into
Conversation
theory
requested changes
Aug 6, 2026
theory
left a comment
Collaborator
There was a problem hiding this comment.
Partial review, more later.
Comment on lines
+3527
to
+3537
| if ((node->consttype == FLOAT4OID || node->consttype == FLOAT8OID) && | ||
| strcmp(extval, "NaN") == 0) { | ||
| appendStringInfoString(buf, "nan"); | ||
| } else if ( | ||
| (node->consttype == FLOAT4OID || node->consttype == FLOAT8OID) && | ||
| (strcmp(extval, "Infinity") == 0 || strcmp(extval, "+Infinity") == 0) | ||
| ) { | ||
| appendStringInfoString(buf, "inf"); | ||
| } else if ( | ||
| (node->consttype == FLOAT4OID || node->consttype == FLOAT8OID) && | ||
| strcmp(extval, "-Infinity") == 0 |
Collaborator
There was a problem hiding this comment.
Use case-insensitive comparisons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
Fix
array_position()pushdown forreal[]anddouble precision[]columns.ClickHouse
indexOf()can miss aNaNwhen the array value and the search value were produced independently. PostgreSQL treats those values as a match forarray_position(), so the existing pushdown could returnNULLincorrectly.Implementation
nullIf(indexOf(...), 0)path for non-floating-point arrays.arrayFirstIndex()with an explicit predicate for floating-point arrays.NULL, and anyNaNpayload.x.NaN,Infinity, and-Infinityconstants as ClickHouse numeric float literals.starthandling witharraySlice()and restore the original PostgreSQL position.The floating-point predicate is equivalent to:
nullIf( arrayFirstIndex( value -> ( (isNull(value) AND isNull(r1.needle)) OR (value = r1.needle) OR (isNaN(value) AND isNaN(r1.needle)) ), r1.float_array ), 0 )Regression coverage
x, matching the lambda parameter nameNaN, positive infinity, and negative infinity constantsNULLneedles, including exact returned positionsRelated issue
ClickHouse/ClickHouse#113169 tracks the underlying floating-point
NaNmatching behavior in ClickHouse.Follow-up fix
The follow-up commit also covers array_position() expressions used only in pushed-down ORDER BY pathkeys. These expressions are resolved after the base relation is emitted, so they now share the same pathkey resolver during alias preflight and SQL generation. This keeps captured columns qualified in cases such as ORDER BY array_position(float64_vals, x), id.
Added regression coverage for the ORDER BY path and qualified generated SQL.