diff --git a/dbms/src/Common/ProfileEvents.cpp b/dbms/src/Common/ProfileEvents.cpp index 947e3890078..6cbbc07d8d8 100644 --- a/dbms/src/Common/ProfileEvents.cpp +++ b/dbms/src/Common/ProfileEvents.cpp @@ -114,6 +114,7 @@ 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(Merge, "Number of launched background merges.") \ M(MergedRows, "Rows read for background merges. This is the number of rows before merge.") \ M(MergedUncompressedBytes, "Uncompressed bytes (for columns as they stored in memory) that was read for background merges. This is the number before merge.") \ M(MergesTimeMilliseconds, "Total time spent for background merges.")\ diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp b/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp index 83604f99dd1..df3720359d3 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp @@ -39,6 +39,7 @@ namespace ProfileEvents extern const Event MergedRows; extern const Event MergedUncompressedBytes; extern const Event MergesTimeMilliseconds; + extern const Event Merge; } namespace CurrentMetrics @@ -508,7 +509,10 @@ public: { ProfileEvents::increment(ProfileEvents::MergedUncompressedBytes, value.read_bytes); if (stage.is_first) + { ProfileEvents::increment(ProfileEvents::MergedRows, value.read_rows); + ProfileEvents::increment(ProfileEvents::Merge); + } updateWatch(); merge_entry->bytes_read_uncompressed += value.read_bytes; diff --git a/dbms/tests/queries/0_stateless/01014_count_of_merges_metrics.reference b/dbms/tests/queries/0_stateless/01014_count_of_merges_metrics.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01014_count_of_merges_metrics.reference @@ -0,0 +1 @@ +1 diff --git a/dbms/tests/queries/0_stateless/01014_count_of_merges_metrics.sql b/dbms/tests/queries/0_stateless/01014_count_of_merges_metrics.sql new file mode 100644 index 00000000000..85dd8707a90 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01014_count_of_merges_metrics.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS new_table_test; +DROP TABLE IF EXISTS check_table_test; + +CREATE TABLE new_table_test(name String) ENGINE = MergeTree ORDER BY name; +INSERT INTO new_table_test VALUES ('test'); +CREATE TABLE check_table_test(value1 UInt64, value2 UInt64) ENGINE = MergeTree ORDER BY tuple(); +INSERT INTO check_table_test (value1) SELECT value FROM system.events WHERE event = 'Merge'; +OPTIMIZE TABLE new_table_test FINAL; +INSERT INTO check_table_test (value2) SELECT value FROM system.events WHERE event = 'Merge'; +SELECT count() FROM check_table_test WHERE value2 > value1; + + +DROP TABLE new_table_test; +DROP TABLE check_table_test; diff --git a/docs/en/operations/system_tables.md b/docs/en/operations/system_tables.md index 5eae7ecd544..36008cffdc6 100644 --- a/docs/en/operations/system_tables.md +++ b/docs/en/operations/system_tables.md @@ -251,6 +251,8 @@ Columns: - `value` ([Int64](../data_types/int_uint.md)) — Metric value. - `description` ([String](../data_types/string.md)) — Metric description. +The list of supported metrics you can find in the [dbms/src/Common/CurrentMetrics.cpp](https://github.com/ClickHouse/ClickHouse/blob/master/dbms/src/Common/CurrentMetrics.cpp) source file of ClickHouse. + **Example** ```sql diff --git a/docs/zh/operations/table_engines/mergetree.md b/docs/zh/operations/table_engines/mergetree.md index 2afb50af155..4c35f3cf6b9 100644 --- a/docs/zh/operations/table_engines/mergetree.md +++ b/docs/zh/operations/table_engines/mergetree.md @@ -10,7 +10,7 @@ Clickhouse 中最强大的表引擎当属 `MergeTree` (合并树)引擎及 这让你可以创建一个用于快速检索数据的小稀疏索引。 -- 允许使用分区,如果指定了 [主键](custom_partitioning_key.md) 的话。 +- 允许使用分区,如果指定了 [分区键](custom_partitioning_key.md) 的话。 在相同数据集和相同结果集的情况下 ClickHouse 中某些带分区的操作会比普通操作更快。查询中指定了分区键时 ClickHouse 会自动截取分区数据。这也有效增加了查询性能。