db=> explain analyze with data as (select a, b, c from D where e='something') select * from Data;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------
Seq Scan on D (cost=0.00..3060987.06 rows=1955179 width=42) (actual time=0.022..81146.222 rows=2027407 loops=1)
Filter: ((e)::text = 'something'::text)
Rows Removed by Filter: 9757878
Planning Time: 0.083 ms
Execution Time: 89924.754 ms
(5 rows)
db=> explain analyze select * from (select a, b, c from D where e='something') x;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------
Seq Scan on documentsubjecthistory (cost=0.00..3060987.06 rows=1955179 width=42) (actual time=0.025..81148.606 rows=2027407 loops=1)
Filter: ((subjectentitycodesystem)::text = '2.16.840.1.113883.6.69'::text)
Rows Removed by Filter: 9757878
Planning Time: 0.105 ms
Execution Time: 89925.772 ms
(5 rows)
然而,当我实际运行第一个带有with Data (...) select * from Data
CTE 的程序时,结果实际上只在这 89 秒之后才出现,而当我运行时select * from (...) x
,我很快就得到了初始页面。
我\set FETCH_COUNT 1000
在.psqlrc中有