Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8685c47

Browse files
committed
Fix performance issue in exprTypmod(): for a COALESCE expression, it
recursed twice on its first argument, leading to exponential time spent on a deep nest of COALESCEs ... such as a deeply nested FULL JOIN would produce. Per report from Matt Carter.
1 parent b410475 commit 8685c47

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/backend/parser/parse_expr.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.185 2005/10/15 02:49:22 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.186 2005/11/18 23:08:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1664,8 +1664,12 @@ exprTypmod(Node *expr)
16641664
int32 typmod;
16651665
ListCell *arg;
16661666

1667+
if (exprType((Node *) linitial(cexpr->args)) != coalescetype)
1668+
return -1;
16671669
typmod = exprTypmod((Node *) linitial(cexpr->args));
1668-
foreach(arg, cexpr->args)
1670+
if (typmod < 0)
1671+
return -1; /* no point in trying harder */
1672+
for_each_cell(arg, lnext(list_head(cexpr->args)))
16691673
{
16701674
Node *e = (Node *) lfirst(arg);
16711675

@@ -1688,8 +1692,12 @@ exprTypmod(Node *expr)
16881692
int32 typmod;
16891693
ListCell *arg;
16901694

1695+
if (exprType((Node *) linitial(mexpr->args)) != minmaxtype)
1696+
return -1;
16911697
typmod = exprTypmod((Node *) linitial(mexpr->args));
1692-
foreach(arg, mexpr->args)
1698+
if (typmod < 0)
1699+
return -1; /* no point in trying harder */
1700+
for_each_cell(arg, lnext(list_head(mexpr->args)))
16931701
{
16941702
Node *e = (Node *) lfirst(arg);
16951703

0 commit comments

Comments
 (0)