|
|
|
@ -278,3 +278,80 @@ drop table pc_list_part_1; |
|
|
|
|
execute pstmt_def_insert(1); |
|
|
|
|
drop table pc_list_parted, pc_list_part_null; |
|
|
|
|
deallocate pstmt_def_insert; |
|
|
|
|
-- Test plan_cache_mode |
|
|
|
|
create table test_mode (a int); |
|
|
|
|
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; |
|
|
|
|
-- up to 5 executions, custom plan is used |
|
|
|
|
explain (costs off) execute test_mode_pp(2); |
|
|
|
|
QUERY PLAN |
|
|
|
|
---------------------------------------------------------- |
|
|
|
|
Aggregate |
|
|
|
|
-> Index Only Scan using test_mode_a_idx on test_mode |
|
|
|
|
Index Cond: (a = 2) |
|
|
|
|
(3 rows) |
|
|
|
|
|
|
|
|
|
-- force generic plan |
|
|
|
|
set plan_cache_mode to force_generic_plan; |
|
|
|
|
explain (costs off) execute test_mode_pp(2); |
|
|
|
|
QUERY PLAN |
|
|
|
|
----------------------------- |
|
|
|
|
Aggregate |
|
|
|
|
-> Seq Scan on test_mode |
|
|
|
|
Filter: (a = $1) |
|
|
|
|
(3 rows) |
|
|
|
|
|
|
|
|
|
-- get to generic plan by 5 executions |
|
|
|
|
set plan_cache_mode to auto; |
|
|
|
|
execute test_mode_pp(1); -- 1x |
|
|
|
|
count |
|
|
|
|
------- |
|
|
|
|
1000 |
|
|
|
|
(1 row) |
|
|
|
|
|
|
|
|
|
execute test_mode_pp(1); -- 2x |
|
|
|
|
count |
|
|
|
|
------- |
|
|
|
|
1000 |
|
|
|
|
(1 row) |
|
|
|
|
|
|
|
|
|
execute test_mode_pp(1); -- 3x |
|
|
|
|
count |
|
|
|
|
------- |
|
|
|
|
1000 |
|
|
|
|
(1 row) |
|
|
|
|
|
|
|
|
|
execute test_mode_pp(1); -- 4x |
|
|
|
|
count |
|
|
|
|
------- |
|
|
|
|
1000 |
|
|
|
|
(1 row) |
|
|
|
|
|
|
|
|
|
execute test_mode_pp(1); -- 5x |
|
|
|
|
count |
|
|
|
|
------- |
|
|
|
|
1000 |
|
|
|
|
(1 row) |
|
|
|
|
|
|
|
|
|
-- we should now get a really bad plan |
|
|
|
|
explain (costs off) execute test_mode_pp(2); |
|
|
|
|
QUERY PLAN |
|
|
|
|
----------------------------- |
|
|
|
|
Aggregate |
|
|
|
|
-> Seq Scan on test_mode |
|
|
|
|
Filter: (a = $1) |
|
|
|
|
(3 rows) |
|
|
|
|
|
|
|
|
|
-- but we can force a custom plan |
|
|
|
|
set plan_cache_mode to force_custom_plan; |
|
|
|
|
explain (costs off) execute test_mode_pp(2); |
|
|
|
|
QUERY PLAN |
|
|
|
|
---------------------------------------------------------- |
|
|
|
|
Aggregate |
|
|
|
|
-> Index Only Scan using test_mode_a_idx on test_mode |
|
|
|
|
Index Cond: (a = 2) |
|
|
|
|
(3 rows) |
|
|
|
|
|
|
|
|
|
drop table test_mode; |
|
|
|
|