From a5ac39b564745c6a1a652e933de62ab4317ac3e5 Mon Sep 17 00:00:00 2001 From: hchen9 Date: Wed, 30 Sep 2020 16:47:42 -0700 Subject: [PATCH] Pass Context parameter for IStorage.totalRows and IStorage.totalBytes --- src/Interpreters/InterpreterSelectQuery.cpp | 2 +- src/Storages/IStorage.h | 4 ++-- src/Storages/StorageBuffer.cpp | 6 +++--- src/Storages/StorageBuffer.h | 4 ++-- src/Storages/StorageMemory.cpp | 4 ++-- src/Storages/StorageMemory.h | 4 ++-- src/Storages/StorageMergeTree.cpp | 4 ++-- src/Storages/StorageMergeTree.h | 4 ++-- src/Storages/StorageNull.h | 4 ++-- src/Storages/System/StorageSystemTables.cpp | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Interpreters/InterpreterSelectQuery.cpp b/src/Interpreters/InterpreterSelectQuery.cpp index 8c0643f78d7..96844223b1c 100644 --- a/src/Interpreters/InterpreterSelectQuery.cpp +++ b/src/Interpreters/InterpreterSelectQuery.cpp @@ -1125,7 +1125,7 @@ void InterpreterSelectQuery::executeFetchColumns( { const auto & desc = query_analyzer->aggregates()[0]; const auto & func = desc.function; - std::optional num_rows = storage->totalRows(); + std::optional num_rows = storage->totalRows(context); if (num_rows) { AggregateFunctionCount & agg_count = static_cast(*func); diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index dc7c684d5b4..7ddab4fa8a4 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -455,7 +455,7 @@ public: /// - For total_rows column in system.tables /// /// Does takes underlying Storage (if any) into account. - virtual std::optional totalRows() const { return {}; } + virtual std::optional totalRows(const Context &) const { return {}; } /// If it is possible to quickly determine exact number of bytes for the table on storage: /// - memory (approximated, resident) @@ -470,7 +470,7 @@ public: /// Memory part should be estimated as a resident memory size. /// In particular, alloctedBytes() is preferable over bytes() /// when considering in-memory blocks. - virtual std::optional totalBytes() const { return {}; } + virtual std::optional totalBytes(const Context &) const { return {}; } /// Number of rows INSERTed since server start. /// diff --git a/src/Storages/StorageBuffer.cpp b/src/Storages/StorageBuffer.cpp index 5b9957f4ed4..720ca90327d 100644 --- a/src/Storages/StorageBuffer.cpp +++ b/src/Storages/StorageBuffer.cpp @@ -793,13 +793,13 @@ void StorageBuffer::checkAlterIsPossible(const AlterCommands & commands, const S } } -std::optional StorageBuffer::totalRows() const +std::optional StorageBuffer::totalRows(const Context & context) const { std::optional underlying_rows; auto underlying = DatabaseCatalog::instance().tryGetTable(destination_id, global_context); if (underlying) - underlying_rows = underlying->totalRows(); + underlying_rows = underlying->totalRows(context); if (!underlying_rows) return underlying_rows; @@ -812,7 +812,7 @@ std::optional StorageBuffer::totalRows() const return rows + *underlying_rows; } -std::optional StorageBuffer::totalBytes() const +std::optional StorageBuffer::totalBytes(const Context & /*context*/) const { UInt64 bytes = 0; for (const auto & buffer : buffers) diff --git a/src/Storages/StorageBuffer.h b/src/Storages/StorageBuffer.h index 8f1354399ef..593e394fb46 100644 --- a/src/Storages/StorageBuffer.h +++ b/src/Storages/StorageBuffer.h @@ -94,8 +94,8 @@ public: /// The structure of the subordinate table is not checked and does not change. void alter(const AlterCommands & params, const Context & context, TableLockHolder & table_lock_holder) override; - std::optional totalRows() const override; - std::optional totalBytes() const override; + std::optional totalRows(const Context & context) const override; + std::optional totalBytes(const Context & context) const override; std::optional lifetimeRows() const override { return writes.rows; } std::optional lifetimeBytes() const override { return writes.bytes; } diff --git a/src/Storages/StorageMemory.cpp b/src/Storages/StorageMemory.cpp index 25e232dc4ad..0be49ee7bd3 100644 --- a/src/Storages/StorageMemory.cpp +++ b/src/Storages/StorageMemory.cpp @@ -210,7 +210,7 @@ void StorageMemory::truncate( data.clear(); } -std::optional StorageMemory::totalRows() const +std::optional StorageMemory::totalRows(const Context &) const { UInt64 rows = 0; std::lock_guard lock(mutex); @@ -219,7 +219,7 @@ std::optional StorageMemory::totalRows() const return rows; } -std::optional StorageMemory::totalBytes() const +std::optional StorageMemory::totalBytes(const Context &) const { UInt64 bytes = 0; std::lock_guard lock(mutex); diff --git a/src/Storages/StorageMemory.h b/src/Storages/StorageMemory.h index e67e3015028..586be298808 100644 --- a/src/Storages/StorageMemory.h +++ b/src/Storages/StorageMemory.h @@ -45,8 +45,8 @@ public: void truncate(const ASTPtr &, const StorageMetadataPtr &, const Context &, TableExclusiveLockHolder &) override; - std::optional totalRows() const override; - std::optional totalBytes() const override; + std::optional totalRows(const Context &) const override; + std::optional totalBytes(const Context &) const override; /** Delays initialization of StorageMemory::read() until the first read is actually happen. * Usually, fore code like this: diff --git a/src/Storages/StorageMergeTree.cpp b/src/Storages/StorageMergeTree.cpp index 347474753dc..fc907edb43e 100644 --- a/src/Storages/StorageMergeTree.cpp +++ b/src/Storages/StorageMergeTree.cpp @@ -184,12 +184,12 @@ Pipe StorageMergeTree::read( context, max_block_size, num_streams); } -std::optional StorageMergeTree::totalRows() const +std::optional StorageMergeTree::totalRows(const Context &) const { return getTotalActiveSizeInRows(); } -std::optional StorageMergeTree::totalBytes() const +std::optional StorageMergeTree::totalBytes(const Context &) const { return getTotalActiveSizeInBytes(); } diff --git a/src/Storages/StorageMergeTree.h b/src/Storages/StorageMergeTree.h index 5662f9e0088..162321668a2 100644 --- a/src/Storages/StorageMergeTree.h +++ b/src/Storages/StorageMergeTree.h @@ -46,8 +46,8 @@ public: size_t max_block_size, unsigned num_streams) override; - std::optional totalRows() const override; - std::optional totalBytes() const override; + std::optional totalRows(const Context &) const override; + std::optional totalBytes(const Context &) const override; BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override; diff --git a/src/Storages/StorageNull.h b/src/Storages/StorageNull.h index b5387c6b924..db2d169b7dd 100644 --- a/src/Storages/StorageNull.h +++ b/src/Storages/StorageNull.h @@ -46,11 +46,11 @@ public: void alter(const AlterCommands & params, const Context & context, TableLockHolder & table_lock_holder) override; - std::optional totalRows() const override + std::optional totalRows(const Context &) const override { return {0}; } - std::optional totalBytes() const override + std::optional totalBytes(const Context &) const override { return {0}; } diff --git a/src/Storages/System/StorageSystemTables.cpp b/src/Storages/System/StorageSystemTables.cpp index 0ad961ad7d8..dabf4685b29 100644 --- a/src/Storages/System/StorageSystemTables.cpp +++ b/src/Storages/System/StorageSystemTables.cpp @@ -430,7 +430,7 @@ protected: if (columns_mask[src_index++]) { assert(table != nullptr); - auto total_rows = table->totalRows(); + auto total_rows = table->totalRows(context); if (total_rows) res_columns[res_index++]->insert(*total_rows); else @@ -440,7 +440,7 @@ protected: if (columns_mask[src_index++]) { assert(table != nullptr); - auto total_bytes = table->totalBytes(); + auto total_bytes = table->totalBytes(context); if (total_bytes) res_columns[res_index++]->insert(*total_bytes); else