Repository navigation
Do not claim toDayOfWeek monotonicity for the Sunday-first modes - #117683
Conversation
`ToDayOfWeekImpl` declares monotonicity with `ToMondayImpl` as its factor transform,
which means "monotonic inside the enclosing Monday-based week". That is true for the
Monday-first modes 0 and 1, but not for the Sunday-first modes 2 and 3: there the
value drops back at Sunday, in the middle of the factor's interval.
`KeyCondition` consults that claim for the two-argument form through
`FunctionWithOptionalConstArg`, so a range predicate on `toDayOfWeek(key, 2)` over a
date key pruned granules that hold matching rows, at default settings:
SELECT count() FROM t WHERE toDayOfWeek(d, 2) >= 5; -- 1
SELECT countIf(toDayOfWeek(d, 2) >= 5) FROM t; -- 4
The wrapper knows the constant mode, so it now declines monotonicity for the
Sunday-first modes. The Monday-first modes keep pruning as before.
Closes: #117264
|
Workflow [PR], commit [b8626cb] Summary: ❌
AI ReviewSummaryThis PR teaches Final Verdict✅ No new review findings. LLVM Coverage ReportMeasured on commit b8626cb.
Changed lines: Changed C/C++ lines covered: 10/13 (76.92%) · Uncovered code |
|
While looking at this fix I found two adjacent monotonicity-liar cases in the same
Flagging in case the maintainers prefer to address the custom-week monotonicity in |
…mode-monotonicity-117264
…nt form `arm_tidy` failed with `variable 'mode_value' is not initialized` (`cppcoreguidelines-init-variables`) - initialize it. Master meanwhile added `05058_max_joined_block_size_rows_zero_with_bytes`, so renumber the test to `05175`. Address the review comment asking about `toDayOfWeek(key, mode, timezone)`: both monotonic-chain builders in `KeyCondition` reject functions of arity greater than two (`isKeyPossiblyWrappedByMonotonicFunctionsImpl` bails on `arguments_size > 2`, and `extractMonotonicFunctionsChainFromKey` requires `children.size() <= 2`), so the 3-argument overload never enters a chain and never prunes at all - in either numbering. Add explicit test coverage that pins this down, checking both the row counts and that the 3-argument form reads every mark while the 2-argument Monday-first form still prunes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Thanks — both are real and both are genuinely orthogonal to this PR, so I would rather keep them separate than widen this change. On the placement question: I agree that a timezone-aware factor in #117697 ( Left both as filed. |
…equests Several other in-flight pull requests also renumbered their tests to `05175` against the same master state, so pick a number that is free in all of them. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing commit See the job log for details. |
… old analyzer The old analyzer fails with `Unknown column: _subquery721 (UNKNOWN_IDENTIFIER)` when scalar subqueries are used inside a `UNION ALL` of constant rows, which made the test fail in the `old analyzer` stateless configuration. One statement per mode produces the same reference output. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117683&sha=214ad2f8f99323968f5c03640170eafe288a83bf&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20old%20analyzer%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F3%29 PR: #117683 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…mode-monotonicity-117264
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117683&sha=214ad2f8f99323968f5c03640170eafe288a83bf&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The server did not come back after the stress restart, aborting with |
|
That failure is already fixed on master, so there is no new PR to send for it; the engine defect underneath it is still open, with a fix in review that is not mine. All of the below is measured from that job's own artifacts. Producer: Mechanism. Fix for the CI failure: #119188, merged 2026-09-10 18:12:21Z, tagging 04935 Open, engine side: #115632, which refuses such a CREATE TABLE t (c Tuple(`a.keys` Array(String), a Map(String, UInt64)))
ENGINE = MergeTree ORDER BY tuple() SETTINGS min_bytes_for_wide_part = 1073741824;
INSERT INTO t VALUES ((['x', 'y'], {'k': 1}));Measured on 2026-09-10 at master One gap #115632 leaves: it only logs on attach, so an existing table keeps accepting inserts that write an unreadable part. I have a measured write side refusal for that case (one function, 0 false positives across 2342 stateless tests), dropped rather than put a second design against an open PR. If you want it, I will send it as a separate PR. |
|
🕵 @groeneai, thank you for the precise attribution. Agreed on all three points: the producer was |
#117683 declined monotonicity for `toDayOfWeek` with a Sunday-first mode in `FunctionWithOptionalConstArg`, because the factor transform was `ToMondayImpl`. This branch replaces that factor with `ToDayOfWeekFactorImpl`, which pairs the Monday-week with the Sunday-week and is sound for every mode, so the carve-out is redundant and only disabled the pruning that `05230` pins for modes 2 and 3. `05186` keeps checking that no row is lost; its last assertion now checks that both numberings prune. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ToDayOfWeekImpldeclares monotonicity withToMondayImplas its factor transform, which means "monotonic inside the enclosing Monday-based week". That is true for the Monday-first modes 0 and 1, but not for the Sunday-first modes 2 and 3: there the value drops back at Sunday, in the middle of the factor's interval.KeyConditionconsults that claim for the two-argument form throughFunctionWithOptionalConstArg, so a range predicate ontoDayOfWeek(key, 2)over a date key pruned granules that hold matching rows, at default settings:The wrapper knows the constant mode, so it now declines monotonicity for the Sunday-first modes (only the two lowest bits of the mode are significant, as in
DateLUTImpl::check_week_day_mode). The Monday-first modes keep pruning as before, which the test asserts.Closes: #117264
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed silently missing rows for a range predicate on
toDayOfWeek(key, mode)with the Sunday-first modes 2 and 3 over a date primary key: the primary key analysis assumed a monotonicity that does not hold for those modes and pruned granules holding matching rows.Workflow [PR]
Sync PR [sync-upstream/pr/117683]
Version info
26.10.1.277-master(included in26.10and later)