diff --git a/dbms/include/DB/Storages/StorageTinyLog.h b/dbms/include/DB/Storages/StorageTinyLog.h index d91cc88d9a3..770259f69d4 100644 --- a/dbms/include/DB/Storages/StorageTinyLog.h +++ b/dbms/include/DB/Storages/StorageTinyLog.h @@ -144,6 +144,8 @@ public: Files_t & getFiles(); + std::string full_path() { return path + escapeForFileName(name) + '/';} + private: String path; String name; diff --git a/dbms/src/Storages/StorageTinyLog.cpp b/dbms/src/Storages/StorageTinyLog.cpp index d48cbea70e3..92b5a0cc65a 100644 --- a/dbms/src/Storages/StorageTinyLog.cpp +++ b/dbms/src/Storages/StorageTinyLog.cpp @@ -16,7 +16,7 @@ #include #include - +#include #define DBMS_STORAGE_LOG_DATA_FILE_EXTENSION ".bin" @@ -61,6 +61,12 @@ Block TinyLogBlockInputStream::readImpl() return res; } + { + /// если в папке нет файлов, то это значит, что таблица пока пуста + if (Poco::DirectoryIterator(storage.full_path()) == Poco::DirectoryIterator()) + return res; + } + /// Если файлы не открыты, то открываем их. if (streams.empty()) for (Names::const_iterator it = column_names.begin(); it != column_names.end(); ++it) diff --git a/dbms/tests/queries/0_stateless/00068_empty_tiny_log.reference b/dbms/tests/queries/0_stateless/00068_empty_tiny_log.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql b/dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql new file mode 100644 index 00000000000..620f872a3d8 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00068_empty_tiny_log.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS test_empty_tiny_log(A UInt8) Engine = TinyLog; + +SELECT A FROM test_empty_tiny_log; + +DROP TABLE test_empty_tiny_log;