@ -284,7 +284,15 @@ insert into test_mode select 1 from generate_series(1,1000) union all select 2;
create index on test_mode (a);
analyze test_mode;
prepare test_mode_pp (int) as select count(*) from test_mode where a = $1;
select name, generic_plans, custom_plans from pg_prepared_statements
where name = 'test_mode_pp';
name | generic_plans | custom_plans
--------------+---------------+--------------
test_mode_pp | 0 | 0
(1 row)
-- up to 5 executions, custom plan is used
set plan_cache_mode to auto;
explain (costs off) execute test_mode_pp(2);
QUERY PLAN
----------------------------------------------------------
@ -293,6 +301,13 @@ explain (costs off) execute test_mode_pp(2);
Index Cond: (a = 2)
(3 rows)
select name, generic_plans, custom_plans from pg_prepared_statements
where name = 'test_mode_pp';
name | generic_plans | custom_plans
--------------+---------------+--------------
test_mode_pp | 0 | 1
(1 row)
-- force generic plan
set plan_cache_mode to force_generic_plan;
explain (costs off) execute test_mode_pp(2);
@ -303,6 +318,13 @@ explain (costs off) execute test_mode_pp(2);
Filter: (a = $1)
(3 rows)
select name, generic_plans, custom_plans from pg_prepared_statements
where name = 'test_mode_pp';
name | generic_plans | custom_plans
--------------+---------------+--------------
test_mode_pp | 1 | 1
(1 row)
-- get to generic plan by 5 executions
set plan_cache_mode to auto;
execute test_mode_pp(1); -- 1x
@ -329,12 +351,26 @@ execute test_mode_pp(1); -- 4x
1000
(1 row)
select name, generic_plans, custom_plans from pg_prepared_statements
where name = 'test_mode_pp';
name | generic_plans | custom_plans
--------------+---------------+--------------
test_mode_pp | 1 | 5
(1 row)
execute test_mode_pp(1); -- 5x
count
-------
1000
(1 row)
select name, generic_plans, custom_plans from pg_prepared_statements
where name = 'test_mode_pp';
name | generic_plans | custom_plans
--------------+---------------+--------------
test_mode_pp | 2 | 5
(1 row)
-- we should now get a really bad plan
explain (costs off) execute test_mode_pp(2);
QUERY PLAN
@ -354,4 +390,11 @@ explain (costs off) execute test_mode_pp(2);
Index Cond: (a = 2)
(3 rows)
select name, generic_plans, custom_plans from pg_prepared_statements
where name = 'test_mode_pp';
name | generic_plans | custom_plans
--------------+---------------+--------------
test_mode_pp | 3 | 6
(1 row)
drop table test_mode;