Merge pull request #30565 from ClickHouse/try-to-fix-30397

Try to fix #30397
This commit is contained in:
alexey-milovidov 2021-10-26 09:45:45 +03:00 committed by GitHub
commit e528bfdb1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 6 deletions

View File

@ -446,7 +446,8 @@ static void appendBlock(const Block & from, Block & to)
if (!to)
throw Exception("Cannot append to empty block", ErrorCodes::LOGICAL_ERROR);
assertBlocksHaveEqualStructure(from, to, "Buffer");
if (to.rows())
assertBlocksHaveEqualStructure(from, to, "Buffer");
from.checkNumberOfRows();
to.checkNumberOfRows();
@ -464,14 +465,21 @@ static void appendBlock(const Block & from, Block & to)
{
MemoryTracker::BlockerInThread temporarily_disable_memory_tracker;
for (size_t column_no = 0, columns = to.columns(); column_no < columns; ++column_no)
if (to.rows() == 0)
{
const IColumn & col_from = *from.getByPosition(column_no).column.get();
last_col = IColumn::mutate(std::move(to.getByPosition(column_no).column));
to = from;
}
else
{
for (size_t column_no = 0, columns = to.columns(); column_no < columns; ++column_no)
{
const IColumn & col_from = *from.getByPosition(column_no).column.get();
last_col = IColumn::mutate(std::move(to.getByPosition(column_no).column));
last_col->insertRangeFrom(col_from, 0, rows);
last_col->insertRangeFrom(col_from, 0, rows);
to.getByPosition(column_no).column = std::move(last_col);
to.getByPosition(column_no).column = std::move(last_col);
}
}
}
catch (...)

View File

@ -0,0 +1,3 @@
2020-01-01 00:05:00
2020-01-01 00:05:00
2020-01-01 00:06:00 hello

View File

@ -0,0 +1,25 @@
DROP TABLE IF EXISTS buf_dest;
DROP TABLE IF EXISTS buf;
CREATE TABLE buf_dest (timestamp DateTime)
ENGINE = MergeTree PARTITION BY toYYYYMMDD(timestamp)
ORDER BY (timestamp);
CREATE TABLE buf (timestamp DateTime) Engine = Buffer(currentDatabase(), buf_dest, 16, 0.1, 0.1, 2000000, 20000000, 100000000, 300000000);;
INSERT INTO buf (timestamp) VALUES (toDateTime('2020-01-01 00:05:00'));
--- wait for buffer to flush
SELECT sleep(1) from numbers(1) settings max_block_size=1 format Null;
ALTER TABLE buf_dest ADD COLUMN s String;
ALTER TABLE buf ADD COLUMN s String;
SELECT * FROM buf;
INSERT INTO buf (timestamp, s) VALUES (toDateTime('2020-01-01 00:06:00'), 'hello');
SELECT * FROM buf ORDER BY timestamp;
DROP TABLE IF EXISTS buf;
DROP TABLE IF EXISTS buf_dest;