提交 433fdffc 编写于 作者: A Azat Khuzhin

Add lifetime_rows/lifetime_bytes interface (exported via system.tables)

上级 84c93a6b
......@@ -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.
......@@ -460,6 +460,16 @@ public:
/// when considering in-memory blocks.
virtual std::optional<UInt64> totalBytes() const { return {}; }
/// Number of rows INSERTed since server start.
///
/// Does not takes underlying Storage (if any) into account.
virtual std::optional<UInt64> lifetimeRows() const { return {}; }
/// Number of bytes INSERTed since server start.
///
/// Does not takes underlying Storage (if any) into account.
virtual std::optional<UInt64> 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
......
......@@ -55,6 +55,8 @@ StorageSystemTables::StorageSystemTables(const std::string & name_)
{"storage_policy", std::make_shared<DataTypeString>()},
{"total_rows", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>())},
{"total_bytes", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>())},
{"lifetime_rows", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>())},
{"lifetime_bytes", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>())},
}));
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();
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册