]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix performance issue in exprTypmod(): for a COALESCE expression, it
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 18 Nov 2005 23:08:28 +0000 (23:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 18 Nov 2005 23:08:28 +0000 (23:08 +0000)
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.

src/backend/parser/parse_expr.c

index 9082efe7eaf49943df586373e3ee84141e02be99..f95e58593a44f4552eb850e92233075c76057331 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.179.4.2 2005/05/25 02:17:55 ishii Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.179.4.3 2005/11/18 23:08:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1562,8 +1562,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);