From 1cf174cf627306250540533cc58be9315352e25a Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@vondra.me>
Date: Wed, 25 Nov 2026 13:47:05 +0100
Subject: [PATCH v7 11/30] GEQO: Add a starjoin_geqo test for star queries
 planned by GEQO

A FROM list of tables is never split into join search subproblems, so
with the default settings a star query with 11 or more dimensions is
planned by GEQO, even though the canonical order makes the number of
joinrels in the standard join search linear in the number of dimensions.
And GEQO evaluates a fixed number of join orders, so the pruning only
adds overhead.

The checks detect GEQO by setting geqo_pool_size so large that GEQO
fails to allocate the population.  Also move the starjoin_other check
that GEQO uses the canonical order into the new test.

Update STARJOINS.md, adding the issue and the test.
---
 STARJOINS.md                                 |  13 ++
 src/test/regress/expected/starjoin_geqo.out  | 192 +++++++++++++++++++
 src/test/regress/expected/starjoin_other.out |  23 +--
 src/test/regress/parallel_schedule           |   2 +-
 src/test/regress/sql/starjoin_geqo.sql       | 187 ++++++++++++++++++
 src/test/regress/sql/starjoin_other.sql      |  19 +-
 6 files changed, 403 insertions(+), 33 deletions(-)
 create mode 100644 src/test/regress/expected/starjoin_geqo.out
 create mode 100644 src/test/regress/sql/starjoin_geqo.sql

diff --git a/STARJOINS.md b/STARJOINS.md
index 5505085dc4c..578548de587 100644
--- a/STARJOINS.md
+++ b/STARJOINS.md
@@ -381,6 +381,16 @@ the plans, the planning cost, or the regression tests.
   the multiplied rows.  The clauseless_first_cost_higher check in
   starjoin_other shows this, for a star with two scans of a 2-row table
   without join clauses.
+- A FROM list of tables is never split into join search subproblems, so
+  with the default settings a star with 11 or more dimensions is planned
+  by GEQO, even though the canonical order makes the number of joinrels
+  in the standard join search linear in the number of dimensions.  For a
+  star with 11 dimensions, planning takes 20ms with the GUC enabled
+  (18ms with the GUC disabled), while the standard join search takes
+  0.3ms (the star_list_standard_search check in starjoin_geqo).
+- GEQO evaluates a fixed number of join orders, so enforcing the
+  canonical order in GEQO only adds overhead, and the GUC changes the
+  GEQO plans (the geqo_plan_unaffected check in starjoin_geqo).
 
 ## Regression tests
 
@@ -422,3 +432,6 @@ the plans, the planning cost, or the regression tests.
   with a sample of a dimension estimated to have a single row (which the
   canonical order would join last), and that the join search for a
   sampled fact is still pruned.
+- starjoin_geqo checks which star queries are planned by GEQO, and how
+  the GUC affects their plans.  It detects GEQO by setting
+  `geqo_pool_size` so large that GEQO fails to allocate the population.
diff --git a/src/test/regress/expected/starjoin_geqo.out b/src/test/regress/expected/starjoin_geqo.out
new file mode 100644
index 00000000000..5e0369616cd
--- /dev/null
+++ b/src/test/regress/expected/starjoin_geqo.out
@@ -0,0 +1,192 @@
+--
+-- Checks for star queries and GEQO with enable_starjoin_ordering
+--
+-- The standard join search joins the dimensions of a star to the fact only
+-- in the canonical order, so it considers only d+1 of the 2^d subsets of the
+-- d dimensions.  But a star with more rels than geqo_threshold is planned by
+-- GEQO, even though the standard join search would be much cheaper.  And the
+-- pruning does not make GEQO any cheaper, because GEQO evaluates a fixed
+-- number of join orders, each joining all the rels.  Checking the canonical
+-- order only adds overhead.
+--
+-- Each check is a single boolean, phrased as the desired behavior.  EXPLAIN
+-- does not show whether a query was planned by GEQO, so the checks detect
+-- GEQO by making it fail (see starjoin_geqo_used).
+--
+SET max_parallel_workers_per_gather = 0;
+-- the plan (without costs), with enable_starjoin_ordering enabled/disabled
+CREATE FUNCTION starjoin_geqo_plan(query text, starjoin bool) RETURNS text
+LANGUAGE plpgsql AS $$
+DECLARE
+  plan json;
+BEGIN
+  PERFORM set_config('enable_starjoin_ordering', starjoin::text, true);
+  EXECUTE 'EXPLAIN (COSTS OFF, FORMAT JSON) ' || query INTO plan;
+  RETURN plan::text;
+END;
+$$;
+-- is the query planned by GEQO? (with enable_starjoin_ordering
+-- enabled/disabled)  GEQO fails to allocate a population this large, while
+-- the standard join search ignores geqo_pool_size.
+CREATE FUNCTION starjoin_geqo_used(query text, starjoin bool) RETURNS bool
+LANGUAGE plpgsql SET geqo_pool_size = 100000000 AS $$
+BEGIN
+  PERFORM set_config('enable_starjoin_ordering', starjoin::text, true);
+  EXECUTE 'EXPLAIN ' || query;
+  RETURN false;
+EXCEPTION WHEN internal_error THEN
+  IF SQLERRM NOT LIKE 'invalid memory alloc request size %' THEN
+    RAISE;
+  END IF;
+  RETURN true;
+END;
+$$;
+-- star with 10 dimensions d1-d10 and a table "a" referenced by the fact (an
+-- 11th dimension), and a table c1 joined to the fact on its primary key (not
+-- a dimension, as there's no foreign key)
+CREATE TABLE starjoin_geqo_a (id int PRIMARY KEY, v int) WITH (autovacuum_enabled = off);
+INSERT INTO starjoin_geqo_a SELECT i, i FROM generate_series(1, 100) i;
+CREATE TABLE starjoin_geqo_c1 (id int PRIMARY KEY, v int) WITH (autovacuum_enabled = off);
+INSERT INTO starjoin_geqo_c1 SELECT i, i FROM generate_series(1, 100) i;
+DO $$
+BEGIN
+  FOR i IN 1..10 LOOP
+    EXECUTE format('CREATE TABLE starjoin_geqo_d%s (id int PRIMARY KEY, v int) WITH (autovacuum_enabled = off)', i);
+    EXECUTE format('INSERT INTO starjoin_geqo_d%s SELECT i, i FROM generate_series(1, 100) i', i);
+  END LOOP;
+END;
+$$;
+CREATE TABLE starjoin_geqo_f (id int PRIMARY KEY, a int NOT NULL,
+  d1 int NOT NULL, d2 int NOT NULL, d3 int NOT NULL, d4 int NOT NULL,
+  d5 int NOT NULL, d6 int NOT NULL, d7 int NOT NULL, d8 int NOT NULL,
+  d9 int NOT NULL, d10 int NOT NULL) WITH (autovacuum_enabled = off);
+INSERT INTO starjoin_geqo_f
+SELECT i, 1 + i % 100, 1 + (i * 3) % 100, 1 + (i * 7) % 100, 1 + (i * 11) % 100,
+       1 + (i * 13) % 100, 1 + (i * 17) % 100, 1 + (i * 19) % 100,
+       1 + (i * 23) % 100, 1 + (i * 29) % 100, 1 + (i * 31) % 100,
+       1 + (i * 37) % 100
+  FROM generate_series(1, 1000) i;
+-- add the foreign keys after loading the data (faster than checking each row)
+ALTER TABLE starjoin_geqo_f
+  ADD FOREIGN KEY (a) REFERENCES starjoin_geqo_a,
+  ADD FOREIGN KEY (d1) REFERENCES starjoin_geqo_d1,
+  ADD FOREIGN KEY (d2) REFERENCES starjoin_geqo_d2,
+  ADD FOREIGN KEY (d3) REFERENCES starjoin_geqo_d3,
+  ADD FOREIGN KEY (d4) REFERENCES starjoin_geqo_d4,
+  ADD FOREIGN KEY (d5) REFERENCES starjoin_geqo_d5,
+  ADD FOREIGN KEY (d6) REFERENCES starjoin_geqo_d6,
+  ADD FOREIGN KEY (d7) REFERENCES starjoin_geqo_d7,
+  ADD FOREIGN KEY (d8) REFERENCES starjoin_geqo_d8,
+  ADD FOREIGN KEY (d9) REFERENCES starjoin_geqo_d9,
+  ADD FOREIGN KEY (d10) REFERENCES starjoin_geqo_d10;
+VACUUM ANALYZE starjoin_geqo_a, starjoin_geqo_c1, starjoin_geqo_d1,
+  starjoin_geqo_d2, starjoin_geqo_d3, starjoin_geqo_d4, starjoin_geqo_d5,
+  starjoin_geqo_d6, starjoin_geqo_d7, starjoin_geqo_d8, starjoin_geqo_d9,
+  starjoin_geqo_d10, starjoin_geqo_f;
+--
+-- Star with explicit joins
+--
+-- With join_collapse_limit = 20 the star with 10 dimensions (11 rels) is a
+-- single subproblem, above geqo_threshold = 8, so it's planned by GEQO,
+-- which joins the dimensions in the canonical order too.
+--
+SELECT $$
+SELECT count(*) FROM starjoin_geqo_f AS f
+  JOIN starjoin_geqo_d1 AS d1 ON f.d1 = d1.id
+  JOIN starjoin_geqo_d2 AS d2 ON f.d2 = d2.id
+  JOIN starjoin_geqo_d3 AS d3 ON f.d3 = d3.id
+  JOIN starjoin_geqo_d4 AS d4 ON f.d4 = d4.id
+  JOIN starjoin_geqo_d5 AS d5 ON f.d5 = d5.id
+  JOIN starjoin_geqo_d6 AS d6 ON f.d6 = d6.id
+  JOIN starjoin_geqo_d7 AS d7 ON f.d7 = d7.id
+  JOIN starjoin_geqo_d8 AS d8 ON f.d8 = d8.id
+  JOIN starjoin_geqo_d9 AS d9 ON f.d9 = d9.id
+  JOIN starjoin_geqo_d10 AS d10 ON f.d10 = d10.id
+$$ AS q_star \gset
+-- the plan with the canonical order, forced by join_collapse_limit = 1
+SET join_collapse_limit = 1;
+SELECT starjoin_geqo_plan(:'q_star', true) AS plan_canonical \gset
+SET join_collapse_limit = 20;
+SET geqo_threshold = 8;
+-- GEQO uses the canonical order
+SELECT starjoin_geqo_plan(:'q_star', true) = :'plan_canonical' AS geqo_plan_canonical;
+ geqo_plan_canonical 
+---------------------
+ t
+(1 row)
+
+RESET geqo_threshold;
+RESET join_collapse_limit;
+--
+-- Star in a FROM list
+--
+-- A FROM list of tables is never split into subproblems (join_collapse_limit
+-- applies to explicit joins, from_collapse_limit to subqueries), so with the
+-- default settings a star with 11 dimensions (12 rels) is planned by GEQO,
+-- and it's pruned too.
+--
+SELECT $$
+SELECT count(*)
+  FROM starjoin_geqo_f AS f, starjoin_geqo_a AS a,
+       starjoin_geqo_d1 AS d1, starjoin_geqo_d2 AS d2,
+       starjoin_geqo_d3 AS d3, starjoin_geqo_d4 AS d4,
+       starjoin_geqo_d5 AS d5, starjoin_geqo_d6 AS d6,
+       starjoin_geqo_d7 AS d7, starjoin_geqo_d8 AS d8,
+       starjoin_geqo_d9 AS d9, starjoin_geqo_d10 AS d10
+ WHERE f.a = a.id AND f.d1 = d1.id AND f.d2 = d2.id AND f.d3 = d3.id
+   AND f.d4 = d4.id AND f.d5 = d5.id AND f.d6 = d6.id AND f.d7 = d7.id
+   AND f.d8 = d8.id AND f.d9 = d9.id AND f.d10 = d10.id
+$$ AS q_star_list \gset
+-- the same star, with another rel (c1) joined to the fact
+SELECT $$
+SELECT count(*)
+  FROM starjoin_geqo_f AS f, starjoin_geqo_a AS a,
+       starjoin_geqo_d1 AS d1, starjoin_geqo_d2 AS d2,
+       starjoin_geqo_d3 AS d3, starjoin_geqo_d4 AS d4,
+       starjoin_geqo_d5 AS d5, starjoin_geqo_d6 AS d6,
+       starjoin_geqo_d7 AS d7, starjoin_geqo_d8 AS d8,
+       starjoin_geqo_d9 AS d9, starjoin_geqo_d10 AS d10,
+       starjoin_geqo_c1 AS c1
+ WHERE f.a = a.id AND f.d1 = d1.id AND f.d2 = d2.id AND f.d3 = d3.id
+   AND f.d4 = d4.id AND f.d5 = d5.id AND f.d6 = d6.id AND f.d7 = d7.id
+   AND f.d8 = d8.id AND f.d9 = d9.id AND f.d10 = d10.id AND f.id = c1.id
+$$ AS q_star_list_c1 \gset
+-- with the GUC disabled, GEQO is used as usual
+SELECT starjoin_geqo_used(:'q_star_list', false) AS star_list_geqo_off;
+ star_list_geqo_off 
+--------------------
+ t
+(1 row)
+
+-- XXX the dimensions count towards geqo_threshold
+SELECT NOT starjoin_geqo_used(:'q_star_list', true) AS star_list_standard_search;
+ star_list_standard_search 
+---------------------------
+ f
+(1 row)
+
+-- the star with c1 has two rels other than the dimensions, so with
+-- geqo_threshold = 2 it's planned by GEQO
+SET geqo_threshold = 2;
+SELECT starjoin_geqo_used(:'q_star_list_c1', true) AS star_list_c1_geqo;
+ star_list_c1_geqo 
+-------------------
+ t
+(1 row)
+
+-- XXX GEQO is pruned too, so the GUC changes the plan
+SELECT starjoin_geqo_plan(:'q_star_list_c1', true)
+       = starjoin_geqo_plan(:'q_star_list_c1', false) AS geqo_plan_unaffected;
+ geqo_plan_unaffected 
+----------------------
+ f
+(1 row)
+
+RESET geqo_threshold;
+RESET max_parallel_workers_per_gather;
+DROP FUNCTION starjoin_geqo_plan(text, bool);
+DROP FUNCTION starjoin_geqo_used(text, bool);
+DROP TABLE starjoin_geqo_f, starjoin_geqo_a, starjoin_geqo_c1,
+  starjoin_geqo_d1, starjoin_geqo_d2, starjoin_geqo_d3, starjoin_geqo_d4,
+  starjoin_geqo_d5, starjoin_geqo_d6, starjoin_geqo_d7, starjoin_geqo_d8,
+  starjoin_geqo_d9, starjoin_geqo_d10;
diff --git a/src/test/regress/expected/starjoin_other.out b/src/test/regress/expected/starjoin_other.out
index f3050b6dbf4..3efe1b3dd2a 100644
--- a/src/test/regress/expected/starjoin_other.out
+++ b/src/test/regress/expected/starjoin_other.out
@@ -1,6 +1,7 @@
 --
 -- Checks for various other cases with enable_starjoin_ordering (the
--- planning failures are covered by starjoin_reproducers).
+-- planning failures are covered by starjoin_reproducers, and GEQO by
+-- starjoin_geqo).
 --
 -- Each check is a single boolean, so that the output does not depend on
 -- platform-specific costs or memory usage.  Some checks show known
@@ -439,7 +440,9 @@ SELECT starjoin_other_memory(:'q_exists', true)
 -- Star split into subproblems
 --
 -- With the default join_collapse_limit, the star with 10 dimensions is split
--- into two subproblems, and the canonical order is enforced in both.
+-- into two subproblems, and the canonical order is enforced in both.  The
+-- checks with GEQO (and with the whole star in a single subproblem above
+-- geqo_threshold) are in starjoin_geqo.
 --
 SELECT starjoin_other_memory(:'q_star', true)
        < starjoin_other_memory(:'q_star', false) * 0.5 AS split_search_pruned;
@@ -448,22 +451,6 @@ SELECT starjoin_other_memory(:'q_star', true)
  t
 (1 row)
 
---
--- GEQO
---
--- The canonical order is enforced by GEQO too.
---
-SET join_collapse_limit = 20;
-SET geqo_threshold = 8;
--- GEQO uses the canonical order
-SELECT starjoin_other_plan(:'q_star', true) = :'plan_canonical' AS geqo_plan_canonical;
- geqo_plan_canonical 
----------------------
- t
-(1 row)
-
-RESET geqo_threshold;
-RESET join_collapse_limit;
 --
 -- Overhead in subproblems unrelated to the star
 --
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index ae5a40811f2..b27463614ff 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -149,7 +149,7 @@ test: event_trigger_login
 test: fast_default
 
 # some tests for starjoin planning
-test: starjoin_planning starjoin_eager starjoin_plan starjoin_width starjoin_reproducers starjoin_other starjoin_sample
+test: starjoin_planning starjoin_eager starjoin_plan starjoin_width starjoin_reproducers starjoin_other starjoin_sample starjoin_geqo
 
 # more expensive tests for starjoin planning (larger variants of earlier tests)
 # test: starjoin_eager_large starjoin_plan_large starjoin_width_large
diff --git a/src/test/regress/sql/starjoin_geqo.sql b/src/test/regress/sql/starjoin_geqo.sql
new file mode 100644
index 00000000000..e815f48b142
--- /dev/null
+++ b/src/test/regress/sql/starjoin_geqo.sql
@@ -0,0 +1,187 @@
+--
+-- Checks for star queries and GEQO with enable_starjoin_ordering
+--
+-- The standard join search joins the dimensions of a star to the fact only
+-- in the canonical order, so it considers only d+1 of the 2^d subsets of the
+-- d dimensions.  But a star with more rels than geqo_threshold is planned by
+-- GEQO, even though the standard join search would be much cheaper.  And the
+-- pruning does not make GEQO any cheaper, because GEQO evaluates a fixed
+-- number of join orders, each joining all the rels.  Checking the canonical
+-- order only adds overhead.
+--
+-- Each check is a single boolean, phrased as the desired behavior.  EXPLAIN
+-- does not show whether a query was planned by GEQO, so the checks detect
+-- GEQO by making it fail (see starjoin_geqo_used).
+--
+
+SET max_parallel_workers_per_gather = 0;
+
+-- the plan (without costs), with enable_starjoin_ordering enabled/disabled
+CREATE FUNCTION starjoin_geqo_plan(query text, starjoin bool) RETURNS text
+LANGUAGE plpgsql AS $$
+DECLARE
+  plan json;
+BEGIN
+  PERFORM set_config('enable_starjoin_ordering', starjoin::text, true);
+  EXECUTE 'EXPLAIN (COSTS OFF, FORMAT JSON) ' || query INTO plan;
+  RETURN plan::text;
+END;
+$$;
+
+-- is the query planned by GEQO? (with enable_starjoin_ordering
+-- enabled/disabled)  GEQO fails to allocate a population this large, while
+-- the standard join search ignores geqo_pool_size.
+CREATE FUNCTION starjoin_geqo_used(query text, starjoin bool) RETURNS bool
+LANGUAGE plpgsql SET geqo_pool_size = 100000000 AS $$
+BEGIN
+  PERFORM set_config('enable_starjoin_ordering', starjoin::text, true);
+  EXECUTE 'EXPLAIN ' || query;
+  RETURN false;
+EXCEPTION WHEN internal_error THEN
+  IF SQLERRM NOT LIKE 'invalid memory alloc request size %' THEN
+    RAISE;
+  END IF;
+  RETURN true;
+END;
+$$;
+
+-- star with 10 dimensions d1-d10 and a table "a" referenced by the fact (an
+-- 11th dimension), and a table c1 joined to the fact on its primary key (not
+-- a dimension, as there's no foreign key)
+CREATE TABLE starjoin_geqo_a (id int PRIMARY KEY, v int) WITH (autovacuum_enabled = off);
+INSERT INTO starjoin_geqo_a SELECT i, i FROM generate_series(1, 100) i;
+
+CREATE TABLE starjoin_geqo_c1 (id int PRIMARY KEY, v int) WITH (autovacuum_enabled = off);
+INSERT INTO starjoin_geqo_c1 SELECT i, i FROM generate_series(1, 100) i;
+
+DO $$
+BEGIN
+  FOR i IN 1..10 LOOP
+    EXECUTE format('CREATE TABLE starjoin_geqo_d%s (id int PRIMARY KEY, v int) WITH (autovacuum_enabled = off)', i);
+    EXECUTE format('INSERT INTO starjoin_geqo_d%s SELECT i, i FROM generate_series(1, 100) i', i);
+  END LOOP;
+END;
+$$;
+
+CREATE TABLE starjoin_geqo_f (id int PRIMARY KEY, a int NOT NULL,
+  d1 int NOT NULL, d2 int NOT NULL, d3 int NOT NULL, d4 int NOT NULL,
+  d5 int NOT NULL, d6 int NOT NULL, d7 int NOT NULL, d8 int NOT NULL,
+  d9 int NOT NULL, d10 int NOT NULL) WITH (autovacuum_enabled = off);
+
+INSERT INTO starjoin_geqo_f
+SELECT i, 1 + i % 100, 1 + (i * 3) % 100, 1 + (i * 7) % 100, 1 + (i * 11) % 100,
+       1 + (i * 13) % 100, 1 + (i * 17) % 100, 1 + (i * 19) % 100,
+       1 + (i * 23) % 100, 1 + (i * 29) % 100, 1 + (i * 31) % 100,
+       1 + (i * 37) % 100
+  FROM generate_series(1, 1000) i;
+
+-- add the foreign keys after loading the data (faster than checking each row)
+ALTER TABLE starjoin_geqo_f
+  ADD FOREIGN KEY (a) REFERENCES starjoin_geqo_a,
+  ADD FOREIGN KEY (d1) REFERENCES starjoin_geqo_d1,
+  ADD FOREIGN KEY (d2) REFERENCES starjoin_geqo_d2,
+  ADD FOREIGN KEY (d3) REFERENCES starjoin_geqo_d3,
+  ADD FOREIGN KEY (d4) REFERENCES starjoin_geqo_d4,
+  ADD FOREIGN KEY (d5) REFERENCES starjoin_geqo_d5,
+  ADD FOREIGN KEY (d6) REFERENCES starjoin_geqo_d6,
+  ADD FOREIGN KEY (d7) REFERENCES starjoin_geqo_d7,
+  ADD FOREIGN KEY (d8) REFERENCES starjoin_geqo_d8,
+  ADD FOREIGN KEY (d9) REFERENCES starjoin_geqo_d9,
+  ADD FOREIGN KEY (d10) REFERENCES starjoin_geqo_d10;
+
+VACUUM ANALYZE starjoin_geqo_a, starjoin_geqo_c1, starjoin_geqo_d1,
+  starjoin_geqo_d2, starjoin_geqo_d3, starjoin_geqo_d4, starjoin_geqo_d5,
+  starjoin_geqo_d6, starjoin_geqo_d7, starjoin_geqo_d8, starjoin_geqo_d9,
+  starjoin_geqo_d10, starjoin_geqo_f;
+
+--
+-- Star with explicit joins
+--
+-- With join_collapse_limit = 20 the star with 10 dimensions (11 rels) is a
+-- single subproblem, above geqo_threshold = 8, so it's planned by GEQO,
+-- which joins the dimensions in the canonical order too.
+--
+SELECT $$
+SELECT count(*) FROM starjoin_geqo_f AS f
+  JOIN starjoin_geqo_d1 AS d1 ON f.d1 = d1.id
+  JOIN starjoin_geqo_d2 AS d2 ON f.d2 = d2.id
+  JOIN starjoin_geqo_d3 AS d3 ON f.d3 = d3.id
+  JOIN starjoin_geqo_d4 AS d4 ON f.d4 = d4.id
+  JOIN starjoin_geqo_d5 AS d5 ON f.d5 = d5.id
+  JOIN starjoin_geqo_d6 AS d6 ON f.d6 = d6.id
+  JOIN starjoin_geqo_d7 AS d7 ON f.d7 = d7.id
+  JOIN starjoin_geqo_d8 AS d8 ON f.d8 = d8.id
+  JOIN starjoin_geqo_d9 AS d9 ON f.d9 = d9.id
+  JOIN starjoin_geqo_d10 AS d10 ON f.d10 = d10.id
+$$ AS q_star \gset
+
+-- the plan with the canonical order, forced by join_collapse_limit = 1
+SET join_collapse_limit = 1;
+SELECT starjoin_geqo_plan(:'q_star', true) AS plan_canonical \gset
+
+SET join_collapse_limit = 20;
+SET geqo_threshold = 8;
+-- GEQO uses the canonical order
+SELECT starjoin_geqo_plan(:'q_star', true) = :'plan_canonical' AS geqo_plan_canonical;
+RESET geqo_threshold;
+RESET join_collapse_limit;
+
+--
+-- Star in a FROM list
+--
+-- A FROM list of tables is never split into subproblems (join_collapse_limit
+-- applies to explicit joins, from_collapse_limit to subqueries), so with the
+-- default settings a star with 11 dimensions (12 rels) is planned by GEQO,
+-- and it's pruned too.
+--
+SELECT $$
+SELECT count(*)
+  FROM starjoin_geqo_f AS f, starjoin_geqo_a AS a,
+       starjoin_geqo_d1 AS d1, starjoin_geqo_d2 AS d2,
+       starjoin_geqo_d3 AS d3, starjoin_geqo_d4 AS d4,
+       starjoin_geqo_d5 AS d5, starjoin_geqo_d6 AS d6,
+       starjoin_geqo_d7 AS d7, starjoin_geqo_d8 AS d8,
+       starjoin_geqo_d9 AS d9, starjoin_geqo_d10 AS d10
+ WHERE f.a = a.id AND f.d1 = d1.id AND f.d2 = d2.id AND f.d3 = d3.id
+   AND f.d4 = d4.id AND f.d5 = d5.id AND f.d6 = d6.id AND f.d7 = d7.id
+   AND f.d8 = d8.id AND f.d9 = d9.id AND f.d10 = d10.id
+$$ AS q_star_list \gset
+
+-- the same star, with another rel (c1) joined to the fact
+SELECT $$
+SELECT count(*)
+  FROM starjoin_geqo_f AS f, starjoin_geqo_a AS a,
+       starjoin_geqo_d1 AS d1, starjoin_geqo_d2 AS d2,
+       starjoin_geqo_d3 AS d3, starjoin_geqo_d4 AS d4,
+       starjoin_geqo_d5 AS d5, starjoin_geqo_d6 AS d6,
+       starjoin_geqo_d7 AS d7, starjoin_geqo_d8 AS d8,
+       starjoin_geqo_d9 AS d9, starjoin_geqo_d10 AS d10,
+       starjoin_geqo_c1 AS c1
+ WHERE f.a = a.id AND f.d1 = d1.id AND f.d2 = d2.id AND f.d3 = d3.id
+   AND f.d4 = d4.id AND f.d5 = d5.id AND f.d6 = d6.id AND f.d7 = d7.id
+   AND f.d8 = d8.id AND f.d9 = d9.id AND f.d10 = d10.id AND f.id = c1.id
+$$ AS q_star_list_c1 \gset
+
+-- with the GUC disabled, GEQO is used as usual
+SELECT starjoin_geqo_used(:'q_star_list', false) AS star_list_geqo_off;
+-- XXX the dimensions count towards geqo_threshold
+SELECT NOT starjoin_geqo_used(:'q_star_list', true) AS star_list_standard_search;
+
+-- the star with c1 has two rels other than the dimensions, so with
+-- geqo_threshold = 2 it's planned by GEQO
+SET geqo_threshold = 2;
+SELECT starjoin_geqo_used(:'q_star_list_c1', true) AS star_list_c1_geqo;
+-- XXX GEQO is pruned too, so the GUC changes the plan
+SELECT starjoin_geqo_plan(:'q_star_list_c1', true)
+       = starjoin_geqo_plan(:'q_star_list_c1', false) AS geqo_plan_unaffected;
+RESET geqo_threshold;
+
+RESET max_parallel_workers_per_gather;
+
+DROP FUNCTION starjoin_geqo_plan(text, bool);
+DROP FUNCTION starjoin_geqo_used(text, bool);
+
+DROP TABLE starjoin_geqo_f, starjoin_geqo_a, starjoin_geqo_c1,
+  starjoin_geqo_d1, starjoin_geqo_d2, starjoin_geqo_d3, starjoin_geqo_d4,
+  starjoin_geqo_d5, starjoin_geqo_d6, starjoin_geqo_d7, starjoin_geqo_d8,
+  starjoin_geqo_d9, starjoin_geqo_d10;
diff --git a/src/test/regress/sql/starjoin_other.sql b/src/test/regress/sql/starjoin_other.sql
index ed53b58c752..fb74645b1c6 100644
--- a/src/test/regress/sql/starjoin_other.sql
+++ b/src/test/regress/sql/starjoin_other.sql
@@ -1,6 +1,7 @@
 --
 -- Checks for various other cases with enable_starjoin_ordering (the
--- planning failures are covered by starjoin_reproducers).
+-- planning failures are covered by starjoin_reproducers, and GEQO by
+-- starjoin_geqo).
 --
 -- Each check is a single boolean, so that the output does not depend on
 -- platform-specific costs or memory usage.  Some checks show known
@@ -415,23 +416,13 @@ SELECT starjoin_other_memory(:'q_exists', true)
 -- Star split into subproblems
 --
 -- With the default join_collapse_limit, the star with 10 dimensions is split
--- into two subproblems, and the canonical order is enforced in both.
+-- into two subproblems, and the canonical order is enforced in both.  The
+-- checks with GEQO (and with the whole star in a single subproblem above
+-- geqo_threshold) are in starjoin_geqo.
 --
 SELECT starjoin_other_memory(:'q_star', true)
        < starjoin_other_memory(:'q_star', false) * 0.5 AS split_search_pruned;
 
---
--- GEQO
---
--- The canonical order is enforced by GEQO too.
---
-SET join_collapse_limit = 20;
-SET geqo_threshold = 8;
--- GEQO uses the canonical order
-SELECT starjoin_other_plan(:'q_star', true) = :'plan_canonical' AS geqo_plan_canonical;
-RESET geqo_threshold;
-RESET join_collapse_limit;
-
 --
 -- Overhead in subproblems unrelated to the star
 --
-- 
2.56.1

