Repository navigation
AST fuzzer oracle: skip a mismatch only if the data changed between the reads - #119465
alexey-milovidov merged 10 commits into
Conversation
An oracle validates a fuzzed SELECT by executing a reference query and a metamorphic rewrite of it as two separate executeQuery calls, then comparing sorted row sets. Its premise is that both sides read the same relation. makeOracleContext pins threads, caps and overflow modes, so a plan difference is excluded, but nothing excluded a relation difference between two consecutive executions. When the row set is a function of physical part layout rather than of contents, the two reads observe different snapshots and the oracle attributes the difference to the rewrite: a merge-collapsing engine read without FINAL (SummingMergeTree, AggregatingMergeTree, ReplacingMergeTree, CollapsingMergeTree), a concurrent INSERT into a plain MergeTree, or an AggregateFunction state column with non-canonical serialization. Reported as a TLP WHERE mismatch on a Buffer over a SummingMergeTree, 2000 reference rows against 3000 partitioned rows. The TLP arms (p / NOT p / p IS NULL) are exhaustive over every value the predicate can take, so predicate evaluation can only move a row between arms, never add one; +1000 rows is exactly one insert unit, so the relation changed under the oracle. checkSubqueryWrap was fixed for this class in 59efd8b by re-executing the reference once on the mismatch path and skipping when it is not stable. Eight other oracles compared without that guard. Generalize it into one shared helper, probe each site with the same collector its original read used (sorted rows, sorted unique rows for TLP GROUP BY, a scalar Field for NoREC), and refold the inline version onto the helper so the invariant has one shape. The probe precedes ASTFuzzerOracleMismatches at all nine sites, so a flaky query no longer bumps the mismatch counter. std::nullopt counts as not reproduced, and a probe that throws degrades to a skipped oracle, so every path fails close. checkIdentityWhere's comparison lambda returns bool because its three variants share one reference vector: an unreproducible reference disqualifies all three, and a bare return inside a void lambda would have returned from the lambda alone. An engine screen was considered and rejected: it would stop checking those engines altogether, and it cannot see the concurrent-INSERT or AggregateFunction-state cases. This costs one extra execution on the mismatch path only. The trade, which the precedent already accepted, is that a wrong-results bug that is itself non-deterministic now makes the oracle skip rather than report. With no reproducible reference there is nothing to compare against. Subquery wrap has carried this guard since 2026-07-13 and still reported 9 mismatches in the last 30 days, the sampled ones genuine. Validated locally in both directions with a failpoint rendezvous: pausing a read of a merges-stopped SummingMergeTree at infinite_sleep and appending one part per pause reproduces the reported message on the first attempt in 5 of 5 runs without the guard, and produces no mismatch in any run with it, at 10x to 25x the growth-event count that armed the unguarded binary, while ASTFuzzerOracleChecks advances from 12 to 568. A genuine Subquery wrap mismatch taken from CI, whose reference reads no storage, still throws with the guard in place. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewReviewed cold against the code, then adjudicated. Nothing structural: nine mismatch sites, nine
💡 A dedicated unstable-reference skip counter was suggested and not taken: it would make the skip |
|
Workflow [PR], commit [98dd7a6] Summary: ✅
AI ReviewSummaryThe change suppresses AST-fuzzer oracle mismatches when recorded Findings
Missing context / blind spots
Tests
Final Verdict |
|
cc @qoega, could you review this? It generalizes the reference-stability guard you added to |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+78.40 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units8 translation units recompiled, 27 s compile time in total, 7 of them have a recent master baseline. Translation units without a recent master baseline:
|
CI finish ledger - 9e6f653Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260911-203047 |
|
This PR also suppresses a false positive that is currently red on true master. Measured today.
The third arm attributes the suppression to that guard specifically rather than to any other effect of the patch. On the patched binary the same query still reports Why the guard is a sound gate for this family and not a lucky one: The same aggregate also trips I considered the name-based alternative (skip aggregates the factory declares |
|
@groeneai update pr |
|
Updated. I merged current master ( The merge was clean and the fix content is unchanged, so the approval still applies to exactly what was reviewed: the PR diff against master is byte-identical to the approved head (same The only red on the previous head was |
CI finish ledger - f287a41Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Everything else on this head is green: 176 of 177 checks passed or skipped, including all Session id: cron:our-pr-ci-monitor:20260917-113202 |
|
Fixing PR for test_max_bytes_ratio_before_external_distinct[server] created: #120751 |
|
Two more carriers for this guard's class, and one of them is on true master. Measured today. Since
The fifth is I cannot yet say whether these four are the unreproducible-reference class this PR guards, and I
So this PR is also the discriminator for the family: once it is in, a surviving report proves the One aside I hit while triaging, unrelated to this diff and not a request to change it: of the nine |
…he reads The previous version of this change re-ran the reference on a mismatch and skipped when the re-run differed. A re-run that differs does not prove that the data changed: a non-deterministic wrong result (for example from JIT compilation) also differs between runs, and that version hid it. Instead, each oracle records every MergeTree table the query reads, including through views and `IN t`, with its active parts (regular and patch), before its first read, and on a mismatch skips only when that list is different afterwards. Parts are immutable and a part name is never reused, so an unchanged list means every read saw the same data, and the mismatch is reported even when a re-run would not reproduce it. A merge, an insert or a mutation committed between the reads changes the list. The check and the `ASTFuzzerOracleMismatches` increment move into `run_oracle`, so the counter does not count a skipped mismatch. `checkSubqueryWrap` keeps its existing re-run check. Validated locally with a pause on `infinite_sleep` inside the oracle's reads: - an INSERT at every pause (a new part): master reports a TLP WHERE oracle mismatch on the first attempt; with this change the mismatch is logged as skipped and no Code: 906 is thrown while the oracles keep running; - an ALTER of the ALIAS column the query reads at every pause (the result changes, the parts do not): reported by master and by this change, and not reported by the previous version of this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Done in 731a1e1: the re-run is gone, and a mismatch is skipped only if the active parts of a |
…ability-guard Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ASTColumnsApplyTransformer` keeps `lambda` and `parameters` outside `children`. Every recursive screen in this file now walks them through `forEachChild` (master, ClickHouse#122055); `collectReadParts` still walked `children` only, so a table read inside an `APPLY` lambda, e.g. `SELECT * APPLY (x -> (SELECT count() FROM t)) FROM s`, was missing from the part snapshot and a mismatch caused by a new part of `t` was reported instead of skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In a database with `lazy_load_tables = 1` the catalog hands out a `StorageTableProxy` for a `MergeTree` table for its whole life, so the direct `dynamic_cast<const MergeTreeData *>` never matched: no parts were recorded and a mismatch caused by an insert into such a table was reported. `castStorage<MergeTreeData>(storage, DeferredTable::Load)` looks through the proxy; `Load` because the oracle reads the table anyway. Required by the `storage_casts` style check that master added. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const StorageID resolved = context->tryResolveStorageID(StorageID{table_id->getDatabaseName(), table_id->shortName()}); | ||
| if (auto storage = resolved ? DatabaseCatalog::instance().tryGetTable(resolved, context) : nullptr) |
There was a problem hiding this comment.
This resolves every table-shaped identifier through the catalog, even when the query resolves it to a CTE. For example, with a physical MergeTree table t, WITH t AS (SELECT 1 AS k) SELECT k FROM t WHERE k = 1 reads only the constant CTE, but this collector records the physical table's parts. If that unrelated table merges while an oracle finds a genuine mismatch, parts_after != parts_before suppresses it despite the oracle's input being unchanged. Unused CTE bodies and subqueries in the ORDER BY removed by stripOrderAndLimit can similarly add unrelated dependencies.
Collect the dependencies of the queries actually executed, with scope-aware CTE resolution, rather than treating every identifier in the original AST as a storage read. Please cover a CTE shadowing an existing table when validating that genuine mismatches remain visible.
There was a problem hiding this comment.
Fixed in db4c1fc: the collector now walks a copy of the query in which ApplyWithSubqueryVisitor replaced each CTE reference (and each IN operand naming a WITH alias) by its definition, so a CTE named like a table, or an unused CTE, no longer counts that table.
There was a problem hiding this comment.
The ordinary CTE case is fixed, but the original attribution issue remains for CTE references inside APPLY. At src/Interpreters/QueryOracleChecker.cpp:1231, ApplyWithSubqueryVisitor walks only children; an ASTColumnsApplyTransformer keeps its lambda outside that list. For example, with physical MergeTree tables s and t:
WITH t AS (SELECT k FROM s)
SELECT * APPLY (x -> (SELECT count() FROM t))
FROM s WHERE k = 1The query reads only s, but expansion leaves the lambda's FROM t untouched. removeWithElements then removes the outer CTE, and the collector's forEachChild reaches that identifier and records the unrelated physical t. An insert into that table can still suppress a genuine mismatch. The expansion needs to reach hidden APPLY members with the enclosing bindings intact.
The removed-ORDER BY case from the original comment also remains: src/Interpreters/QueryOracleChecker.cpp:2907 collects from the original query, so SELECT k FROM s WHERE k = 1 ORDER BY (SELECT count() FROM t) records t even for the TLP comparisons that delete that clause. Those dependencies need to come from the queries the individual oracle executes.
There was a problem hiding this comment.
Fixed in ed5e331: each executor now records the parts of the tables the query it runs reads, so a clause an oracle strips no longer counts, and APPLY members, which the WITH expansion does not reach, are not walked.
There was a problem hiding this comment.
The removed-ORDER BY case is fixed, but unused CTE bodies still add unread tables when they are inside a view. At src/Interpreters/QueryOracleChecker.cpp:1200, the collector descends directly into the stored view AST, bypassing expandWithElements and its removeWithClauses step. For example, with MergeTree tables s and t:
CREATE VIEW v SQL SECURITY INVOKER AS
WITH unused AS (SELECT k FROM t)
SELECT k, w FROM s;
SELECT k, w FROM v WHERE k = 1;This reads only s, but the collector visits the unused definition and records t. An insert into t can still suppress a genuine mismatch over unchanged s. InterpreterCreateQuery expands CTE references without removing the WITH list, and StorageView stores that list in inner_query, so creation does not eliminate this case. Apply the dependency normalization to each reached view body as well.
There was a problem hiding this comment.
Fixed in 98dd7a6: view bodies now get the same WITH expansion before their tables are recorded.
There was a problem hiding this comment.
The view-body case is fixed, but the original attribution issue remains when a table alias shadows a CTE. At src/Interpreters/QueryOracleChecker.cpp:1194, ApplyWithSubqueryVisitor substitutes CTEs before getTableExpressionAliases runs. With MergeTree tables s and t:
WITH x AS (SELECT k FROM t)
SELECT x.k
FROM s AS x ALL INNER JOIN x AS y ON x.k = y.k
WHERE x.k = 1QueryAnalyzer::tryResolveIdentifier resolves the second source through the table alias x before consulting CTEs, so both sides read s. The visitor instead replaces that source with the CTE body, and the collector records the unread t. An insert into t can therefore still suppress a genuine mismatch over unchanged s. The alias filter runs after the identifier has already become a subquery, so it cannot correct this binding. Dependency expansion needs to preserve the analyzer's alias-before-CTE precedence.
| else if (storage->getName() == "View") | ||
| { | ||
| const auto metadata = storage->getInMemoryMetadataPtr(context, /* bypass_metadata_cache = */ false); | ||
| collectReadParts(metadata->getSelectQuery().inner_query, context, parts, depth + 1); |
There was a problem hiding this comment.
Only view bodies are followed here; a table's effective row-policy expression is never visited. The earlier referencesUnscreenedDefinitionAnywhere explicitly permits deterministic policy subqueries, so these queries reach the oracle. For example, give s a policy USING k IN (SELECT k FROM allowed) with both tables using MergeTree, then run SELECT k FROM s WHERE k = 1. An insert into allowed between the reference and partitioned reads can change which rows of s are visible, but the collector records only s, whose parts stay unchanged. The resulting legitimate read drift is still reported as AST_FUZZER_ORACLE_MISMATCH.
Traverse effective policy expressions for every reached table/view, including their transitive table dependencies, and include this case in the validation.
| for (const auto & part : merge_tree->getDataPartsVectorForInternalUsage( | ||
| {MergeTreeData::DataPartState::Active}, | ||
| {MergeTreeData::DataPartKind::Regular, MergeTreeData::DataPartKind::Patch})) | ||
| parts.push_back(part->name); |
There was a problem hiding this comment.
Unchanged part names do not imply unchanged read data when the session has apply_mutations_on_fly = 1; makeOracleContext preserves that setting. With merges stopped, another session can register an ALTER TABLE s UPDATE v = 2 WHERE k = 1 between the two oracle reads. The second read applies the newly pending mutation while the first did not, yet both snapshots here contain exactly the same regular and patch part names. This still produces a false mismatch. MergeTreeData::createStorageSnapshot captures a separate mutations snapshot precisely because the part list does not describe this state; the existing 03047_on_fly_mutations_basics.sh also exercises changed results without materializing new parts.
Include the applicable pending mutation state in the fingerprint, or explicitly skip oracle comparisons in this mode, and validate a mutation registered between reads before its replacement part is committed.
…ITH elements With a physical `MergeTree` table `t`, `WITH t AS (SELECT k, w FROM s) SELECT ... FROM t` reads only `s`, but `collectReadParts` resolved the identifier `t` through the catalog and recorded the physical table's parts. A part change on that unread table then skipped a mismatch whose reads all saw the same data. The same over-recording happened for `k IN t` naming a `WITH` literal alias and for the body of an unused CTE. `check` now walks a copy of the query in which `ApplyWithGlobalVisitor` (with `enable_global_with_statement`) and `ApplyWithSubqueryVisitor` replaced each CTE reference and each `IN` operand naming a `WITH` alias by its definition, the substitution the query's own `WITH` processing does, so the scoping rules (`WITH t AS (SELECT * FROM t)` reads the physical `t`, a nested select sees enclosing names only with `enable_global_with_statement`, a subquery's own `SETTINGS`) are the engine's. The then unused `WITH` elements are dropped from the copy. A `TOO_BIG_AST` from the expansion stops the checks for that query, like any other error of `check`. `collectReadParts` is unchanged. Validated with a failpoint pause inside the oracle's reads (`infinite_sleep`, seeds with `sleep(0)`, `--ast_fuzzer_runs=300 --ast_fuzzer_oracle=1`): - an ALIAS ALTER of `s.w` (result changes, parts do not) plus an insert into the physical `t` at every pause, with `t` a CTE over `s`, a `WITH [5] AS t` literal in `k IN t`, or an unused CTE reading `t`: the previous head skipped them (0 reported over 890, 734 and 541 pauses); this commit reports `Code: 906` within the first two attempts. - an insert at every pause into the table the query really reads, through the CTE body, a self-referencing `WITH t AS (SELECT k, w FROM t)`, an outer `FROM t` whose nested subquery shadows `t`, or (with `enable_global_with_statement = 0`) a nested `IN (SELECT k FROM t)` under an outer CTE `t`: skipped, never reported. A scope-less name set reported the last three. - the earlier arms are unchanged: an insert into `s` and into `s2` read as `x IN s2` in an `APPLY` lambda are skipped, the ALIAS ALTER control is reported. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| for (const auto & part : merge_tree->getDataPartsVectorForInternalUsage( | ||
| {MergeTreeData::DataPartState::Active}, | ||
| {MergeTreeData::DataPartKind::Regular, MergeTreeData::DataPartKind::Patch})) |
There was a problem hiding this comment.
UNIQUE KEY tables
An unchanged active-part list does not imply unchanged rows for a UNIQUE KEY table. UniqueKeyTxnCommit::InsertCommit::publish makes the new part active before UniqueKeyTxnManager::commitTransaction commits it; MergeTreeData::createStorageSnapshot deliberately filters these parts using a separate visibility snapshot.
For example, start with (k, v) = (1, 1) and pause an overwrite with (1, 2) at unique_key_insert_pause_before_commit. Both parts are already active when parts_before is collected. The reference SELECT v FROM s WHERE k = 1 returns 1; let the overwrite commit before the partitioned read, which returns 2. parts_after contains the same names, so this legitimate data change is reported as AST_FUZZER_ORACLE_MISMATCH. The existing 04196_unique_key_read_skips_an_uncommitted_part.sh exercises precisely this active-before-visible transition, and the fuzzer enables this feature.
Include the table's committed visibility state in the fingerprint, or exclude UNIQUE KEY tables from these comparisons until that state is accounted for. Validate a commit between the oracle reads while the active-part names remain unchanged.
The part snapshot was taken from the fuzzed query, so a table named only in a clause an oracle drops (the `ORDER BY`, `LIMIT` and `SETTINGS` that `stripOrderAndLimit` removes) was recorded, and a part change in that table skipped a genuine mismatch on the tables the oracle really reads. Each executor now parses the query it is about to run, expands its `WITH` elements and records the parts of the tables that query reads; on a mismatch only those are compared again. This also narrows the skip to tables that changed after the query reading them started. The collector no longer walks `APPLY` lambdas and parameters: the `WITH` expansion (`ApplyWithSubqueryVisitor`) does not reach them, so a table name there may be a CTE, and `WITH t AS (SELECT k FROM s) SELECT * APPLY (x -> (SELECT count() FROM t)) FROM s` recorded the physical `t`. A table read only inside an `APPLY` lambda is now not recorded, so a concurrent insert into it is reported, as on master. The expanded copy also drops its `WITH` clauses rather than only the CTE declarations, so an unused `WITH (SELECT count() FROM u) AS c` no longer records `u`. A table read only through a used `WITH` alias is not recorded either; a scalar subquery there is usually answered from the scalars the oracle contexts copy from the fuzzed query's context. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| func && functionIsInOrGlobalInOperator(func->name) && func->arguments && func->arguments->children.size() > 1) | ||
| { | ||
| if (const auto * identifier = func->arguments->children[1]->as<ASTIdentifier>()) | ||
| collectReadParts(identifier->createTable(), context, parts, depth); |
There was a problem hiding this comment.
IN
Expanding WITH does not make every remaining right-hand identifier a table name. For example, with s (k UInt32, arr Array(UInt32)) and an unrelated MergeTree table named arr, SELECT k FROM s WHERE k IN arr reads only s: QueryAnalyzer::resolveExpressionNode resolves the column before attempting table resolution. The same applies to expression aliases.
This branch nevertheless converts arr to an ASTTableIdentifier and records the unrelated table's parts. If that table inserts or merges while the oracle finds a genuine mismatch over unchanged s, readPartsChanged returns true and suppresses the finding. The new guard therefore hides wrong results even without any CTE.
Resolve the operand in its query scope before attributing it to storage, or omit the dependency when a table binding cannot be established. Please validate a column/table name collision; 04506_in_function_array_column_right_argument.sql already documents the column semantics.
There was a problem hiding this comment.
Fixed in 98dd7a6: a bare IN operand is no longer recorded, and neither is a FROM name that is the alias of another table expression of the same FROM (FROM s AS x JOIN x AS y).
There was a problem hiding this comment.
The bare-operand branch is gone, but the original column-versus-table attribution issue still occurs through expandWithElements at src/Interpreters/QueryOracleChecker.cpp:1194. With s (k UInt32, arr Array(UInt32)) and an unrelated MergeTree table t:
WITH arr AS (SELECT k FROM t)
SELECT k FROM s WHERE k IN arrQueryAnalyzer::resolveExpressionNode resolves arr as the column before attempting table/CTE resolution. However, ApplyWithSubqueryVisitor::visit replaces it with the CTE subquery unconditionally (src/Interpreters/ApplyWithSubqueryVisitor.cpp:258), so the collector still records unread t. An insert into t can suppress a genuine mismatch even though both reads use only unchanged s. Omitting bare operands must also prevent this pre-expansion from introducing a table dependency for an operand bound to a value.
Three ways the part snapshot still recorded a table the oracle's query does not read, so a part change there skipped a genuine mismatch: - A view body was walked as stored. `CREATE VIEW` keeps the `WITH` list, so `WITH unused AS (SELECT k FROM t) SELECT k, w FROM s` recorded `t`. View bodies now get the same `WITH` expansion as the query. - A bare `IN` operand was recorded as a table, but the analyzer resolves it as a column or an alias first: `k IN arr` with a column `arr` reads the column. Such operands are no longer recorded; a table read only as `x IN t` is then not recorded, so a change there is reported, as on master. - A `FROM` name resolves to the alias of another table expression of the same `FROM` before the database catalog: in `FROM s AS x JOIN x AS y` both sides read `s`. A name that is such an alias is no longer recorded; aliases of other `FROM` clauses do not apply. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
||
| ASTPtr read_ast = expandWithElements(ast, context); | ||
| Strings parts; | ||
| collectReadParts(read_ast, context, parts); |
There was a problem hiding this comment.
This collects tables inside scalar subqueries even when execution uses an inherited cached value. makeOracleContext copies ContextData::scalars, makeQueryContext preserves it, and QueryAnalyzer::evaluateScalarSubqueryIfNeeded returns the cached scalar on a matching query-tree hash.
For example, after the successful fuzzed query SELECT k, (SELECT count() FROM t) FROM s WHERE k = 1 has populated that cache, the Identity WHERE reference and variants can use the same cached count without reading t. The collector nevertheless snapshots t; an insert or merge there during the comparison makes readPartsChanged suppress a genuine mismatch over unchanged inputs. This violates the new guard's requirement that the changed table actually supply data to the compared reads.
Account for scalar substitution/cache hits when collecting dependencies, while retaining dependencies for fresh or correlated subqueries. Validate that changing only a cached scalar's source cannot suppress a mismatch.
|
@qoega a question before I change this further. The tables an oracle query reads are found from its AST, and over four review rounds the bot has kept finding names that the analyzer resolves differently, so a table is recorded that the oracle's queries do not read. The latest: a CTE that the analyzer resolves to a table alias or to a column first (1, 2), and a scalar subquery whose value the oracle's queries take from the fuzzed query's scalar cache (3). Such a table can hide a mismatch only if its parts change between the oracle's first read and the mismatch. The same already holds for every table the query does read, since the skip does not check that the change caused the mismatch. If no recorded table changes, the mismatch is reported, so the JIT case stays visible. Is this approximation acceptable to you, or would you prefer no skip at all? In that case I will close this PR. |
|
@groeneai is this PR still needed? |
|
Yes. On master ( Latest CI case I measured: AST fuzzer (amd_release, oracle), 2026-10-28: a fuzzer-created #117187 does not cover it: The last CI run on this head is from 2026-10-20, and several master PRs have changed this file since, so it needs a fresh run before a merge. If you would rather fold this into the oracle series, I will close it. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
I'm ok with this. The remaining threads can be fixed as follow-ups.
|
Thanks. I'll address the remaining threads in a follow-up PR and link it here. |
|
@alexey-milovidov one question before I write the follow-up for the remaining threads. Threads 1-3 (a table alias or a column shadowing a CTE, a cached scalar subquery) come from finding the tables from the AST: the guard records a table the oracle's queries do not read. I tried taking them from a separate analysis of each oracle query instead, but that still differs from what the execution reads: it has to redo the AST preparation of
Threads 4-6 (row policies, on-the-fly mutations, |
Related: #117006 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
AST fuzzer (amd_release, oracle)reported aTLP WHERE oracle mismatch, 2000 reference vs 3000partitioned rows over a
Bufferon aSummingMergeTree(report);
@ alexey-milovidov asked for a separate fix PR
(comment). The TLP
arms are exhaustive, so +1000 rows means the data changed between the reads.
Each oracle compares separate
executeQueryreads, so a merge, an insert or a mutation committedbetween them makes it compare different data and blame the rewrite.
Before each query an oracle executes, the active parts of every
MergeTreetable that query readsare recorded (also through views, and behind the proxy of a
lazy_load_tablesdatabase). CTEreferences are first replaced by their definitions and
WITHclauses dropped, in view bodies too,so no table is counted for a CTE named like it, an unused
WITHalias, a clause the oracle stripssuch as
ORDER BY, or a name resolving to another table expression's alias (FROM s AS x JOIN x AS y). On a mismatch the oracle is skipped only if one of those lists changed. A table read onlyinside an
APPLYlambda, through aWITHalias, or as a bareIN toperand (it may name a column)is not recorded, so a change there is reported, as on master. Parts are immutable and a part name is
never reused, so an unchanged list means all reads saw the same data: the mismatch is reported, also
when a re-run would not reproduce it (for example a non-deterministic result from JIT compilation).
The
ASTFuzzerOracleMismatchesincrement moves intorun_oracle, so a skipped mismatch is notcounted. Other engines, and the existing re-run check of
Subquery wrap, are unchanged.No test ships: arming it needs a server-global
PAUSEABLEfailpoint held across a fuzz loop.Validated locally in both directions instead (below).
Local validation
infinite_sleepis aPAUSEABLEfailpoint insideFunctionSleep::execute, sosleep(0)pauses aread, and
sleepis not screened by the oracle. Tables (k UInt32, v UInt32, w UInt32 ALIAS v + 1) ENGINE = MergeTree ORDER BY k, merges stopped, seedSELECT sleep(0), sleep(0), sleep(0), k, w FROM s WHERE k = 5with--ast_fuzzer_runs=300 --ast_fuzzer_oracle=1 --ast_fuzzer_any_query=0. At everypause the driver either inserts one part, or runs
ALTER TABLE s MODIFY COLUMN w UInt32 ALIAS v + N(the result changes, the part names do not), then
SYSTEM NOTIFY FAILPOINT infinite_sleep.Code: 906 TLP WHERE oracle mismatch, first attemptCode: 906, first attemptCode: 906Code: 906Also skipped with this PR and reported without it: the same INSERT race on a table of a
lazy_load_tables = 1database. The ALTER control is reported in thelazy_load_tablesdatabasetoo, and also while an unread table
tgains a part at every pause, for a CTEtovers, aWITH [5] AS tink IN t, an unused CTE overt, an unusedWITH (SELECT count() FROM t) AS c,ORDER BY (SELECT count() FROM t), a CTEtread inside anAPPLYlambda, an unused CTE overtinside a view,
k IN twheretis also a column or an alias, andFROM s AS t JOIN t AS y(previous versions skipped these). An INSERT into
tread throughWITH t AS (SELECT ... FROM t)or under a nested CTE namedtis skipped, and so is one intosread as
FROM s WHERE k IN (SELECT k FROM t AS s).The in-tree AST fuzzer tests pass with random settings:
03823,03833,04305,04344,04658,05227,05288,053385/5 each,053391/1.Workflow [PR]
Sync PR [sync-upstream/pr/119465]
Version info
26.11.1.1577-master(included in26.11and later)