Skip to content

Bound the {a,b,c} glob expansion in paths - #118467

Merged
alexey-milovidov merged 23 commits into
masterfrom
bound-glob-expansion
Sep 23, 2026
Merged

alexey-milovidov merged 23 commits into
masterfrom
bound-glob-expansion

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

The {a,b,c} selector globs of a path are not compiled into a regexp; they are enumerated into separate paths by expandSelectionGlob. The enumeration is a Cartesian product of the groups and had no bound at all, in either time or memory:

-- 2^100 paths: ate all the memory of the server and never returned
SELECT * FROM file(repeat('{a,b}', 100));

It is reached from file, from s3/azure/hdfs (StorageObjectStorage::getPathSample) and from StorageObjectStorageSource::createFileIterator. Nothing on the way bounds it: the expansion runs while the table function is being resolved, so max_execution_time cancellation does not reach it (the server log below shows CancellationChecker: Cancelling the task because of the timeout having no effect), and it is not stopped by max_memory_usage either. The server grows until it is OOM-killed.

The AST fuzzer found it as SELECT * FROM file(file('data.jsonl'), 'data.jsonl'): the file function reads the file into a string, the file table function takes that string as a path, and every {...} of a JSONEachRow file is a glob group. On the failure below the file had 130818 of them, and the server went from 1 GiB to 45 GiB of RSS in 25 seconds:

2026.09.06 17:48:14.018686 [ 144 ] {eada5c59} <Debug> executeQuery: (internal) SELECT * FROM file(file('data.jsonl'), 'data.jsonl') ORDER BY x ASC NULLS FIRST (stage: Complete)
2026.09.06 17:48:24.114943 [ 162 ] {} <Debug> CancellationChecker: Cancelling the task because of the timeout: 10000000 us, query_id: eada5c59
2026.09.06 17:48:37.329000 [ 363 ] {} <Error> ... (total) memory limit exceeded: would use 31.48 GiB, current RSS: 40.39 GiB, maximum: 40.33 GiB
[ 1508.482026] Memory cgroup out of memory: Killed process 2769 (clickhouse-serv) total-vm:112945024kB, anon-rss:39598452kB

The expansion now refuses a pattern that asks for more than 100000 paths, for more than 64 MiB of paths, or that has more than 1000 groups. The limits are constants rather than settings because Common/parseGlobs.cpp has no access to a Context, and because they are a guard against a pathological pattern rather than a knob: the smallest of them is two orders of magnitude above any plausible glob.

The byte limit is charged the length each path actually has, and not the length of the pattern it comes from. A group with one long alternative among many short ones makes the two differ without bound, so reserving the pattern for every path would hold number of paths * pattern size while the charged amount stays small: a group of 100000 alternatives whose first one is 1 MiB is charged about 1 MiB and would hold about 120 GiB. The refusal also happens before the path is allocated rather than after it.

While there, the enumeration itself is rewritten to split the pattern into its groups once instead of once per produced path. Which text is a group does not depend on the alternatives picked for the groups before it, so the recursion was re-scanning and re-copying the whole pattern at every level of every branch — quadratic in the pattern size, and the reason repeat('{a,b}', 100) still needed 22 seconds of CPU to reach the 100000-path limit. It is now rejected without generating anything.

Looking for the next group ran both regexps over the whole remaining pattern once per group, so the scan alone cost their product, and the pattern is not bounded either — file(file(...)) makes it as long as a file. Neither answer has to be recomputed that often. A {N..M} range glob cannot appear in a tail of the pattern without appearing in the pattern, so it is looked for once; and the leftmost {a,b,c} match is still the leftmost match of every tail that starts at or before it, so it is searched for again only once the enumeration has consumed past it, and successive searches then cover disjoint parts of the pattern. On repeat('{a*}', 999) followed by a 100 MB literal that is 8131 ms -> 129 ms, and 1000 regexp calls -> 2.

{N..M} is the other half of the same problem. A range glob is not enumerated into separate paths — makeRegexpPatternFromGlobs turns it into a regexp alternation of every number of the range — and that had no bound at all, reached from the same table functions and just as uncancellable and unaccounted:

SELECT * FROM file('{1..60000000}.csv');
-- 4.2 GiB of RSS and 22.7 s, then CANNOT_ALLOCATE_MEMORY

A range covering more than 100000 values is refused, and so is a pattern whose ranges emit more than 8 MiB of regexp in total: capping one range does not cap how many of them a path may hold, and every range of repeat('{1..100000}', 128) is within the per-range cap while those 1408 bytes of path emit 75 MB of alternations. RE2's own default memory budget is 8 MiB, so a larger regexp is not one it could compile. The enumeration is also counted rather than compared against the end of the range, because for the single value 2^64-1 the difference is zero - the per-range cap passes - and the increment then wrapped and the loop ran from zero.

One caller must not be bounded this way. getPathSample needs a single path to infer hive partition columns from, and got it by expanding the whole Cartesian product and taking the first element, while the reader enumerates a pattern only when it has exactly one brace group and matches anything with more as a regexp. Bounding the expansion therefore failed s3('.../{a,b}{c,d}.../x.parquet') during analysis, in both StorageObjectStorage::getPathSample and the cluster variant, for a pattern the reader would have read. expandSelectionGlobFirst picks the first alternative of every group and keeps nothing else, so it cannot be refused: one pass over the pattern, and a result no longer than it. createFileIterator and StorageFile keep the full expansion, since they need every path.

The rewrite is behavior-preserving: a differential check against the previous implementation over 700000 random patterns (comma-rich short patterns, and long patterns with deeply nested groups) reports identical output, and identical throw/no-throw, on every one of them. The regexp caching is checked the same way: over 700000 random patterns it gives the same answer as the uncached predicate on every tail the enumeration visits.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=7a5d669906cc37af41a4260c942417d72d880bfe&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29

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 unbounded memory and CPU usage when a path passed to file, s3, azureBlobStorage or hdfs contains many {a,b,c} glob groups or long {N..M} ranges. A path with several {a,b,c} groups expands to the Cartesian product of the groups, and a {N..M} range expands to a regexp listing every number of the range, so a pattern of a few hundred bytes could exhaust the memory of the server; the expansion was neither cancellable nor accounted by max_memory_usage. Such a path is now rejected with an error. The limits are 100000 expanded paths, 64 MiB of expanded paths, 1000 {a,b,c} groups, 100000 values in a single {N..M} range, and 8 MiB of regexp for all the ranges of a path together.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

Version info

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

The `{a,b,c}` selector globs of a path are not compiled into a regexp; they
are enumerated into separate paths by `expandSelectionGlob`. The enumeration
is a Cartesian product of the groups and had no bound in either time or
memory, so `SELECT * FROM file(repeat('{a,b}', 100))` asks for 2^100 paths
and eats all the memory of the server without ever returning. It cannot be
interrupted: the expansion runs while the table function is being resolved,
where `max_execution_time` cancellation does not reach it, and it is not
stopped by `max_memory_usage` either.

The AST fuzzer found it as `SELECT * FROM file(file('data.jsonl'),
'data.jsonl')`: the `file` function reads the file into a string, the `file`
table function takes that string as a path, and every `{...}` of a
`JSONEachRow` file is a glob group. The server went from 1 GiB to 45 GiB of
RSS in 25 seconds and was OOM-killed.

Refuse a pattern that asks for more than 100000 paths, for more than 64 MiB
of paths, or that has more than 1000 groups. The limits are constants, not
settings, because `Common/parseGlobs.cpp` has no access to a `Context`, and
because they guard against a pathological pattern rather than being a knob:
the smallest of them is two orders of magnitude above any plausible glob.

Also split the pattern into its groups once instead of once per produced
path. Which text is a group does not depend on the alternatives picked for
the groups before it, so the recursion was re-scanning and re-copying the
whole pattern at every level of every branch - quadratic in the pattern
size, and the reason `repeat('{a,b}', 100)` still needed 22 seconds of CPU
to reach the path limit. It is now rejected without generating anything.
The rewrite is behavior-preserving: a differential check against the
previous implementation over 700000 random patterns reports identical
output, and identical throw/no-throw, on every one of them.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=7a5d669906cc37af41a4260c942417d72d880bfe&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6f5fe0e]

Summary: ✅


AI Review

Summary

This PR bounds selector-glob expansion and range-glob regexp generation, and it now keeps hive-partition sample-path inference aligned with the actual object-storage reader across the pure-brace, regexp, and refusal paths. I re-checked the current diff and every prior inline thread against the current code; the earlier analysis/execution mismatches appear addressed, and the added gtests plus stateless coverage are proportionate to the touched invariants.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 6f5fe0e.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 193/195 (98.97%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Sep 6, 2026
Comment thread src/Common/parseGlobs.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 6f5fe0e8c019d7c2f6373a06c91c1d9bb61450cb was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

alexey-milovidov and others added 3 commits September 11, 2026 10:41
`MAX_EXPANDED_PATHS` was checked only after a group had been parsed, so one
selector with an enormous number of alternatives - which is what a whole file
passed as a path by `file(file(...))` looks like - still cost one offset and
one `string_view` per alternative before the limit was reached. The memory
`expandSelectionGlob` took therefore still grew with the size of its input,
even though nothing was ever expanded.

Check the running Cartesian product against the number of commas seen so far,
at the comma: after `k` commas the group has at least `k + 1` alternatives, so
the scan stops at the comma that makes the group exceed the limit and the
parsing state stays bounded by the limit rather than by the input.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Passing the pattern through a file read it back as a 2 MiB CSV line of a
million columns, and the 21 seconds the test took were all spent in schema
inference for that file, not in the glob expansion the case is about. Fold the
pattern in the query instead: a two-megabyte argument does not fit on a command
line anyway (`MAX_ARG_STRLEN` is 128 KiB), while `file('{' || repeat('a,',
1000000) || 'a}')` is a constant expression and reaches `expandSelectionGlob`
with the same million-alternative group. The test now takes a second.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Common/parseGlobs.cpp Resolved
`expandSelectionGlob` charged `MAX_EXPANDED_BYTES` the length of each
produced path but allocated the length of the whole pattern for it, so a
group with one long alternative among many short ones defeated the
bound. A group of 100000 alternatives whose first one is 1 MiB is
charged ~1 MiB and holds ~120 GiB:

    SELECT * FROM file('{' || repeat('A', 1000000) || ','
        || repeat('a,', 99998) || 'a}');

Charge and reserve the length the path actually has, and throw before
allocating rather than after. The pattern above now costs what any other
100000-path expansion costs.

Looking for the next glob ran both regexps over the whole remaining
pattern once per glob, so the scan alone cost their product, and the
pattern is not bounded. Neither answer has to be recomputed that often.
A `{N..M}` range glob cannot appear in a tail without appearing in the
pattern, so it is looked for once. The leftmost `{a,b,c}` match is still
the leftmost match of every tail that starts at or before it, so it is
searched for again only once the enumeration has consumed past it, and
successive searches then cover disjoint parts of the pattern. On
`repeat('{a*}', 999)` followed by a 100 MB literal this is 8131 ms ->
129 ms, and 1000 regexp calls -> 2. A differential check over 700000
random patterns reports the same answer as the previous predicate on
every tail the enumeration visits.

While there, `makeRegexpPatternFromGlobs` turns a `{N..M}` range glob
into a regexp alternation of every number of the range, with no bound at
all - the same unbounded, uncancellable, unaccounted growth, reached
from the same table functions:

    SELECT * FROM file('{1..60000000}.csv');
    -- 4.2 GiB RSS and 22.7 s, then CANNOT_ALLOCATE_MEMORY

Refuse a range covering more than 100000 values, which is already a
regexp of hundreds of kilobytes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Common/parseGlobs.cpp Resolved
`getPathSample` needs one path to infer hive partition columns from, and
got it by expanding the whole `{a,b,c}` Cartesian product and taking the
first element. The reader does not work that way: `createFileIterator`
enumerates a pattern only when it has exactly one brace group, and
matches anything with more as a regexp. Bounding the expansion therefore
made `s3('.../{a,b}{c,d}.../x.parquet')` throw during analysis, in both
`StorageObjectStorage::getPathSample` and the cluster variant, for a
pattern the reader would have read. Neither call site catches, so the
query fails rather than losing partitioning.

Add `expandSelectionGlobFirst`, which picks the first alternative of
every group and keeps nothing else. It cannot be refused: one pass over
the pattern and a result no longer than it, whatever the groups multiply
out to. The brace scan is shared with the full expansion, so both refuse
a malformed glob identically.

`createFileIterator` and `StorageFile` keep the full expansion: they need
every path, and the former is gated on a single brace group, so its limit
matches what it has to enumerate.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@groeneai groeneai mentioned this pull request Sep 17, 2026
1 task done
Comment thread src/Common/parseGlobs.cpp Resolved
`MAX_RANGE_GLOB_VALUES` caps one range, and nothing capped how many
ranges a path may hold, so the invariant it was meant to establish did
not hold. Every range of `repeat('{1..100000}', 128)` is within the
per-range cap, yet 1408 bytes of path emitted 75 MB of alternations
before RE2 saw any of it - the same uncancellable, unaccounted growth,
reached the same way.

Cap the total as well, at `MAX_REGEXP_BYTES`. RE2's own default memory
budget is 8 MiB, so a larger regexp is not one it could compile, and the
overshoot is one range's worth because a single range is still capped.

The per-range cap could also be stepped around: for the single value
2^64-1 the difference is zero, so it passed the cap, and `range_begin +
1` then wrapped and the loop enumerated from zero. Count the iterations
instead of comparing against `range_end`, so the increment cannot wrap.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Address review: `getPathSample` took every pure-brace path through
`expandSelectionGlobFirst`, but `StorageObjectStorageSource::createFileIterator`
still materializes a pattern with exactly one brace group through
`expandSelectionGlob`. With `use_hive_partitioning = 1` analysis could then infer
hive partition columns - and persist them in a table definition - from a path
that the reader always rejects on `MAX_EXPANDED_PATHS` / `MAX_EXPANDED_BYTES`.

Mirror the reader's split instead: keep the limit-enforcing expansion for
`hasExactlyOneBracketsExpansion`, and reserve the first-alternative fast path for
the shapes the reader matches as a regexp (multiple groups, or web object storage,
which always goes through `GlobIterator`).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

Both picked up, with the measurements on each: #120202 and #121048.

Neither is waiting on a review, and the order matters:

  • CI: "Build profile diff" is green when the CI logs cluster does not answer #121048 first, because it clears the Build profile diff red here and on Retry poll on EINTR in the vendored nats-io client #120202, and its own Build profile diff job is already green. What holds it is the AI Review's request for changes, which is correct: status >= 500 is not "the cluster never answered", since codes 164, 158, 241 and 395 all arrive as 500 with the exception code in the header (measured, 9 cases). I posted the classification patch keyed on X-ClickHouse-Exception-Code instead, together with the is_ready one from yesterday. It also changes nothing for the live outage, which never gets a response at all (ReadTimeout, 4 of 4 logs sampled from the last hour). Pushing it is yours; or say so and I will send both as a follow-up once this one lands.
  • Retry poll on EINTR in the vendored nats-io client #120202 is verified: I built the vendored client at master's pointer and at b88704df and reproduced (unix/sock.c:56): poll error: 4 under a 1 kHz signal storm, 3/3, with the deadline intact and the failure gone at the bumped pointer. Its blocker is not a review either: new_tests_check.py fails with "No new tests have been added", because the Bug Fix category put pr-bugfix on a one-line gitlink bump, and Mergeable Check surfaces that as Failed: Workflow Post Hook. The comment has the two ways out and their mechanics; both need a decision from you. One thing worth knowing before either merges: Bump nats-io from v3.9.2 to v3.14.0 #119507 moves the submodule to the divergent v3.13.0 branch, which has no EINTR retry anywhere in src/.

New here since your comment: Performance Comparison (arm_release, master_head, 4/6) went red. That shard compares master with itself and failed on 14 distinct pull requests in the last 7 days, so it is not yours; 15 jobs are still running.

I cannot request reviewers on pull requests I do not own, so that part stays with you.

alexey-milovidov added a commit that referenced this pull request Sep 21, 2026
…e status

Address review: `status >= 500` is not "the cluster never answered". The
server reports several of its own verdicts on a query as a 500 - 164 for a
setting change on a readonly profile, 158 for `max_rows_to_read`, 241 for the
memory limit, 395 for a `throwIf` after the result started - so a real defect
in one of the `Build profile diff` reads would have reported the check green.

`X-ClickHouse-Exception-Code` is the exact discriminator: it is present on
every answer the server produced and absent when the answer did not come from
it, whatever the status. `LogCluster._classify` keys on it - absent means a
gateway, a proxy or a closed connection (`LogClusterUnavailable`); a code in
`TRANSIENT_EXCEPTION_CODES` (159, 202, 209, 241) is the shared cluster talking
about its own load (`LogClusterUnavailable`); anything else is its verdict on
this very query (`LogClusterQueryError`, fail closed, and the same verdict on
every retry so it is not retried). 241 in the transient set also closes azat's
ask on #118708 in its general form, by the exception code rather than by the
coincidence that the status happens to be 500.

`raise` on that verdict has to escape the loop, so `except LogClusterError:
raise` precedes the generic transport handler; without it the handler catches
the verdict and retries it eight times.

An endpoint that never became ready is now its own `LogClusterNotReady`, a
sibling of `LogClusterError` that `main` does not catch: a readiness probe
that never answers is indistinguishable from a rotated password or a deleted
SSM parameter, and completing green on that would blank the check fleet-wide
for as long as the condition lasts.

Neither change affects the outage this pull request is about: those failures
never get a response at all (`ReadTimeout`), so they end at "every POST
attempt failed with an exception".

Related: #118708
Related: #118467

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (362 behind, clean) and pushed 92d86a46dfb7. No change to the PR's own code was needed: the three affected translation units (Common/parseGlobs.cpp, Storages/ObjectStorage/StorageObjectStorage.cpp, StorageObjectStorageCluster.cpp) and the Common/tests/gtest_makeRegexpPatternFromGlobs.cpp gtest all compile clean against the merged tree, and the AI Review verdict is still ✅ Approve with 0 unresolved threads.

@groeneai, thank you for the two write-ups — both decisions are made and both are acted on, so neither is waiting on me any more.

#121048 (Build profile diff) — your classification patch is adopted and pushed as 0c06b1809c3d. X-ClickHouse-Exception-Code is now the discriminator instead of status >= 500, with {159, 202, 209, 241} transient, so a real defect in one of those SELECTs can no longer report the check green, and 241 in that set closes azat's ask on #118708 by the code rather than by the 500 coincidence. Your LogClusterNotReady is in too. One correction to the snippet: raise error sat inside the try of the POST, so the generic except Exception: caught the verdict and retried it eight times — an except LogClusterError: raise ahead of the transport handler fixes that. Details and the 7/7 throwaway verification are in the comment there.

#120202 (NATS poll error: 4) — taking your option 1, with Build/Testing/Packaging Improvement rather than CI Fix or Improvement: it is a contrib submodule bump, and unlike pr-ci that category still carries a changelog entry, which this deserves since the failure is reachable outside CI. I edited the category and swapped pr-bugfix for pr-build by hand, so new_tests_check.py now exits at "Not a bug fix PR - skip" and Mergeable Check is unblocked. Agreed on not adding an in-tree test — please send your setitimer harness to the fork's own suite. I also left the ordering note on #119507 so the three fork-only fixes are carried forward if that one lands second.

The third red, Performance Comparison (arm_release, master_head, 4/6), is confirmed not ours, as you said. The report classifies bitmap_cardinality #1 as unstable (+31.2% against a +31.2% threshold), not as a change — 0 faster, 0 slower, 1 unstable across all six shards — and that shard ended failure on 21 distinct pull requests over 31597 runs in the last 7 days. It compares master with itself, so it cannot see anything under src/Common/parseGlobs.cpp.

Requesting reviewers on #121048 and #120202 is on me; I will do that.

@groeneai

Copy link
Copy Markdown
Collaborator

Harness sent to the fork's own suite: ClickHouse/nats.c#10, test only on top of b88704df. The reverted-library and mutated-retry controls are in the comment on #120202.

On #121048 I posted one dissent from the patch you adopted, in favour of the AI Review's new finding: 159 and 209 should come out of TRANSIENT_EXCEPTION_CODES. _classify is reached only from the reporting SELECTs, since the readiness probe never consults it, so those two codes cannot help the probe and can only turn a regressed reporting query green. Reasoning and the one-line patch are there.

Neither PR needs anything from me now. #120202 needs a re-run of Finish Workflow, which re-reads the labels live so the pr-build swap takes effect without a commit, and a re-run of Build profile diff, which is green in 72 of the last 76 rows.

@clickhouse-gh

clickhouse-gh Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 36 queries analysed

This PR bounds path-glob expansion ({a,b,c} and {N..M}) in the file/s3 table functions and adds a cheap single-sample-path helper for hive-partition inference. That code only runs while resolving object-storage/file table functions, not while executing ClickBench SELECTs over local MergeTree tables. The three flagged ClickBench queries (Q28, Q33, Q34) all show modest improvements (roughly -5% to -7%), but none exercise the changed path, so these deltas are run-to-run variance rather than a PR effect. Q33 and Q34 were already correctly suppressed within master's current variance band; Q28 is downgraded to not-sure for the same reason (Q34 is additionally an intrinsically noisy query). No real performance impact is expected from this change.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 28 not_sure 1105 1047 -5.2% <0.0001 This PR only touches path-glob expansion for file/s3 table functions; a ClickBench SELECT on a local MergeTree table never runs that code, so the -5.2% delta is run-to-run variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 4296b69b-21b6-4759-a278-7ca7e486073e
  • MIRAI run: da0ce9c2-6d68-4d38-bc79-19c729b9e7c4
  • PR check IDs:
    • clickbench_1146607_1789989486
    • clickbench_1146613_1789989486
    • clickbench_1146619_1789989486
    • tpch_adapted_1_official_1146629_1789989486
    • tpch_adapted_1_official_1146642_1789989486
    • tpch_adapted_1_official_1146679_1789989486

…le path instead of swallowing it

`StorageObjectStorage` caught every exception from `getPathSample` as a listing failure and only
dropped hive partition inference. Since `expandSelectionGlob` refuses an unbounded `{a,b,c}` group
with `BAD_ARGUMENTS`, that left analysis and execution disagreeing: with `use_hive_partitioning = 1`,
`SELECT date FROM s3('.../{a,a,...}.tsv')` reported `UNKNOWN_IDENTIFIER`, while reading the same
path and `s3Cluster` rejected it with `BAD_ARGUMENTS`.

Rethrow `BAD_ARGUMENTS` from both fallback catches (the constructor and the deferred resolution,
where `throw_on_hive_partitioning_resolution_failure = 0` tolerates only endpoint failures): a
refused path fails the same way on every read, so it is not something the next query might not hit.
Test `05230` now expects `BAD_ARGUMENTS` from the plain table function as well as from `s3Cluster`,
so the `parallel_replicas_for_cluster_engines` pin is gone, and probes the deferred path with the
setting disabled.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed c54fa82: adopted the AI Review Major - StorageObjectStorage no longer swallows the BAD_ARGUMENTS that expandSelectionGlob raises for an unbounded single-brace pattern as if the listing had failed, so the plain table function, a table definition and s3Cluster now all reject such a path consistently (details in the thread reply). Test 05230 extended accordingly and passing locally.

The only red on the previous head was CH Inc sync (https://github.com/ClickHouse/clickhouse-private/pull/73005, still on the old head 1dcaea4ec03c): Stateless tests (amd_asan_ubsan, distributed cache, meta in keeper, s3 storage, parallel, 1/2) ended with Hung check failed: server liveness check failed after 6196/7352 tests with 0 test failures (05104_glob_expansion_limits passed there; glob parsing takes no locks), and Integration tests E2E failed on google.auth.exceptions.RefreshError: Reauthentication is needed. Both are environmental; the new push re-creates the sync PR.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master into the branch (531cbd0, clean; the four touched translation units compile against the merged tree).

The only red on c54fa82, Stress test (amd_msan) Segmentation fault (STID: 3132-38cf), is unrelated: a null query_info.query dereferenced in ReadFromMerge::createChildrenPlans when it checks sampleSize on a Merge table. It is tracked in #119899 and fixed by #119387, which is still open, so this merge does not clear it. @groeneai, please push #119387 forward.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118467&sha=c54fa82a71a927beaae189d9171858c5380e5b35&name_0=PR&name_1=Stress%20test%20%28amd_msan%29

@groeneai

Copy link
Copy Markdown
Collaborator

#119387 is unblocked. It had drifted into a merge conflict in StorageProxy.h, where master's new getUnderlyingStorages delegation landed next to the one this PR adds; both are kept. Master is merged, the merged tree builds, and the PR is MERGEABLE again on 1311df6 with CI running. I requested review from KochetovNicolai, who owns the routing condition in resolveStorages.cpp that the fix replaces, and from you.

One decision is still open from your 2026-09-12 comment there. After you called the predicate ugly I replaced it with IStorage::readRequiresAnalyzedQuery() (default isRemote(), true for Merge, delegated by the four read-forwarding wrappers) in 73ada5c, so IStorage.h no longer names an engine and resolveStorages.cpp reads one term. The alternative I offered is to drop the predicate entirely and always re-analyze the query on this path, which also removes the isRemote() term. The PR stands on the first shape; if you prefer the second, I will measure the routing change it causes for plain MergeTree reads and push it.

alexey-milovidov and others added 2 commits September 22, 2026 21:36
… the hive sample path

A glob that is not a pure `{a,b,c}` selection is listed through `GlobIterator`, which refuses
a regexp RE2 cannot compile with `CANNOT_COMPILE_REGEXP` before anything is listed. Both
fallback catches of `StorageObjectStorage` (the constructor and
`resolveHivePartitioningSamplePathIfDeferred`) downgraded that to a listing failure, so the
plain `s3` table function reported `UNKNOWN_IDENTIFIER` for a hive column while `s3Cluster` and
the reader reported the real refusal. Both catches now rethrow it, like `BAD_ARGUMENTS`.

New test `05237_s3_glob_uncompilable_regexp_sample_path`; the plain `s3` probe gives code 47
with the previous binary and 427 with this one.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The reader lists everything under the prefix before the first brace group, which was the bucket
root. With the s3 storage that root holds the data of the server's own disks, so the listing was
slow (396 s locally) and in the private flaky check MinIO answered `500 Internal Server Error`,
failing the test on the `AWSClient` error in stderr (18 of 200 runs).

ClickHouse/clickhouse-private#73005

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 4868d64:

  • Adopted the AI Review thread on StorageObjectStorage.cpp:300: CANNOT_COMPILE_REGEXP from the listing path is now rethrown like BAD_ARGUMENTS. New test 05237, confirmed with a control run (details in the thread).
  • Fixed the CH Inc sync red (https://github.com/ClickHouse/clickhouse-private/pull/73005). It was ours: in Stateless tests (amd_asan_ubsan, flaky check, s3 storage, meta in keeper), 05182_s3_brace_glob_sample_path_not_bounded failed 18 of 200 runs because of AWSClient: Response status: 500 in stderr. Its glob listed the whole bucket root, which with the s3 storage holds the server's own disk data (396 s locally). The test now uses its own test/05182/ prefix and takes 0.41 s.

@groeneai thanks, the #119387 design question is for that PR, nothing is needed here.

alexey-milovidov and others added 3 commits September 23, 2026 02:37
…matches it

Address review: for a pattern with several `{a,b,c}` groups the reader matches the path as the
regexp `makeRegexpPatternFromGlobs` builds, and a selector glob does not always agree with it.
An empty alternative (`{,a}`), an empty group or a one-character group is literal text for the
regexp, and RE2 refuses an alternation too large to compile. `getPathSample` in both
`StorageObjectStorage` and `StorageObjectStorageCluster` took the first alternative of every group
anyway, so hive partition columns were resolved - and persisted for a table definition - from a
path the reader never reads.

The new `tryExpandSelectionGlobFirstMatchedByRegexp` returns the first alternative only when that
regexp compiles and matches it; otherwise the path is listed the same way the reader lists it, so
an uncompilable regexp is reported as `CANNOT_COMPILE_REGEXP` and a literal-brace path resolves no
hive columns when nothing matches. Test `05241` is control-proved: the binary without this change
resolves `date` for `date={2020-01-01,2020-01-02}/{,x}{a,b}.tsv`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The flaky check under TSan reported `Test runs too long (> 180s)`: most of the time is spent in
`makeRegexpPatternFromGlobs` and in RE2 on a 3.4 MB pattern, five times. RE2 gives up from about
50000 alternatives of 16 characters, so 100000 are enough; the `s3Cluster` probe (a plain listing,
no code of this PR) and the `SELECT` repeating the `DESC` of the same deferred table are dropped.
Adds a case for two `{a,b,c}` groups, where the sample path must not be taken from the first
alternatives when the reader's regexp does not compile (control-proved: `DESC` succeeded before).

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118467&sha=4868d64915a62c6adc207d4113ddb4cb7e94e7a7&name_0=PR
Related: #118467

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 23, 2026
Merged via the queue into master with commit 455029b Sep 23, 2026
177 checks passed
@alexey-milovidov
alexey-milovidov deleted the bound-glob-expansion branch September 23, 2026 21:31
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). 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.

4 participants