@@ -284,7 +284,15 @@ insert into test_mode select 1 from generate_series(1,1000) union all select 2;
284
284
create index on test_mode (a);
285
285
analyze test_mode;
286
286
prepare test_mode_pp (int) as select count(*) from test_mode where a = $1;
287
+ select name, generic_plans, custom_plans from pg_prepared_statements
288
+ where name = 'test_mode_pp';
289
+ name | generic_plans | custom_plans
290
+ --------------+---------------+--------------
291
+ test_mode_pp | 0 | 0
292
+ (1 row)
293
+
287
294
-- up to 5 executions, custom plan is used
295
+ set plan_cache_mode to auto;
288
296
explain (costs off) execute test_mode_pp(2);
289
297
QUERY PLAN
290
298
----------------------------------------------------------
@@ -293,6 +301,13 @@ explain (costs off) execute test_mode_pp(2);
293
301
Index Cond: (a = 2)
294
302
(3 rows)
295
303
304
+ select name, generic_plans, custom_plans from pg_prepared_statements
305
+ where name = 'test_mode_pp';
306
+ name | generic_plans | custom_plans
307
+ --------------+---------------+--------------
308
+ test_mode_pp | 0 | 1
309
+ (1 row)
310
+
296
311
-- force generic plan
297
312
set plan_cache_mode to force_generic_plan;
298
313
explain (costs off) execute test_mode_pp(2);
@@ -303,6 +318,13 @@ explain (costs off) execute test_mode_pp(2);
303
318
Filter: (a = $1)
304
319
(3 rows)
305
320
321
+ select name, generic_plans, custom_plans from pg_prepared_statements
322
+ where name = 'test_mode_pp';
323
+ name | generic_plans | custom_plans
324
+ --------------+---------------+--------------
325
+ test_mode_pp | 1 | 1
326
+ (1 row)
327
+
306
328
-- get to generic plan by 5 executions
307
329
set plan_cache_mode to auto;
308
330
execute test_mode_pp(1); -- 1x
@@ -329,12 +351,26 @@ execute test_mode_pp(1); -- 4x
329
351
1000
330
352
(1 row)
331
353
354
+ select name, generic_plans, custom_plans from pg_prepared_statements
355
+ where name = 'test_mode_pp';
356
+ name | generic_plans | custom_plans
357
+ --------------+---------------+--------------
358
+ test_mode_pp | 1 | 5
359
+ (1 row)
360
+
332
361
execute test_mode_pp(1); -- 5x
333
362
count
334
363
-------
335
364
1000
336
365
(1 row)
337
366
367
+ select name, generic_plans, custom_plans from pg_prepared_statements
368
+ where name = 'test_mode_pp';
369
+ name | generic_plans | custom_plans
370
+ --------------+---------------+--------------
371
+ test_mode_pp | 2 | 5
372
+ (1 row)
373
+
338
374
-- we should now get a really bad plan
339
375
explain (costs off) execute test_mode_pp(2);
340
376
QUERY PLAN
@@ -354,4 +390,11 @@ explain (costs off) execute test_mode_pp(2);
354
390
Index Cond: (a = 2)
355
391
(3 rows)
356
392
393
+ select name, generic_plans, custom_plans from pg_prepared_statements
394
+ where name = 'test_mode_pp';
395
+ name | generic_plans | custom_plans
396
+ --------------+---------------+--------------
397
+ test_mode_pp | 3 | 6
398
+ (1 row)
399
+
357
400
drop table test_mode;
0 commit comments