Repository navigation
Decline divide and multiply monotonicity for a constant that yields NaN - #118720
Conversation
```sql CREATE TABLE t (x Float64) ENGINE = MergeTree ORDER BY x; INSERT INTO t VALUES (-inf), (1), (2), (3); SELECT x / inf AS n FROM t ORDER BY n; -- nan, 0, 0, 0 SELECT x / inf AS n FROM t ORDER BY n LIMIT 2; -- nan, 0 ``` No `NaN` is in the data or in the query: the key holds `-inf` and the `ORDER BY` expression turns it into one. The read-in-order match asks for monotonicity with Null endpoints (`matchTrees` passes empty fields), `divide` by a positive constant answers "monotonically increasing", so the forward read of the key is kept - while the transformed value of the `-inf` row sorts last, and nothing sorts the stream afterwards. The check added in #118468 declines when a concrete endpoint maps to `NaN`, and cannot fire here because the endpoints are unknown. So the constant itself is examined: `divide`/`multiply` of a `Float` result by `0`, `±inf` or `NaN` can turn a legal input into `NaN` (`±inf / ±inf`, `0 * ±inf`), and only those constants can, so an ordinary `x / 2` still reads in order. Closes: #118472 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [4b8c55f] Summary: ✅
AI ReviewSummaryThis PR narrows Final Verdict
LLVM Coverage ReportMeasured on commit 4b8c55f.
Changed lines: Changed C/C++ lines covered: 37/38 (97.37%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units33 translation units recompiled, 491 s compile time in total, 33 of them have a recent master baseline. |
…form-to-nan-118472
…g operand's type The early rejection of `divide`/`multiply` monotonicity for a constant of `0`, `±inf` or `NaN` keyed off the `Float` result alone, so `UInt64 / inf` and `UInt64 * 0.` were declined too, although an integer domain has no `±inf` to turn into `NaN`. Now the constant is matched with the inputs that reach the `NaN`: `0 / 0` and `±inf * 0` with the constant `±inf` happen at a zero input, which every numeric domain holds, and remain declined; `±inf / ±inf`, `c / ±inf` and `±inf * 0` with the constant `0` need an infinite input and are declined only for a `Float` varying operand. The test now checks the read type through `EXPLAIN PLAN` for both a `Float64` and a `UInt64` key, and that index analysis keeps the matching rows. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: This PR only changes how clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…form-to-nan-118472
`UInt64 / inf` is `0` for every value, so reporting `is_strict = true` let `optimizeReadInOrder` keep matching later `ORDER BY` terms from the key, e.g. `ORDER BY x / inf, y` over a key `(x, y)` returned rows in `x` order instead of `y` order. Mark `variable / ±inf` and `±inf / variable` as non-strict, and add a two-key regression. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tant only when the concrete range reaches it `KeyCondition` passes the bounds of a range of marks to `getMonotonicityForRange`; a closed range with finite endpoints holds no `±inf`, and one on either side of zero holds no zero, so `x / inf` over a `Float64` range like `[1, 10]` keeps its monotonicity and its pruning. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…form-to-nan-118472
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a native numeric domain The `NaN`-producing-constant check compared concrete range endpoints with a numeric `0`. For an `IPv4` key the endpoints are `IPv4` fields, and the comparison threw `Cannot compare long with DB::IPv4` (`BAD_TYPE_OF_FIELD`) during index analysis, failing `04651_intdiv_const_variable_monotonicity_ip` and `04652_intdiv_ip_key_monotonicity` in the Fast test. Use the endpoints only for a native integer or float domain; otherwise assume the range holds zero, which is conservative. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118720&sha=a4cc31ad74918c6831c8d164a57f2ae349e56a7f&name_0=PR&name_1=Fast%20test #118720 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…form-to-nan-118472
…Float16` key too Also extract `Granules: N/M` from the `EXPLAIN` output in the test instead of trimming the line, because with parallel replicas the line has a tree prefix (`│`): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118720&sha=latest&name_0=PR&name_1=Stateless%20tests%20(amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecimal` key too The endpoints of a `Decimal` key are `DecimalField`, which compare with an integer `0`, so a range away from zero no longer declines the monotonicity of `0. / x` and keeps pruning granules. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #118472
Related: #118468
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a wrong order (and wrong rows under
LIMIT) from the read-in-order optimization when theORDER BYexpression maps a storedinftoNaN, as inORDER BY x / inf.Description
No
NaNis in the data or in the query: the key holds-inf, and theORDER BYexpression turns it into one. The read-in-order match asks for monotonicity with Null endpoints (matchTreespasses empty fields),divideby a positive constant answers "monotonically increasing", so the forward read of the key is kept - while the transformed value of the-infrow sorts last, and nothing sorts the stream afterwards.#118468 declines monotonicity when a concrete endpoint maps to
NaN; that check cannot fire here, because the endpoints are unknown. So the constant itself is examined now:divide/multiplyof aFloatresult by0,±inforNaNcan turn a legal input intoNaN(±inf / ±inf,0 * ±inf), and only those constants can, so an ordinaryx / 2keeps reading in order.Workflow [PR]
Sync PR [sync-upstream/pr/118720]
Version info
26.10.1.1922-master(included in26.10and later)