Repository navigation
Allow INSERT into regular views - #102866
Daedalus-Icarus wants to merge 74 commits into
Conversation
…anularity Lightweight `DELETE` mutations on tables with `index_granularity_bytes = 0` (non-adaptive granularity) could cause a logical error after `DETACH`/`ATTACH`: "Incorrect mark rows for part ... in-memory N, on disk 8192". The root cause: `DELETE` reports `affectsAllColumns() == true`, so `MutateAllPartColumnsTask` created a new index granularity object instead of reusing the source part's granularity. The new object was adjusted during writing to match the actual row count, but non-adaptive mark files don't store per-mark granularity, so `validateColumnOfFixedSize` saw a mismatch between the in-memory value and the fixed 8192 assumed from settings. The fix reuses the source part's granularity for lightweight deletes, since they only update the `_row_exists` column without changing the row count. Closes #98585 CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8bc6bb7c5c71412f303aa0705d11b667e2a6659c&name_0=MasterCI&name_1=BuzzHouse%20%28amd_debug%29
Implement `StorageView::write` so that simple views (single table, no JOINs, GROUP BY, HAVING, LIMIT, or DISTINCT) accept INSERTs. Data is routed to the underlying table through an internal INSERT pipeline. Column aliases are remapped, missing target columns receive their defaults, and a WHERE clause in the view definition acts as a constraint — rows that do not satisfy it are rejected with `VIOLATED_CONSTRAINT`. ORDER BY is allowed and ignored for inserts. Closes #91535
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Workflow [PR], commit [1966823] Summary: ❌
AI ReviewSummaryThis PR makes simple regular Findings❌ Blockers
Tests
Final Verdict❌ Block LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 471/534 (88.20%) · Uncovered code |
- Revert unrelated lightweight-delete change in `MutateTask.cpp` that broke `02932_lwd_and_mutations` (UPDATE `_row_exists` combined with regular DELETE changes the row count, so source granularity must not be reused). The separate non-adaptive-granularity test is dropped along with it. - Fix clang-tidy `readability-qualified-auto` failure on `Build (arm_tidy)`: `auto` -> `const auto *` for `ASTTableIdentifier`. - Reject views whose `WHERE` references columns not projected by the `SELECT` list (e.g. `CREATE VIEW v AS SELECT a FROM t WHERE b > 0`) with `NOT_IMPLEMENTED` instead of failing during expression analysis on every INSERT. `WHERE` on unprojected columns is still allowed when the view's `SELECT` is an asterisk. - Drop obsolete `00595_insert_into_view`, which asserted that `INSERT` into a simple view fails — this is the behavior the PR is changing. The new positive coverage lives in `04098_insert_into_view`, which now also exercises both new cases above. - Document `INSERT` into normal views in `docs/en/sql-reference/statements/create/view.md`. CI report: #102866
Add `insertable` to the aspell ignore list — it's used in the new `docs/en/sql-reference/statements/create/view.md` section about INSERT into normal views. CI report: #102866
- Reject PREWHERE in insertable views - Use IdentifierSemantic for proper column identification in WHERE constraints - Add comprehensive tests for the feature
…views - Remove non-existent IdentifierSemantic function call - Simplify WHERE clause validation - relying on runtime validation instead - This fixes compilation issues and allows WHERE with lambda parameters to work - Updated tests to reflect the new behavior
- Don't return early when finding asterisk - scan entire projection list - Reject views that mix asterisk with explicit column references (SELECT *, col) - This prevents incorrect 'insertable' classification for views like SELECT *, x+1 AS y - Add comprehensive test cases for asterisk with expressions and mixed scenarios
Handle transformed asterisks as non-insertable projections and translate missing columns from view WHERE validation to NOT_IMPLEMENTED. Also fix stateless expected-error annotations for INSERT into views. PR: #102866 CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102866&sha=56f8c9c64003d8a9729e164ce94ac06564823d68&name_0=PR&name_1=Fast%20test
The MSan function property fuzzer currently fails inside CLD2 when testing ; this is tracked by #103765. Exclude the function from the generic stress list until that issue is fixed. PR: #102866 CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102866&sha=dcf7b9fc5885f8d48c92b473a0daeb0b9f816586&name_0=PR&name_1=Unit%20tests%20%28msan%2C%20function_prop_fuzzer%29 Issue: #103765
|
CI is green on latest commit |
|
🕵 Picked this up again via Merged Unwedged CI: the 2026-08-06 heads ( Remaining blockers are unchanged: the five reserved target-default/privilege design threads (left open deliberately as design decisions), and the CLA situation (six commits authored by the deleted |
…ert constraint `stripTargetTableQualifier` rewrote any compound identifier whose leading part matched the view's table name or alias, including inside lambda bodies. When a lambda parameter shadowed the table alias, as in `FROM t AS x WHERE arrayExists(x -> x.a > 0, arr)`, the tuple-element access `x.a` was rewritten to the outer column `a`, so the insert-time constraint enforced the opposite of the view's read-time `WHERE`. Mask lambda parameter scopes during the rewrite, the same way `collectIdentifierShortNames` already does. The preserved compound is not resolvable by the write-time constraint analysis, so such inserts now fail close with `NOT_IMPLEMENTED` instead of storing or rejecting the wrong rows. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The |
|
#112231 does not cover it, and neither does any other open PR of mine. Here is the measurement. The carrier is not a fuzzer mutation. The The test file at Why #112231 cannot fire here. It gates the canary on a new What I believe the actual mechanism is. I could not reproduce it locally yet on a pristine post-#109023 debug build (five layouts: default granularity, granularity 2 with straddling boundaries, and a 4-part split-block layout, all clean), so I do not want to assert the mechanism as settled. The part name and mark geometry say the stress run reached a multi-part, multi-mark layout my fixtures have not matched. Two things worth separating from this:
The residual is real rather than stale-base: of the 10 PR-side hits of this canary since #109023 merged, I checked each build's ancestry and 7 carry the fix and fired anyway (the other 3 are genuinely pre-merge bases). So there is a live cause left over after #109023, and this occurrence is one instance of it. I will take this as its own fix and open a separate PR. Given that the failing statement is a committed test rather than a fuzzer mutation, I would rather land the real exactness fix than widen #112231, whose guard is keyed on a condition this shape does not satisfy. I will link the PR here. |
|
🕵 CI status on
in The stack matches the open issue #112213 (stale @groeneai, please confirm #112484 covers this occurrence (and consider prioritizing it — it is now reddening most stress runs); if it does not, please provide a fix in a separate PR. Everything else on this head is green. The remaining AI-review findings are exactly the target-default/privilege design threads @alexey-milovidov has marked as reserved design decisions; no new actionable feedback. |
|
Confirmed: #112484 covers this occurrence. Same defect, verified from the artifact rather than the message text. Why that route is gated by the fix. The aborting Fix presence at your failing build: absent, as expected for an open PR. On prioritizing it: agreed, and it is the next thing I push. #112484 is open, mergeable, 178/178 checks green on One correction on the surge explanation. #113608 is mine, and it merged at 2026-08-07T12:58:39Z, but 23 of the 51 rows on 2026-08-07 landed before that merge, starting 01:52:23Z, across 21 distinct commits and 8 check flavours; the reporting change is absent from Also worth separating: Tracking issue for the 6444 half: #112213. |
|
Fix PR, as promised: #113965 It did reproduce in the end, in 20 rows with no fuzzer and no stress harness, and the mechanism is Only a boundary at the column type's own maximum or minimum can wrap, which the tests pin per type: This does not change the earlier point about 26.6 and 26.7: those abort for the missing #109023 |
|
Linking the fix as I promised above: #121089. To be precise about its scope, it narrows the nullable-key exactness safeguard that reached master on 2026-09-05, so it covers the set-membership shape of that assert from that date onwards and does not explain the 2026-08-08 occurrence discussed here, which predates the safeguard. |
Closes #91535
Simple views that only SELECT columns from a single table now accept INSERTs. Data is routed to the underlying table through an internal INSERT pipeline. Column aliases are remapped, missing target columns receive their defaults, and a
WHEREclause in the view definition acts as a constraint — rows that do not satisfy it are rejected withVIOLATED_CONSTRAINT.ORDER BYis allowed and ignored for inserts.Views containing
JOIN,GROUP BY,HAVING,LIMIT,DISTINCT,UNION, or complex expressions in theSELECTlist are not insertable and will raiseNOT_IMPLEMENTED.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow
INSERTinto regular (non-materialized) views when the view is simple enough: it selects columns from a single table withoutJOIN,GROUP BY,HAVING,LIMIT,DISTINCT, or complex expressions. AWHEREclause in the view acts as a check constraint for inserted rows. This makes views usable as table aliases, especially withSQL SECURITY DEFINER.Documentation entry for user-facing changes
You can now insert into a regular view when its definition is a simple column selection from a single table: