summaryrefslogtreecommitdiff
path: root/src/backend/rewrite/rewriteManip.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-10-20 00:58:55 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-10-20 00:58:55 +0000
commita044e2abddfe96a4309d4e8b3ac1cc603f8d50ad (patch)
tree1eaa0d72b9a694a9ffbff941a8f89284aa9b4cbe /src/backend/rewrite/rewriteManip.c
parent6d6b5828500e348580faf6bdda69fe62fc0faa28 (diff)
Rule rewriter was doing the wrong thing with conditional INSTEAD rules
whose conditions might yield NULL. The negated qual to attach to the original query is properly 'x IS NOT TRUE', not 'NOT x'. This fix produces correct behavior, but we may be taking a performance hit because the planner is much stupider about IS NOT TRUE than it is about NOT clauses. Future TODO: teach prepqual, other parts of planner how to cope with BooleanTest clauses more effectively.
Diffstat (limited to 'src/backend/rewrite/rewriteManip.c')
-rw-r--r--src/backend/rewrite/rewriteManip.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c
index 12154b8da6e..94a940648c0 100644
--- a/src/backend/rewrite/rewriteManip.c
+++ b/src/backend/rewrite/rewriteManip.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.66 2002/09/11 14:48:54 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.67 2002/10/20 00:58:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -690,34 +690,26 @@ AddHavingQual(Query *parsetree, Node *havingQual)
parsetree->hasSubLinks |= checkExprHasSubLink(copy);
}
-#ifdef NOT_USED
-void
-AddNotHavingQual(Query *parsetree, Node *havingQual)
-{
- Node *notqual;
-
- if (havingQual == NULL)
- return;
-
- /* Need not copy input qual, because AddHavingQual will... */
- notqual = (Node *) make_notclause((Expr *) havingQual);
-
- AddHavingQual(parsetree, notqual);
-}
-#endif
+/*
+ * Invert the given clause and add it to the WHERE qualifications of the
+ * given querytree. Inversion means "x IS NOT TRUE", not just "NOT x",
+ * else we will do the wrong thing when x evaluates to NULL.
+ */
void
-AddNotQual(Query *parsetree, Node *qual)
+AddInvertedQual(Query *parsetree, Node *qual)
{
- Node *notqual;
+ BooleanTest *invqual;
if (qual == NULL)
return;
/* Need not copy input qual, because AddQual will... */
- notqual = (Node *) make_notclause((Expr *) qual);
+ invqual = makeNode(BooleanTest);
+ invqual->arg = qual;
+ invqual->booltesttype = IS_NOT_TRUE;
- AddQual(parsetree, notqual);
+ AddQual(parsetree, (Node *) invqual);
}