Repository navigation
Fix _path / _file filtering for object storage, file and url - #112968
Conversation
`SELECT ... FROM s3(...) WHERE _path GLOBAL IN (SELECT ...)` over a path
without globs threw
Logical error: 'Not-ready Set is passed as the second argument for function 'globalIn''
`ReadFromObjectStorageStep::applyFilters` intentionally leaves the sets of
`globalIn` / `globalNotIn` unbuilt, so that `ReadFromRemote` can attach an
external table to them first. Plan optimization then moves the subquery plan of
such a set into a `CreatingSetsStep` (`DelayedCreatingSetsStep::makePlansForSets`),
which means the set is only created once the pipeline runs.
`StorageObjectStorageSource::createFileIterator` prunes an explicit key list
while the pipeline is being built, and its `buildSetsForDAG` call is a no-op for
a set whose subquery plan is already gone, so the pruning expression was
executed with a set that was not ready yet. `GlobIterator` is unaffected: it
applies the same filter while listing objects, when the set is already built.
Pruning the keys is an optimization - the same predicate is applied by the
`Filter` step above the source - so skip it when a set is not ready.
`buildSetsForDAG` now reports whether every set in the DAG ended up ready.
Reproduced by an AST fuzzer query in the stress test on master:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1c3181d592a4aaeec15077107e15b7edab5bca8d&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29
|
Workflow [PR], commit [e7f1766] Summary: ✅
AI ReviewSummaryThis PR fixes several Findings
Final VerdictRequest changes: add a focused top-level LLVM Coverage ReportMeasured on commit e7f1766.
Changed lines: Changed C/C++ lines covered: 286/319 (89.66%) · Uncovered code |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code |
`QUALIFY` is not supported in the old analyzer, so the test failed with `QUALIFY clause is not supported in the old analyzer` in the old-analyzer stateless run. The function form of `globalNotIn` in `WHERE` exercises the same pruning path and works with both analyzers.
|
🕵 The only CI red, Stress test (arm_msan), is the known master issue #113165 ( |
Skipping the pruning entirely was not semantics-preserving: `KeysIterator::next` still probed the metadata of every explicit key before the `Filter` step above the source ever ran, so with `s3_ignore_file_doesnt_exist = 0` a nonexistent key that the predicate excludes threw FILE_DOESNT_EXIST instead of returning no rows. Defer the filter to `KeysIterator::next` instead: it runs when the pipeline runs, after `CreatingSetsStep` has built the set, and it is applied before the metadata probe, mirroring how `GlobIterator` filters while listing. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The AST fuzzer (amd_debug) red is unrelated to this PR: |
|
🕵 The fix for the unrelated AST fuzzer (amd_debug) failure is up: #113412 (single-argument |
When `s3` runs in cluster mode (for example when `parallel_replicas_for_cluster_engines` converts it to `s3Cluster`), `StorageObjectStorageCluster::getPathSample` builds a `KeysIterator` during query analysis to infer hive partitioning. For an explicitly specified key, `throw_on_zero_files_match = false` is not enough: `KeysIterator::next` probes the object metadata, and the probe throws `S3_ERROR` (HTTP 404) for a key that does not exist, so the query failed during analysis even when the `_path` / `_file` predicate excludes that key and the answer is zero rows - which is what the non-cluster path returns. Sample the path with `ignore_non_existent_file = true`: a missing key leaves the sample empty, as the existing comment in `getPathSample` already intends. A key that is really needed for reading is probed again by the reader, which does report the error. This is what made the new test `04669_object_storage_path_filter_global_in` fail in the `Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel)` report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112968&sha=5f0602ae3ca8c39bc8049c12fa40f4732221eed2&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 PR: #112968
|
🕵 The only CI red, AST fuzzer (amd_debug), is unrelated to this PR: |
The `_path` extraction fast path swaps `GlobIterator` for a `KeysIterator` over the validated candidates. A listing never yields a key that does not exist, so a candidate that fits the glob but names no object must be skipped, not probed with an exception: `azureBlobStorage(..., '/*.csv') WHERE _path = '<container>/missing.csv'` threw on the metadata lookup instead of returning zero rows, and a mixed `IN` threw after reading the existing blob. The iterator now ignores missing keys and fetches the metadata even when the caller would defer it, since the probe is what identifies a missing candidate.
| /// `WithMergeableState` (`IStorageCluster::getQueryProcessingStage`), so there is no `Filter` step | ||
| /// above `ReadFromCluster` to collect the `WHERE` from - without this the predicate is null and | ||
| /// no `_path` / `_file` pruning happens at all. | ||
| if (dynamic_cast<const IStorageCluster *>(raw)) |
There was a problem hiding this comment.
This IStorageCluster widening is what makes StorageFileCluster claim the same initiator-side _path / _file pruning fix as StorageURLCluster, but there is still no focused top-level fileCluster regression for it. 05048 only proves the urlCluster path, and the existing 05030 parallel_distributed_insert_select test exercises a different task-dispatch stack. A small fileCluster('missing.tsv') case with _path / _file GLOBAL IN would close the gap and would fail immediately if StorageFileCluster::getTaskIteratorExtension ever stopped receiving the collected predicate again.
|
TL;DR: one of the defects this PR fixes is a silent wrong result at default settings on the latest release, and the fix has no backport. On 26.8.2.7 (and older releases), any exact There is no backport of this PR to a release branch (the last 100 commits of |
…distributed Pick up ClickHouse#112968, which fixes the `Not-ready Set` logical error the AST fuzzer hit in the `Stress test (amd_tsan)` run of this PR. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Closes: #117806
SELECT ... FROM s3(...) WHERE _path GLOBAL IN (SELECT ...)over a path without globs threwReadFromObjectStorageStep::applyFiltersintentionally leaves the sets ofglobalIn/globalNotInunbuilt, so thatReadFromRemotecan attach an external table to them first. Plan optimization then moves the subquery plan of such a set into aCreatingSetsStep(DelayedCreatingSetsStep::makePlansForSets), which means the set is only created once the pipeline runs.StorageObjectStorageSource::createFileIteratorprunes an explicit key list while the pipeline is being built, and itsbuildSetsForDAGcall is a no-op for a set whose subquery plan is already gone, so the pruning expression was executed with a set that was not ready yet.GlobIteratoris unaffected: it applies the same filter while listing objects, when the set is already built.Pruning the keys is mostly an optimization - the same predicate is applied by the
Filterstep above the source - but it must not simply be skipped, because a nonexistent explicit key has its metadata probed before thatFilterstep ever runs. SoKeysIteratornow applies such a filter lazily, innext, when the pipeline runs and the set is ready.buildSetsForDAGreports whether every set in the DAG ended up ready, so a caller that executes the DAG right away can tell.The same deferral was missing for
fileandurl, and fixing it surfaced several neighbouring defects in_path/_filefiltering:urlbypassed the filtering iterator entirely, so a URL excluded by the predicate was still opened. All local URL reads now go throughDisclosedGlobIterator, and a URL without globs is no longer split on commas (a comma is literal there).file('archive.zip :: entry.csv')and the object-storage equivalent did not filter on the entry's virtual path before opening the outer archive, so a missing archive excluded by the predicate threw instead of returning no rows. The_pathextraction fast path (s3_path_filter_limit) is now skipped for archives, whose_pathvalues are entry paths (<archive>::<member>) rather than object keys._path/_filefilter block; one duplicate stayed empty, so applying the one-row filter threwSIZES_OF_COLUMNS_DOESNT_MATCH.getPathSampleprobed object metadata for an explicitly named key, so hive partition inference failed for a key that does not exist or is filtered out before reading. The path string itself carries the partition columns, so it must not depend on the object being present.collectFiltersForAnalysisnamed onlyStorageObjectStorageClusteramong the cluster engines. The initiator's plan for a cluster read stops atWithMergeableState, so there is noFilterstep aboveReadFromClusterto collect theWHEREfrom, andSelectQueryInfo::filter_actions_dagis the only way a predicate reachesgetTaskIteratorExtension.StorageURLClusterandStorageFileClustertherefore always got a null predicate and never pruned a path before handing it to a replica - forurlthat meant an excluded URL was opened by the replica.Reproducer (deterministic, fails on
master, passes with this change):The stress test hit the original one through an AST fuzzer query over
test_s3_race:https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1c3181d592a4aaeec15077107e15b7edab5bca8d&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29
Related: #107619
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
_path/_filefiltering for object storage,fileandurlreads. AGLOBAL INsubquery over_pathor_fileof a path without globs no longer throwsNot-ready Set is passed as the second argument for function 'globalIn'; an explicitly named archive member is filtered before the archive is opened; hive partition columns are inferred for an explicitly named key that does not exist; andurlCluster/fileClusternow prune a filtered-out path on the initiator instead of handing it to a replica.Workflow [PR]
Sync PR [sync-upstream/pr/112968]
Version info
26.9.1.647(included in26.9and later)