Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a8a968a

Browse filesBrowse files
committed
Consider cheap startup paths in add_paths_to_append_rel
6b94e7a did this for ordered append paths to allow fast startup MergeAppends, however, nothing was done for the Append case. Here we adjust add_paths_to_append_rel() to have it build an AppendPath containing the cheapest startup paths from each of the child relations when the append rel has "consider_startup" set. Author: Andy Fan, David Rowley Discussion: https://www.postgresql.org/message-id/CAKU4AWrXSkUV=Pt-gRxQT7EbfUeNssprGyNsB=5mJibFZ6S3ww@mail.gmail.com
1 parent 0b053e7 commit a8a968a
Copy full SHA for a8a968a

File tree

Expand file treeCollapse file tree

3 files changed

+53
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+53
-0
lines changed

‎src/backend/optimizer/path/allpaths.c

Copy file name to clipboardExpand all lines: src/backend/optimizer/path/allpaths.c
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,8 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13071307
{
13081308
List *subpaths = NIL;
13091309
bool subpaths_valid = true;
1310+
List *startup_subpaths = NIL;
1311+
bool startup_subpaths_valid = true;
13101312
List *partial_subpaths = NIL;
13111313
List *pa_partial_subpaths = NIL;
13121314
List *pa_nonpartial_subpaths = NIL;
@@ -1346,6 +1348,20 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13461348
else
13471349
subpaths_valid = false;
13481350

1351+
/*
1352+
* When the planner is considering cheap startup plans, we'll also
1353+
* collect all the cheapest_startup_paths and build an AppendPath
1354+
* containing those as subpaths.
1355+
*/
1356+
if (rel->consider_startup && childrel->pathlist != NIL &&
1357+
childrel->cheapest_startup_path->param_info == NULL)
1358+
accumulate_append_subpath(childrel->cheapest_startup_path,
1359+
&startup_subpaths,
1360+
NULL);
1361+
else
1362+
startup_subpaths_valid = false;
1363+
1364+
13491365
/* Same idea, but for a partial plan. */
13501366
if (childrel->partial_pathlist != NIL)
13511367
{
@@ -1478,6 +1494,11 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
14781494
NIL, NULL, 0, false,
14791495
-1));
14801496

1497+
/* build an AppendPath for the cheap startup paths, if valid */
1498+
if (startup_subpaths_valid)
1499+
add_path(rel, (Path *) create_append_path(root, rel, startup_subpaths,
1500+
NIL, NIL, NULL, 0, false, -1));
1501+
14811502
/*
14821503
* Consider an append of unordered, unparameterized partial paths. Make
14831504
* it parallel-aware if possible.

‎src/test/regress/expected/union.out

Copy file name to clipboardExpand all lines: src/test/regress/expected/union.out
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,3 +1432,24 @@ where (x = 0) or (q1 >= q2 and q1 <= q2);
14321432
4567890123456789 | 4567890123456789 | 1
14331433
(6 rows)
14341434

1435+
--
1436+
-- Test the planner's ability to produce cheap startup plans with Append nodes
1437+
--
1438+
-- Ensure we get a Nested Loop join between tenk1 and tenk2
1439+
explain (costs off)
1440+
select t1.unique1 from tenk1 t1
1441+
inner join tenk2 t2 on t1.tenthous = t2.tenthous
1442+
union all
1443+
(values(1)) limit 1;
1444+
QUERY PLAN
1445+
--------------------------------------------------------
1446+
Limit
1447+
-> Append
1448+
-> Nested Loop
1449+
Join Filter: (t1.tenthous = t2.tenthous)
1450+
-> Seq Scan on tenk1 t1
1451+
-> Materialize
1452+
-> Seq Scan on tenk2 t2
1453+
-> Result
1454+
(8 rows)
1455+

‎src/test/regress/sql/union.sql

Copy file name to clipboardExpand all lines: src/test/regress/sql/union.sql
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,14 @@ select * from
540540
union all
541541
select *, 1 as x from int8_tbl b) ss
542542
where (x = 0) or (q1 >= q2 and q1 <= q2);
543+
544+
--
545+
-- Test the planner's ability to produce cheap startup plans with Append nodes
546+
--
547+
548+
-- Ensure we get a Nested Loop join between tenk1 and tenk2
549+
explain (costs off)
550+
select t1.unique1 from tenk1 t1
551+
inner join tenk2 t2 on t1.tenthous = t2.tenthous
552+
union all
553+
(values(1)) limit 1;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.