Skip to content

Allow duplicate inputs when evaluating the Merge table-selection filter - #117612

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-index-hint-merge-table-virtual-114013
Sep 20, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-index-hint-merge-table-virtual-114013

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fixed NOT_FOUND_COLUMN_IN_BLOCK when a predicate on a Merge table's _table or _database virtual column is wrapped in indexHint.

Documentation entry for user-facing changes

The Merge engine decides which tables to read by evaluating the part of the filter that depends only on _database and _table over a one-row block holding exactly those two columns. An indexHint argument contributes a second input for the same virtual column, and the expression was executed without allowing duplicate inputs, so the second input found nothing in the block and the query failed instead of narrowing the read:

SELECT _table, key FROM m_all
WHERE indexHint(_table = 'm_v1') AND (_table = 'm_v1');
-- Code: 10. Not found column _table in block:
-- while executing 'INPUT : 1 -> _table LowCardinality(String) : 3'

indexHint may only narrow which data is read, never fail the query, and the bare predicate worked. Duplicate inputs are now bound to the same block column - they all carry the same value - which is what filterBlockWithExpression, every other consumer of these split predicates, already does.

Closes: #114013


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

Version info

  • Merged into: 26.10.1.302-master (included in 26.10 and later)

…n inputs

The `Merge` engine decides which tables to read by evaluating the part of the
filter that depends only on `_database` and `_table` over a one-row block
holding exactly those two columns. An `indexHint` argument contributes a
second input for the same virtual column, and a block holding it once cannot
satisfy both, so the query failed instead of narrowing the read:

    SELECT _table, key FROM m_all
    WHERE indexHint(_table = 'm_v1') AND (_table = 'm_v1');
    -- Code: 10. Not found column _table in block:
    -- while executing 'INPUT : 1 -> _table LowCardinality(String) : 3'

`indexHint` may only narrow which data is read, never fail the query, and the
bare predicate worked. The block is now built from the expression's required
columns, so it provides each input as many times as the expression asks for
it.

Closes: #114013
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [86bfcd4]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR fixes Merge table pruning for predicates where indexHint duplicates the _table or _database virtual-column input by evaluating the split filter with allow_duplicates_in_input = true while keeping the existing one-row block. I found no remaining correctness issues in the current patch: it now matches the established filterBlockWithExpression semantics, and the new stateless test covers both the duplicate-input failure from #114013 and the constant-only zero-input edge raised in earlier review.

Final Verdict

✅ No new findings on the current diff. Residual risk: I did not run the new stateless test locally in this review, so this verdict is based on code inspection and the added regression coverage.

LLVM Coverage Report

Measured on commit 86bfcd4.

Metric Baseline Current Δ
Lines 88.40% 88.50% +0.10%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.70% +0.10%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 2, 2026
@zlareb1

zlareb1 commented Sep 2, 2026

Copy link
Copy Markdown
Member

There is a zero-input edge in the new block construction that turns a fail-loud case into a silently empty result.

The new block is built from getRequiredColumnsWithTypes, which returns one entry per INPUT of the split DAG. When the split filter ends up with zero inputs, the block has zero columns, so ExpressionActions::execute derives num_rows = 0 and every action runs on 0 rows. A non-foldable function of constants then yields a full column of size 0, and the final column->getBool(0) on an empty ColumnVector reads data[0] out of bounds into the static zero-initialized empty_pod_array (src/Columns/ColumnVector.h, src/Common/PODArray.h), returning false — so the table filter deselects every table and the query silently returns an empty result. The old fixed {_database, _table} block always had exactly one row (the comment "Valid only when block has exactly one row" still stands above the getBool call), which is what made this unreachable before.

Zero-input split DAGs are reachable at default settings: the indexHint branch of splitFilterNodeForAllowedInputs keeps constant-only atoms. Verified on a current 26.9 master build (both analyzers) that the constant-only DAG is built and evaluated by the table filter today: SELECT count() FROM m_all WHERE indexHint(materialize(0)) returns 0, and WHERE indexHint(materialize(1)) returns all rows. With this PR as written, WHERE indexHint(materialize(1)) — and any shape like indexHint(materialize(1)) AND key >= 1 — should come back empty instead, deterministically, and the out-of-bounds read lands in valid static memory so sanitizers stay quiet. Pure-constant shapes such as indexHint(1) keep working only by accident of ColumnConst::getBool ignoring its index.

A small guard closes it: if getRequiredColumnsWithTypes is empty, keep a one-row dummy block (or assert block.rows() == 1 before the getBool call). Alternatively, the duplicate-input exception from #114013 can also be fixed by keeping the old fixed one-row block and calling filter->execute(block, /*dry_run=*/false, /*allow_duplicates_in_input=*/true) — the value bound to both duplicate _table inputs is identical, and every other consumer of these split DAGs already goes through filterBlockWithExpression, which passes allow_duplicates_in_input = true.

Comment thread src/Storages/StorageMerge.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 86bfcd47c2f52c015d47fd234dd40bc9be540e21 with master failed: RuntimeError: CI logs cluster query failed: SELECT file, detail, sumIf(dur, side = 'pr'….

See the job log for details.

@alexey-milovidov alexey-milovidov left a comment

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.

Good.

Building the block from the expression's own inputs is wrong for a split
predicate that needs no input at all. `indexHint(materialize(1))` produces a
constant-only DAG, so `getRequiredColumnsWithTypes` is empty, the block has zero
columns, and `ExpressionActions::execute` therefore derives `num_rows = 0` and
evaluates every action over zero rows. The `getBool(0)` that decides table
selection then reads past the end of an empty column - landing in the static
zero-initialized `empty_pod_array`, so no sanitizer notices - and returns false,
which prunes every child table and silently returns an empty result.

Measured against a local build of the previous commit, with two `MergeTree`
tables of one row each behind a `Merge` table:

    SELECT count() FROM m_all WHERE indexHint(materialize(1))              -- 0, master gives 2
    SELECT count() FROM m_all WHERE indexHint(materialize(1)) AND key >= 1 -- 0, master gives 2

Restore the fixed one-row `_database` / `_table` block and pass
`allow_duplicates_in_input = true` instead. That binds every duplicate input to
the same block column - they all carry the same value - and keeps the one-row
invariant the `getBool` relies on. It is also what `filterBlockWithExpression`,
every other consumer of these split predicates, already does.

Cover the constant-only shapes in the test.

Address review: #117612 (comment)
@alexey-milovidov alexey-milovidov changed the title Build the Merge table-selection filter block from the expression's own inputs Allow duplicate inputs when evaluating the Merge table-selection filter Sep 2, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-storage-merge Merge table engine (logical union over tables) and related mechanics. label Sep 4, 2026
Naz-Ovh pushed a commit to 0x-fork/ClickHouse that referenced this pull request Sep 13, 2026
…an fire

`apt-get update` does not treat a failed repository index fetch as fatal: it
reports the failure at `W:` severity, exits 0, and proceeds with a stale or
absent index. The `RUN` chain therefore continues into `apt-get install`, which
resolves against an index that was never refreshed and dies at `E:` severity with
`E: Unable to correct problems, you have held broken packages`, preceded by
`wget : Depends: libpsl5 (>= 0.16.0) but it is not installable`.

Everything downstream then behaves correctly on the evidence it is handed. buildx
fences the tail of the failing step, which by then holds only the resolution
error; `terminal_build_failure` returns that fence; `is_apt_mirror_failure` finds
no `APT_MIRROR_ERRORS` token at `E:` severity, because the lines that do carry
those tokens are `W:` and sit above the fence; `should_try_next_mirror` returns
False and the mirror loop exits without ever rebuilding against Canonical. The
Canonical fallback is therefore handed exactly the evidence it is designed to
reject, on the outage it exists for.

`--error-on=any` promotes those lines to `E:` and stops the chain before the
install runs, which is the shape the merged classifier was written to recognise.
Nothing in `ci/` changes.

Measured in `ubuntu:22.04` (apt 2.4.14), against a local 503 server and against a
refused port:

  failure shape       apt-get update    rc     severity of the mirror lines
  503 on InRelease    plain             0      W:
  503 on InRelease    --error-on=any    100    E:
  connection refused  plain             0      W:
  connection refused  --error-on=any    100    E:

`any` is apt's only accepted value; `no`, `some` and `warn` each return
`E: Unknown update error mode`.

End to end, with each captured buildx output fed to the shipped
`should_try_next_mirror`:

  docker/server/Dockerfile.distroless   503                  False -> True
  docker/keeper/Dockerfile.distroless   503                  False -> True
  docker/server/Dockerfile.ubuntu       503                  False -> True
  docker/server/Dockerfile.distroless   connection refused   False -> True

The pristine tree reproduces the CI failure byte-for-byte: same failure point
(`Dockerfile.distroless:31`), same `exit code: 100`, same unmet dependency, same
terminal error. Both arms still fail the build, so this changes the
classification, not the outcome of a broken mirror. Control: a full `ch-builder`
build against the real mirrors still succeeds with rc 0 and zero `E:` lines,
exercising all three flagged sites including the `packages.clickhouse.com`
refresh.

The repository already documents this defect on the sibling package manager, in
`docker/server/Dockerfile.alpine` and `docker/keeper/Dockerfile`: "`apk` has no
retry option, and it does not treat a failed repository index fetch as fatal: it
proceeds with an empty index, so every requested package is then reported as
`no such package`". apt behaves the same way and, unlike apk, has an option for
it.

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117612&sha=641c9b6831e3c49cc505ac66eed049c46b1f4a4d&name_0=PR&name_1=Docker%20server%20image
Related: ClickHouse#117612
Related: ClickHouse#116444

Co-Authored-By: Claude Opus 5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

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.

Ok.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 20, 2026
Merged via the queue into master with commit 762fe11 Sep 20, 2026
174 of 176 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-index-hint-merge-table-virtual-114013 branch September 20, 2026 21:01
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-storage-merge Merge table engine (logical union over tables) and related mechanics. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

indexHint over a Merge table's _table virtual column fails with NOT_FOUND_COLUMN_IN_BLOCK instead of narrowing the read

3 participants