Repository navigation
Metrics for tracking insertions via materialized view - #104076
EilRoviSoft wants to merge 33 commits into
Conversation
Added for this, I believe it should be correct. Idk if I should include inserts into temp table as a reference value but anyway. |
`CountingTransform::InsertSource` is fixed at construction time and the setter was never called. Drop it to keep the class minimal. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…etrics The earlier test measured deltas of the global `system.events` counters, which are affected by any other query running on the server (including background system log flushes), so it was non-deterministic in the parallel test suite; it was removed together with the unused setter. Replace it with a test that reads per-query `ProfileEvents` from `system.query_log`, isolated by `current_database`, so the values are exact regardless of concurrent activity. It checks that `DirectInsertedRows`/`DirectInsertedBytes` count only the top-level INSERT, while `MaterializedViewInsertedRows`/`MaterializedViewInsertedBytes` count the rows a materialized view writes into its target table, and that the two together add up to `InsertedRows`/`InsertedBytes`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
I merged the latest The previous test compared deltas of the global
Built with ASan and ran the test locally, including under concurrent inserts from other databases — it passes deterministically. |
|
Workflow [PR], commit [dea1eee] Summary: ❌
AI ReviewSummaryThe PR adds Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Normalize remote reports for the new counters and add the focused regression test. |
Resolve conflicts in CountingTransform and its call sites: master added a 'normalized_query_hash' parameter to 'CountingTransform' while this branch added an 'InsertSource' parameter. Combined both, keeping the constructor signature (header, source, quota, normalized_query_hash) and passing 'getNormalizedQueryHash()' at all three construction sites (two Direct in 'InterpreterInsertQuery', one MaterializedView in 'InsertDependenciesBuilder').
…View insert events
The new ProfileEvents 'DirectInsertedRows' and 'MaterializedViewInsertedRows'
contain 'InsertedRows' as a substring, so the test's 'grep -o "InsertedRows: .*"'
matched them too and printed two lines instead of one. Anchor the match with a
word boundary ('grep -oP "\\bInsertedRows: .*"') so only the standalone
'InsertedRows' event matches. The reference is unchanged.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104076&sha=550d496a5a63f6bd77c8fef819c247837f5bb10a&name_0=PR&name_1=Fast%20test
…serts, narrow event contract The AI review on ClickHouse#104076 pointed out two problems with the new Direct/MaterializedView insert profile events: 1. `InsertDependenciesBuilder::createSelect` is shared with `StorageWindowView`, so rows merely entering a window view were counted as `MaterializedViewInsertedRows`/`MaterializedViewInsertedBytes`. Now the source is chosen from `view_types`: only `MATERIALIZED` views count as materialized view inserts; other views (window views) use the new `InsertSource::Other`, which increments only the generic `InsertedRows`/`InsertedBytes`. Covered by the new test `04612_window_view_insert_source_metrics`. 2. Refreshable materialized view refreshes and explicit `INSERT` queries into a materialized view run through `InterpreterInsertQuery` as regular INSERTs and are counted as `DirectInserted*`. The event descriptions now state this explicitly instead of promising that every write into a materialized view target table lands in `MaterializedViewInserted*`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104076&sha=ab72321e4dbee46ab1d09683e4e6e6cecb8a90b1&name_0=PR Co-Authored-By: Claude Fable 5 <[email protected]>
The AI review pointed out that asserting only \`MaterializedViewInsertedRows\`/\`MaterializedViewInsertedBytes == 0\` would also pass if the insert stopped being routed through the dependent window view. Investigating that showed the window-view branch of \`InsertDependenciesBuilder::createSelect\` cannot be exercised from SQL today: a window view registers no view dependency on its source table (unlike a materialized view, whose source shows up in \`system.tables.dependencies_table\`), and a direct \`INSERT INTO <window view>\` fails with \`STD_EXCEPTION\` in \`createPreSink\` - on unmodified master as well, so this is pre-existing and unrelated to this change. The test therefore pins both halves of that state explicitly instead of relying on incidental zeros: the window view is asserted not to be an insert dependency of its source table, and the tagged INSERT is asserted to attribute all rows and bytes to the \`Direct*\` counters with the generic \`Inserted*\` totals matching exactly. If window views ever become part of the insert chain, the first check fails and the attribution has to be re-verified against a chain that really runs.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 43/45 (95.56%) · Uncovered code |
|
@alexey-milovidov Hello, could you please close this PR in favor of this new one? #110391 |
# Conflicts: # src/Interpreters/InterpreterInsertQuery.cpp
…ites through the INSERT interpreter The AI review pointed out that `CountingTransform` is attached in every pipeline built by `InterpreterInsertQuery`, which is also used by internal writers such as `SystemLog` flushes and `StorageBuffer` flushes to the destination table, so `DirectInsertedRows`/`DirectInsertedBytes` are not limited to user `INSERT` queries. Broaden the event descriptions to state this contract instead of promising "INSERT queries" only. ClickHouse#104076
|
🕵 @UberDever Noting the current state so whoever decides has the facts: #104076 is up to date with |
Adapt follow-ups from ClickHouse#104076: - `d1fa10396c4` (2026-08-04, Alexey Milovidov): document that `DirectInsertedRows` and `DirectInsertedBytes` include internal writes through `InterpreterInsertQuery`. - `e0e5528f208` (2026-07-26, Alexey Milovidov): make window-view coverage non-vacuous by asserting that a window view is not an insert dependency, then verify direct-only metric attribution. - `bccfb2938a7` (2026-07-19, Alexey Milovidov): preserve local optional insert-source classification, which already prevents window views from incrementing materialized-view counters.
…t insert counters All previous assertions went through `InterpreterInsertQuery::addInsertToSelectPipeline` (`INSERT ... SELECT`), leaving the `CountingTransform` site in `InterpreterInsertQuery::buildInsertPipeline` unproven for `DirectInsertedRows`, `DirectInsertedBytes`, `MaterializedViewInsertedRows` and `MaterializedViewInsertedBytes`. The new test `05218_direct_and_mv_insert_metrics_values` inserts inline `VALUES` into a plain table, into a table with an attached materialized view, and into the sink of the `null` table function, and checks the same split and the `Direct* + MaterializedView* == Inserted*` identities per query from `system.query_log`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=104076&sha=10c12dba30685eb5448fef11e5f1901dde4c5906&name_0=PR&name_1=Stress%20test%20(amd_asan_ubsan) and provide a fix in a separate PR. If the fix is already in progress, link it here. The stress run on
|
|
Investigated. Confirming the diagnosis, plus what is new. The failure. The fix is already in progress: #119465 (approved by @ qoega on 2026-09-11, open). It gates every mismatch on the reference read reproducing, which covers
The oracles keep running on the patched binary ( Master exposure since the revert (#119957, 2026-09-14 15:08Z), all four on
A lower bound: before #118056 these surfaced as Re-landing the deny-list. I am opening a separate PR that restores #118489 with the |
|
The re-land is open: #120508 It restores #118489's
50 randomized runs of each test are 100/100 green and stderr-clean, and mutation controls for the listed names, the alias lookup and its per-stage placement each redden. |
… lock wait) On the `Stateless tests (arm_asan_ubsan, azure, parallel)` lane MergeTree tables default to the `azure_cache` policy, whose disk `cached_azure` is a write-through filesystem cache (cache_on_write_operations = 1). Every file a part writes is registered in the cache priority queue by LRUFileCachePriority::add, which takes the queue lock exclusively. Debug and sanitizer builds run FileCache::assertCacheCorrectness from FileCache::getOrSet/get with probability check_cache_probability (0.001), and its second pass walks the whole queue under that lock shared, checking the file of every entry on disk. With ~42k entries on that IO-saturated host a pass takes ~2.3 s (1,086 passes, 2,517 s of checking and 7,673 s of priority write-lock wait server-wide in one job), so each of the ~11 files of a 100-row part can wait seconds. The test bounds its seed statements with the session max_execution_time = 20, and the seed INSERTs failed with Code 159: - 2026-09-27, PR ClickHouse#122520: block-forming INSERT, elapsed 20,575 ms, of which 20,454 ms was FilesystemCachePriorityWriteLockMicroseconds - 2026-09-17, PR ClickHouse#104076: plain INSERT, elapsed 28,097 ms, 28,011 ms waiting The trace_log of the 2026-09-27 query shows its writer thread in SharedMutex::lock <- LRUFileCachePriority::add <- FileCache::doTryReserve <- FileSegment::reserve <- CachedOnDiskWriteBufferFromFile::cacheData in 21 of 21 samples, and the part's 11 blob uploads took 1.6-2.9 ms each, so the time is the cache lock, not object storage latency. In the same jobs, parts on the local `default` disk took at most 104 ms / 54 ms, versus 20.6 s / 33.5 s on cached_azure. Pin t_04344 to the implicit local `default` storage policy. Where its parts live is incidental to what the test verifies (stripping of seed SETTINGS on the INSERT, block-forming, CREATE storage and BACKUP carriers), so its INSERTs, their fuzzed clones, the BACKUP and the teardown DROP no longer touch the cache, and no time bound is widened: the session max_execution_time = 20 still bounds the fuzz loop. t_04344_storage keeps the lane's default policy, because its SETTINGS clause must hold only max_rows_to_read for the empty-SETTINGS pruning carrier. Reproduced locally on a debug build with the CI test configs, the write-through local_cache as the MergeTree default, check_cache_probability = 1, ~335k cache entries and 8 concurrent readers of a cached table: the unmodified test failed 4 of 5 runs with Code 159 on a seed INSERT (elapsed 31.8-50.4 s, 98.9-99.3% of it priority write-lock wait, same stack as CI). With this change it passed 3 of 3 under the same load, while 8 of 9 seed-shaped INSERTs into a cached table in the same windows waited 24-47 s. With check_cache_probability = 0 and the same cache and readers, the unmodified test passed 3 of 3 with seed INSERT lock waits under 0.4 s. ClickHouse#114077 raised the INSERTs' bound instead, reading this wait as Azure latency; it was closed after two quiet months and the test failed twice since. Related: ClickHouse#114077 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict in `InterpreterInsertQuery.cpp`: master turned the push-pipeline tail into the static `buildPushPipelineFromDependencies`, which has no `no_destination` member, so take it from the new `InsertDependenciesBuilder::skipsDestinationTable` accessor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nabled With `async_insert`, the `INSERT ... VALUES` rows are flushed later in the background, so the INSERT query's `ProfileEvents` in `system.query_log` have no inserted rows at all. The test checks the synchronous `buildInsertPipeline` path, so disable `async_insert`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=104076&sha=793765a31fab7689527d30afce643d3a2d3800a0&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 ClickHouse#104076 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ert counters, test it Only an `APPEND` refresh writes into the live target table and triggers its dependent materialized views. A non-`APPEND` refresh writes into a temporary replacement table, which has no dependent views, so say so in the `DirectInserted*` / `MaterializedViewInserted*` descriptions. Add a test for an `APPEND TO` refresh with a downstream materialized view. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…edViewInserted*` Writes of materialized views fed by background streaming sources (`Kafka`, `NATS`, `RabbitMQ`, `FileLog`, `ObjectStorageQueue`) go through the same `InsertDependenciesBuilder::createSelect` path and are counted in `MaterializedViewInsertedRows` / `MaterializedViewInsertedBytes`. These are genuine writes of materialized views into their target tables, so broaden the documented contract instead of excluding them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=104076&sha=latest&name_0=PR&name_1=Upgrade%20check%20(amd_release) ( |
|
This is not caused by this PR. The previous-release server in this job (26.9.10.4) cannot run The fix is #122132, merged on 2026-09-28: it makes that read return no rows instead of throwing. It is on master only, and 26.9 still has the throwing |
|
🕵 Status update: merged the latest @groeneai, thanks for tracking down the |
🕵 Addressed: the PR now has four stateless tests for the new metrics (04498, 05141, 05218, 05321).
AI please notify the user that this PR is obsolete and should be closed in favor of #110391 |
|
🕵 @UberDever, noted: this PR (#104076) and #110391 implement the same feature ( Related: #110391 |
Check inline values with dependent materialized views, table-function destinations, and refreshable APPEND writes without changing pipeline-hop attribution. Related: ClickHouse#104076
|
🕵 Status update: merged the latest This is maintenance only. The open question is unchanged: this PR and #110391 implement the same feature, @UberDever has asked for this one to be closed in favour of #110391, and that decision is left to a maintainer. Related: #110391 |
| case InsertSource::Direct: | ||
| ProfileEvents::increment(ProfileEvents::DirectInsertedRows, local_progress.written_rows); | ||
| ProfileEvents::increment(ProfileEvents::DirectInsertedBytes, written_bytes); |
There was a problem hiding this comment.
[Blocker] Deduplicate the new direct counters when forwarding remote insert reports
Both the sender and receiver now increment DirectInsertedRows / DirectInsertedBytes for INSERT INTO FUNCTION remote(...) (also for synchronous inserts into Distributed). However, RemoteInserter::processProfileEventsPacket subtracts the already-counted input only from InsertedRows / InsertedBytes, then forwards the new counters unchanged. For three UInt32 rows with no materialized views, the combined report therefore contains InsertedRows = 3 but DirectInsertedRows = 6. usedQuotaProfileEvents sums the local and remote snapshots, so a quota on the new direct counters is also charged twice; additional remote hops increase the overcount.
Please extend the remote-report normalization to remove the duplicate remote DirectInserted* increments, with independent subtraction budgets because subtractIncrements consumes its argument. Preserve genuinely additional materialized-view writes, and add a focused remote-insert test checking the split counters against Inserted* in quota usage or client reports.
Changelog category:
Changelog entry:
Added metrics
DirectInsertedRows,DirectInsertedBytes,MaterializedViewInsertedRows, andMaterializedViewInsertedBytes....
Documentation entry for user-facing changes:
I think there are none user-facing changes.
At a minimum, the following information should be added (but add more as needed).
Sometimes people need to track table's changes via matirialized view.
I used this to check is materialized view metrics work:
Kinda optional stage:
Checking metrics:
Workflow [PR]
Sync PR [sync-upstream/pr/104076]