Skip to content

Check the temporary table limits on RESTORE - #124587

Merged
alexey-milovidov merged 1 commit into
masterfrom
temporary-table-limits-restore
Oct 9, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
temporary-table-limits-restore

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #122165, from two of its review comments that were still unresolved when it was merged.

RESTORE TEMPORARY TABLE got around the new limits:

  • for Memory tables, StorageMemory::restoreDataImpl called setData without checking max_temporary_table_memory_usage;
  • for MergeTree tables, StorageMergeTree::attachRestoredParts committed the restored parts without checking max_temporary_table_size_bytes_compressed / max_temporary_table_size_bytes_uncompressed.

Both are now checked with the settings of the RESTORE query, as INSERT and ALTER already do. A MergeTree restore is checked for the whole batch before the first part is committed, so it is rejected as a whole, as ATTACH PARTITION is. To make this possible, attachRestoredParts now receives the restore context.

Related: #122165

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

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

`RESTORE TEMPORARY TABLE` bypassed `max_temporary_table_memory_usage` for `Memory`
tables (`StorageMemory::restoreDataImpl` called `setData` without a check) and
`max_temporary_table_size_bytes_compressed` / `max_temporary_table_size_bytes_uncompressed`
for `MergeTree` tables (`StorageMergeTree::attachRestoredParts` committed the parts
without a check). Both are now checked with the settings of the `RESTORE` query;
a `MergeTree` restore is checked for the whole batch before the first part is
committed, so it is rejected as a whole.

Addresses the review comments on #122165

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [00001a8]

Summary: ✅


AI Review

Summary

This PR threads the RESTORE query context into the temporary-table restore paths so max_temporary_table_memory_usage, max_temporary_table_size_bytes_compressed, and max_temporary_table_size_bytes_uncompressed are enforced with the settings of the RESTORE query, and it adds focused stateless coverage for both Memory and MergeTree. I reviewed the current diff, the touched restore/attach paths, and the existing discussion, and I did not find any correctness or contract violations in the current code. The PR metadata is appropriate, and the linked CI report is all green.

Final Verdict

✅ No blockers or majors found in the current revision; this looks ready to merge.

LLVM Coverage Report

Measured on commit 00001a8.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-backup Backup/restore infrastructure and backup formats. labels Oct 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 00001a88c with master 41ffcf2a3 (stripped binary size, per-symbol sizes and ThinLTO time; 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

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

Job report

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 32 queries analysed

This PR checks temporary-table size and memory limits during RESTORE, in StorageMemory::restoreDataImpl and StorageMergeTree::attachRestoredParts, and passes the RESTORE query's settings down to those checks. None of this code runs in the clickbench or tpch_adapted_1_official SELECT queries, so it should have no effect on these benchmarks. Two queries were flagged, and the automatic checks already held both back: clickbench Q31 (-19.1%) falls inside master's normal range, and clickbench Q34 (-9.3%) is not_sure because master's own timings for it are unstable after a shift in early October. Both look like normal baseline movement rather than an effect of this PR, and nothing here needs action.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 34 not_sure 1092 990 -9.3% <0.0001 CPU time also dropped, and the change is -9.3%. Master's baseline for this query is unstable, and this PR's RESTORE-only changes are not on the SELECT path, so it stays not_sure.

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: 2770f5bd-7412-43ec-b57d-7f25e006dbce
  • MIRAI run: fdf9b2cd-83a7-43ec-aea4-96e56143d540
  • PR check IDs:
    • clickbench_442381_1791497499
    • clickbench_442387_1791497499
    • clickbench_442393_1791497499
    • tpch_adapted_1_official_442404_1791497499
    • tpch_adapted_1_official_442414_1791497499
    • tpch_adapted_1_official_442451_1791497499

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is excessive, but okay.

@alexey-milovidov alexey-milovidov self-assigned this Oct 9, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Why do we even backup temporary tables? This is to @vitlibar, I've already asked this question before. It is just a mis-feature.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 9, 2026
Merged via the queue into master with commit b22ff71 Oct 9, 2026
152 checks passed
@alexey-milovidov
alexey-milovidov deleted the temporary-table-limits-restore branch October 9, 2026 09:22
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 9, 2026
clickgapai added a commit to clickgapai/ClickHouse that referenced this pull request Oct 9, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 9, 2026
Conflict in StorageMergeTree::attachRestoredParts: master added a check
of the temporary table size limits before the parts are committed
(ClickHouse#124587). Keep that check first and declare reset_level after it; the
check reads only part sizes, so the level and mutation reset do not
affect it.

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

comp-backup Backup/restore infrastructure and backup formats. pr-not-for-changelog This PR should not be mentioned in the changelog 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.

2 participants