From 13ae87d2feee6aafd5a9f531365d87fce0f2d702 Mon Sep 17 00:00:00 2001 From: Zhong ShiHao Date: Mon, 7 Sep 2026 21:18:43 -0400 Subject: [PATCH v2 2/2] Lower generate_subscripts()'s prorows estimate to 10 With a support function in place, prorows is consulted only when that function declines: when the dimension number isn't known at plan time, or when a dimension above the first is requested for a non-constant array. The old value of 1000 has no particular justification. Use 10, which is what estimate_array_length() assumes for an array it knows nothing about, and hence what the dimension-one path already produces in that situation. --- src/include/catalog/pg_proc.dat | 4 ++-- src/test/regress/expected/planner_est.out | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index c1fa1984bd9..0c1debb26b3 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -1711,12 +1711,12 @@ proargtypes => 'anycompatiblearray anycompatible', prosrc => 'array_positions' }, { oid => '1191', descr => 'array subscripts generator', - proname => 'generate_subscripts', prorows => '1000', + proname => 'generate_subscripts', prorows => '10', prosupport => 'generate_subscripts_support', proretset => 't', prorettype => 'int4', proargtypes => 'anyarray int4 bool', prosrc => 'generate_subscripts' }, { oid => '1192', descr => 'array subscripts generator', - proname => 'generate_subscripts', prorows => '1000', + proname => 'generate_subscripts', prorows => '10', prosupport => 'generate_subscripts_support', proretset => 't', prorettype => 'int4', proargtypes => 'anyarray int4', prosrc => 'generate_subscripts_nodir' }, diff --git a/src/test/regress/expected/planner_est.out b/src/test/regress/expected/planner_est.out index 44eb5eeca32..64da9e2ca00 100644 --- a/src/test/regress/expected/planner_est.out +++ b/src/test/regress/expected/planner_est.out @@ -308,9 +308,9 @@ true, true, false, true); SELECT explain_mask_costs($$ SELECT * FROM generate_subscripts(ARRAY[1, 2, (SELECT 3)], (SELECT 1)) g(s);$$, false, true, false, true); - explain_mask_costs ------------------------------------------------------------------------ - Function Scan on generate_subscripts g (cost=N..N rows=1000 width=N) + explain_mask_costs +--------------------------------------------------------------------- + Function Scan on generate_subscripts g (cost=N..N rows=10 width=N) InitPlan expr_1 -> Result (cost=N..N rows=1 width=N) InitPlan expr_2 @@ -342,11 +342,11 @@ true, true, false, true); SELECT explain_mask_costs($$ SELECT * FROM subscript_table_1 t, LATERAL generate_subscripts(t.a, 2) g(s);$$, false, true, false, true); - explain_mask_costs ------------------------------------------------------------------------------ - Nested Loop (cost=N..N rows=100000 width=N) + explain_mask_costs +--------------------------------------------------------------------------- + Nested Loop (cost=N..N rows=1000 width=N) -> Seq Scan on subscript_table_1 t (cost=N..N rows=100 width=N) - -> Function Scan on generate_subscripts g (cost=N..N rows=1000 width=N) + -> Function Scan on generate_subscripts g (cost=N..N rows=10 width=N) (3 rows) RESET enable_memoize;