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

Commitbbb7b6f

Browse files
committed
Remove some dead code, simplify calling convention.
1 parentcee82fa commitbbb7b6f

File tree

3 files changed

+50
-82
lines changed

3 files changed

+50
-82
lines changed

‎src/backend/rewrite/rewriteHandler.c

Lines changed: 44 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*-------------------------------------------------------------------------
22
*
33
* rewriteHandler.c
4+
*Primary module of query rewriter.
45
*
56
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
67
* Portions Copyright (c) 1994, Regents of the University of California
78
*
8-
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.94 2001/06/12 18:54:22 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.95 2001/06/13 18:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,16 +27,16 @@
2727
#include"parser/parse_target.h"
2828
#include"parser/parsetree.h"
2929
#include"parser/parse_type.h"
30+
#include"rewrite/rewriteHandler.h"
3031
#include"rewrite/rewriteManip.h"
3132
#include"utils/lsyscache.h"
3233

3334

34-
staticRewriteInfo*gatherRewriteMeta(Query*parsetree,
35-
Query*rule_action,
36-
Node*rule_qual,
37-
intrt_index,
38-
CmdTypeevent,
39-
boolinstead_flag);
35+
staticQuery*rewriteRuleAction(Query*parsetree,
36+
Query*rule_action,
37+
Node*rule_qual,
38+
intrt_index,
39+
CmdTypeevent);
4040
staticList*adjustJoinTreeList(Query*parsetree,boolremovert,intrt_index);
4141
staticvoidmarkQueryForUpdate(Query*qry,boolskipOldNew);
4242
staticList*matchLocks(CmdTypeevent,RuleLock*rulelocks,
@@ -45,40 +45,33 @@ static Query *fireRIRrules(Query *parsetree);
4545

4646

4747
/*
48-
* gatherRewriteMeta -
49-
* Gather meta information about parsetree, and rule. Fix rule body
50-
* and qualifier so that they can be mixed with the parsetree and
51-
* maintain semantic validity
48+
* rewriteRuleAction -
49+
* Rewrite the rule action with appropriate qualifiers (taken from
50+
* the triggering query).
5251
*/
53-
staticRewriteInfo*
54-
gatherRewriteMeta(Query*parsetree,
52+
staticQuery*
53+
rewriteRuleAction(Query*parsetree,
5554
Query*rule_action,
5655
Node*rule_qual,
5756
intrt_index,
58-
CmdTypeevent,
59-
boolinstead_flag)
57+
CmdTypeevent)
6058
{
61-
RewriteInfo*info;
59+
intcurrent_varno,
60+
new_varno;
61+
intrt_length;
6262
Query*sub_action;
6363
Query**sub_action_ptr;
64-
intrt_length;
6564

66-
info= (RewriteInfo*)palloc(sizeof(RewriteInfo));
67-
info->rt_index=rt_index;
68-
info->event=event;
69-
info->instead_flag=instead_flag;
70-
info->rule_action= (Query*)copyObject(rule_action);
71-
info->rule_qual= (Node*)copyObject(rule_qual);
72-
if (info->rule_action==NULL)
73-
{
74-
info->nothing= TRUE;
75-
returninfo;
76-
}
77-
info->nothing= FALSE;
78-
info->action=info->rule_action->commandType;
79-
info->current_varno=rt_index;
65+
/*
66+
* Make modifiable copies of rule action and qual (what we're passed
67+
* are the stored versions in the relcache; don't touch 'em!).
68+
*/
69+
rule_action= (Query*)copyObject(rule_action);
70+
rule_qual= (Node*)copyObject(rule_qual);
71+
72+
current_varno=rt_index;
8073
rt_length=length(parsetree->rtable);
81-
info->new_varno=PRS2_NEW_VARNO+rt_length;
74+
new_varno=PRS2_NEW_VARNO+rt_length;
8275

8376
/*
8477
* Adjust rule action and qual to offset its varnos, so that we can
@@ -88,14 +81,14 @@ gatherRewriteMeta(Query *parsetree,
8881
* will be in the SELECT part, and we have to modify that rather than
8982
* the top-level INSERT (kluge!).
9083
*/
91-
sub_action=getInsertSelectQuery(info->rule_action,&sub_action_ptr);
84+
sub_action=getInsertSelectQuery(rule_action,&sub_action_ptr);
9285

9386
OffsetVarNodes((Node*)sub_action,rt_length,0);
94-
OffsetVarNodes(info->rule_qual,rt_length,0);
87+
OffsetVarNodes(rule_qual,rt_length,0);
9588
/* but references to *OLD* should point at original rt_index */
9689
ChangeVarNodes((Node*)sub_action,
9790
PRS2_OLD_VARNO+rt_length,rt_index,0);
98-
ChangeVarNodes(info->rule_qual,
91+
ChangeVarNodes(rule_qual,
9992
PRS2_OLD_VARNO+rt_length,rt_index,0);
10093

10194
/*
@@ -135,8 +128,8 @@ gatherRewriteMeta(Query *parsetree,
135128

136129
keeporig= (!rangeTableEntry_used((Node*)sub_action->jointree,
137130
rt_index,0))&&
138-
(rangeTableEntry_used(info->rule_qual,rt_index,0)||
139-
rangeTableEntry_used(parsetree->jointree->quals,rt_index,0));
131+
(rangeTableEntry_used(rule_qual,rt_index,0)||
132+
rangeTableEntry_used(parsetree->jointree->quals,rt_index,0));
140133
newjointree=adjustJoinTreeList(parsetree, !keeporig,rt_index);
141134
sub_action->jointree->fromlist=
142135
nconc(newjointree,sub_action->jointree->fromlist);
@@ -146,7 +139,8 @@ gatherRewriteMeta(Query *parsetree,
146139
* We copy the qualifications of the parsetree to the action and vice
147140
* versa. So force hasSubLinks if one of them has it. If this is not
148141
* right, the flag will get cleared later, but we mustn't risk having
149-
* it not set when it needs to be.
142+
* it not set when it needs to be. (XXX this should probably be handled
143+
* by AddQual and friends, not here...)
150144
*/
151145
if (parsetree->hasSubLinks)
152146
sub_action->hasSubLinks= TRUE;
@@ -158,7 +152,7 @@ gatherRewriteMeta(Query *parsetree,
158152
* two queries one w/rule_qual, one w/NOT rule_qual. Also add user
159153
* query qual onto rule action
160154
*/
161-
AddQual(sub_action,info->rule_qual);
155+
AddQual(sub_action,rule_qual);
162156

163157
AddQual(sub_action,parsetree->jointree->quals);
164158

@@ -168,23 +162,23 @@ gatherRewriteMeta(Query *parsetree,
168162
*
169163
* KLUGE ALERT: since ResolveNew returns a mutated copy, we can't just
170164
* apply it to sub_action; we have to remember to update the sublink
171-
* insideinfo->rule_action, too.
165+
* inside rule_action, too.
172166
*/
173-
if (info->event==CMD_INSERT||info->event==CMD_UPDATE)
167+
if (event==CMD_INSERT||event==CMD_UPDATE)
174168
{
175169
sub_action= (Query*)ResolveNew((Node*)sub_action,
176-
info->new_varno,
170+
new_varno,
177171
0,
178172
parsetree->targetList,
179-
info->event,
180-
info->current_varno);
173+
event,
174+
current_varno);
181175
if (sub_action_ptr)
182176
*sub_action_ptr=sub_action;
183177
else
184-
info->rule_action=sub_action;
178+
rule_action=sub_action;
185179
}
186180

187-
returninfo;
181+
returnrule_action;
188182
}
189183

190184
/*
@@ -708,26 +702,14 @@ fireRules(Query *parsetree,
708702
foreach(r,actions)
709703
{
710704
Query*rule_action=lfirst(r);
711-
RewriteInfo*info;
712705

713706
if (rule_action->commandType==CMD_NOTHING)
714707
continue;
715708

716-
info=gatherRewriteMeta(parsetree,rule_action,event_qual,
717-
rt_index,event,*instead_flag);
718-
719-
/* handle escapable cases, or those handled by other code */
720-
if (info->nothing)
721-
{
722-
if (*instead_flag)
723-
returnNIL;
724-
else
725-
continue;
726-
}
727-
728-
results=lappend(results,info->rule_action);
709+
rule_action=rewriteRuleAction(parsetree,rule_action,
710+
event_qual,rt_index,event);
729711

730-
pfree(info);
712+
results=lappend(results,rule_action);
731713
}
732714

733715
/*

‎src/include/rewrite/rewriteHandler.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*-------------------------------------------------------------------------
22
*
33
* rewriteHandler.h
4-
*
4+
*External interface to query rewriter.
55
*
66
*
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: rewriteHandler.h,v 1.14 2001/01/24 19:43:27 momjian Exp $
10+
* $Id: rewriteHandler.h,v 1.15 2001/06/13 18:56:30 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,21 +16,7 @@
1616

1717
#include"nodes/parsenodes.h"
1818

19-
typedefstructRewriteInfo
20-
{
21-
intrt_index;
22-
boolinstead_flag;
23-
intevent;
24-
CmdTypeaction;
25-
intcurrent_varno;
26-
intnew_varno;
27-
Query*rule_action;
28-
Node*rule_qual;
29-
boolnothing;
30-
}RewriteInfo;
31-
3219

3320
externList*QueryRewrite(Query*parsetree);
3421

35-
3622
#endif/* REWRITEHANDLER_H */

‎src/include/rewrite/rewriteManip.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/*-------------------------------------------------------------------------
22
*
33
* rewriteManip.h
4-
*
4+
*Querytree manipulation subroutines for query rewriter.
55
*
66
*
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: rewriteManip.h,v 1.26 2001/03/22 04:01:04 momjian Exp $
10+
* $Id: rewriteManip.h,v 1.27 2001/06/13 18:56:29 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#ifndefREWRITEMANIP_H
1515
#defineREWRITEMANIP_H
1616

17-
#include"rewrite/rewriteHandler.h"
17+
#include"nodes/parsenodes.h"
18+
1819

19-
/* RewriteManip.c */
2020
externvoidOffsetVarNodes(Node*node,intoffset,intsublevels_up);
2121
externvoidChangeVarNodes(Node*node,intold_varno,intnew_varno,
2222
intsublevels_up);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp