result_cache

对查询结果进行缓存。

举例:

--  清理环境
DROP TABLE a CASCADE;

--  创建表
CREATE TABLE a(a1 INT primary key, a2 INT,a3 INT);

insert into a values(4,4,9);
insert into a values(3,3,9);
insert into a values(2,5,9);
insert into a values(8,2,9);
analyze a;


--  使用result_cache
explain analyze select /*+ result_cache */ * from a;
QUERY PLAN(text)      
----------------------
Result Cache  (cost=7.04..7.04 rows=4 width=12) (actual time=0.02..0.03 rows=4 loops=1)
  ->  Seq Scan on A  (cost=0.00..7.04 rows=4 width=12) (actual time=0.02..0.03 rows=4 loops=1)
Planning Time: 0.60 msec
Execution Time: 0.11 msec
总数目:4


--  不使用result_cache
explain analyze select * from a;
QUERY PLAN(text)      
----------------------
Seq Scan on A  (cost=0.00..7.04 rows=4 width=12) (actual time=0.02..0.04 rows=4 loops=1)
Planning Time: 0.17 msec
Execution Time: 0.12 msec
总数目:3

--  删除表
DROP TABLE a CASCADE;