鉴于这两个查询,我无法解释为什么,
SELECT YEAR(TIMESTAMP) AS YEAR,
MONTH(TIMESTAMP) AS MONTH,
DAY(TIMESTAMP) AS DAY,
COUNT(IDENTITY) AS number,
type
FROM entity AS e,
annotation AS a
WHERE e.annotationIdAnnotation = a.idAnnotation
AND type = "Location"
GROUP BY YEAR(TIMESTAMP),
MONTH(TIMESTAMP),
DAY(TIMESTAMP),
type
SELECT YEAR(TIMESTAMP) AS YEAR,
MONTH(TIMESTAMP) AS MONTH,
DAY(TIMESTAMP) AS DAY,
COUNT(IDENTITY) AS number
FROM entity AS e,
annotation AS a
WHERE e.annotationIdAnnotation = a.idAnnotation
AND type = "Location"
GROUP BY YEAR(TIMESTAMP),
MONTH(TIMESTAMP),
DAY(TIMESTAMP)
第二个比第一个多 100%。我有一个关于类型的 btree 索引,但我无法解释为什么对已经被 where 子句过滤的字段进行分组可以提高查询的性能。
提前致谢