diff --git a/docs/en/operations/system-tables/tables.md b/docs/en/operations/system-tables/tables.md index d92db720f12dad6b18ec8d4dbb4b3c69cf49c9ef..f66eae1a431546148e01949d99e46c1b1dc13bbf 100644 --- a/docs/en/operations/system-tables/tables.md +++ b/docs/en/operations/system-tables/tables.md @@ -46,4 +46,8 @@ This table contains the following columns (the column type is shown in brackets) - If the table stores data on disk, returns used space on disk (i.e. compressed). - If the table stores data in memory, returns approximated number of used bytes in memory. +- `lifetime_rows` (Nullable(UInt64)) - Total number of rows INSERTed since server start. + +- `lifetime_bytes` (Nullable(UInt64)) - Total number of bytes INSERTed since server start. + The `system.tables` table is used in `SHOW TABLES` query implementation. diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index 55f90160ff0a37abeea942d92bcb7af6da1028cd..3022a234625d921ec9aeebdd599cbb5c14a36d5a 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -460,6 +460,16 @@ public: /// when considering in-memory blocks. virtual std::optional totalBytes() const { return {}; } + /// Number of rows INSERTed since server start. + /// + /// Does not takes underlying Storage (if any) into account. + virtual std::optional lifetimeRows() const { return {}; } + + /// Number of bytes INSERTed since server start. + /// + /// Does not takes underlying Storage (if any) into account. + virtual std::optional lifetimeBytes() const { return {}; } + private: /// Lock required for alter queries (lockForAlter). Always taken for write /// (actually can be replaced with std::mutex, but for consistency we use diff --git a/src/Storages/System/StorageSystemTables.cpp b/src/Storages/System/StorageSystemTables.cpp index 44d0d579157b2fb07e84299c6fb593cf8cb576df..b8a65183be18010069134dee6b6f1fac58f958be 100644 --- a/src/Storages/System/StorageSystemTables.cpp +++ b/src/Storages/System/StorageSystemTables.cpp @@ -55,6 +55,8 @@ StorageSystemTables::StorageSystemTables(const std::string & name_) {"storage_policy", std::make_shared()}, {"total_rows", std::make_shared(std::make_shared())}, {"total_bytes", std::make_shared(std::make_shared())}, + {"lifetime_rows", std::make_shared(std::make_shared())}, + {"lifetime_bytes", std::make_shared(std::make_shared())}, })); setInMemoryMetadata(storage_metadata); } @@ -223,6 +225,14 @@ protected: // total_bytes if (columns_mask[src_index++]) res_columns[res_index++]->insertDefault(); + + // lifetime_rows + if (columns_mask[src_index++]) + res_columns[res_index++]->insertDefault(); + + // lifetime_bytes + if (columns_mask[src_index++]) + res_columns[res_index++]->insertDefault(); } } @@ -430,6 +440,26 @@ protected: else res_columns[res_index++]->insertDefault(); } + + if (columns_mask[src_index++]) + { + assert(table != nullptr); + auto lifetime_rows = table->lifetimeRows(); + if (lifetime_rows) + res_columns[res_index++]->insert(*lifetime_rows); + else + res_columns[res_index++]->insertDefault(); + } + + if (columns_mask[src_index++]) + { + assert(table != nullptr); + auto lifetime_bytes = table->lifetimeBytes(); + if (lifetime_bytes) + res_columns[res_index++]->insert(*lifetime_bytes); + else + res_columns[res_index++]->insertDefault(); + } } }