psql:repro_e2e.sql:19: NOTICE: function pc_f(pg_catalog.int4[],timestamptz) does not exist, skipping psql:repro_e2e.sql:20: NOTICE: table "pc_ev" does not exist, skipping psql:repro_e2e.sql:20: NOTICE: table "pc_lk" does not exist, skipping PREPARE === 10 executions with plan_cache_mode = auto === generic_plans | custom_plans ---------------+-------------- 5 | 5 (1 row) === plan used under auto === QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=50100.95..50100.96 rows=1 width=8) (actual time=2.011..2.013 rows=1.00 loops=1) -> Nested Loop (cost=4996.31..50100.50 rows=180 width=9) (actual time=0.036..1.976 rows=500.00 loops=1) -> Nested Loop (cost=4996.02..49964.29 rows=180 width=4) (actual time=0.030..0.914 rows=500.00 loops=1) -> Function Scan on unnest g (cost=0.00..0.10 rows=10 width=4) (actual time=0.009..0.016 rows=100.00 loops=1) -> Limit (cost=4996.01..4996.06 rows=18 width=12) (actual time=0.008..0.008 rows=5.00 loops=100) -> Sort (cost=4996.01..4996.06 rows=18 width=12) (actual time=0.007..0.008 rows=5.00 loops=100) Sort Key: e.ts DESC Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on pc_ev e (cost=43.47..4995.64 rows=18 width=12) (actual time=0.003..0.005 rows=5.00 loops=100) Recheck Cond: (gid = g.id) Filter: ((ts <= $2) AND (ts >= ($2 - '90 days'::interval))) Heap Blocks: exact=372 -> Bitmap Index Scan on pc_ev_gid_idx (cost=0.00..43.47 rows=3606 width=0) (actual time=0.002..0.002 rows=5.00 loops=100) Index Cond: (gid = g.id) Index Searches: 100 -> Memoize (cost=0.30..6.98 rows=1 width=13) (actual time=0.002..0.002 rows=1.00 loops=500) Cache Key: e.lk_id Cache Mode: logical Hits: 0 Misses: 500 Evictions: 0 Overflows: 0 Memory Usage: 57kB -> Index Scan using pc_lk_pkey on pc_lk k (cost=0.29..6.97 rows=1 width=13) (actual time=0.001..0.001 rows=1.00 loops=500) Index Cond: (id = e.lk_id) Index Searches: 500 (22 rows) === generic plan === SET QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=50100.95..50100.96 rows=1 width=8) (actual time=1.988..1.989 rows=1.00 loops=1) -> Nested Loop (cost=4996.31..50100.50 rows=180 width=9) (actual time=0.033..1.952 rows=500.00 loops=1) -> Nested Loop (cost=4996.02..49964.29 rows=180 width=4) (actual time=0.028..0.917 rows=500.00 loops=1) -> Function Scan on unnest g (cost=0.00..0.10 rows=10 width=4) (actual time=0.009..0.016 rows=100.00 loops=1) -> Limit (cost=4996.01..4996.06 rows=18 width=12) (actual time=0.008..0.008 rows=5.00 loops=100) -> Sort (cost=4996.01..4996.06 rows=18 width=12) (actual time=0.007..0.008 rows=5.00 loops=100) Sort Key: e.ts DESC Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on pc_ev e (cost=43.47..4995.64 rows=18 width=12) (actual time=0.003..0.005 rows=5.00 loops=100) Recheck Cond: (gid = g.id) Filter: ((ts <= $2) AND (ts >= ($2 - '90 days'::interval))) Heap Blocks: exact=372 -> Bitmap Index Scan on pc_ev_gid_idx (cost=0.00..43.47 rows=3606 width=0) (actual time=0.002..0.002 rows=5.00 loops=100) Index Cond: (gid = g.id) Index Searches: 100 -> Memoize (cost=0.30..6.98 rows=1 width=13) (actual time=0.002..0.002 rows=1.00 loops=500) Cache Key: e.lk_id Cache Mode: logical Hits: 0 Misses: 500 Evictions: 0 Overflows: 0 Memory Usage: 57kB -> Index Scan using pc_lk_pkey on pc_lk k (cost=0.29..6.97 rows=1 width=13) (actual time=0.001..0.001 rows=1.00 loops=500) Index Cond: (id = e.lk_id) Index Searches: 500 (22 rows) RESET CREATE FUNCTION === SQL function, auto: 10 calls, then timed 3 === Timing is on. pc_f ------ 500 (1 row) Time: 1.895 ms pc_f ------ 500 (1 row) Time: 1.827 ms pc_f ------ 500 (1 row) Time: 1.827 ms Timing is off. === SQL function, force_generic_plan: timed 3 === ALTER FUNCTION Timing is on. pc_f ------ 500 (1 row) Time: 2.126 ms pc_f ------ 500 (1 row) Time: 1.837 ms pc_f ------ 500 (1 row) Time: 1.822 ms Timing is off.