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

Commit7c22d2e

Browse files
committed
Correct error in rewriter that caused SELECT count(*) FROM view
to give wrong results: it should be looking at inJoinSet not inFromCl.Also, make 'modified' flag be local to ApplyRetrieveRule: we shouldappend a rule's quals to the query iff that particular rule applies,not if we have fired any previously-considered rule for the query!
1 parent0156fdf commit7c22d2e

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.71 2000/04/12 17:15:32 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.72 2000/04/20 00:31:49 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -704,8 +704,7 @@ ApplyRetrieveRule(Query *parsetree,
704704
intrt_index,
705705
intrelation_level,
706706
Relationrelation,
707-
boolrelWasInJoinSet,
708-
int*modified)
707+
boolrelWasInJoinSet)
709708
{
710709
Query*rule_action=NULL;
711710
Node*rule_qual;
@@ -714,6 +713,7 @@ ApplyRetrieveRule(Query *parsetree,
714713
*l;
715714
intnothing,
716715
rt_length;
716+
intmodified= false;
717717
intbadsql= false;
718718

719719
rule_qual=rule->qual;
@@ -809,18 +809,23 @@ ApplyRetrieveRule(Query *parsetree,
809809
parsetree= (Query*)apply_RIR_view((Node*)parsetree,
810810
rt_index,rte,
811811
rule_action->targetList,
812-
modified,0);
812+
&modified,0);
813813
rule_action= (Query*)apply_RIR_view((Node*)rule_action,
814814
rt_index,rte,
815815
rule_action->targetList,
816-
modified,0);
816+
&modified,0);
817+
/* always apply quals of relation-level rules, whether we found a
818+
* var to substitute or not.
819+
*/
820+
modified= true;
817821
}
818822
else
819823
{
820824
HandleRIRAttributeRule(parsetree,rtable,rule_action->targetList,
821-
rt_index,rule->attrno,modified,&badsql);
825+
rt_index,rule->attrno,&modified,&badsql);
826+
/* quals will be inserted only if we found uses of the attribute */
822827
}
823-
if (*modified&& !badsql)
828+
if (modified&& !badsql)
824829
{
825830
AddQual(parsetree,rule_action->qual);
826831
AddGroupClause(parsetree,rule_action->groupClause,
@@ -894,7 +899,6 @@ fireRIRrules(Query *parsetree)
894899
RewriteRule*rule;
895900
RewriteRuleRIRonly;
896901
boolrelWasInJoinSet;
897-
intmodified= false;
898902
inti;
899903
List*l;
900904

@@ -910,18 +914,15 @@ fireRIRrules(Query *parsetree)
910914
rte=rt_fetch(rt_index,parsetree->rtable);
911915

912916
/*
913-
* If the table is not one named in the original FROM clause then
914-
* it must be referenced in the query, or we ignore it. This
915-
* prevents infinite expansion loop due to new rtable entries
916-
* inserted by expansion of a rule.
917+
* If the table is not referenced in the query, then we ignore it.
918+
* This prevents infinite expansion loop due to new rtable entries
919+
* inserted by expansion of a rule. A table is referenced if it is
920+
* part of the join set (a source table), or is the result table,
921+
* or is referenced by any Var nodes.
917922
*/
918-
if (!rte->inFromCl&&rt_index!=parsetree->resultRelation&&
923+
if (!rte->inJoinSet&&rt_index!=parsetree->resultRelation&&
919924
!rangeTableEntry_used((Node*)parsetree,rt_index,0))
920-
{
921-
/* Make sure the planner ignores it too... */
922-
rte->inJoinSet= false;
923925
continue;
924-
}
925926

926927
rel=heap_openr(rte->relname,AccessShareLock);
927928
rules=rel->rd_rules;
@@ -989,8 +990,7 @@ fireRIRrules(Query *parsetree)
989990
rt_index,
990991
RIRonly.attrno==-1,
991992
rel,
992-
relWasInJoinSet,
993-
&modified);
993+
relWasInJoinSet);
994994
}
995995

996996
heap_close(rel,AccessShareLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp