From d7d81aa81342887ea94c88c7b8b464f863781397 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 12 Nov 2008 23:08:55 +0000 Subject: [PATCH] In predtest.c, install a limit on the number of branches we will process in AND, OR, or equivalent clauses: if there are too many (more than 100) just exit without proving anything. This ensures that we don't spend O(N^2) time trying (and most likely failing) to prove anything about very long IN lists and similar cases. Also, install a couple of CHECK_FOR_INTERRUPTS calls to ensure that a long proof attempt can be interrupted. Per gripe from Sergey Konoplev. Back-patch the whole patch to 8.2 and just the CHECK_FOR_INTERRUPTS addition to 8.1. (The rest of the patch doesn't apply cleanly, and since 8.1 doesn't show the complained-of behavior anyway, it doesn't seem necessary to work hard on it.) --- src/backend/optimizer/util/predtest.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c index 48ae77ac55..7a38df5475 100644 --- a/src/backend/optimizer/util/predtest.c +++ b/src/backend/optimizer/util/predtest.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.4 2005/10/15 02:49:21 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.4.2.1 2008/11/12 23:08:55 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,6 +19,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "executor/executor.h" +#include "miscadmin.h" #include "optimizer/clauses.h" #include "optimizer/predtest.h" #include "utils/catcache.h" @@ -482,6 +483,9 @@ predicate_refuted_by_recurse(Node *clause, Node *predicate) static bool predicate_implied_by_simple_clause(Expr *predicate, Node *clause) { + /* Allow interrupting long proof attempts */ + CHECK_FOR_INTERRUPTS(); + /* First try the equal() test */ if (equal((Node *) predicate, clause)) return true; @@ -529,6 +533,9 @@ predicate_implied_by_simple_clause(Expr *predicate, Node *clause) static bool predicate_refuted_by_simple_clause(Expr *predicate, Node *clause) { + /* Allow interrupting long proof attempts */ + CHECK_FOR_INTERRUPTS(); + /* First try the IS NULL case */ if (predicate && IsA(predicate, NullTest) && ((NullTest *) predicate)->nulltesttype == IS_NULL) -- 2.40.0