Repository navigation
Fix null pointer dereference when logging a distributed plan local task - #107570
alexey-milovidov merged 1 commit into
Conversation
A local distributed-plan task fragment is built from a serialized query plan, not parsed, so it has no query AST. doExecuteTask passed an empty ASTSelectQuery() to logQueryStart only to carry query_kind. An empty ASTSelectQuery has no SELECT expression list, so with log_formatted_queries = 1 the log path formatted it and ASTSelectQuery::formatImpl dereferenced the absent SELECT (select()->format()), a member call on a null IAST. The server aborts. Fix: pass a null ASTPtr instead of the malformed stub. logQueryStart, logQueryFinish and logQueryException already treat a null AST as QueryKind::Select (the kind the stub was constructed to provide), so behavior is unchanged for query_kind while the formatting crash is avoided. Remove the now-dead include of Parsers/ASTSelectQuery.h. Found by the BuzzHouse fuzzer (amd_msan), STID 2257-2710, on the make_distributed_plan + distributed_plan_execute_locally path. The same bug was fixed once before (PR ClickHouse#107079) but that fix was closed obsolete when the feature was reverted, and the feature was then re-landed with the buggy stub intact, so the fix is re-applied here. Regression test 04327_distributed_plan_local_log_formatted_queries runs the affected path; it aborts the server before this change and passes after. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Note: this is a re-application of PR #107079 (closed obsolete after the feature was reverted in #107122 and then re-landed with the buggy stub). The surrounding per-task context/thread-group code changed in the re-land, so the fix was re-applied against current master rather than cherry-picked. Session id: cron:clickhouse-worker-slot-0:20260615-221900 |
|
cc @davenger @KochetovNicolai — could you review this? It re-applies the fix for the null-AST crash in the distributed-plan local task executor: |
|
Workflow [PR], commit [407aa6c] Summary: ✅
AI ReviewSummaryThis PR removes the malformed empty Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 18/18 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
📊 Cloud Performance Report 🟢 AI verdict: This PR only changes query-logging plumbing in the distributed-plan executor (it replaces an unnecessary AST stub with a null pointer) and adds one test. Neither ClickBench nor the TPC-H suite runs with make_distributed_plan enabled, so the diff cannot plausibly change any of these queries' execution time. On that basis the +15.76% on TPC-H Q8 and the high-variance -21% on ClickBench Q22 are read as run-to-run variance and downgraded. The remaining large, consistent improvements (ClickBench Q23, TPC-H Q7 and Q20) are too big to override, but they sit on a code path this PR doesn't touch and most likely reflect build/version baseline differences rather than the change itself. clickbench🟢 1 improved · Flagged queries (2 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 2 improved · Flagged queries (3 of 22)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
Related: #107079
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a crash (null pointer dereference) that could happen when a distributed query plan was executed locally (
make_distributed_plan+distributed_plan_execute_locally) withlog_formatted_queries = 1.Description
A local distributed-plan task fragment is built from a serialized query plan, not parsed, so it has no query AST.
doExecuteTask(src/QueryPipeline/DistributedPlanExecutor.cpp) passed an emptyASTSelectQuery()tologQueryStartonly to carryquery_kind. An emptyASTSelectQueryhas no SELECT expression list, so withlog_formatted_queries = 1the log path formatted it andASTSelectQuery::formatImpldereferenced the absent SELECT (select()->format()), a member call on a nullIAST, and the server aborts.Fix: pass a null
ASTPtrinstead of the malformed stub.logQueryStart,logQueryFinishandlogQueryExceptionalready treat a null AST asQueryKind::Select(the kind the stub was constructed to provide), so behavior is unchanged forquery_kindwhile the formatting crash is avoided. The now-dead include ofParsers/ASTSelectQuery.his removed.This bug was fixed once before in PR #107079, but that fix was closed obsolete when the Multi-stage distributed queries feature was reverted (#107122) and the feature was then re-landed with the buggy stub intact, so the fix is re-applied here against current master (the surrounding per-task context/thread-group code changed in the re-land).
CI provenance:
BuzzHouse (amd_msan).IAST::isParenthesized->decideParensEmission->IAST::format->ASTSelectQuery::formatImpl->formatWithSecretsOneLine->logQueryStart->doExecuteTask.Regression test
04327_distributed_plan_local_log_formatted_queriesruns the affected path; it aborts the server before this change and passes after.Version info
26.6.1.880