]> granicus.if.org Git - postgresql/commitdiff
In predtest.c, install a limit on the number of branches we will process in
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Nov 2008 23:08:55 +0000 (23:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Nov 2008 23:08:55 +0000 (23:08 +0000)
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

index 48ae77ac55ea8b28425998bee8f32aa5b4d48742..7a38df5475ef49cdb3e91c7607fc13188afdd9e4 100644 (file)
@@ -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)