数据库是postgres。
我在同一张桌子上有两个查询。这两个查询完全相同,只是一个在With记录中使用文本列siteid,另一个在With记录中使用smallint列sitegid。但是解释分析对使用smallint sitegid的查询返回了更长的估计。这对我来说没有意义。有谁知道为什么?
我在这里为这两个查询添加了解释分析输出的一部分。它们完全相同,除了实际用于groupAggregate的时间。不顾一切地寻求帮助。谢谢!
查询就像:
With records as (...)
SELECT source, siteid, observed_contingency_row, forecast_contingency_col,
count(*),sum(diff) as sum_error
FROM records
GROUP BY source, siteid, observed_contingency_row, forecast_contingency_col
ORDER BY source, siteid, observed_contingency_row, forecast_contingency_col
这是一个非常长的查询,无法在此处发布所有内容。
解释分析的输出是:
-> WindowAgg (cost=0.08..0.11 rows=1 width=74) (actual time=14.880..14.894 rows=15 loops=1)
-> Sort (cost=0.08..0.09 rows=1 width=74) (actual time=14.876..14.877 rows=15 loops=1)
Sort Key: records.observed_contingency_row, records.forecast_contingency_col
Sort Method: quicksort Memory: 27kB
-> GroupAggregate (cost=0.03..0.07 rows=1 width=74) (actual time=14.775..14.869 rows=15 loops=1)
Group Key: records.source, records.siteid, records.observed_contingency_row, records.forecast_contingency_col
-> Sort (cost=0.03..0.04 rows=1 width=74) (actual time=14.762..14.773 rows=176 loops=1)
Sort Key: records.source, records.siteid, records.observed_contingency_row, records.forecast_contingency_col
Sort Method: quicksort Memory: 38kB
-> CTE Scan on records (cost=0.00..0.02 rows=1 width=74) (actual time=10.664..14.306 rows=176 loops=1)
和
-> WindowAgg (cost=0.08..0.11 rows=1 width=74) (actual time=1558.508..1558.516 rows=15 loops=1)
-> Sort (cost=0.08..0.09 rows=1 width=74) (actual time=1558.503..1558.503 rows=15 loops=1)
Sort Key: records.observed_contingency_row, records.forecast_contingency_col
Sort Method: quicksort Memory: 27kB
-> GroupAggregate (cost=0.03..0.07 rows=1 width=74) (actual time=1558.403..1558.495 rows=15 loops=1)
Group Key: records.source, records.siteid, records.observed_contingency_row, records.forecast_contingency_col
-> Sort (cost=0.03..0.04 rows=1 width=74) (actual time=1558.388..1558.407 rows=176 loops=1)
Sort Key: records.source, records.siteid, records.observed_contingency_row, records.forecast_contingency_col
Sort Method: quicksort Memory: 38kB
-> CTE Scan on records (cost=0.00..0.02 rows=1 width=74) (actual time=7.106..1557.779 rows=176 loops=1)