Merge pull request #12638 from ianton-ru/selected_rows_event

Add SelectedRows and SelectedBytes events
This commit is contained in:
alexey-milovidov 2020-07-31 12:48:46 +03:00 committed by GitHub
commit 065db05665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 0 deletions

View File

@ -117,6 +117,8 @@
M(SelectedParts, "Number of data parts selected to read from a MergeTree table.") \ 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(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(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(Merge, "Number of launched background merges.") \
M(MergedRows, "Rows read for background merges. This is the number of rows before merge.") \ M(MergedRows, "Rows read for background merges. This is the number of rows before merge.") \

View File

@ -9,6 +9,8 @@
namespace ProfileEvents namespace ProfileEvents
{ {
extern const Event ThrottlerSleepMicroseconds; 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) if (quota && limits.mode == LIMITS_TOTAL)
quota->used({Quota::READ_ROWS, value.read_rows}, {Quota::READ_BYTES, value.read_bytes}); 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);
} }

View File

@ -3,6 +3,12 @@
#include <Interpreters/ProcessList.h> #include <Interpreters/ProcessList.h>
#include <Access/EnabledQuota.h> #include <Access/EnabledQuota.h>
namespace ProfileEvents
{
extern const Event SelectedRows;
extern const Event SelectedBytes;
}
namespace DB namespace DB
{ {
@ -107,6 +113,9 @@ void SourceWithProgress::progress(const Progress & value)
if (quota && limits.mode == LimitsMode::LIMITS_TOTAL) if (quota && limits.mode == LimitsMode::LIMITS_TOTAL)
quota->used({Quota::READ_ROWS, value.read_rows}, {Quota::READ_BYTES, value.read_bytes}); 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);
} }
} }

View File

@ -0,0 +1,7 @@
1
1
2
2
2 2
3
3

View File

@ -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;