diff --git a/dbms/src/Storages/StorageTinyLog.cpp b/dbms/src/Storages/StorageTinyLog.cpp index 8cabd658b9b..06d84d8e5bd 100644 --- a/dbms/src/Storages/StorageTinyLog.cpp +++ b/dbms/src/Storages/StorageTinyLog.cpp @@ -245,6 +245,10 @@ void TinyLogBlockOutputStream::writeSuffix() return; done = true; + /// If nothing was written - leave the table in initial state. + if (streams.empty()) + return; + /// Finish write. for (auto & stream : streams) stream.second->finalize(); diff --git a/dbms/tests/queries/0_stateless/00663_tiny_log_empty_insert.reference b/dbms/tests/queries/0_stateless/00663_tiny_log_empty_insert.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00663_tiny_log_empty_insert.reference @@ -0,0 +1 @@ +1 diff --git a/dbms/tests/queries/0_stateless/00663_tiny_log_empty_insert.sql b/dbms/tests/queries/0_stateless/00663_tiny_log_empty_insert.sql new file mode 100644 index 00000000000..c238a3abc0e --- /dev/null +++ b/dbms/tests/queries/0_stateless/00663_tiny_log_empty_insert.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS test.empty; +DROP TABLE IF EXISTS test.data; + +CREATE TABLE test.empty (value Int8) ENGINE = TinyLog; +CREATE TABLE test.data (value Int8) ENGINE = TinyLog; + +INSERT INTO test.data SELECT * FROM empty; +SELECT * FROM test.data; + +INSERT INTO test.data SELECT 1; +SELECT * FROM test.data; + +DROP TABLE test.empty; +DROP TABLE test.data;