我使用这个查询创建了一个物化视图
CREATE MATERIALIZED VIEW db.top_ids_mv (
`date_time` DateTime,
`id` String,
`total` UInt64
) ENGINE = SummingMergeTree
ORDER BY
(date_time, id) SETTINGS index_granularity = 8192 POPULATE AS
SELECT
toDateTime((intDiv(toUInt32(date_time), 60 * 60) * 60) * 60) AS date_time,
id AS id,
count(*) AS count
FROM
db.table
WHERE
type = 'user'
GROUP BY
date_time,id
我的表包含近 180 亿条记录。我已经使用POPULATE
. 但是新插入的数据并没有被插入到这个物化视图中。我创建了许多其他视图,它们运行良好,但这会产生问题。
这是我在日志中收到的内容
2021.09.23 19:54:54.424457 [ 137949 ] {5b0f3c32-2900-4ce4-996d-b9696bd38568} <Trace> PushingToViewsBlockOutputStream: Pushing (sequentially) from db.table (15229c91-c202-4809-9522-9c91c2028809) to db.top_ids_mv (0cedb783-bf17-42eb-8ced-b783bf1742eb) took 0 ms.
我注意到的一件事是它需要 0 毫秒。我认为这是错误的,因为查询必须花费一些时间。
谢谢。任何帮助,将不胜感激
total UInt64 <----> count(*) AS count
-- 名称不匹配。您的 Mat.View 将 0 插入total
,count
无处可去。由于原因,两者都是预期的并且是专门实施的。
https://den-crane.github.io/Everything_you_should_know_about_materialized_views_commented.pdf
...
SELECT
toDateTime((intDiv(toUInt32(date_time), 60 * 60) * 60) * 60) AS date_time,
id AS id,
count(*) AS total --<<<<<------
FROM
db.table
...
为了查询性能和更好的数据压缩,我会做
ENGINE = SummingMergeTree
ORDER BY ( id, date_time ) --- order id , time
还可以尝试编解码器
`date_time` DateTime CODEC(Delta, LZ4),
`id` LowCardinality(String),
`total` UInt64 CODEC(T64, LZ4)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句