clickhouse - ClickHouse MergeTree 使用 ORDER BY 进行慢速选择
问题描述
我开始学习 CH 并且在尝试提高查询速度时似乎遇到了死胡同,表是这样创建的
CREATE TABLE default.stats(
aa String,
ab String,
user_id UInt16,
ac UInt32,
ad UInt8,
ae UInt8,
created_time DateTime,
created_date Date,
af UInt8,
ag UInt32,
ah UInt32,
ai String,
aj String)
ENGINE = MergeTree
PARTITION BY toYYYYMM(created_time)
ORDER BY(created_time, user_id)
我正在运行这样的查询
SELECT ad, created_time, ab, aa, user_id, ac, ag, af
FROM stats
WHERE user_id = 1 AND lowerUTF8(ab) = 'xxxxxxxxx' AND ad != 12
ORDER BY created_time DESC
LIMIT 50 OFFSET 0
这是集合中 50 行的结果。经过:2.881 秒。处理了 7462 万行
如果我在没有订单部分的情况下运行相同的查询,则设置为 50 行。经过:0.020 秒。处理了 49150 行
如果理论上查询只需要订购大约 10k(所有返回的行没有限制)行,为什么它似乎处理了表中的所有行?我错过了什么和/或如何提高 CH 的速度?
解决方案
尝试 ORDER BY created_time DESC, user_id
optimize_read_in_order 功能在 ClickHouse 版本 19.14.3.3 中实现,2019-09-10
推荐阅读
- node.js - NodeJs TypeError:无法读取未定义的属性“键”
- activejdbc - 无法在 Gitlab CI 上通过测试
- jquery - Summernote 初始化后如何更改选项?
- javascript - onTouch 事件不起作用
- firebase - Google Firebase 中的自定义身份验证
- c# - UWP 可见性绑定不起作用(mvvmlight)
- c++ - 使用 Visual Studio 代码读取 C++ 中读取的输入流时出错
- c - 在 sprintf 中隐藏整数
- php - 如何安排 API 调用和数据库更新
- python - 如何使用 Python 从 Excel 列中提取重复的变量?