Repository navigation
Conversation
ClickHouse#109097 reworked `year` from a case-insensitive alias of `toYear` into its own variadic function. Its resolver reports `isDeterministic() == false` for every arity, but `build()` forwards every non-empty argument list to `toYear`, whose base is deterministic. Determinism gates that inspect the unresolved AST by function name therefore get one arity-blind answer and reject the argument-bearing form: `SELECT count() FROM t WHERE YEAR(d) = 2020 SETTINGS use_query_cache = 1` throws `QUERY_CACHE_USED_WITH_NONDETERMINISTIC_FUNCTIONS`, and a mutation predicate on `year(<date>)` throws `BAD_ARGUMENTS` both at submission on a Replicated table and on the `apply_mutations_on_fly` read path. `YEAR` has been a spelling of `toYear` since 421d285 (2022-08-27), so queries written against any released version hit this after upgrading. `IFunctionOverloadResolver` could only be asked "is this function deterministic?", never "is the form with N arguments deterministic?", so the single answer had to cover both forms and the conservative one is what the niladic form needs. This adds `isDeterministicForArity(size_t)`, defaulting to `isDeterministic()`, overridden only by `year`, and passes the argument count at the eleven gates that ask a resolver rather than a built `IFunctionBase`: the query-result-cache and mutation determinism gates (which threw), plus partition pruning for mutations, `additional_table_filters` push-down, normal and aggregate projection selection, the query-oracle probe, and three analyzer sites (constant folding, the function-base cache, early short-circuit). Because exactly one resolver overrides the new method, the only behaviour that changes is `year(<date>)`, which goes back to behaving like `toYear(<date>)`. The gates keep asking the resolver rather than the built base on purpose: `joinGet` and `dictGetDescendants` report `false` from their resolvers while inheriting `true` on their bases, so asking the base would have started folding those as deterministic constants, well outside the scope of this change. `system.functions` keeps reporting `deterministic = 0` for `year`: it has one row per name and cannot express arity, so the arity-blind answer stays the conservative one. The new entry point is a distinctly named method rather than a second `isDeterministic` overload, which was declined on ClickHouse#109097 (r3569877383): no name hiding, no `-Woverloaded-virtual` exposure, and a self-documenting call site. Closes: ClickHouse#119947 Related: ClickHouse#109097 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings) plus my own cold
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260914-151400 |
|
Workflow [PR], commit [4fa33a0] Summary: ⏳
AI ReviewSummaryThis PR makes overload-level determinism checks arity-aware so Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1300 translation units recompiled, 7690 s compile time in total, 1300 of them have a recent master baseline. |
Closes: #119947
Related: #109097
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: the behaviour being fixed was introduced in 26.9, and 26.9 is not released, so no released version ever reported
year(<date>)as non-deterministic.Description
#109097 turned
yearfrom a case-insensitive alias oftoYearinto its own variadic function. Its resolver reportsisDeterministic() == falsefor every arity, whilebuild()forwards any non-empty argument list totoYear, whose base is deterministic. Gates that inspect the unresolved AST by name therefore see one arity-blind answer and reject the argument-bearing form:ALTER TABLE ... UPDATE ... WHERE year(d) = ...likewise throwsBAD_ARGUMENTS, both at submission on a Replicated table and on theapply_mutations_on_flyread path.YEARhas spelledtoYearsince 2022 (421d28542bc76eb), so queries written against any released version hit this after upgrading to 26.9.Root cause:
IFunctionOverloadResolvercould only be asked whether the function is deterministic, never whether its N-argument form is, so one answer had to cover both forms and the conservative one is whatyear()needs.This adds
isDeterministicForArity(size_t), defaulting toisDeterministic(), and passes the argument count at the eleven gates that ask a resolver rather than a builtIFunctionBase. Exactly one resolver overrides it, so the only behaviour that changes isyear(<date>), which goes back to behaving liketoYear(<date>). The gates keep asking the resolver on purpose:joinGetanddictGetDescendantsreportfalsefrom their resolvers while inheritingtrueon their bases, so asking the base instead would have started folding those as deterministic constants.system.functionsstill reportsdeterministic = 0foryear: one row per name cannot express arity, so the arity-blind answer stays conservative.The new method is distinctly named rather than a second
isDeterministicoverload, which was declined on #109097 (r3569877383).Workflow [PR]
Sync PR [sync-upstream/pr/120009]