diff --git a/src/Common/ProfileEvents.cpp b/src/Common/ProfileEvents.cpp index eceb082f524..908adbe1d12 100644 --- a/src/Common/ProfileEvents.cpp +++ b/src/Common/ProfileEvents.cpp @@ -117,6 +117,8 @@ M(SelectedParts, "Number of data parts selected to read from a MergeTree table.") \ M(SelectedRanges, "Number of (non-adjacent) ranges in all data parts selected to read from a MergeTree table.") \ M(SelectedMarks, "Number of marks (index granules) selected to read from a MergeTree table.") \ + M(SelectedRows, "Number of rows SELECTed from all tables.") \ + M(SelectedBytes, "Number of bytes (uncompressed; for columns as they stored in memory) SELECTed from all tables.") \ \ M(Merge, "Number of launched background merges.") \ M(MergedRows, "Rows read for background merges. This is the number of rows before merge.") \ diff --git a/src/DataStreams/IBlockInputStream.cpp b/src/DataStreams/IBlockInputStream.cpp index 66c747207e8..94f7544480a 100644 --- a/src/DataStreams/IBlockInputStream.cpp +++ b/src/DataStreams/IBlockInputStream.cpp @@ -9,6 +9,8 @@ namespace ProfileEvents { extern const Event ThrottlerSleepMicroseconds; + extern const Event SelectedRows; + extern const Event SelectedBytes; } @@ -263,6 +265,9 @@ void IBlockInputStream::progressImpl(const Progress & value) if (quota && limits.mode == LIMITS_TOTAL) quota->used({Quota::READ_ROWS, value.read_rows}, {Quota::READ_BYTES, value.read_bytes}); } + + ProfileEvents::increment(ProfileEvents::SelectedRows, value.read_rows); + ProfileEvents::increment(ProfileEvents::SelectedBytes, value.read_bytes); } diff --git a/src/Processors/Sources/SourceWithProgress.cpp b/src/Processors/Sources/SourceWithProgress.cpp index 6488289d5ce..d6972f99369 100644 --- a/src/Processors/Sources/SourceWithProgress.cpp +++ b/src/Processors/Sources/SourceWithProgress.cpp @@ -3,6 +3,12 @@ #include #include +namespace ProfileEvents +{ + extern const Event SelectedRows; + extern const Event SelectedBytes; +} + namespace DB { @@ -107,6 +113,9 @@ void SourceWithProgress::progress(const Progress & value) if (quota && limits.mode == LimitsMode::LIMITS_TOTAL) quota->used({Quota::READ_ROWS, value.read_rows}, {Quota::READ_BYTES, value.read_bytes}); } + + ProfileEvents::increment(ProfileEvents::SelectedRows, value.read_rows); + ProfileEvents::increment(ProfileEvents::SelectedBytes, value.read_bytes); } } diff --git a/tests/queries/0_stateless/01413_rows_events.reference b/tests/queries/0_stateless/01413_rows_events.reference new file mode 100644 index 00000000000..7779d718461 --- /dev/null +++ b/tests/queries/0_stateless/01413_rows_events.reference @@ -0,0 +1,7 @@ +1 +1 +2 +2 +2 2 +3 +3 diff --git a/tests/queries/0_stateless/01413_rows_events.sql b/tests/queries/0_stateless/01413_rows_events.sql new file mode 100644 index 00000000000..375502d4976 --- /dev/null +++ b/tests/queries/0_stateless/01413_rows_events.sql @@ -0,0 +1,31 @@ +DROP TABLE IF EXISTS rows_events_test; +CREATE TABLE rows_events_test (k UInt32, v UInt32) ENGINE = MergeTree ORDER BY k; + +SYSTEM FLUSH LOGS; +TRUNCATE TABLE system.query_log; +INSERT INTO rows_events_test VALUES (1,1); +SYSTEM FLUSH LOGS; +SELECT written_rows FROM system.query_log WHERE query LIKE 'INSERT INTO rows_events_test%' AND type=2; +SELECT value FROM ( + SELECT ProfileEvents.Names as name, ProfileEvents.Values as value FROM system.query_log ARRAY JOIN ProfileEvents WHERE query LIKE 'INSERT INTO rows_events_test%' AND type=2 +) WHERE name='InsertedRows'; + +SYSTEM FLUSH LOGS; +TRUNCATE TABLE system.query_log; +INSERT INTO rows_events_test VALUES (2,2), (3,3); +SYSTEM FLUSH LOGS; +SELECT written_rows FROM system.query_log WHERE query LIKE 'INSERT INTO rows_events_test%' AND type=2; +SELECT value FROM ( + SELECT ProfileEvents.Names as name, ProfileEvents.Values as value FROM system.query_log ARRAY JOIN ProfileEvents WHERE query LIKE 'INSERT INTO rows_events_test%' AND type=2 +) WHERE name='InsertedRows'; + +SYSTEM FLUSH LOGS; +TRUNCATE TABLE system.query_log; +SELECT * FROM rows_events_test WHERE v = 2; +SYSTEM FLUSH LOGS; +SELECT read_rows FROM system.query_log WHERE query LIKE 'SELECT * FROM rows_events_test%' AND type=2; +SELECT value FROM ( + SELECT ProfileEvents.Names as name, ProfileEvents.Values as value FROM system.query_log ARRAY JOIN ProfileEvents WHERE query LIKE 'SELECT * FROM rows_events_test%' AND type=2 +) WHERE name='SelectedRows'; + +DROP TABLE rows_events_test;