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 ---------------+-------------- 0 | 10 (1 row) === plan used under auto === QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=26814.72..26814.73 rows=1 width=8) (actual time=132.005..132.008 rows=1.00 loops=1) -> Nested Loop (cost=5188.72..26689.72 rows=50000 width=9) (actual time=0.258..131.959 rows=500.00 loops=1) -> Function Scan on unnest g (cost=0.00..1.00 rows=100 width=4) (actual time=0.012..0.040 rows=100.00 loops=1) -> Hash Join (cost=5188.72..5398.72 rows=500 width=9) (actual time=0.164..1.317 rows=5.00 loops=100) Hash Cond: (k.id = e.lk_id) -> Seq Scan on pc_lk k (cost=0.00..155.00 rows=10000 width=13) (actual time=0.001..0.571 rows=10000.00 loops=100) -> Hash (cost=5182.47..5182.47 rows=500 width=4) (actual time=0.011..0.011 rows=5.00 loops=100) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Subquery Scan on e (cost=5176.22..5182.47 rows=500 width=4) (actual time=0.009..0.010 rows=5.00 loops=100) -> Limit (cost=5176.22..5177.47 rows=500 width=12) (actual time=0.009..0.010 rows=5.00 loops=100) -> Sort (cost=5176.22..5185.23 rows=3606 width=12) (actual time=0.009..0.009 rows=5.00 loops=100) Sort Key: e_1.ts DESC Sort Method: quicksort Memory: 25kB -> Bitmap Heap Scan on pc_ev e_1 (cost=44.37..4996.54 rows=3606 width=12) (actual time=0.004..0.007 rows=5.00 loops=100) Recheck Cond: (gid = g.id) Filter: ((ts <= '2026-03-31 00:00:00+00'::timestamp with time zone) AND (ts >= ('2026-03-31 00:00:00+00'::timestamp with time zone - '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 (20 rows) === generic plan === SET QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=50100.95..50100.96 rows=1 width=8) (actual time=2.184..2.186 rows=1.00 loops=1) -> Nested Loop (cost=4996.31..50100.50 rows=180 width=9) (actual time=0.043..2.148 rows=500.00 loops=1) -> Nested Loop (cost=4996.02..49964.29 rows=180 width=4) (actual time=0.033..0.952 rows=500.00 loops=1) -> Function Scan on unnest g (cost=0.00..0.10 rows=10 width=4) (actual time=0.011..0.019 rows=100.00 loops=1) -> Limit (cost=4996.01..4996.06 rows=18 width=12) (actual time=0.008..0.009 rows=5.00 loops=100) -> Sort (cost=4996.01..4996.06 rows=18 width=12) (actual time=0.008..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.006 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.002..0.002 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: 65.080 ms pc_f ------ 500 (1 row) Time: 65.069 ms pc_f ------ 500 (1 row) Time: 65.067 ms Timing is off. === SQL function, force_generic_plan: timed 3 === ALTER FUNCTION Timing is on. pc_f ------ 500 (1 row) Time: 2.402 ms pc_f ------ 500 (1 row) Time: 1.862 ms pc_f ------ 500 (1 row) Time: 1.802 ms Timing is off.