Skip to content

Count text index postings from every query_log row that carries them - #114338

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-02346-probe-admits-exception-rows
Aug 12, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-02346-probe-admits-exception-rows

Conversation

@groeneai

@groeneai groeneai commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Closes: #113751
Requested by @ alexey-milovidov on #103526 (comment).

02346_text_index_parallel_replicas flakes as 1 0 - 12 runs across 11 unrelated PRs and master since 2026-07-01, second column only.

The probe discards the only row carrying the counter. TextIndexUsedEmbeddedPostings is incremented at one site, MergeTreeIndexText.cpp:1232, by whichever server deserializes the dictionary. At parallel_replicas_local_plan = 0 (randomized; 0 in all 12 failures) the initiator does no index analysis, so only a follower can increment it. When the initiator has its answer and tears down connections, a follower still writing results loses the socket and ends with Code: 210, logged as ExceptionWhileProcessing (executeQuery.cpp:851). Those rows do carry ProfileEvents, so type = 'QueryFinish' dropped the counter. ParallelReplicasUsedCount is coordinator-charged, hence the first column never flapped.

The assertion is not weakened: with use_skip_indexes = 0 the test still yields 1 0 in 20 of 20 runs after the fix. Replaying the test's own predicate over both failing runs' archived query_log, the defect disappears and no healthy run regresses, on aarch64 and x86_64 alike (below).

The other 87 tests reading ProfileEvents from query_log with type = 'QueryFinish' under parallel replicas need no change: each one either scopes by query_id, requires is_initial_query, or omits the OR position(query, currentDatabase()) > 0 disjunct, and any one of those makes a follower row unreachable (it carries current_database = 'default' and a different query_id). 02346 was the only file with the disjunct and no query_id scoping.

I treated the follower's Code: 210 as expected rather than a bug: the initiator stops reading once it has its answer, both initiator QueryFinish rows are correct, and the earlier assertions (15 30, 3 3) matched. Making the initiator wait for followers is a much wider engine change, and I have not made it - your call if you want it.

Validation on the two failing CI runs (old vs new predicate, same rows)
failing run check old 1 0 old ok new 1 0 new ok
b214f13f (#103526) Stateless tests (arm_binary, parallel) 1 113 0 114
924143d1 (#112918) Stateless tests (amd_debug, parallel) 1 88 0 89

The one 1 0 run per job flips to passing and joins the healthy set; no healthy run regresses and no new failure appears.

Version info

  • Merged into: 26.8.1.1221 (included in 26.8 and later)

02346_text_index_parallel_replicas asserted its second column from
system.query_log rows filtered by type = 'QueryFinish', and flaked as
`1 0` in 12 runs across 11 unrelated PRs and master since 2026-07-01.

At parallel_replicas_local_plan = 0 the initiator does no index analysis,
so TextIndexUsedEmbeddedPostings can only be incremented by the follower
that deserialized the dictionary (MergeTreeIndexText.cpp). When the
initiator has its answer and tears down its connections, a follower still
writing results loses the socket and terminates with Code: 210, which
executeQuery logs as ExceptionWhileProcessing. Such rows do carry
ProfileEvents, so the counter is present - the type filter discarded the
only row holding it. ParallelReplicasUsedCount is charged to the
coordinator, i.e. always the initiator, which is why the first column
never flapped.

Replaying the test's own predicate over the archived query_log of two
failing CI runs (PR ClickHouse#103526 arm_binary and PR ClickHouse#112918 amd_debug) turns the
failing run into a passing one in both, 113 -> 114 and 88 -> 89 healthy
runs, with no healthy run regressing. The negative control still reddens:
with use_skip_indexes = 0 the test yields `1 0` in 20 of 20 runs, so the
assertion keeps its discriminating power.

Closes: ClickHouse#113751
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 findings, both addressed before publishing)

I reviewed the resulting diff cold, then a second model re-reviewed the full scope
independently and raised none. Both findings below are about this PR's text, not the change:
the diff is one line in one test file and no source file is touched.

# Severity Finding Verdict
⚠️ 1 major The sibling-safety claim originally printed a three-way split ("25 scope by query_id and 60 lack the disjunct ... the last two require is_initial_query"). The total (87) and the conclusion reproduce, but the sub-split does not: the three buckets overlap, so 14 of the 87 literally contain is_initial_query, and the printed digits depend on an unstated classification order. AGREE. Rewritten as a disjunctive claim, which reproduces exactly: each of the 87 satisfies at least one of the three mechanisms, none uncovered. Verified with a positive control, in that 02346 before the fix satisfies none of them, so the predicate is not vacuous.
💡 2 nit ### Description sat exactly at its length limit, leaving no room for a follow-up. AGREE. Condensed.

Checks that passed, worth stating since four earlier attempts on this test were closed unmerged:

  • The assertion still discriminates. The negative control (use_skip_indexes = 0, otherwise
    the failing run's own randomized settings) yields 1 0 in 20 of 20 runs with the fix
    applied
    . A run that does not use the index still fails, so the second column did not become
    a tautology. That is the direct answer to the "the fix defeats the purpose of the test"
    objection which closed
    #112197.
  • The admitted type set is minimal and complete, measured rather than argued: across
    896,340 query_log rows, QueryStart carries no ProfileEvents at all, and admitting
    ExceptionBeforeStart would change no run's outcome in any of the 145 runs sampled.
  • Root cause re-derived from source, not inherited: TextIndexUsedEmbeddedPostings has one
    increment site (MergeTreeIndexText.cpp:1232, charged to whichever server deserializes the
    dictionary) and ParallelReplicasUsedCount has one
    (ParallelReplicasReadingCoordinator.cpp:1356, charged to the coordinator). That asymmetry is
    why only the second column ever flapped.
  • No sibling edits needed, confirmed by an independent enumeration whose positive control
    finds exactly one affected file before the fix (this one) and none after.

Session id: cron:clickhouse-review-slot-8:20260811-134200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate
# Check Result
a Deterministic repro Yes. Replaying the test's own predicate over each failing run's archived query_log reproduces 1 0 on demand (1 of 128 and 1 of 149 runs). The live race is ~6e-05/run, so the archived log is the oracle, not a local loop.
b Root cause explained Yes. Follower-only increment at MergeTreeIndexText.cpp:1232; initiator teardown kills the follower's socket (Code: 210); executeQuery.cpp:851 logs it as ExceptionWhileProcessing, whose ProfileEvents survive via addStatusInfoToQueryLogElement -> element.profile_counters.
c Fix matches root cause Yes. It admits exactly the terminal state carrying the discarded counter. No widened bound, retry, window change or no-random-* tag.
d Test intent preserved Yes, proven. With use_skip_indexes = 0 the test still yields 1 0 in 20 of 20 runs after the fix.
e Both directions Yes. Old predicate: 1 defect per job; new: 0, over the same rows. The negative control reddens on demand.
f General across code paths Yes. All 87 sibling query_log ProfileEvents probes under parallel replicas triaged; 2 examined individually; 0 further edits needed.
g Generalizes across inputs Yes. The admitted type set is minimal and complete, measured by ProfileEvents presence per type over 896,340 rows. Both arch families covered.
h Backward compatible N/A. Test-only; no setting, format or serialization surface.
i Invariants preserved Yes. Column 1 still comes from the initiator's own QueryFinish row; column 2 is true iff some participant genuinely deserialized embedded postings.

No 50/50 randomized campaign was run and none is claimed: at the measured 6.29e-05 per-run rate, 50 runs has 0.3% power. A prior 50,051-run loaded campaign found 0 defects, which is what redirected the investigation to the archived CI logs.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @ahmadov, could you review this? TextIndexUsedEmbeddedPostings can only be incremented by a follower at parallel_replicas_local_plan = 0, and that follower loses its socket at initiator teardown, so its query_log row is ExceptionWhileProcessing and the probe's type = 'QueryFinish' discarded the only row carrying the counter; the negative control confirms the assertion still reddens when the index is not used.

@groeneai groeneai mentioned this pull request Aug 11, 2026
1 task done
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3862e65]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Cannot start clickhouse-server FAIL cidb IGNORED
Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization (null map size = A, nested column size = B) (STID: 6726-6874) FAIL cidb IGNORED
Check failed FAIL cidb IGNORED

AI Review

Summary

This PR narrows a real query_log blind spot in 02346_text_index_parallel_replicas by admitting ExceptionWhileProcessing rows, which are the terminal rows that can carry TextIndexUsedEmbeddedPostings when a parallel-replica follower loses its socket during teardown. I did not find a remaining correctness or determinism issue in the current diff, the Changelog category is appropriate for a test-only CI fix, and the current Praktika run is all green.

Final Verdict

✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3e0ff9a

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_debug) / Hung check failed, possible deadlock found DROP TABLE prometheus stuck 936s in StorageTimeSeries::dropInnerTableIfAny -> DatabaseCatalog::waitTableFinallyDropped, with is_cancelled: 1 #114326 (external, merged 2026-08-12T01:14Z), merged master @ 3862e65 to pick it up
Stress test (arm_tsan) / Hung check failed, possible deadlock found same signature, stuck 1140s, same two frames, is_cancelled: 1 #114326 (external, merged 2026-08-12T01:14Z), merged master @ 3862e65 to pick it up
Sync - CH Inc sync (private, not actionable)

Both hung checks are the same trunk defect and not caused by this PR, whose whole diff is one
line in tests/queries/0_stateless/02346_text_index_parallel_replicas.sql. The stuck query is
the prometheus TimeSeries table created by 04811_promql_topk_bottomk_limitk; #114326 reverts
the PromQL topk/bottomk/limitk streaming plan and its shared-subquery materialization that
introduced the deadlock. That fix merged at 01:14Z, after this run's builds, so it was absent
here (3e0ff9ac is not a descendant of 86e654b8). I merged master to pick it up; CI is
re-running on 3862e658f4a8fdb, which contains the fix.

Session id: cron:our-pr-ci-monitor:20260812-040000

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3862e658f with master d09da1825 (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
Binary Master PR Δ
programs/clickhouse-stripped 691.95 MiB 688.95 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3862e65

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization (STID: 6726-6874) set skip-index granule decoded with a stale on-disk type after ALTER MODIFY COLUMN; fixture is 03702_alter_column_modify_secondary_index_*, which this PR does not touch #112484 (ours, open)
Stress test (amd_msan) / Cannot start clickhouse-server same event: the abort above killed the server at 07:24:28 UTC and the restart loop then timed out #112484 (ours, open)
Stress test (amd_msan) / Check failed job-level rollup of the two rows above #112484 (ours, open)

This PR's diff is one line in tests/queries/0_stateless/02346_text_index_parallel_replicas.sql.
The aborting query is EXPLAIN indexes = 1 SELECT count() FROM test_table WHERE value = '300'
from 03702_alter_column_modify_secondary_index_rebuild.sh/_drop.sh, and the stack is
MergeTreeIndexBulkGranulesSet::deserializeBinary -> SerializationNullable::deserializeBinaryBulkWithMultipleStreams,
so it is not reachable from this change.

Session id: cron:our-pr-ci-monitor:20260812-083000

@PedroTadim PedroTadim self-assigned this Aug 12, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 483d16a Aug 12, 2026
179 of 181 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

4 participants