Add total_rows to the system.tables

This commit is contained in:
Azat Khuzhin 2020-03-29 11:06:07 +03:00
parent b66f2efc9e
commit 2489481a46
2 changed files with 22 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <Columns/ColumnsNumber.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataStreams/OneBlockInputStream.h>
#include <Storages/System/StorageSystemTables.h>
#include <Storages/VirtualColumnUtils.h>
@ -49,6 +50,7 @@ StorageSystemTables::StorageSystemTables(const std::string & name_)
{"primary_key", std::make_shared<DataTypeString>()},
{"sampling_key", std::make_shared<DataTypeString>()},
{"storage_policy", std::make_shared<DataTypeString>()},
{"total_rows", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt64>())},
}));
}
@ -204,6 +206,10 @@ protected:
// storage_policy
if (columns_mask[src_index++])
res_columns[res_index++]->insertDefault();
// total_rows
if (columns_mask[src_index++])
res_columns[res_index++]->insertDefault();
}
}
@ -379,6 +385,16 @@ protected:
else
res_columns[res_index++]->insertDefault();
}
if (columns_mask[src_index++])
{
assert(table != nullptr);
auto total_rows = table->totalRows();
if (total_rows)
res_columns[res_index++]->insert(*total_rows);
else
res_columns[res_index++]->insertDefault();
}
}
}

View File

@ -934,6 +934,12 @@ This table contains the following columns (the column type is shown in brackets)
- `sorting_key` (String) - The sorting key expression specified in the table.
- `primary_key` (String) - The primary key expression specified in the table.
- `sampling_key` (String) - The sampling key expression specified in the table.
- `storage_policy` (String) - The storage policy:
- [MergeTree](table_engines/mergetree.md#table_engine-mergetree-multiple-volumes)
- [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).
The `system.tables` table is used in `SHOW TABLES` query implementation.