On Tue, Jan 30, 2024 at 1:20 PM David Rowley <dgrowle...@gmail.com> wrote: > You should likely focus on trying to find a test that does not require > making 2 tables with 10k rows.
Is 1k smallint OK? It should fit in one page. Still reproduces the error, and the entire test case runs in under 10 ms.
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index 8dbf790e89..2e1ec41a54 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -1470,7 +1470,7 @@ create_merge_append_path(PlannerInfo *root, root, pathkeys, subpath->total_cost, - subpath->parent->tuples, + subpath->rows, subpath->pathtarget->width, 0.0, work_mem, diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 56a40d50f9..7804333399 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -1716,6 +1716,28 @@ order by t1.b limit 10; reset enable_nestloop; drop table matest0 cascade; NOTICE: drop cascades to table matest1 +-- Check that merge append is chosen in presence of filters. +create table ma0(a smallint primary key); +create table ma1() inherits (ma0); +insert into ma0 select generate_series(1, 1000); +insert into ma1 select generate_series(1, 1000); +analyze ma0; +analyze ma1; +explain (costs off) select * from ma0 where a < 100 order by a; + QUERY PLAN +--------------------------------------------------- + Merge Append + Sort Key: ma0.a + -> Index Only Scan using ma0_pkey on ma0 ma0_1 + Index Cond: (a < 100) + -> Sort + Sort Key: ma0_2.a + -> Seq Scan on ma1 ma0_2 + Filter: (a < 100) +(8 rows) + +drop table ma0 cascade; +NOTICE: drop cascades to table ma1 -- -- Test merge-append for UNION ALL append relations -- diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index 971aac54fd..dae8cc7dbe 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -624,6 +624,19 @@ reset enable_nestloop; drop table matest0 cascade; +-- Check that merge append is chosen in presence of filters. +create table ma0(a smallint primary key); +create table ma1() inherits (ma0); +insert into ma0 select generate_series(1, 1000); +insert into ma1 select generate_series(1, 1000); +analyze ma0; +analyze ma1; + +explain (costs off) select * from ma0 where a < 100 order by a; + +drop table ma0 cascade; + + -- -- Test merge-append for UNION ALL append relations --