11--
22-- Tests to exercise the plan caching/invalidation mechanism
33--
4- CREATE TEMP TABLE foo AS SELECT * FROM int8_tbl;
4+ CREATE TEMP TABLE pcachetest AS SELECT * FROM int8_tbl;
55-- create and use a cached plan
6- PREPARE prepstmt AS SELECT * FROM foo ;
6+ PREPARE prepstmt AS SELECT * FROM pcachetest ;
77EXECUTE prepstmt;
88 q1 | q2
99------------------+-------------------
@@ -15,7 +15,7 @@ EXECUTE prepstmt;
1515(5 rows)
1616
1717-- and one with parameters
18- PREPARE prepstmt2(bigint) AS SELECT * FROM foo WHERE q1 = $1;
18+ PREPARE prepstmt2(bigint) AS SELECT * FROM pcachetest WHERE q1 = $1;
1919EXECUTE prepstmt2(123);
2020 q1 | q2
2121-----+------------------
@@ -24,14 +24,14 @@ EXECUTE prepstmt2(123);
2424(2 rows)
2525
2626-- invalidate the plans and see what happens
27- DROP TABLE foo ;
27+ DROP TABLE pcachetest ;
2828EXECUTE prepstmt;
29- ERROR: relation "foo " does not exist
29+ ERROR: relation "pcachetest " does not exist
3030EXECUTE prepstmt2(123);
31- ERROR: relation "foo " does not exist
31+ ERROR: relation "pcachetest " does not exist
3232-- recreate the temp table (this demonstrates that the raw plan is
3333-- purely textual and doesn't depend on OIDs, for instance)
34- CREATE TEMP TABLE foo AS SELECT * FROM int8_tbl ORDER BY 2;
34+ CREATE TEMP TABLE pcachetest AS SELECT * FROM int8_tbl ORDER BY 2;
3535EXECUTE prepstmt;
3636 q1 | q2
3737------------------+-------------------
@@ -51,13 +51,13 @@ EXECUTE prepstmt2(123);
5151
5252-- prepared statements should prevent change in output tupdesc,
5353-- since clients probably aren't expecting that to change on the fly
54- ALTER TABLE foo ADD COLUMN q3 bigint;
54+ ALTER TABLE pcachetest ADD COLUMN q3 bigint;
5555EXECUTE prepstmt;
5656ERROR: cached plan must not change result type
5757EXECUTE prepstmt2(123);
5858ERROR: cached plan must not change result type
5959-- but we're nice guys and will let you undo your mistake
60- ALTER TABLE foo DROP COLUMN q3;
60+ ALTER TABLE pcachetest DROP COLUMN q3;
6161EXECUTE prepstmt;
6262 q1 | q2
6363------------------+-------------------
@@ -77,8 +77,9 @@ EXECUTE prepstmt2(123);
7777
7878-- Try it with a view, which isn't directly used in the resulting plan
7979-- but should trigger invalidation anyway
80- CREATE TEMP VIEW voo AS SELECT * FROM foo;
81- PREPARE vprep AS SELECT * FROM voo;
80+ CREATE TEMP VIEW pcacheview AS
81+ SELECT * FROM pcachetest;
82+ PREPARE vprep AS SELECT * FROM pcacheview;
8283EXECUTE vprep;
8384 q1 | q2
8485------------------+-------------------
@@ -89,7 +90,8 @@ EXECUTE vprep;
8990 4567890123456789 | 4567890123456789
9091(5 rows)
9192
92- CREATE OR REPLACE TEMP VIEW voo AS SELECT q1, q2/2 AS q2 FROM foo;
93+ CREATE OR REPLACE TEMP VIEW pcacheview AS
94+ SELECT q1, q2/2 AS q2 FROM pcachetest;
9395EXECUTE vprep;
9496 q1 | q2
9597------------------+-------------------
0 commit comments