减少 ClickHouse 中的资源消耗

时间:2021-02-05 17:23:19

标签: clickhouse

桌子

CREATE TABLE events
(
    site_id UInt64,
    name    String
    -- other columns
)
ENGINE = CollapsingMergeTree(sign_flag)
PARTITION BY site_id
ORDER BY (name)
SETTINGS index_granularity = 8192;

查询

SELECT 'wtf',
       *
FROM events
WHERE site_id = 1 AND
      name = 'some_name'
LIMIT 100000;

日志

SELECT formatReadableSize(read_bytes)    AS read_bytes,
       formatReadableSize(memory_usage)  AS memory_usage,
       formatReadableQuantity(read_rows) AS read_rows,
       query_duration_ms / 1000 AS query_duration_sec,
       query
FROM system.query_log
WHERE query LIKE '%wtf%'
ORDER BY
    event_time DESC
LIMIT 100;
+------------+--------------+--------------+--------------------+
| read_bytes | memory_usage | read_rows    | query_duration_sec |
+------------+--------------+--------------+--------------------+
| 578.41 MiB | 131.95 MiB   | 1.01 million | 10.773             |
+------------+--------------+--------------+--------------------+

我认为日志中有非常大的数字。

如何优化它或者我错过了一些关于服务器配置的内容?

1 个答案:

答案 0 :(得分:1)

考虑定义另一个主键 - 为此查询 ORDER BY (name, site_id)

选择PK是设计中非常重要的一部分,选择正确的PK需要观察所有用例图。 查看更多详情: