Skip to content

Cherry pick #116371 to 26.7: Fix a _table/_database filter over a Merge table returning no rows for children that read from other tables - #117025

Open
robot-ch-test-poll2 wants to merge 5 commits into
backport/26.7/116371from
cherrypick/26.7/116371
Open

Cherry pick #116371 to 26.7: Fix a _table/_database filter over a Merge table returning no rows for children that read from other tables#117025
robot-ch-test-poll2 wants to merge 5 commits into
backport/26.7/116371from
cherrypick/26.7/116371

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #116371

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 5 commits August 25, 2026 17:53
… that read from other tables

The values of the `_table`/`_database` virtual columns are stamped by the
table that actually produces the rows: the remote table for `Distributed`,
the destination for `Buffer`, the target for `Alias`, the children for a
nested `Merge`. But `ReadFromMerge::getSelectedTables` pruned children by
their own names, so whenever a child reads its data from other tables, the
two disagree and the query silently returned no rows.

Prune only the children that do not read from other tables; the rest are
always read, and the predicate filters their rows.

A rework of #113735.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
In a database with the lazy_load_tables setting, an unloaded table is a
StorageTableProxy, and StorageProxy did not forward the new
readsFromOtherTables flag to the nested storage. A lazily loaded
Distributed, Merge, Buffer, or Alias child of a Merge table would
therefore still be pruned by a `_table`/`_database` filter by the
proxy's own name, silently returning no rows after a restart or
`ATTACH DATABASE`. Forward the flag like the other capability bits and
add a `lazy_load_tables = 1` regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The `various` style check (`ci/jobs/scripts/check_style/various_checks.sh`) requires every test querying `system.tables` to scope it to a single database, and recognizes only three spellings: `database ... currentDatabase`, `database ... $CLICKHOUSE_DATABASE`, and a quoted literal. The SQL query-parameter form `database = {CLICKHOUSE_DATABASE_1:String}` is equally scoped but matches none of them, so the check failed:

    Queries to system.tables ... does not have database = currentDatabase()/$CLICKHOUSE_DATABASE condition in ./tests/queries/0_stateless/05045_merge_prefilter_lazy_load_tables.sql

Since the style check is a `run_after` dependency of the whole workflow, this dropped 151 jobs, including both `Bugfix validation (functional tests, *)` jobs, which in turn failed the `new_tests_check.py` post-hook in `Finish Workflow`, and the same failure blocked the `CH Inc sync` workflow.

Spell the probe with `currentDatabase()` under a `USE`, as `04870_column_declaration_statistics_lazy_load` already does for the same situation. `USE` does not load the lazily loaded tables, so the reported engine is still `TableProxy` and the reference file is unchanged.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116371&sha=1193fcaafc2d139446ca246788530956cd79b7d8&name_0=PR
Related: #116371
…-children

Fix a `_table`/`_database` filter over a `Merge` table returning no rows for children that read from other tables
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants