Repository navigation
Fix view source substitution in subqueries inside view inner queries - #124875
alexey-milovidov merged 2 commits into
Conversation
Subqueries (IN and scalar) of a row policy inside an ordinary view read the inserted block of the materialized view instead of the real source table. Do not pass the view source when the context is a view inner query, as already done in resolveFunction and evaluateScalarSubqueryIfNeeded. Fixes ClickHouse#124551.
|
Workflow [PR], commit [bef3a20] Summary: ✅
AI ReviewSummaryThis PR closes the two remaining analyzer entry points that still passed Final Verdict✅ No findings from me on the current version of this PR. |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124875&sha=64ff1cd5ae444d858972bb8edba99394fd1daf7e&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 ( The other failures ( |
|
Not caused by this PR. The fix is #123121 (mine, open). It is the parallel replicas race from #112642: the initiator's local plan waits for the materialized CTE only in its own branch, so the query sent to the other replicas can start before |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+41.09 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, 15 s compile time in total, 8 of them have a recent master baseline. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes wrong results when a materialized view reads an ordinary view over a table with a row policy that contains a subquery (
x IN (SELECT ...)or a scalar subquery). The policy's subquery now reads the real source table instead of the block being inserted into the materialized view.Closes #124551
Details
When a materialized view query reads an ordinary view, only the top-level
SELECTof the materialized view should read the inserted block. The inner query of the view must read real tables. PR #122345 added an!isViewInnerQuery()guard for this in several places, but two places that passgetViewSource()toInterpreterSelectQueryAnalyzerwere missed:src/Interpreters/interpretSubquery.cpp(interpretSubqueryWithAnalyzer)src/Interpreters/ExecuteScalarSubqueriesVisitor.cpp(getQueryInterpreter)Both now pass
nullptrwhenisViewInnerQuery()is true. The check-only usages inExecuteScalarSubqueriesVisitor.cppdo not substitute anything and are unchanged.Test:
05345_in_subquery_row_policy_under_view_inner_query_in_materialized_view. TheINsection covers a view over aMergetable and a direct view. The scalar section covers a view over aMergetable.Verification (local build on master
08480e808f7, branch rebased onto48f09dce392afterwards without rebuild):2 1 0 / 3 1 0 / 4 0 0. After the fix:2 0 0 / 3 0 0 / 4 0 0.interpretSubquery.cppfix, the scalar section of the new test fails (1 1). With both fixes it passes.05321_in_subquery_of_standalone_expression_under_materialized_viewstill passes.SELECTof a non-view materialized view still reads the inserted block.--no-random-settings.Not changed:
JoinedTables.cpp(old planner) also usesgetViewSource()without the guard, but the bug did not reproduce withenable_analyzer = 0.Workflow [PR]
Sync PR [sync-upstream/pr/124875]
Version info
26.10.1.2030-master(included in26.10and later)