我有一个表(postgres 9.6),它按日期划分为大约 70 个子表。
EXPLAIN下面的输出被截断,因为它的大部分是每个子表的相同位图索引/堆扫描(这里是完整的详细输出)。我感兴趣的部分是树顶部附近的Append和Result节点。
Append只是所有子查询的总和。事实上,它需要比这长约 3.5 秒。多余的从哪里来?Resultwhich states当您的查询选择某个常量值时,将使用此操作。此节点大约需要 7 秒,但查询未选择常量值。如果可能的话,我很想节省这 10 秒,但我实际上并不知道这些节点在做什么,所以我不知道该尝试什么。
EXPLAIN ANALYZE 输出:
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
? QUERY PLAN ?
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
? HashAggregate (cost=4459946.40..4473566.96 rows=1089645 width=64) (actual time=26289.308..26419.989 rows=190112 loops=1) ?
? Group Key: frontend_prescription.processing_date, frontend_prescription.pct_id, substr((frontend_prescription.presentation_code)::text, 1, 9) ?
? Buffers: shared hit=172527 ?
? -> Result (cost=0.00..4296499.68 rows=10896448 width=60) …Run Code Online (Sandbox Code Playgroud)