Repository navigation
Fix exception when querying a Hive table without a WHERE clause - #108094
Conversation
`StorageHive` dereferenced `filter_actions_dag` while collecting files even when the query had no filter. The read path passes `nullptr` for `filter_actions_dag` when there is no `WHERE` clause, but `collectHiveFilesFromPartition` and `getHiveFileIfNeeded` unconditionally called `filter_actions_dag->getOutputs().front()` inside their partition- and file-level pruning blocks, leading to a null pointer dereference. Skip the pruning blocks when there is no filter: without a predicate there is nothing to prune by, so all files of the partition are collected. Closes: #102636 Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [1dde26b] Summary: ✅
AI ReviewSummaryThis PR fixes the no-filter Final Verdict
|
`StorageHive::getHiveFileIfNeeded` serves `IHiveFile` objects from a process-wide `hive_files_cache`. A filtered query stores a split-skip set on the cached file via `setSkipSplits`, and `updateFormatSettings` later copies it into `orc.skip_stripes` / `parquet.skip_row_groups`. Now that the file-level pruning block is skipped for unfiltered reads, that stale split-skip set would persist on the cached file and make a subsequent `SELECT *` silently drop the row groups or stripes excluded by the earlier predicate, turning the original crash into wrong results. Clear the split-skip set when there is no filter, so an unfiltered read always returns all splits. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Revives a minimal `test_hive_query` integration test focused on the crash fixed by this pull request: `SELECT` from a partitioned `Hive` (Parquet) table without a `WHERE` clause used to pass a null filter to `StorageHive`, which dereferenced it and terminated the server. The test also checks that a filtered read (which exercises partition/split pruning) followed by an unfiltered read of the same table still returns all rows, so stale pruning state is not served from the cached hive file. Closes: #102636 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Make `prepare_hive_data.sh` fail fast (`set -e`) and retry the data preparation while the Hive metastore / HiveServer2 is still starting up. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The set of splits to skip (Parquet row groups / ORC stripes) is computed from the query filter, but it was stored on the `IHiveFile` objects served from the process-wide `hive_files_cache`. Those objects are shared between concurrent queries, so a filtered read could leave a stale split-skip set on a cached file and a later `SELECT *` (or a concurrent query with a different filter) would silently drop the row groups or stripes excluded by the earlier predicate. The unsynchronized `std::unordered_set` was also a data race. Carry the skip set per query instead: `getHiveFileIfNeeded` now returns the file together with its skip set (`HiveFileWithSkipSplits`), the collection functions propagate it, and the reader copies it into `orc.skip_stripes` / `parquet.skip_row_groups` from the per-query value. Nothing query-specific is written to the cached file anymore, which also removes the need to clear the set for unfiltered reads (an empty per-query set already means "read all splits"). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The integration test added in this PR covers the no-`WHERE` null-filter crash, but it does not exercise the per-query split-skip set introduced by the later commits: its filter is on the partition key `day` (satisfied by partition pruning), Hive split-level minmax indexes default to off, and the Parquet reader does not consume `skip_row_groups`. The test would still pass if the query-local `skip_splits` plumbing were removed. Add an ORC-based regression (`test_orc_split_skip_state_is_query_local`). The new `test.demo_orc` table has two ORC files in one partition with disjoint `score` ranges; with `enable_orc_stripe_minmax_index = 1` a filter on the non-partition `score` column prunes one file's stripe, producing a non-empty per-query split-skip set. The ORC reader honours `orc.skip_stripes`, so a subsequent unfiltered read of the same (process-wide cached) table must still return all rows - before the fix the stale skip set on the cached file dropped the pruned stripe. Also wrap each `hive` invocation in the data-preparation script in a `timeout` so a stuck `hive` CLI (the metastore can still be starting up) aborts the script and lets the existing retry loop run again, instead of consuming the whole test budget - the cause of the occasional setup timeout in CI. Addresses the AI review on #108094 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed
The remaining CI reds are unrelated, known flakes: the |
`test_orc_split_skip_state_is_query_local` set only `enable_orc_stripe_minmax_index = 1`, but `enable_orc_file_minmax_index` defaults to `true`, so a `score < 5` filter discarded the `[10, 11]` file at file-pruning time (`getHiveFileIfNeeded` returns early once `useFileMinMaxIndex` rejects the file) before stripe pruning ran. The kept `[1, 2]` file then had no skipped stripe, so the query never built the non-empty per-query `skip_splits` set the test is meant to cover - it would have passed even without the fix. Disable file-level pruning (`enable_orc_file_minmax_index = 0`) so the `[10, 11]` file survives to stripe-level pruning, where its stripe is added to `skip_splits` - the non-empty query-local state whose staleness on the shared cached file the fix prevents. Addresses the AI review on #108094 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`prepare_hive_data.sh` ran its first statement under a 150s `timeout`; while the Hive metastore was still starting the `hive` CLI blocked on the connection and was killed (exit code 124), so only a handful of attempts fit into the integration-test budget before pytest's 900s timeout fired. This timed out `Integration tests (arm_binary, distributed plan, 3/4)` for both test_select_without_where and test_orc_split_skip_state_is_query_local, even though every other shard passed. Probe the metastore with a short-timeout trivial query and poll instead: a stuck probe is killed quickly and retried, while a successful one returns fast once the metastore is up, fitting many more connection attempts into the budget. The actual DDL / data load still runs with the generous timeout. If `timeout` is unavailable the probe is skipped, preserving the previous behaviour. #108094 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed
The remaining CI reds are unrelated, known flakes: the |
|
Re-checked at head `973b2001826` — no new code needed.
The full PR workflow run is still in progress, so the two flaky jobs cannot be rerun yet; they should be rerun once the run completes. The PR is |
The `Integration tests (arm_binary, distributed plan, 4/4)` shard timed out both new tests in the `started_cluster` fixture: pytest-timeout fired after the default 900s while the fixture was still polling the Hive metastore in `prepare_hive_data.sh` (the traceback ends inside `started_cluster`, before any assertion ran). The metastore came up in 7/8 of the previous attempts, so the bottleneck is the heavy Hadoop + Hive metastore + HiveServer2 JVM stack occasionally needing more than 900s to become reachable on a loaded (cpus=3) runner, not the test logic. Give the whole module a more generous budget with a module-level `pytest.mark.timeout(1800)`, matching other heavy external-service tests (`test_storage_rabbitmq`, `test_backup_restore_new`). pytest-timeout applies to fixture setup, so this directly extends the time available for the metastore-readiness poll, letting a slow-but-eventually-ready metastore finish instead of flaking the tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed
The remaining CI reds are unrelated, confirmed flakes — this PR touches only
The AI review is ✅ Approve and there are no unresolved review threads. The new commit re-triggers the full workflow; the metastore-timeout fix should clear the integration-test red, and the three flaky jobs above should be rerun once the run completes. |
The `Integration tests (arm_binary, distributed plan, 4/4)` shard timed out both new tests in the `started_cluster` fixture. The Hive test cluster runs the `lgboustc/hive_test:v2.0` image, whose Docker Hub manifest is published for `amd64` only, so on ARM runners it can only start under (very slow) QEMU emulation. Emulating the full Hadoop + Hive metastore + HiveServer2 JVM stack is so slow that the metastore never becomes reachable within the test budget, so no per-test timeout bump can make the ARM shard pass. Every `amd64` integration shard runs the tests fine. Skip the module on ARM via `is_arm`, matching the other tests that depend on amd64-only images (e.g. `test_mysql57_database_engine`). The generous `pytest.mark.timeout(1800)` is kept for the `amd64` path, where the metastore does eventually come up on a loaded runner. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed Root cause (not a slow-runner flake). The Hive test cluster runs the Fix. Skip the module on ARM via No re-merge with master: the merge-base is < 1 day old and master touches none of the PR files ( |
|
Re-checked at head The AI Review is ✅ Approve on this head, and there are 0 unresolved review threads. The remaining reds are pre-existing, transient, and unrelated to this PR (which touches only
|
|
Merged the latest
No code changes were needed: the diff is |
|
Re-checked at head The re-merge run is still in progress and clean apart from one red, which is an unrelated, pre-existing flake — the crash fix and the query-local
Every autocomplete assertion in the test passes (all On macOS ( Evidence it is unrelated to this PR (diff is
@groeneai, please investigate this flake and provide a fix in a separate PR (either suppress the benign
|
|
Re-checked at head The re-merge run I've rerun the failed job (now in progress); once it is green the only remaining non-success will be No code changes. The two AI-review threads are unchanged and already addressed above: |
|
Re-checked at head Both failing jobs in the private sync are unrelated integration-test flakes, in areas this change does not touch — this PR is Hive-only (
Neither is reachable from the Hive code path. I've re-run the two failed sync jobs; once they pass, |
|
This is not a critical bug fix - because we don't care about Hive. |
In `StorageHive::collectHiveFiles`, the branch for a non-partitioned Hive table declares `file_infos` inside the `else` block and schedules worker tasks that capture the range-`for` variable `file_info` by reference (`[&]`). `file_infos` is destroyed at the closing brace of the `else` block, but `pool.wait()` - which joins those tasks - runs on the next line, after the vector is already freed. A task still executing (or queued) at that point dereferences a dangling reference into the freed `std::vector<FileInfo>`, so a multi-threaded read of a non-partitioned `Hive` table can read freed memory (a data race / use-after-free, reported by the AI review). The partition branch above is not affected: `partitions` is a function-scope local that outlives `pool.wait()`, so its `[&]` capture of `partition` (a reference bound to a `partitions` element) is well-defined and is left unchanged. The fix captures `file_info` by value in the `else`-branch task (`FileInfo` is a small, copyable struct: `path`, `last_modify_time`, `size`), so the closure owns its data and no longer depends on `file_infos` outliving the tasks.
|
Correction to my previous comment. I initially pushed Disposition of the two AI blockers, for the record:
|
This reverts commit 9363645.
|
Fix already in progress: #107438 ("Do not log benign ENOTCONN on socket shutdown during ZooKeeper finalize"). It is your first suggested option, applied at the source.
Confirmed unrelated to this PR: the #108094 diff is Hive-only ( |
The `hive_files_cache` lives on the per-remote-table `HiveTableMetadata` and is shared by every `StorageHive` table over the same remote Hive table, but a cached `IHiveFile` bakes in table-specific state: the partition values, the minmax-index column layout (`index_names_and_types`), the file format, and the `enable_orc_*` / `enable_parquet_rowgroup_minmax_index` settings. `Hive` allows different ClickHouse schemas/settings over one remote table, so two such tables previously shared one cached file (keyed only by the remote `file_info.path`); the second table then pruned and interpreted the cached minmax index against the first table's layout and could silently keep or skip the wrong data. Key the cache by the remote path plus a `SipHash` signature of that table-specific state, so mismatched tables get independent cache entries while an identical table still reuses the cache. Add `test_hive_files_cache_is_table_local`, which reads the same remote ORC table through two ClickHouse `Hive` tables that differ in column order and minmax settings and asserts each returns its own correct rows. Addresses review: #108094 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed
The change is compile-verified (clang, |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 74/95 (77.89%) · Uncovered code |
The integration test added in this PR covers the no-`WHERE` null-filter crash, but it does not exercise the per-query split-skip set introduced by the later commits: its filter is on the partition key `day` (satisfied by partition pruning), Hive split-level minmax indexes default to off, and the Parquet reader does not consume `skip_row_groups`. The test would still pass if the query-local `skip_splits` plumbing were removed. Add an ORC-based regression (`test_orc_split_skip_state_is_query_local`). The new `test.demo_orc` table has two ORC files in one partition with disjoint `score` ranges; with `enable_orc_stripe_minmax_index = 1` a filter on the non-partition `score` column prunes one file's stripe, producing a non-empty per-query split-skip set. The ORC reader honours `orc.skip_stripes`, so a subsequent unfiltered read of the same (process-wide cached) table must still return all rows - before the fix the stale skip set on the cached file dropped the pruned stripe. Also wrap each `hive` invocation in the data-preparation script in a `timeout` so a stuck `hive` CLI (the metastore can still be starting up) aborts the script and lets the existing retry loop run again, instead of consuming the whole test budget - the cause of the occasional setup timeout in CI. Addresses the AI review on ClickHouse#108094 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`test_orc_split_skip_state_is_query_local` set only `enable_orc_stripe_minmax_index = 1`, but `enable_orc_file_minmax_index` defaults to `true`, so a `score < 5` filter discarded the `[10, 11]` file at file-pruning time (`getHiveFileIfNeeded` returns early once `useFileMinMaxIndex` rejects the file) before stripe pruning ran. The kept `[1, 2]` file then had no skipped stripe, so the query never built the non-empty per-query `skip_splits` set the test is meant to cover - it would have passed even without the fix. Disable file-level pruning (`enable_orc_file_minmax_index = 0`) so the `[10, 11]` file survives to stripe-level pruning, where its stripe is added to `skip_splits` - the non-empty query-local state whose staleness on the shared cached file the fix prevents. Addresses the AI review on ClickHouse#108094 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`prepare_hive_data.sh` ran its first statement under a 150s `timeout`; while the Hive metastore was still starting the `hive` CLI blocked on the connection and was killed (exit code 124), so only a handful of attempts fit into the integration-test budget before pytest's 900s timeout fired. This timed out `Integration tests (arm_binary, distributed plan, 3/4)` for both test_select_without_where and test_orc_split_skip_state_is_query_local, even though every other shard passed. Probe the metastore with a short-timeout trivial query and poll instead: a stuck probe is killed quickly and retried, while a successful one returns fast once the metastore is up, fitting many more connection attempts into the budget. The actual DDL / data load still runs with the generous timeout. If `timeout` is unavailable the probe is skipped, preserving the previous behaviour. ClickHouse#108094 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `hive_files_cache` lives on the per-remote-table `HiveTableMetadata` and is shared by every `StorageHive` table over the same remote Hive table, but a cached `IHiveFile` bakes in table-specific state: the partition values, the minmax-index column layout (`index_names_and_types`), the file format, and the `enable_orc_*` / `enable_parquet_rowgroup_minmax_index` settings. `Hive` allows different ClickHouse schemas/settings over one remote table, so two such tables previously shared one cached file (keyed only by the remote `file_info.path`); the second table then pruned and interpreted the cached minmax index against the first table's layout and could silently keep or skip the wrong data. Key the cache by the remote path plus a `SipHash` signature of that table-specific state, so mismatched tables get independent cache entries while an identical table still reuses the cache. Add `test_hive_files_cache_is_table_local`, which reads the same remote ORC table through two ClickHouse `Hive` tables that differ in column order and minmax settings and asserts each returns its own correct rows. Addresses review: ClickHouse#108094 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lter-crash Fix exception when querying a Hive table without a WHERE clause
Querying a
Hivetable without aWHEREclause (e.g.SELECT * FROM hive_table) caused a null pointer dereference inStorageHive.The read path passes
nullptrforfilter_actions_dagwhen the query has no filter, butStorageHive::collectHiveFilesFromPartitionandStorageHive::getHiveFileIfNeededunconditionally dereferenced it viafilter_actions_dag->getOutputs().front()inside their partition- and file-level pruning blocks. The defaultprune_levelisMax, so both blocks always run, and the query terminated the server with a segmentation fault. Adding aWHEREclause avoided the issue only because that madefilter_actions_dagnon-null.The fix skips the pruning blocks when there is no filter: without a predicate there is nothing to prune by, so all files of the partition are collected.
The set of splits to skip (Parquet row groups / ORC stripes) is computed from the query filter, but it was stored on the
IHiveFileobjects served from the process-widehive_files_cache. Because those objects are shared between concurrent queries, a filtered read could leave a stale split-skip set on a cached file, so a laterSELECT *— or a concurrent query with a different filter — would silently drop the row groups or stripes excluded by the earlier predicate (and the unsynchronizedstd::unordered_setwas also a data race). The split-skip set is now carried per query (HiveFileWithSkipSplits) instead of being stored on the cached file, so unfiltered reads always return all splits and concurrent queries do not interfere with each other's pruning.A regression test (
tests/integration/test_hive_query) reads a partitionedHive(Parquet) table without aWHEREclause and verifies that a filtered read followed by an unfiltered read of the same table still returns all rows.A second test (
test_orc_split_skip_state_is_query_local) covers the per-query split-skip set directly: a partitionedORCtable has two files with disjointscoreranges, and withenable_orc_stripe_minmax_index = 1a filter on the non-partitionscorecolumn prunes one file's stripe (a non-empty split-skip set). Since theORCreader honoursorc.skip_stripes(unlike Parquet'sskip_row_groups), a subsequent unfiltered read of the same cached table must still return all rows.Closes: #102636
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a crash (null pointer dereference) when querying a
Hivetable without aWHEREclause, e.g.SELECT * FROM hive_table.Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.7.1.630(included in26.7and later)