Fix std::out_of_range when reading from Buffer table with sample#99141
Fix std::out_of_range when reading from Buffer table with sample#99141
Conversation
src/Storages/StorageBuffer.h
Outdated
| /// If there is no destination, only the buffer is read, so sampling is always supported. | ||
| if (auto destination = getDestinationTable()) | ||
| return destination->supportsSampling(); | ||
| return true; |
There was a problem hiding this comment.
Hm, is the following possible?
SELECT * FROM buffer:
getSampling()==return true-- because underlying table supports sampling- then another thread re-create table w/o sampling, in the middle of that SELECT
- then
StorageBuffer::readcallsgetDestinationTableagain and got table that does not support it
I think so. Then we need a check in MergeTreeDataSelectExecutor::getSampling
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (7/7) |
azat
left a comment
There was a problem hiding this comment.
BTW do we have the same problem for i.e. views?
| DROP TABLE IF EXISTS t0; | ||
| DROP TABLE IF EXISTS t1; | ||
|
|
||
| CREATE TABLE t0 (c0 Int) ENGINE = MergeTree ORDER BY tuple(); |
There was a problem hiding this comment.
I think it also make sense to test Buffer over MergeTree table with sampling, just in case
There was a problem hiding this comment.
I see there is such test already
ClickHouse/tests/queries/0_stateless/00061_storage_buffer.sql
Lines 5 to 12 in f8a8eb2
I'll check, but I'd merge this PR for now. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix crash on usage of Buffer table with SAMPLE when destination does not support it.
Documentation entry for user-facing changes
Closes #99134
Note
Low Risk
Low risk bug fix that adds a guard and a regression test; behavior changes only when
SAMPLEis used on tables without a sampling key, now returning a clearSAMPLING_NOT_SUPPORTEDerror instead of potentially crashing.Overview
Prevents a crash when executing
SAMPLEagainst a MergeTree-backedBuffertable whose destination MergeTree has noSAMPLE BYkey.MergeTreeDataSelectExecutor::getSampling()now explicitly checksmetadata_snapshot->hasSamplingKey()before accessing the sampling key and throwsErrorCodes::SAMPLING_NOT_SUPPORTEDwith a clear message when absent.Adds a stateless regression test covering the failing Buffer+MergeTree case (expects
SAMPLING_NOT_SUPPORTED) and confirmsSAMPLEstill works for Buffer tables without a destination table (in-memory only).Written by Cursor Bugbot for commit f5aec3e. This will update automatically on new commits. Configure here.