Skip to content

Scope SHOW DATABASES in 02105_backslash_letter_commands - #113713

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/scope-show-databases-02105-expect
Aug 7, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/scope-show-databases-02105-expect

Conversation

@groeneai

@groeneai groeneai commented Aug 6, 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

02105_backslash_letter_commands.expect matches against SHOW DATABASES, whose size is set by
whatever other tests are running. It is the only one of the 54 .expect tests rendering
SHOW DATABASES or SHOW TABLES unscoped, which is why the sibling client tests passed in
every job where it failed.

The rendered table pads every row to the widest database name (bounded only by
output_format_pretty_max_column_pad_width, default 250), so a concurrent test creating very
long names inflated what this test must match by 7.6x. Past a few kilobytes the client stops
emitting output mid-stream, the prompt is never written, and expect_after turns the 60s
timeout into a failure. The reason strings return code: 1 and
Timeout! Killing process group are one event.

This scopes both \l sends with like 'system', the idiom this test already uses for \d on
line 49. Measured against ~120 databases whose widest name is 214 characters: the largest
buffer expect must retain drops from 6001 characters, exactly its cap of 3 * match_max + 1,
to about 340, and buffers at that cap from 11 to 0. Interleaved to cancel load drift, the
current test fails 9 of 12 runs and the scoped one 0 of 12; 50 randomized and 50 plain runs
pass.

Since the client echoes the formatted query, the predicate alone would have let
expect "system" match the echoed LIKE 'system' rather than a result row, so the test also
gains a 1 row in set assertion. That count is printed only below the rendered result, and the
unfiltered statement reports a count that varies with the environment and is never one.
00419_show_sql_queries.sh still covers unfiltered SHOW DATABASES.

I did not identify why the client stops writing, and this does not claim to. It removes the
measured precondition: a test matching unbounded output controlled by other tests.

The test matched against `SHOW DATABASES`, whose size is set by whatever other
tests happen to be running concurrently. It is the only one of the 54 `.expect`
tests that renders `SHOW DATABASES` or `SHOW TABLES` unscoped, which is why the
sibling client/expect tests passed in every job where this one failed.

`ClientBase::mainImpl`'s alias loop substitutes only the first backslash alias
(the `break` at src/Client/ClientBase.cpp:4657), so line 35 sent
`SHOW DATABASES ;  \d;` and line 38 sent `SHOW DATABASES ;`. The rendered table
pads every row to the widest database name, bounded only by
`output_format_pretty_max_column_pad_width` (default 250), so a concurrent test
creating very long database names inflated the matched output by roughly 8x.
Past a few kilobytes the client stops emitting output mid-stream, the prompt is
never written, and the script's `expect_after` turns the 60s timeout into a
failure. The two reason strings seen in CI, `return code: 1` and
`Timeout! Killing process group`, are the same event and differ only in which
timeout fires first.

Scoping both `\l` sends with `like 'system'` matches the idiom this test already
uses for `\d` on line 49. Measured on one binary against a fixture of ~120
databases whose widest name is 214 characters: the largest buffer expect must
retain drops from 6001 characters, exactly its cap of `3 * match_max + 1`, to
340, and buffers sitting at that cap from 11 to 0. Interleaving both variants to
cancel load drift on a shared box, the previous form fails 9 of 12 runs and the
scoped one 0 of 12. 50 randomized and 50 non-randomized runs pass, and a suite
slice over all 54 `.expect` tests plus 04655, 03566 and 00419 has identical
failure sets on both arms.

Because the client echoes the formatted query in interactive mode, the predicate
also appears in that echo, so the pre-existing `expect "system"` would have been
satisfied by the echoed text alone. An `expect "1 row in set"` is therefore added
after it: that string is emitted only below the rendered result, and the
unfiltered statement reports a row count that varies with the environment and is
never one, so the assertion pins both that the predicate reached the server and
that it was applied. Reverting the two
predicates while keeping the assertion makes the test fail while awaiting it,
against an otherwise complete and correct unfiltered answer.

Coverage is preserved and slightly extended. All 19 assertions fire in order;
unfiltered `SHOW DATABASES` keeps separate coverage in
00419_show_sql_queries.sh; and `\l` argument pass-through
(src/Client/ClientBase.cpp:4655) becomes newly covered, having previously been
exercised only through `\c` and `\d`.

Why the client stops writing is not identified, and this does not claim to fix
it. What it removes is the measured precondition: a test matching unbounded
output that unrelated tests control.
@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — 1 blocker fixed, 2 nits

Before opening this PR I ran an independent cold review of the resulting code plus a
second-model review pass, and adjudicated every finding. Verdicts below.

❌ Blockers

The like predicate initially made the test's own result assertion vacuous. AGREE — fixed.

Raised independently by both passes. clickhouse-client echoes the formatted query in
interactive mode (ClientBase::setupEchoAndHighlightSettings → echoQuery,
src/Client/ClientBase.cpp:3124, :3136), and ASTShowTablesQuery::formatLike emits the
predicate verbatim via quoteString (src/Parsers/ASTShowTablesQuery.cpp:37-44). So the
echoed line becomes SHOW DATABASES LIKE 'system', and the existing expect "system" was
satisfied by that echoed text before any result arrived. Measured from expect's own
instrumentation, in both directions:

arm what expect "system" consumed
before this PR ... 3. │ information_schema │\r\n 4. │ system — a result row
predicate only LIKE 'system — the echo

So with the predicate alone, SHOW / DATABASES / system would have asserted nothing about
the server's answer: the test would still have passed if the query returned zero rows, in a
test whose purpose is that \l is substituted and executed. Neither the pass/fail bit nor
the assertion-order oracle can see this, since the latter checks that the patterns fire in
order and not what they matched.

Fixed by adding expect "1 row in set" after the database name. Verified before adopting it:
that string lands strictly after the echo and after Query id:, it is present in every fixed
run, and it discriminates. The count is printed only below the rendered result
(src/Client/ClientBase.cpp:2923), and the scoped statement is rewritten to
SELECT name FROM system.databases WHERE name LIKE 'system'
(InterpreterShowTablesQuery::getRewrittenQuery), so exactly one row comes back, whereas the
unfiltered statement's count varies with the environment and is never one. So the assertion now
pins that the predicate was both forwarded and applied, which is strictly stronger than the
original test. Reverting the two predicates while keeping the assertion leaves it unsatisfied
against an otherwise complete and correct answer, so it is not a tautology.

⚠️ Majors

None.

💡 Nits

  • Four figures in an earlier draft of this description did not reproduce, and are corrected
    here.
    AGREE — fixed. The fixed arm's largest retained buffer is about 340 characters (376
    bytes), not 342; the base arm quoted has 11 buffers at the cap, not 12; the inflation factor
    is 7.6x, not roughly 9x; and the unfiltered row count was quoted as a fixed 115 when it is
    115, 120, 122 or 126 depending on what else is running, which is the environment dependence
    this PR removes and therefore not a publishable constant. The cap's unit is characters, not
    bytes: three arms each retain 6001 characters while holding 6525, 6109 and 6531 bytes, so a
    byte cap could not take one value. The load-bearing figures reproduce exactly: 6001 is the cap
    3 * match_max + 1, match_max 100000 before spawn is a no-op that leaves the channel at
    the default 2000, 9 of 12 versus 0 of 12 interleaved, and 1 of 54 .expect tests renders an
    unscoped SHOW DATABASES/SHOW TABLES.
  • Reverting only the second \l predicate does not make the test fail. Noted, not changed. It is retained on a different measured basis: unscoped, its expect "system"
    matched on an already-saturated buffer in 14 of 40 base runs, which is a latent vacuous
    assertion rather than a present failure. The new 1 row in set assertion now pins that line
    positively as well.

Verified and deliberately not changed

  • The client-side stall's own mechanism is unexplained, and this PR offers none. What it
    removes is the measured precondition.
  • The symmetric \d path needs no change: it already runs after \c system; and carries
    like 'one'.
  • Unfiltered SHOW DATABASES keeps coverage in 00419_show_sql_queries.sh, and \l argument
    pass-through (src/Client/ClientBase.cpp:4655) becomes newly covered, having previously been
    exercised only through \c and \d.
  • No no-parallel tag, no timeout increase and no match_max change: a longer timeout would
    hide the stall rather than remove its precondition, and the parallel tag would cost real
    coverage.

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Reproduced locally, which no earlier investigation of this failure managed. The stall is load-sensitive, so the valid comparison is an interleaved A/B that cancels load drift: alternating the current and scoped variants over 12 pairs on one binary against a fixture of ~120 databases whose widest name is 214 chars, the current test failed 9 of 12 runs and the scoped one 0 of 12. Sequentially at higher contention: current 15/20 failed, scoped 20/20 passed. The precondition is fully deterministic and load-independent: the retained buffer saturates at expect's cap (6001 characters, 3 * match_max + 1) on every run of the current test. Signature matches the three CI failures on five properties: expect: timed out (not spawn id not open), final awaited pattern ":) ", client alive, output stops with the prompt never written, buffer at cap.
b Root cause explained? The test matches against SHOW DATABASES, an unbounded result set whose size is set by whatever other tests run concurrently. ClientBase::mainImpl's alias loop substitutes only the first backslash alias (break at src/Client/ClientBase.cpp:4657), so line 35 sends SHOW DATABASES ; \d; and line 38 SHOW DATABASES ;. The rendered table pads every row to the widest database name (bounded only by output_format_pretty_max_column_pad_width, default 250), so long names created elsewhere inflate the matched output ~8x (measured on the live fixture: the rendered table is 30032 bytes with them and 3936 bytes with only short names, 7.63x). ⚠️ The reason the client then stops writing is not identified and this change does not claim to fix it; what it removes is the measured precondition.
c Fix matches root cause? Yes: it removes the dependence on foreign global state at its source. It is not a timeout inflation, not no-parallel, not a match_max change. match_max was refuted by measurement rather than opinion: at the default match_max a lone trailing ":) " pattern still matches after 5000 lines of 220 non-matching bytes each (~1.05 MB), because expect discards the front of the buffer while the prompt arrives last.
d Test intent preserved / new tests added? Preserved, strengthened and slightly extended. Because the client echoes the formatted query in interactive mode, the predicate also appears in that echo, so the pre-existing expect "system" would have been satisfied by the echoed text alone; an expect "1 row in set" is added after it, emitted only below the rendered result and never by the unfiltered form (whose row count varies with the environment and is never one). All 19 expect stages fire in exact order, through expect eof, verified on independent runs of the real runner. Anti-vacuity mutant: reverting both like 'system' predicates while keeping that assertion makes the test fail awaiting 1 row in set against an otherwise complete and correct unfiltered answer (bottom border present, full row count reported), so the assertion pins both that the predicate reached the server and that it was applied. \l argument pass-through is newly covered (confirmed from system.query_log: the test now issues SHOW DATABASES like 'system' ;, exercising new_input.append(it, input.end()) at src/Client/ClientBase.cpp:4655, previously reached only via \c and \d). Unfiltered SHOW DATABASES keeps separate coverage in 00419_show_sql_queries.sh:8. The changed file is itself the test.
e Both directions demonstrated? Yes, two independent oracles. Failure/no-failure: interleaved 9/12 vs 0/12 (row a). Matched-output size: largest retained buffer 6001 characters (exactly expect's cap, 3 * match_max + 1) with 11 buffers at the cap before, 340 characters with 0 at the cap after. The unit is characters, not bytes: a saturated buffer measures exactly 6001 characters while being 6105 UTF-8 bytes, so only the character figure is commensurable with the cap (the 340-character buffer is 376 bytes). Plus a 2x2 negative control closing the causal chain: with the long names absent (115 databases, widest 18 chars) the current test passes 8/8 and its largest buffer falls to 3663, so those names are necessary for the failure and the change removes the dependence on them. 50 randomized and 50 non-randomized runs of the scoped test pass.
f Fix is general across code paths? The symmetric \d (SHOW TABLES) path is already bounded by both USE system and like 'one', so there is no unfixed mirror. 02105 is the only one of the 54 .expect tests that renders SHOW DATABASES or SHOW TABLES unscoped (grep-verified), which is also why the sibling client/expect tests passed in every job where this one failed. Suite slice of all 54 .expect tests plus 04655_table_name_length_underflow_drop, 03566_system_completions_table and 00419_show_sql_queries, compared as reason-bucketed sets: identical failure sets on both arms, zero regressions introduced.
g Fix generalizes across inputs (params/datatypes/wrappers)? Not a typed code path, so the meaningful input axis is how much foreign global state exists. Measured directly: with the scoped test, the largest retained buffer is 340-341 characters both with the 7 long-name databases present (122 rendered rows, widest name 214 chars) and with them absent (115 rows, widest 18 chars). The matched output no longer varies with what other tests create.
h Backward compatible? (maintainer-approved exception only) N/A, test-only. No setting, no serialization format, no SettingsChangesHistory.cpp entry, no changelog-visible behaviour.
i Invariants and contracts preserved? The script's assertion sequence and its expect_after / 60s timeout contract are unchanged; only the two send payloads narrow. The .reference file stays 0 bytes, correctly, because log_user 0 means the script writes nothing to stdout. Executing the runner's own tag parser on both arms returns the identical tag set (test-type-expect), so the added comment changes no CI routing, and the file mode stays 100755.

Session id: cron:clickhouse-impl-slot-42:20260806-173400

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @azat, could you review this? The test matched an unscoped SHOW DATABASES, whose rendered width is set by whatever databases other concurrent tests create, so it scopes both \l sends with like 'system' and adds a 1 row in set assertion so the result side is still asserted rather than the client's echo of the query.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 7, 2026
@PedroTadim PedroTadim self-assigned this Aug 7, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 7, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2f85949]

Summary: ✅


AI Review

Summary

This PR scopes the flaky 02105_backslash_letter_commands.expect \l checks to SHOW DATABASES LIKE 'system' and adds expect "1 row in set" so the test still proves a server-side result instead of only matching the interactive query echo. I did not find a remaining correctness, coverage, or metadata issue in the current patch.

Final Verdict
  • Status: ✅ Approve

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

clickhouse-gh Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2f8594940 with master a96691076 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 16bd8e494; 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 689.52 MiB 687.14 MiB -2.38 MiB (-0.34%)

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, 3 s compile time in total, 6 of them have a recent master baseline.

Job report

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 7, 2026
Merged via the queue into ClickHouse:master with commit 13af815 Aug 7, 2026
180 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 7, 2026
@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-ci 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.

3 participants