Skip to content

Apply result limits to queries without FROM - #129418

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
lazerg:fix/issue-129393-result-limits-system-one
Nov 6, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
lazerg:fix/issue-129393-result-limits-system-one

Conversation

@lazerg

@lazerg lazerg commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #129393

max_result_rows and max_result_bytes did nothing for a query without FROM, or with FROM system.one. Such a query reads system.one, which is in the list of system tables that skip quota and limits, so executeQuery never added the result limits. The same happened to a whole UNION when one of its branches had no FROM, like SELECT number FROM numbers(1000) UNION ALL SELECT 1. The same happened with system.quotas, system.quota_limits, system.quota_usage and system.quotas_usage. Now these tables only skip the quota, so you can still check an exhausted quota, but the limits always apply. InterpreterSelectQuery gets the same change, for backports to versions that still use it.

The new test fails on the current master macOS build. I did not build the patched server locally, so CI has to confirm it.

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):

max_result_rows and max_result_bytes are now applied to queries without FROM and to queries that read from system.one or the quota system tables.


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

Version info

  • Merged into: 26.11.1.1533-master (included in 26.11 and later)

@clickhouse-gh clickhouse-gh Bot added comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. external Author is not a member of the ClickHouse organization labels Nov 5, 2026
@PedroTadim PedroTadim self-assigned this Nov 5, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ba6a002]

Summary: ✅


AI Review

Summary

Reviewed head ba6a002299e58758373e8eaa42e7e1c89836181c and all prior discussion. The change enforces max_result_rows and max_result_bytes for queries without FROM, queries over system.one and quota tables, and affected unions, while preserving quota exemptions. No actionable findings remain. Previous review feedback is addressed, and 05507_max_result_rows_without_from passes in Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ba6a00229 with master 49270a6ea (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 35fed92ff; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 39 s compile time in total, 8 of them have a recent master baseline.

Job report

@PedroTadim

Copy link
Copy Markdown
Member

🕵️ I compared the CI release build of 756f966c with master on about 15 limit cases: max_execution_time and max_rows_to_read/max_bytes_to_read without FROM, IN (SELECT 1), scalar subqueries, max_rows_in_set, and the quota tables. Only the fixed cases differ, so I see no side effects.

One case to add to the test: result_overflow_mode = 'break', which is now applied too. For example, SELECT number FROM numbers(1000) UNION ALL SELECT 1 SETTINGS max_result_rows = 10, result_overflow_mode = 'break', max_block_size = 5 returns 10 rows instead of 1001. The test checks only throw so far.

Nit: the comment at InterpreterExplainQuery.cpp:1464 still calls system.one an example of a table exempt from limits. It is now exempt from the quota only.

@lazerg

lazerg commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking. I added the break case to the test (with max_threads = 1 so the row count stays at 10) and fixed the comment in ba6a002.

@PedroTadim
PedroTadim enabled auto-merge November 6, 2026 11:42
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 6, 2026
Merged via the queue into ClickHouse:master with commit 63242c8 Nov 6, 2026
186 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 6, 2026
alexey-milovidov added a commit that referenced this pull request Nov 9, 2026
…opped exempting `system.one` from result limits

#129418 made a single read of `system.one`
ignore only quotas, not result limits. The query plan cache follows normal execution, so
both the miss and the hit now reject the result with `TOO_MANY_ROWS_OR_BYTES`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=107125&sha=ac33f9a13fab50100f873f73b406f0ded58d6e32&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20sequential%29
PR: #107125

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. external Author is not a member of the ClickHouse organization 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.

max_result_rows / max_result_bytes are not enforced for queries without FROM (or with FROM system.one)

3 participants