Add total_bytes to the system.tables

This commit is contained in:
Azat Khuzhin 2020-03-29 11:58:39 +03:00
parent fe9a638540
commit 997c4682aa
2 changed files with 19 additions and 0 deletions

View File

@ -51,6 +51,7 @@ StorageSystemTables::StorageSystemTables(const std::string & name_)
{"sampling_key", std::make_shared<DataTypeString>()},
{"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>())},
}));
}
@ -210,6 +211,10 @@ protected:
// total_rows
if (columns_mask[src_index++])
res_columns[res_index++]->insertDefault();
// total_bytes
if (columns_mask[src_index++])
res_columns[res_index++]->insertDefault();
}
}
@ -395,6 +400,16 @@ protected:
else
res_columns[res_index++]->insertDefault();
}
if (columns_mask[src_index++])
{
assert(table != nullptr);
auto total_bytes = table->totalBytes();
if (total_bytes)
res_columns[res_index++]->insert(*total_bytes);
else
res_columns[res_index++]->insertDefault();
}
}
}

View File

@ -940,6 +940,10 @@ This table contains the following columns (the column type is shown in brackets)
- [Distributed](table_engines/distributed.md#distributed)
- `total_rows` (Nullable(UInt64)) - Total number of rows, if it is possible to quickly determine exact number of rows in the table, otherwise `Null` (including underying `Buffer` table).
- `total_bytes` (Nullable(UInt64)) - Total number of bytes, if it is possible to quickly determine exact number of bytes for the table on storage, otherwise `Null` (**does not** includes any underlying storage).
- 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.
The `system.tables` table is used in `SHOW TABLES` query implementation.