Repository navigation
Reject a TTL where_expr on non-DELETE elements in AST JSON deserialization - #125475
PedroTadim merged 2 commits into
Conversation
…alization `ParserTTLElement` accepts `WHERE` only after `DELETE`, and `TTLDescription` applies it only for `DELETE`, but `ASTTTLElement::readJSON` restored `where_expr` for every mode. A `clickhouse_json` `CREATE TABLE ... TTL d TO DISK 'default'` carrying a `where_expr` was therefore accepted, the `WHERE` was ignored, and `formatImpl` stored `TTL d TO DISK 'default' WHERE x`, which fails to parse at the next start (`Code: 62`), so the database does not load. Same for `RECOMPRESS` and `GROUP BY`; `formatQueryFromJSON` returned the same unparsable SQL. Reject `where_expr` unless the mode is `DELETE`, like the existing per-mode checks for the codec, destination and `GROUP BY` fields in the same function. The check sits at the read site so it does not textually overlap ClickHouse#108069 (which adds the same check for its new `CLEAR INDEX` mode) or ClickHouse#121585. Requested in ClickHouse#108069 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)Own cold review + Gate B (codex) on
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261012-180800 |
|
Workflow [PR], commit [e37acfd] Summary: ✅
AI ReviewSummaryPR #125475 rejects Final VerdictStatus: ✅ Approve |
CI finish ledger - 6919dd4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261013-013014 |
|
Fixing PR for the |
… that read periodic data `04034_autopr_min_rows_per_replica_reuses_index_analysis`, `04034_autopr_dataflow_cache_reuse_between_different_queries`, `05024_autopr_plan_based_parallel_replicas` and `05059_autopr_settings_in_select_settings_clause` create the same table, insert the same periodic data (`number % 1000 / 500 / 200`) and assert that the query reusing the collected statistics chooses parallel replicas. With the tests' pinned `max_threads = 4` and `max_parallel_replicas = 3` the gate in `considerEnablingParallelReplicas` reduces to `input_bytes > 2 * output_bytes`, where `input_bytes` is the compressed size of the read. A `Wide` part (`min_bytes_for_wide_part = 0`) with a ZSTD server codec compresses the 7 MB read to ~131 KB, so the gate depends on the output estimate, which two-level aggregation makes noisy: on the settings of the failing job of ClickHouse#125475 input was 131499 in every run, output took values from 7735 to 76000, and every run with output above 65749 declined parallel replicas (13 of 40 locally, 36 of 67 in CI). ClickHouse#120190 raised the aggregation state estimate of this query from 12000 to 30000 bytes, which moved the high end of the output estimate up by 18000 (54636 before, 76000 after; 0 of 80 failures on a master build from before it). That is why the four tests started failing on master and on unrelated PRs on 2026-10-12. `CODEC(NONE)` on `WatchID` keeps the read large whatever the part format, server codec, row order, compress block sizes or sparse serialization of a run: input is 2.4 MB or more in every measured configuration (2942464 on the failing job's settings), at least a ~16x margin. Queries, settings and references are unchanged, and no setting is pinned. Same approach as `05045_autopr_skip_plan_build_for_small_reads` (e8588c7). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #108069
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
clickhouse_jsondialect andformatQueryFromJSONnow reject a TTL element that has awhere_exprwith a mode other thanDELETE(TO DISK/TO VOLUME,RECOMPRESS,GROUP BY) withBAD_ARGUMENTS, as SQL parsing does, instead of storing table metadata that cannot be parsed at the next server start.Description
Requested in #108069 (comment), which adds the same check for its new
CLEAR INDEXmode.ParserTTLElementacceptsWHEREonly afterDELETE, andTTLDescriptionapplies it only forDELETE, butASTTTLElement::readJSONrestoredwhere_exprfor every mode. Withdialect = 'clickhouse_json', aCREATE TABLE ... TTL d TO DISK 'default'whose JSON carries awhere_exprwas accepted and stored asTTL d TO DISK 'default' WHERE x, so the next start failed withCode: 62 ... failed at position 150 (WHERE)and the database did not load. The same happened forRECOMPRESSandGROUP BY.formatQueryFromJSONreturned the same unparsable SQL.readJSONnow rejectswhere_exprunless the mode isDELETE, next to the existing per-mode checks for the codec, destination andGROUP BYfields. The check ismode != DELETE, so it also covers theCLEAR INDEXmode from #108069.The new test rejects all three modes on
ALTER ... MODIFY TTLandCREATE TABLE, and keepsDELETE ... WHERE, both from SQL and from JSON. On master the four rejected cases return SQL instead of an error. It passes 50 randomized runs, and all 92 AST JSON tests pass. Category: the harmful path needs the experimentalenable_json_ast_dialect, so this is anImprovement.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125475]
Version info
26.11.1.574-master(included in26.11and later)