在我的 Crate.io 数据库中,我有一个表,目前有 50 mio 行,大小为 16GB。如果我尝试使用以下语句获取每天的条目数量,则一切正常(性能除外,但这目前不应该是问题):
SELECT
date_format('%Y-%m-%d', date_trunc('day', "days")) AS "Day",
count(*) AS "Count"
FROM "doc"."mytable"
WHERE
date_format('%Y-%m-%d', date_trunc('day', "days")) BETWEEN date_format('%Y-%m-%d', date_trunc('day', current_timestamp + -2592000000))
AND date_format('%Y-%m-%d', date_trunc('day', current_timestamp + -86400000))
GROUP BY date_format('%Y-%m-%d', date_trunc('day', "days"))
ORDER BY date_format('%Y-%m-%d', date_trunc('day', "days")) ASC limit 100;
但是,如果我尝试在另一列这样区分:
SELECT
date_format('%Y-%m-%d', date_trunc('day', "days")) AS "Day",
count(DISTINCT customerid) AS "Count"
FROM "doc"."mytable"
WHERE
date_format('%Y-%m-%d', date_trunc('day', "days")) BETWEEN date_format('%Y-%m-%d', date_trunc('day', current_timestamp + -2592000000))
AND date_format('%Y-%m-%d', date_trunc('day', current_timestamp + -86400000))
GROUP BY date_format('%Y-%m-%d', date_trunc('day', "days"))
ORDER BY date_format('%Y-%m-%d', date_trunc('day', "days")) ASC limit 100;
该语句将失败
SQLActionException[CircuitBreakingException: [query] 数据太大,[collect: 0] 的数据将大于 [1267571097/1.1gb] 的限制]
有谁知道为什么 COUNT(DISTINCT col) 有太多数据的问题,但 COUNT(*) 没有?我该如何解决这个问题?