Skip to content

Fix LOGICAL_ERROR on invalidate_query of a remote ClickHouse dictionary source - #129336

Merged
vdimir merged 1 commit into
masterfrom
vdimir/fix-remote-dictionary-invalidate-query
Nov 6, 2026
Merged

vdimir merged 1 commit into
masterfrom
vdimir/fix-remote-dictionary-invalidate-query

Conversation

@vdimir

@vdimir vdimir commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

A dictionary with LIFETIME is reloaded from its source on a timer. To avoid a full reload when nothing changed, the source can have an invalidate_query: a cheap query returning a single value, for example SELECT max(updated_at) FROM src. On every check the result is compared with the previous one, and the dictionary is reloaded only when it differs.

For a ClickHouse source on a remote server, the invalidate query was run through a RemoteSource with an empty header, because the structure of the result is not known in advance: the user may write any SELECT there. An output port validates that the number of columns in a chunk matches its header, so the received column could never be pushed through, and every check failed with

Invalid number of columns in chunk pushed to OutputPort. Expected 0, found 1

Since the check never produced a value to compare, the dictionary was fully reloaded on every tick, and the logical error was written to last_exception and the server log. The local case, where the source is the same server, was not affected: there the pipeline is built from the query itself and knows the result structure.

The fix reads the result directly from RemoteQueryExecutor, which passes blocks through unchanged when its header is empty, the same way clickhouse-benchmark reads a result of unknown structure. readInvalidateQuery is split into a shared implementation with a "next block" callback and two thin wrappers: one over a QueryPipeline for the local, MySQL and ODBC sources, one over a RemoteQueryExecutor. The logic itself is unchanged: take the first non-empty block, require exactly one row, serialize the value to text.

The new stateless test points the source at 127.0.0.2, which is not treated as a local address, so the remote path is exercised against the same server. It checks that two periodic checks after an insert that does not change max(upd) do not reload the dictionary, that an insert with a newer upd is picked up, and that last_exception stays empty.

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 into CHANGELOG.md):

Fixed invalidate_query for a dictionary with a ClickHouse source on a remote server. Every periodic check failed with a logical error Invalid number of columns in chunk pushed to OutputPort, so the dictionary was fully reloaded on every check instead of only when the result of invalidate_query changed.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1569-master (included in 26.11 and later)

…ry source

The remote branch of `ClickHouseDictionarySource::doInvalidateQuery` ran the query
through a `RemoteSource` with an empty header, because the result structure is not
known in advance. The received columns cannot be pushed through such a port, so every
periodic check failed with "Invalid number of columns in chunk pushed to OutputPort.
Expected 0, found N" and the dictionary was reloaded on every check.

Read the result directly from `RemoteQueryExecutor` instead, as `clickhouse-benchmark`
does for a result of unknown structure.

ClickHouse/clickhouse-core-incidents#2212

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [12caa85]

Summary: ✅


AI Review

Summary

Fixes remote ClickHouse dictionary invalidate_query by reading results of unknown structure directly through RemoteQueryExecutor, preserving the shared single-column, single-row validation. No actionable findings. The new regression test 05457_dictionary_remote_clickhouse_invalidate_query passed in Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). labels Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 12caa8526 with master 96dc5c984 (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.

Object file sizes

4 object files changed (+18.77 KiB total), 0 added.

Object file Master PR Δ
src/Dictionaries/CMakeFiles/clickhouse_dictionaries.dir/readInvalidateQuery.cpp.o 73.17 KiB 90.31 KiB +17.14 KiB (+23.43%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@watson-ch

watson-ch Bot commented Nov 4, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2212

Labels added:

  • v26.6-must-backport
  • v26.8-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@vdimir
vdimir requested review from devcrafter and removed request for devcrafter November 5, 2026 12:51
@vdimir
vdimir added this pull request to the merge queue Nov 6, 2026
Merged via the queue into master with commit 0ba40ae Nov 6, 2026
185 checks passed
@vdimir
vdimir deleted the vdimir/fix-remote-dictionary-invalidate-query branch November 6, 2026 22:11
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 6, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Nov 6, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 7, 2026
Backport #129336 to 26.8: Fix LOGICAL_ERROR on invalidate_query of a remote ClickHouse dictionary source
clickhouse-gh Bot added a commit that referenced this pull request Nov 7, 2026
Backport #129336 to 26.9: Fix LOGICAL_ERROR on invalidate_query of a remote ClickHouse dictionary source
clickhouse-gh Bot added a commit that referenced this pull request Nov 7, 2026
Backport #129336 to 26.10: Fix LOGICAL_ERROR on invalidate_query of a remote ClickHouse dictionary source
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants