From e03c5e2d5a32bb01e4cb8eaee67d3b05819dc97b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 18 Nov 2005 23:08:43 +0000 Subject: [PATCH] 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. --- src/backend/parser/parse_expr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 6c0c53d0748..2cfa43caf9a 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.163.2.3 2005/05/25 02:13:48 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.163.2.4 2005/11/18 23:08:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1425,8 +1425,12 @@ exprTypmod(Node *expr) int32 typmod; List *arg; + if (exprType((Node *) lfirst(cexpr->args)) != coalescetype) + return -1; typmod = exprTypmod((Node *) lfirst(cexpr->args)); - foreach(arg, cexpr->args) + if (typmod < 0) + return -1; /* no point in trying harder */ + foreach(arg, lnext(cexpr->args)) { Node *e = (Node *) lfirst(arg);