From 4d1385ef19d4594954433775f7a3774e78de5787 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 23 Oct 2020 21:11:55 +0300 Subject: [PATCH] Add total_rows/total_bytes support for Set/Join --- src/Storages/StorageJoin.cpp | 3 +++ src/Storages/StorageJoin.h | 3 +++ src/Storages/StorageSet.cpp | 4 +++- src/Storages/StorageSet.h | 3 +++ ...0753_system_columns_and_system_tables.reference | 6 ++++++ .../00753_system_columns_and_system_tables.sql | 14 ++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Storages/StorageJoin.cpp b/src/Storages/StorageJoin.cpp index 33c67229cf..c6d85174e6 100644 --- a/src/Storages/StorageJoin.cpp +++ b/src/Storages/StorageJoin.cpp @@ -100,7 +100,10 @@ HashJoinPtr StorageJoin::getJoin(std::shared_ptr analyzed_join) const void StorageJoin::insertBlock(const Block & block) { join->addJoinedBlock(block, true); } + size_t StorageJoin::getSize() const { return join->getTotalRowCount(); } +std::optional StorageJoin::totalRows() const { return join->getTotalRowCount(); } +std::optional StorageJoin::totalBytes() const { return join->getTotalByteCount(); } void registerStorageJoin(StorageFactory & factory) diff --git a/src/Storages/StorageJoin.h b/src/Storages/StorageJoin.h index 95037c4d33..857f364644 100644 --- a/src/Storages/StorageJoin.h +++ b/src/Storages/StorageJoin.h @@ -46,6 +46,9 @@ public: size_t max_block_size, unsigned num_streams) override; + std::optional totalRows() const override; + std::optional totalBytes() const override; + private: Block sample_block; const Names key_names; diff --git a/src/Storages/StorageSet.cpp b/src/Storages/StorageSet.cpp index d6d8b9e144..b7779d2e55 100644 --- a/src/Storages/StorageSet.cpp +++ b/src/Storages/StorageSet.cpp @@ -151,8 +151,10 @@ StorageSet::StorageSet( void StorageSet::insertBlock(const Block & block) { set->insertFromBlock(block); } void StorageSet::finishInsert() { set->finishInsert(); } -size_t StorageSet::getSize() const { return set->getTotalRowCount(); } +size_t StorageSet::getSize() const { return set->getTotalRowCount(); } +std::optional StorageSet::totalRows() const { return set->getTotalRowCount(); } +std::optional StorageSet::totalBytes() const { return set->getTotalByteCount(); } void StorageSet::truncate(const ASTPtr &, const StorageMetadataPtr & metadata_snapshot, const Context &, TableExclusiveLockHolder &) { diff --git a/src/Storages/StorageSet.h b/src/Storages/StorageSet.h index 40d7925de1..98677dcfb1 100644 --- a/src/Storages/StorageSet.h +++ b/src/Storages/StorageSet.h @@ -72,6 +72,9 @@ public: void truncate(const ASTPtr &, const StorageMetadataPtr & metadata_snapshot, const Context &, TableExclusiveLockHolder &) override; + std::optional totalRows() const override; + std::optional totalBytes() const override; + private: SetPtr set; diff --git a/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference b/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference index 4d1fab83cc..12af231d18 100644 --- a/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference +++ b/tests/queries/0_stateless/00753_system_columns_and_system_tables.reference @@ -39,3 +39,9 @@ Check lifetime_bytes/lifetime_rows for Buffer 200 100 200 100 402 201 +Check total_bytes/total_rows for Set +2048 50 +2048 100 +Check total_bytes/total_rows for Join +10240 50 +10240 100 diff --git a/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql b/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql index 9b9fa04e6b..862e3693f0 100644 --- a/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql +++ b/tests/queries/0_stateless/00753_system_columns_and_system_tables.sql @@ -112,3 +112,17 @@ INSERT INTO check_system_tables SELECT * FROM numbers_mt(101); -- direct block w SELECT lifetime_bytes, lifetime_rows FROM system.tables WHERE name = 'check_system_tables'; DROP TABLE check_system_tables; DROP TABLE check_system_tables_null; + +SELECT 'Check total_bytes/total_rows for Set'; +CREATE TABLE check_system_tables Engine=Set() AS SELECT * FROM numbers(50); +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +INSERT INTO check_system_tables SELECT number+50 FROM numbers(50); +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +DROP TABLE check_system_tables; + +SELECT 'Check total_bytes/total_rows for Join'; +CREATE TABLE check_system_tables Engine=Join(ANY, LEFT, number) AS SELECT * FROM numbers(50); +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +INSERT INTO check_system_tables SELECT number+50 FROM numbers(50); +SELECT total_bytes, total_rows FROM system.tables WHERE name = 'check_system_tables'; +DROP TABLE check_system_tables; -- GitLab