提交 1eb8f0a4 编写于 作者: A alesapin

Fix bug in storage buffer during alter

上级 626c2dad
......@@ -447,7 +447,9 @@ private:
/// Sort the columns in the block. This is necessary to make it easier to concatenate the blocks later.
Block sorted_block = block.sortColumns();
if (!buffer.data)
/// During alter we flash all buffers to storage, but buffer structure
/// may change and we update it from the new incoming block
if (buffer.data.rows() == 0)
{
buffer.data = sorted_block.cloneEmpty();
}
......@@ -829,7 +831,9 @@ void StorageBuffer::alter(const AlterCommands & params, const Context & context,
checkAlterIsPossible(params, context.getSettingsRef());
auto metadata_snapshot = getInMemoryMetadataPtr();
/// So that no blocks of the old structure remain.
/// Flush all buffers to storages, so that no non-empty blocks of the old
/// structure remain. Structure of empty blocks will be updated during first
/// insert.
optimize({} /*query*/, metadata_snapshot, {} /*partition_id*/, false /*final*/, false /*deduplicate*/, context);
StorageInMemoryMetadata new_metadata = *metadata_snapshot;
......
2020-01-01 00:05:00
2020-01-01 00:05:00
2020-01-01 00:06:00 hello
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, 3, 20, 2000000, 20000000, 100000000, 300000000);;
INSERT INTO buf (timestamp) VALUES (toDateTime('2020-01-01 00:05:00'));
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;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册