aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-11-18 23:08:00 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-11-18 23:08:00 +0000
commit8685c472235b7a5bcc786f66ba9adde44e3d670c (patch)
tree83d8ef43a21d919000cf20f161907dff2cb4a144 /src
parentb410475672eaf06ba91a03c50c571bd52fd81a32 (diff)
downloadpostgresql-8685c472235b7a5bcc786f66ba9adde44e3d670c.tar.gz
postgresql-8685c472235b7a5bcc786f66ba9adde44e3d670c.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/parse_expr.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index ab9279abd30..3a57e5b5147 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.185 2005/10/15 02:49:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.186 2005/11/18 23:08:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1664,8 +1664,12 @@ exprTypmod(Node *expr)
int32 typmod;
ListCell *arg;
+ if (exprType((Node *) linitial(cexpr->args)) != coalescetype)
+ return -1;
typmod = exprTypmod((Node *) linitial(cexpr->args));
- foreach(arg, cexpr->args)
+ if (typmod < 0)
+ return -1; /* no point in trying harder */
+ for_each_cell(arg, lnext(list_head(cexpr->args)))
{
Node *e = (Node *) lfirst(arg);
@@ -1688,8 +1692,12 @@ exprTypmod(Node *expr)
int32 typmod;
ListCell *arg;
+ if (exprType((Node *) linitial(mexpr->args)) != minmaxtype)
+ return -1;
typmod = exprTypmod((Node *) linitial(mexpr->args));
- foreach(arg, mexpr->args)
+ if (typmod < 0)
+ return -1; /* no point in trying harder */
+ for_each_cell(arg, lnext(list_head(mexpr->args)))
{
Node *e = (Node *) lfirst(arg);