Skip to content

Fixes for AST fuzzer oracle - #118044

Closed
azat wants to merge 4 commits into
ClickHouse:masterfrom
azat:fix-oracle-approx-top-k
Closed

azat wants to merge 4 commits into
ClickHouse:masterfrom
azat:fix-oracle-approx-top-k

Conversation

@azat

@azat azat commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Workflow [PR]
Sync PR [sync-upstream/pr/118044]

@azat
azat requested a review from qoega September 4, 2026 10:44
"anyRespectNulls", "anyLastRespectNulls",
"first_value", "last_value",
"topK", "topKWeighted",
"approx_top_k", "approx_top_sum",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real fix - missing exceptions

@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3b3b87e]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, flaky check) FAIL
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
Too many test failures FAIL cidb
Stateless tests (amd_debug, flaky check) FAIL
05058_ast_fuzzer_oracle_approximate_aggregates FAIL cidb
Unknown error FAIL cidb

AI Review

Summary

This PR extends the AST-fuzzer oracle skip list for approximate / order-dependent aggregates by adding approx_top_* and resolving aggregate aliases before the denylist lookup. The direct-call path looks reasonable, but the same unsafe aggregates are still invisible when they come through APPLY, so the false-mismatch bug is not fully fixed yet.

Findings

⚠️ Majors

  • [src/Interpreters/QueryOracleChecker.cpp:240] The alias-aware denylist only runs for ASTFunction nodes. ASTColumnsApplyTransformer keeps func_name, parameters, and lambda outside children, so SELECT * APPLY any_value, APPLY(array_agg), and APPLY(x -> medianTDigest(x)) still bypass hasNonDeterministicFunctions. Those queries can still reach checkDQP, checkIdentityWhere, and checkSubqueryWrap, where order-dependent / approximate aggregates are supposed to be skipped and can still produce false AST_FUZZER_ORACLE_MISMATCHs. Suggested fix: mirror the existing scanAggregatesSafe special-case here; inspect ASTColumnsApplyTransformer::func_name, recurse into parameters and lambda, and run the same scalar / aggregate determinism checks on that carrier.
  • [tests/queries/0_stateless/05058_ast_fuzzer_oracle_approximate_aggregates.sh:24] The new regression test only covers ordinary aggregate calls. It never builds an ASTColumnsApplyTransformer, so it stays green while the bug above still exists for SELECT * APPLY any_value, APPLY(array_agg), or APPLY(x -> medianTDigest(x)). Suggested fix: add at least one APPLY-based case that exercises the non-ASTFunction carrier the oracle has to reject.
Final Verdict

Changes requested: the direct aggregate-call syntax is fixed, but the APPLY carrier still bypasses the oracle-safety gate, so the PR does not yet close the false-mismatch class it is targeting.

LLVM Coverage Report

Measured on commit 3b3b87e.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 20/20 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 4, 2026
Comment thread src/Interpreters/QueryOracleChecker.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026
@azat
azat force-pushed the fix-oracle-approx-top-k branch from a3e1e56 to e660916 Compare September 7, 2026 11:43
azat and others added 4 commits September 7, 2026 14:04
`isAlias` matches the exact spelling only, so a caller that accepts any
spelling needs the resolver instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…t, ...) before the denylist lookup

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@azat
azat force-pushed the fix-oracle-approx-top-k branch from e660916 to 3b3b87e Compare September 7, 2026 12:05
@azat
azat enabled auto-merge September 7, 2026 12:17
while (true)
{
if (non_deterministic_functions_lower.contains(Poco::toLower(name)))
if (non_deterministic_functions_lower.contains(Poco::toLower(aggregate_factory.getAliasToOrName(name))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scanAggregatesSafe already special-cases ASTColumnsApplyTransformer because APPLY keeps func_name, parameters, and lambda outside children. hasNonDeterministicFunctionsImpl still only inspects ASTFunction and then recurses through children, so SELECT * APPLY any_value, APPLY(array_agg), or APPLY(x -> medianTDigest(x)) never hit this alias-aware denylist. Those queries can still reach checkDQP, checkIdentityWhere, and checkSubqueryWrap, where order-dependent / approximate aggregates are supposed to be skipped and can still raise false AST_FUZZER_ORACLE_MISMATCHs.

Please mirror the ASTColumnsApplyTransformer handling here: inspect func_name, recurse into parameters and lambda, and run the same scalar / aggregate determinism checks on that carrier too.

INSERT INTO oracle_approx_agg SELECT number % 5, number FROM numbers(200);
"

for agg in "approx_top_k(v)" "approx_top_count(v)" "approx_top_sum(v, v)" "APPROX_TOP_K(v)" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regression test only exercises ordinary aggregate calls. It never builds an ASTColumnsApplyTransformer, so it stays green while the bug above still exists for SELECT * APPLY any_value, APPLY(array_agg), or APPLY(x -> medianTDigest(x)).

Please add at least one APPLY-based case here so the non-ASTFunction carrier is covered too.

@azat
azat disabled auto-merge September 7, 2026 12:56
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3b3b87e25 with master 58f74d473 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

1402 translation units recompiled, 7977 s compile time in total, 1402 of them have a recent master baseline.

Job report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants