Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita044e2a

Browse files
committed
Rule rewriter was doing the wrong thing with conditional INSTEAD rules
whose conditions might yield NULL. The negated qual to attach to theoriginal query is properly 'x IS NOT TRUE', not 'NOT x'. This fixproduces correct behavior, but we may be taking a performance hit becausethe planner is much stupider about IS NOT TRUE than it is about NOTclauses. Future TODO: teach prepqual, other parts of planner how tocope with BooleanTest clauses more effectively.
1 parent6d6b582 commita044e2a

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.112 2002/10/19 19:00:47 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.113 2002/10/2000:58:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -842,9 +842,11 @@ fireRIRrules(Query *parsetree)
842842

843843

844844
/*
845-
* Modify the given query by adding 'AND NOT rule_qual' to its qualification.
846-
* This is used to generate suitable "else clauses" for conditional INSTEAD
847-
* rules.
845+
* Modify the given query by adding 'AND rule_qual IS NOT TRUE' to its
846+
* qualification. This is used to generate suitable "else clauses" for
847+
* conditional INSTEAD rules. (Unfortunately we must use "x IS NOT TRUE",
848+
* not just "NOT x" which the planner is much smarter about, else we will
849+
* do the wrong thing when the qual evaluates to NULL.)
848850
*
849851
* The rule_qual may contain references to OLD or NEW.OLD references are
850852
* replaced by references to the specified rt_index (the relation that the
@@ -853,10 +855,10 @@ fireRIRrules(Query *parsetree)
853855
* of the related entries in the query's own targetlist.
854856
*/
855857
staticQuery*
856-
CopyAndAddQual(Query*parsetree,
857-
Node*rule_qual,
858-
intrt_index,
859-
CmdTypeevent)
858+
CopyAndAddInvertedQual(Query*parsetree,
859+
Node*rule_qual,
860+
intrt_index,
861+
CmdTypeevent)
860862
{
861863
Query*new_tree= (Query*)copyObject(parsetree);
862864
Node*new_qual= (Node*)copyObject(rule_qual);
@@ -872,7 +874,7 @@ CopyAndAddQual(Query *parsetree,
872874
event,
873875
rt_index);
874876
/* And attach the fixed qual */
875-
AddNotQual(new_tree,new_qual);
877+
AddInvertedQual(new_tree,new_qual);
876878

877879
returnnew_tree;
878880
}
@@ -956,10 +958,10 @@ fireRules(Query *parsetree,
956958
{
957959
if (*qual_product==NULL)
958960
*qual_product=parsetree;
959-
*qual_product=CopyAndAddQual(*qual_product,
960-
event_qual,
961-
rt_index,
962-
event);
961+
*qual_product=CopyAndAddInvertedQual(*qual_product,
962+
event_qual,
963+
rt_index,
964+
event);
963965
}
964966
}
965967

‎src/backend/rewrite/rewriteManip.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.66 2002/09/11 14:48:54 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.67 2002/10/20 00:58:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -690,34 +690,26 @@ AddHavingQual(Query *parsetree, Node *havingQual)
690690
parsetree->hasSubLinks |=checkExprHasSubLink(copy);
691691
}
692692

693-
#ifdefNOT_USED
694-
void
695-
AddNotHavingQual(Query*parsetree,Node*havingQual)
696-
{
697-
Node*notqual;
698-
699-
if (havingQual==NULL)
700-
return;
701-
702-
/* Need not copy input qual, because AddHavingQual will... */
703-
notqual= (Node*)make_notclause((Expr*)havingQual);
704-
705-
AddHavingQual(parsetree,notqual);
706-
}
707-
#endif
708693

694+
/*
695+
* Invert the given clause and add it to the WHERE qualifications of the
696+
* given querytree. Inversion means "x IS NOT TRUE", not just "NOT x",
697+
* else we will do the wrong thing when x evaluates to NULL.
698+
*/
709699
void
710-
AddNotQual(Query*parsetree,Node*qual)
700+
AddInvertedQual(Query*parsetree,Node*qual)
711701
{
712-
Node*notqual;
702+
BooleanTest*invqual;
713703

714704
if (qual==NULL)
715705
return;
716706

717707
/* Need not copy input qual, because AddQual will... */
718-
notqual= (Node*)make_notclause((Expr*)qual);
708+
invqual=makeNode(BooleanTest);
709+
invqual->arg=qual;
710+
invqual->booltesttype=IS_NOT_TRUE;
719711

720-
AddQual(parsetree,notqual);
712+
AddQual(parsetree,(Node*)invqual);
721713
}
722714

723715

‎src/include/rewrite/rewriteManip.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: rewriteManip.h,v 1.31 2002/06/2020:29:52 momjian Exp $
10+
* $Id: rewriteManip.h,v 1.32 2002/10/2000:58:55 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -32,7 +32,7 @@ extern Query *getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr);
3232

3333
externvoidAddQual(Query*parsetree,Node*qual);
3434
externvoidAddHavingQual(Query*parsetree,Node*havingQual);
35-
externvoidAddNotQual(Query*parsetree,Node*qual);
35+
externvoidAddInvertedQual(Query*parsetree,Node*qual);
3636

3737
externboolcheckExprHasAggs(Node*node);
3838
externboolcheckExprHasSubLink(Node*node);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp