Skip to content

Select plain or swarm mode for cluster query - #2808

Open
ianton-ru wants to merge 22 commits into
antalya-26.8from
feature/antalya-26.8/object-storage-cluster-local-read-probe
Open

ianton-ru wants to merge 22 commits into
antalya-26.8from
feature/antalya-26.8/object-storage-cluster-local-read-probe

Conversation

@ianton-ru

Copy link
Copy Markdown

Changelog category (leave one):

  • Experimental Feature

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

Select plain or swarm mode for cluster query

Documentation entry for user-facing changes

We have a object_storage_cluster feature to make distributed query to table on object storage.
But small query can be executed faster locally, directly on initiator.

This feature allow to select local or distributed way based on expected query size.
It does not give 100% accuracy, it's a some kind of heuristic.

Distributed query is split on tasks for remote nodes.
Now we start to do in on early stage. If we get only few tasks, not greater than object_storage_cluster_local_read_max_tasks and spend not more than object_storage_cluster_local_read_probe_ms milliseconds, we execute query locally. In other case, execute on cluster.

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

ianton-ru and others added 6 commits November 5, 2026 15:51
…probe

Add `object_storage_cluster_local_read_max_files` and `object_storage_cluster_local_read_probe_ms`. When enabled, the initiator lists the object storage files for a `*Cluster` query for up to the time budget. If the listing finishes within the budget and yields at most the file limit, the query is read locally. Otherwise the query keeps the cluster path. The default of `0` keeps the existing behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
The `object_storage_cluster_local_read_max_files` probe listed files and then discarded them, so the local read or the cluster task distributor listed the same files again. Keep the probe iterator and the objects it already returned on the query info, and replay them in `ReadFromObjectStorageStep` and in `getTaskIteratorExtension`. Placeholder metadata from `skip_object_metadata` is dropped for local reads so they fetch the real size. Queries that read `_tags` still list again, because the probe does not request tags.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the local-or-cluster decision on `ObjectStorageClusterReadProbe` instead of a second flag on `SelectQueryInfo`. A finished listing is represented by a null iterator, so the separate exhausted flag is gone. `createObjectIteratorForRead` always sets `tasks_go_to_other_replicas` and emits profile events, so those parameters are removed.

Placeholder metadata from `skip_object_metadata` is no longer cleared for local reads, because the read already treats an unfetched object as an unknown size.

Co-authored-by: Cursor <cursoragent@cursor.com>
…e children

A `Merge` passes one `SelectQueryInfo` to every child, so a single probe slot let the first child's local-read decision apply to later children. The probe is now keyed by the cluster storage, and `05429_object_storage_cluster_local_read_merge` checks a small child read locally next to a large child that stays on the cluster.

Co-authored-by: Cursor <cursoragent@cursor.com>
The probe now counts the same tasks the cluster would run, so with `bucket` split granularity each bucket counts, not each file. The setting `object_storage_cluster_local_read_max_files` is renamed to `object_storage_cluster_local_read_max_tasks`.

Co-authored-by: Cursor <cursoragent@cursor.com>
…probe

The probe drops a finished iterator, so a local read lost the `_data_lake_snapshot_version` that the cluster read reports. The probe now stores the snapshot version before it releases the iterator, and the replay iterator returns it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ianton-ru

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T15:14:23.887280Z 5021b15 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [68cfcdd]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5021b15138

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +760 to +763
auto object = iterator->next(0);
if (!object)
{
probe->read_locally = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce the probe deadline across iterator calls

When iterator->next(0) starts just before the deadline but a slow object-store listing or bucket split returns nullptr after it, this branch marks the probe local without checking elapsed time again. Consequently object_storage_cluster_local_read_probe_ms neither bounds planning latency nor preserves the documented rule that a listing finishing outside the budget stays distributed; use a deadline-aware/cancellable iterator operation and verify the deadline before accepting exhaustion as a local-read decision.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not critical.

@ianton-ru
ianton-ru marked this pull request as ready for review November 11, 2026 08:25
@ianton-ru ianton-ru added antalya port-antalya PRs to be ported to all new Antalya releases antalya-26.8 labels Nov 11, 2026
@Selfeer

Selfeer commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

PR 2808 — confirmed issues

1. Local read drops every file listed without object metadata

Severity: High

object_storage_cluster_local_read_max_tasks lists through createObjectIteratorForRead, which passes skip_object_metadata = true. For a brace expansion (s3('.../{a,b}.tsv')) and for a glob whose paths are taken from the filter (s3_path_filter_limit), that listing is a KeysIterator. The iterator stores a placeholder ObjectMetadata: is_fetched = false, while size_bytes stays 0 and is_size_known stays true.

The local scan reuses those objects. StorageObjectStorageSource only fetches metadata when getObjectMetadata() is empty. The placeholder is present, so it does not fetch. With s3_skip_empty_files (default true) it then treats size_bytes == 0 && is_size_known as an empty object and skips the file.

A cluster read of the same path does not hit this. The worker rebuilds ObjectInfo from the path alone, sees no metadata, and fetches the real size. Turning the new setting on is what moves the read onto the initiator and drops the rows. The query finishes successfully and returns no data.

An exact path with no glob is unaffected: that KeysIterator is constructed with skip_object_metadata = false. A plain glob uses GlobIterator, whose listing already has sizes.

Steps to reproduce:

  1. Write a non-empty object, for example s3('http://localhost:11111/test/local_read_a.tsv', 'TSV', 'x UInt32') with one row.
  2. Run SELECT count(), sum(x) FROM s3('http://localhost:11111/test/local_read_{a}.tsv', 'TSV', 'x UInt32') with object_storage_cluster set to a non-empty cluster, object_storage_cluster_local_read_max_tasks = 10, and leave s3_skip_empty_files at its default.
  3. The result is 0 and 0. The same query with object_storage_cluster_local_read_max_tasks = 0 returns 1 and 1.
  4. The same miss happens for a glob plus a path filter that stays under the task limit, for example s3('http://localhost:11111/test/local_read_*.tsv', ...) with WHERE _path = 'test/local_read_a.tsv' and object_storage_cluster_local_read_max_tasks = 10.

2. The probe time budget does not cover the listing call

Severity: Medium

isSmallEnoughForLocalRead compares object_storage_cluster_local_read_probe_ms only between iterator->next calls. It does not stop a call that is already running. The first next always runs. For a glob that call performs ListObjects for a whole page (list_object_keys_size, 1000 by default). For Iceberg or Delta it can parse metadata. Planning stays blocked for that whole call even when the budget is a few milliseconds, and only afterward can the probe keep the query on the cluster.

Steps to reproduce:

  1. Point s3Cluster or s3(..., SETTINGS object_storage_cluster = '...') at a prefix whose first ListObjects page is slow (large page, or a high-latency endpoint).
  2. Set object_storage_cluster_local_read_max_tasks above 0 and object_storage_cluster_local_read_probe_ms = 1.
  3. Run a SELECT that has to list that prefix. Query planning waits for the list call to return, not for 1 ms. The trace log then says probe time budget exceeded only after that call.

@Selfeer

Selfeer commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

PR 2808: both issues reproduced

Both issues from the audit comment reproduce on the PR build.

Issue 1: a local read drops every file listed without object metadata

Two non-empty files: a.tsv contains 1 and b.tsv contains 2.

SELECT _path, _size, x
FROM s3(s3, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
ORDER BY _path;
-- warehouse/pr2808/local_read_a.tsv    2    1
-- warehouse/pr2808/local_read_b.tsv    2    2

All queries below use these settings:

SETTINGS object_storage_cluster = 'default_cluster',
         object_storage_cluster_local_read_max_tasks = 10,
         object_storage_cluster_local_read_probe_ms = 5000

The bug. The query succeeds and returns no data:

-- One-key brace expansion
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a}.tsv', format = 'TSV', structure = 'x UInt32');
-- 0    0        expected: 1    1

-- Two-key brace expansion
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a,b}.tsv', format = 'TSV', structure = 'x UInt32');
-- 0    0        expected: 2    3

-- Glob whose keys come from the _path filter
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
WHERE _path = 'warehouse/pr2808/local_read_a.tsv';
-- 0    0        expected: 1    1

Controls. Each of these returns the right data:

-- The same brace read with the setting off, so it runs on the cluster
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a,b}.tsv', ...)
SETTINGS object_storage_cluster_local_read_max_tasks = 0;
-- 2    3

-- An exact path, read locally
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_a.tsv', ...);
-- 1    1

-- A plain glob, read locally
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_*.tsv', ...);
-- 2    3

-- The failing brace read with the empty-file skip turned off
SELECT count(), sum(x) FROM s3(s3, filename = 'pr2808/local_read_{a,b}.tsv', ...)
SETTINGS s3_skip_empty_files = 0;
-- 2    3

Which queries read locally. Shards is counted only by the distributed read:

SELECT log_comment, ProfileEvents['Shards'] > 0 AS distributed, result_rows
FROM system.query_log WHERE type = 'QueryFinish' AND log_comment LIKE 'pr2808\_%';
-- pr2808_brace_one_local       0    1
-- pr2808_brace_two_local       0    1
-- pr2808_glob_filter_local     0    1
-- pr2808_brace_cluster         1    1
-- pr2808_exact_local           0    1
-- pr2808_glob_local            0    1
-- pr2808_brace_local_noskip    0    1

Conclusion. Rows are lost only when two things combine:

  • the read happens on the initiator;
  • the file list comes from a KeysIterator, which is used for brace expansion and for keys taken from a _path filter.

Turning off s3_skip_empty_files brings the rows back. The empty-file check is therefore discarding files whose placeholder size of 0 was never replaced by the real size.

Issue 2: the probe time budget does not cover the listing call

Toxiproxy adds 3 s of latency to every S3 response. EXPLAIN plans the query, which runs the probe, without reading any data.

-- Probe on, with a 1 ms budget
EXPLAIN SELECT count() FROM s3(s3_proxy, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
SETTINGS object_storage_cluster = 'default_cluster',
         object_storage_cluster_local_read_max_tasks = 10,
         object_storage_cluster_local_read_probe_ms = 1;
-- planning: 7147 ms, 2 ListObjects batches
-- trace:    Local-read probe for _table_function.s3 saw 1 task(s) (limit 10), read_locally=false,
--           reason=probe time budget exceeded

-- Control: the setting off
EXPLAIN SELECT count() FROM s3(s3_proxy, filename = 'pr2808/local_read_*.tsv', format = 'TSV', structure = 'x UInt32')
SETTINGS object_storage_cluster = 'default_cluster',
         object_storage_cluster_local_read_max_tasks = 0;
-- planning: 3624 ms, 1 ListObjects batch (resolving a sample path; this happens without the PR too)

Conclusion. The probe added 3523 ms to planning, one full ListObjects call, against a 1 ms budget. It logged probe time budget exceeded only after that call returned.

Impact. The full SELECT took the same time either way:

Setting Run 1 Run 2
probe on, 1 ms budget 17767 ms 17789 ms
setting off 17810 ms 17788 ms

The cluster read reuses the probe's iterator, so the listing time moves from execution into planning; it is not added on top. The bug blocks planning, which includes EXPLAIN and the start of the query, but it did not slow the query down overall here. Only the S3 glob case was tested; Iceberg and Delta metadata parsing were not.

ianton-ru and others added 11 commits November 25, 2026 16:26
… read

The cluster local-read probe lists with `skip_object_metadata = true` and the local read reuses
those objects. For a brace expansion and for keys taken from a `_path` filter the listing is a
`KeysIterator`, which returns a placeholder `ObjectMetadata` with `is_fetched = false`,
`size_bytes = 0` and `is_size_known = true`.

`StorageObjectStorageSource` fetched metadata only when it was missing, so the placeholder was
accepted and, with `s3_skip_empty_files` (the default), such files were skipped as empty. The query
succeeded and returned no rows.

Fetch the metadata also when it is a placeholder (`is_fetched = false`).

Review comment: #2808 (comment)
Related: #2808

Co-authored-by: Cursor <cursoragent@cursor.com>
…alya-26.8/object-storage-cluster-local-read-probe
05484 is already taken on the base branch.

Co-authored-by: Cursor <cursoragent@cursor.com>
The S3 object names and log comments still used the old 05484 prefix.

Co-authored-by: Cursor <cursoragent@cursor.com>
…s budget

`isSmallEnoughForLocalRead` checked `object_storage_cluster_local_read_probe_ms` only before each
`next` call. A `next` that started inside the budget but returned `nullptr` after it was still
taken for a small listing, contrary to the documented rule that the query stays on the cluster
when the task list does not end inside the budget.

Check the deadline once more after the last `next`. A finished iterator is no longer attached to
the probe on that path either: all its tasks are already in the probe.

A `next` call that has already started cannot be interrupted, so planning can still exceed the
budget by one listing call. Document it in `object_storage_cluster_local_read_probe_ms`.

Review comment: #2808 (comment)
Related: #2808

Co-authored-by: Cursor <cursoragent@cursor.com>
The local-read probe added a sixth parameter to the virtual `IStorageCluster::getTaskIteratorExtension`.
The whole-query dispatch unit-test mocks still overrode the five-parameter form, so `unit_tests_dbms` failed to compile after the merge of `antalya-26.8`.

Co-authored-by: Cursor <cursoragent@cursor.com>
…e files than without it

The probe lists with the filter known at planning time, before the optimizer pushes filters into the read.
The test compares the files sent to the swarm nodes with `object_storage_cluster_local_read_max_tasks` set to 0
and to 1 for a plain `_path` filter, a filter of the outer query and a `_path` set taken from a subquery.

Co-authored-by: Cursor <cursoragent@cursor.com>
… settings history

`object_storage_cluster_local_read_max_tasks` and `object_storage_cluster_local_read_probe_ms` sat in the
`26.6.8.20003.altinityantalya` block, a release line that does not contain them. The settings history check
requires a new setting under the current version block, so they move to `26.8.39.20001.altinityantalya`.

Co-authored-by: Cursor <cursoragent@cursor.com>
…r `DESCRIBE` and `EXPLAIN`

The probe lists objects while planning. `DESCRIBE (SELECT ...)`, `EXPLAIN PLAN` and
`EXPLAIN PIPELINE` read no data, but they reached `getQueryProcessingStage` and ran the
listing, so with `s3_throw_on_zero_files_match` (or an unreachable storage) they failed
where they did not before the probe existed.

`DESCRIBE` now builds its header in analyze mode, which does not ask the storage for the
processing stage. For `EXPLAIN` the planner sets `object_storage_cluster_local_read_max_tasks`
to 0 for the query, so the explained plan is the one of the cluster read.

Co-authored-by: Cursor <cursoragent@cursor.com>
…EXPLAIN ANALYZE`

The previous commit made `DESCRIBE` only analyze the query. In that mode the planner does not check `SELECT` on the tables of nested subqueries, so a user with a grant on some columns could learn the types of the other columns: `DESCRIBE (SELECT * FROM (SELECT secret FROM t))` returned `secret String`.

`DESCRIBE` plans the query in full again and marks it with the new `SelectQueryOptions::plan_only` flag. The planner uses the flag to skip the local-read probe. `EXPLAIN` without `ANALYZE` sets the same flag, so it keeps showing the plan of the cluster read. The flag is new because `is_explain` also changes how the legacy analyzer handles global subqueries. `EXPLAIN ANALYZE` executes the query, so it does not set the flag and runs the probe, as the query does.

Tests: `05818_object_storage_cluster_local_read_describe_nested_access`, `05819_object_storage_cluster_local_read_explain_analyze_probes`.
Co-authored-by: Cursor <cursoragent@cursor.com>
When `object_storage_cluster_local_read_max_tasks` reuses the probe listing, the listed objects are placeholders: their metadata is not fetched and their size is reported as zero. Two problems followed from this:

- Progress: the local read reported zero bytes for each file, so `total_bytes_to_read` was wrong. The new resolver in `ReadFromObjectStorageStep::createIterator` fetches the metadata of each placeholder once and reports its real size through `FileProgress`.
- Missing files: with `s3_ignore_file_doesnt_exist = 1`, a file deleted after listing made the reader end its stream early, so the objects after it were silently dropped. The same query without the probe returned all the remaining rows. `StorageObjectStorageSource::createReader` now skips such a file with `continue`.

The metadata fetch moved into `StorageObjectStorageSource::fetchObjectMetadataIfNeeded`, shared by the reader and the resolver. `ObjectIteratorWithPrefetchedObjects` applies the resolver outside its mutex, because it may read from the object storage.

Adds the test `05820_object_storage_cluster_local_read_ignore_missing_file`.

Co-authored-by: Cursor <cursoragent@cursor.com>
ianton-ru and others added 3 commits November 25, 2026 20:12
A cluster local read after the `object_storage_cluster_local_read_max_tasks` probe reports each placeholder's real size to the progress callback. With `cluster_table_function_split_granularity = 'bucket'` this reported nothing for a file listed without metadata, so `total_bytes_to_read` stayed zero:

- `ObjectIteratorSplitByBuckets` fetches the metadata of the original object through `createReadBuffer` and then clones it for every bucket. The clones are no longer placeholders, so the metadata resolver in `ReadFromObjectStorageStep` skipped them.
- With `s3_validate_etag_on_read = 0` the clones stay placeholders. Reporting each of them would count the file once per bucket.

`ObjectIteratorSplitByBuckets` now reports the size once per file that the listing skipped the metadata of. The resolver reports a bucket placeholder only the first time it sees its file. Files listed with metadata are still reported by the listing.

Co-authored-by: Cursor <cursoragent@cursor.com>
With `cluster_table_function_split_granularity = 'bucket'`, `ObjectIteratorSplitByBuckets` asks `FormatFactory::getSplitter` for a splitter of the format. Only `Parquet` registers one, and `getSplitter` called the empty creator for any other format, so a query over `TSV` failed with `std::bad_function_call`. The iterator also had no branch for a format without a splitter, so it would have dropped the file.

`getSplitter` now returns null when the format has no splitter, and the iterator passes such a file through as a single task.

Adds the test `05821_object_storage_cluster_local_read_bucket_unsplittable_format`.

Co-authored-by: Cursor <cursoragent@cursor.com>
…doesnt_exist`

With `cluster_table_function_split_granularity = 'bucket'`, `ObjectIteratorSplitByBuckets` opens each file to read its row groups. For a file listed without metadata, `createReadBuffer` fetches the metadata and fails when the file does not exist, so `s3_ignore_file_doesnt_exist = 1` was not honored: the query failed with `S3_ERROR`, both for the distributed read and for the local read after the `object_storage_cluster_local_read_max_tasks` probe.

When missing files are ignored, `ObjectIteratorSplitByBuckets` now fetches the metadata first and skips a file that does not exist. The setting is passed from the storage configuration. Without the setting nothing changes.

Adds the test `05822_object_storage_cluster_local_read_bucket_ignore_missing_file`.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

antalya antalya-26.8 port-antalya PRs to be ported to all new Antalya releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants