Skip to content

Commit 19f9376

Browse files
committed
Tweak joinlist creation to avoid generating useless one-element subproblems
when collapsing of JOIN trees is stopped by join_collapse_limit. For instance a list of 11 LEFT JOINs with limit 8 now produces something like ((1 2 3 4 5 6 7 8) 9 10 11 12) instead of (((1 2 3 4 5 6 7 8) (9)) 10 11 12) The latter structure is really only required for a FULL JOIN. Noted while studying an example from Shane Ambler.
1 parent 9a9a143 commit 19f9376

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/backend/optimizer/plan/initsplan.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.126 2007/01/05 22:19:31 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.127 2007/01/08 16:47:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -402,13 +402,34 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
402402
* except at a FULL JOIN or where join_collapse_limit would be
403403
* exceeded.
404404
*/
405-
if (j->jointype != JOIN_FULL &&
406-
(list_length(leftjoinlist) + list_length(rightjoinlist) <=
407-
join_collapse_limit))
405+
if (j->jointype == JOIN_FULL)
406+
{
407+
/* force the join order exactly at this node */
408+
joinlist = list_make1(list_make2(leftjoinlist, rightjoinlist));
409+
}
410+
else if (list_length(leftjoinlist) + list_length(rightjoinlist) <=
411+
join_collapse_limit)
412+
{
413+
/* OK to combine subproblems */
408414
joinlist = list_concat(leftjoinlist, rightjoinlist);
415+
}
409416
else
410-
/* force the join order at this node */
411-
joinlist = list_make1(list_make2(leftjoinlist, rightjoinlist));
417+
{
418+
/* can't combine, but needn't force join order above here */
419+
Node *leftpart,
420+
*rightpart;
421+
422+
/* avoid creating useless 1-element sublists */
423+
if (list_length(leftjoinlist) == 1)
424+
leftpart = (Node *) linitial(leftjoinlist);
425+
else
426+
leftpart = (Node *) leftjoinlist;
427+
if (list_length(rightjoinlist) == 1)
428+
rightpart = (Node *) linitial(rightjoinlist);
429+
else
430+
rightpart = (Node *) rightjoinlist;
431+
joinlist = list_make2(leftpart, rightpart);
432+
}
412433
}
413434
else
414435
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy