Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
bbb7b6f6
Commit
bbb7b6f6
authored
Jun 13, 2001
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove some dead code, simplify calling convention.
parent
cee82fab
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
82 deletions
+50
-82
src/backend/rewrite/rewriteHandler.c
src/backend/rewrite/rewriteHandler.c
+44
-62
src/include/rewrite/rewriteHandler.h
src/include/rewrite/rewriteHandler.h
+2
-16
src/include/rewrite/rewriteManip.h
src/include/rewrite/rewriteManip.h
+4
-4
No files found.
src/backend/rewrite/rewriteHandler.c
View file @
bbb7b6f6
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* rewriteHandler.c
* rewriteHandler.c
* Primary module of query rewriter.
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.9
4 2001/06/12 18:54:22
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.9
5 2001/06/13 18:56:30
tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -27,16 +27,16 @@
...
@@ -27,16 +27,16 @@
#include "parser/parse_target.h"
#include "parser/parse_target.h"
#include "parser/parsetree.h"
#include "parser/parsetree.h"
#include "parser/parse_type.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteHandler.h"
#include "rewrite/rewriteManip.h"
#include "rewrite/rewriteManip.h"
#include "utils/lsyscache.h"
#include "utils/lsyscache.h"
static
RewriteInfo
*
gatherRewriteMeta
(
Query
*
parsetree
,
static
Query
*
rewriteRuleAction
(
Query
*
parsetree
,
Query
*
rule_action
,
Query
*
rule_action
,
Node
*
rule_qual
,
Node
*
rule_qual
,
int
rt_index
,
int
rt_index
,
CmdType
event
,
CmdType
event
);
bool
instead_flag
);
static
List
*
adjustJoinTreeList
(
Query
*
parsetree
,
bool
removert
,
int
rt_index
);
static
List
*
adjustJoinTreeList
(
Query
*
parsetree
,
bool
removert
,
int
rt_index
);
static
void
markQueryForUpdate
(
Query
*
qry
,
bool
skipOldNew
);
static
void
markQueryForUpdate
(
Query
*
qry
,
bool
skipOldNew
);
static
List
*
matchLocks
(
CmdType
event
,
RuleLock
*
rulelocks
,
static
List
*
matchLocks
(
CmdType
event
,
RuleLock
*
rulelocks
,
...
@@ -45,40 +45,33 @@ static Query *fireRIRrules(Query *parsetree);
...
@@ -45,40 +45,33 @@ static Query *fireRIRrules(Query *parsetree);
/*
/*
* gatherRewriteMeta -
* rewriteRuleAction -
* Gather meta information about parsetree, and rule. Fix rule body
* Rewrite the rule action with appropriate qualifiers (taken from
* and qualifier so that they can be mixed with the parsetree and
* the triggering query).
* maintain semantic validity
*/
*/
static
RewriteInfo
*
static
Query
*
gatherRewriteMeta
(
Query
*
parsetree
,
rewriteRuleAction
(
Query
*
parsetree
,
Query
*
rule_action
,
Query
*
rule_action
,
Node
*
rule_qual
,
Node
*
rule_qual
,
int
rt_index
,
int
rt_index
,
CmdType
event
,
CmdType
event
)
bool
instead_flag
)
{
{
RewriteInfo
*
info
;
int
current_varno
,
new_varno
;
int
rt_length
;
Query
*
sub_action
;
Query
*
sub_action
;
Query
**
sub_action_ptr
;
Query
**
sub_action_ptr
;
int
rt_length
;
info
=
(
RewriteInfo
*
)
palloc
(
sizeof
(
RewriteInfo
));
/*
info
->
rt_index
=
rt_index
;
* Make modifiable copies of rule action and qual (what we're passed
info
->
event
=
event
;
* are the stored versions in the relcache; don't touch 'em!).
info
->
instead_flag
=
instead_flag
;
*/
info
->
rule_action
=
(
Query
*
)
copyObject
(
rule_action
);
rule_action
=
(
Query
*
)
copyObject
(
rule_action
);
info
->
rule_qual
=
(
Node
*
)
copyObject
(
rule_qual
);
rule_qual
=
(
Node
*
)
copyObject
(
rule_qual
);
if
(
info
->
rule_action
==
NULL
)
{
current_varno
=
rt_index
;
info
->
nothing
=
TRUE
;
return
info
;
}
info
->
nothing
=
FALSE
;
info
->
action
=
info
->
rule_action
->
commandType
;
info
->
current_varno
=
rt_index
;
rt_length
=
length
(
parsetree
->
rtable
);
rt_length
=
length
(
parsetree
->
rtable
);
info
->
new_varno
=
PRS2_NEW_VARNO
+
rt_length
;
new_varno
=
PRS2_NEW_VARNO
+
rt_length
;
/*
/*
* Adjust rule action and qual to offset its varnos, so that we can
* Adjust rule action and qual to offset its varnos, so that we can
...
@@ -88,14 +81,14 @@ gatherRewriteMeta(Query *parsetree,
...
@@ -88,14 +81,14 @@ gatherRewriteMeta(Query *parsetree,
* will be in the SELECT part, and we have to modify that rather than
* will be in the SELECT part, and we have to modify that rather than
* the top-level INSERT (kluge!).
* the top-level INSERT (kluge!).
*/
*/
sub_action
=
getInsertSelectQuery
(
info
->
rule_action
,
&
sub_action_ptr
);
sub_action
=
getInsertSelectQuery
(
rule_action
,
&
sub_action_ptr
);
OffsetVarNodes
((
Node
*
)
sub_action
,
rt_length
,
0
);
OffsetVarNodes
((
Node
*
)
sub_action
,
rt_length
,
0
);
OffsetVarNodes
(
info
->
rule_qual
,
rt_length
,
0
);
OffsetVarNodes
(
rule_qual
,
rt_length
,
0
);
/* but references to *OLD* should point at original rt_index */
/* but references to *OLD* should point at original rt_index */
ChangeVarNodes
((
Node
*
)
sub_action
,
ChangeVarNodes
((
Node
*
)
sub_action
,
PRS2_OLD_VARNO
+
rt_length
,
rt_index
,
0
);
PRS2_OLD_VARNO
+
rt_length
,
rt_index
,
0
);
ChangeVarNodes
(
info
->
rule_qual
,
ChangeVarNodes
(
rule_qual
,
PRS2_OLD_VARNO
+
rt_length
,
rt_index
,
0
);
PRS2_OLD_VARNO
+
rt_length
,
rt_index
,
0
);
/*
/*
...
@@ -135,7 +128,7 @@ gatherRewriteMeta(Query *parsetree,
...
@@ -135,7 +128,7 @@ gatherRewriteMeta(Query *parsetree,
keeporig
=
(
!
rangeTableEntry_used
((
Node
*
)
sub_action
->
jointree
,
keeporig
=
(
!
rangeTableEntry_used
((
Node
*
)
sub_action
->
jointree
,
rt_index
,
0
))
&&
rt_index
,
0
))
&&
(
rangeTableEntry_used
(
info
->
rule_qual
,
rt_index
,
0
)
||
(
rangeTableEntry_used
(
rule_qual
,
rt_index
,
0
)
||
rangeTableEntry_used
(
parsetree
->
jointree
->
quals
,
rt_index
,
0
));
rangeTableEntry_used
(
parsetree
->
jointree
->
quals
,
rt_index
,
0
));
newjointree
=
adjustJoinTreeList
(
parsetree
,
!
keeporig
,
rt_index
);
newjointree
=
adjustJoinTreeList
(
parsetree
,
!
keeporig
,
rt_index
);
sub_action
->
jointree
->
fromlist
=
sub_action
->
jointree
->
fromlist
=
...
@@ -146,7 +139,8 @@ gatherRewriteMeta(Query *parsetree,
...
@@ -146,7 +139,8 @@ gatherRewriteMeta(Query *parsetree,
* We copy the qualifications of the parsetree to the action and vice
* We copy the qualifications of the parsetree to the action and vice
* versa. So force hasSubLinks if one of them has it. If this is not
* versa. So force hasSubLinks if one of them has it. If this is not
* right, the flag will get cleared later, but we mustn't risk having
* right, the flag will get cleared later, but we mustn't risk having
* it not set when it needs to be.
* it not set when it needs to be. (XXX this should probably be handled
* by AddQual and friends, not here...)
*/
*/
if
(
parsetree
->
hasSubLinks
)
if
(
parsetree
->
hasSubLinks
)
sub_action
->
hasSubLinks
=
TRUE
;
sub_action
->
hasSubLinks
=
TRUE
;
...
@@ -158,7 +152,7 @@ gatherRewriteMeta(Query *parsetree,
...
@@ -158,7 +152,7 @@ gatherRewriteMeta(Query *parsetree,
* two queries one w/rule_qual, one w/NOT rule_qual. Also add user
* two queries one w/rule_qual, one w/NOT rule_qual. Also add user
* query qual onto rule action
* query qual onto rule action
*/
*/
AddQual
(
sub_action
,
info
->
rule_qual
);
AddQual
(
sub_action
,
rule_qual
);
AddQual
(
sub_action
,
parsetree
->
jointree
->
quals
);
AddQual
(
sub_action
,
parsetree
->
jointree
->
quals
);
...
@@ -168,23 +162,23 @@ gatherRewriteMeta(Query *parsetree,
...
@@ -168,23 +162,23 @@ gatherRewriteMeta(Query *parsetree,
*
*
* KLUGE ALERT: since ResolveNew returns a mutated copy, we can't just
* KLUGE ALERT: since ResolveNew returns a mutated copy, we can't just
* apply it to sub_action; we have to remember to update the sublink
* apply it to sub_action; we have to remember to update the sublink
* inside
info->
rule_action, too.
* inside rule_action, too.
*/
*/
if
(
info
->
event
==
CMD_INSERT
||
info
->
event
==
CMD_UPDATE
)
if
(
event
==
CMD_INSERT
||
event
==
CMD_UPDATE
)
{
{
sub_action
=
(
Query
*
)
ResolveNew
((
Node
*
)
sub_action
,
sub_action
=
(
Query
*
)
ResolveNew
((
Node
*
)
sub_action
,
info
->
new_varno
,
new_varno
,
0
,
0
,
parsetree
->
targetList
,
parsetree
->
targetList
,
info
->
event
,
event
,
info
->
current_varno
);
current_varno
);
if
(
sub_action_ptr
)
if
(
sub_action_ptr
)
*
sub_action_ptr
=
sub_action
;
*
sub_action_ptr
=
sub_action
;
else
else
info
->
rule_action
=
sub_action
;
rule_action
=
sub_action
;
}
}
return
info
;
return
rule_action
;
}
}
/*
/*
...
@@ -708,26 +702,14 @@ fireRules(Query *parsetree,
...
@@ -708,26 +702,14 @@ fireRules(Query *parsetree,
foreach
(
r
,
actions
)
foreach
(
r
,
actions
)
{
{
Query
*
rule_action
=
lfirst
(
r
);
Query
*
rule_action
=
lfirst
(
r
);
RewriteInfo
*
info
;
if
(
rule_action
->
commandType
==
CMD_NOTHING
)
if
(
rule_action
->
commandType
==
CMD_NOTHING
)
continue
;
continue
;
info
=
gatherRewriteMeta
(
parsetree
,
rule_action
,
event_qual
,
rule_action
=
rewriteRuleAction
(
parsetree
,
rule_action
,
rt_index
,
event
,
*
instead_flag
);
event_qual
,
rt_index
,
event
);
/* handle escapable cases, or those handled by other code */
if
(
info
->
nothing
)
{
if
(
*
instead_flag
)
return
NIL
;
else
continue
;
}
results
=
lappend
(
results
,
info
->
rule_action
);
pfree
(
info
);
results
=
lappend
(
results
,
rule_action
);
}
}
/*
/*
...
...
src/include/rewrite/rewriteHandler.h
View file @
bbb7b6f6
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* rewriteHandler.h
* rewriteHandler.h
*
*
External interface to query rewriter.
*
*
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: rewriteHandler.h,v 1.1
4 2001/01/24 19:43:27 momjian
Exp $
* $Id: rewriteHandler.h,v 1.1
5 2001/06/13 18:56:30 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -16,21 +16,7 @@
...
@@ -16,21 +16,7 @@
#include "nodes/parsenodes.h"
#include "nodes/parsenodes.h"
typedef
struct
RewriteInfo
{
int
rt_index
;
bool
instead_flag
;
int
event
;
CmdType
action
;
int
current_varno
;
int
new_varno
;
Query
*
rule_action
;
Node
*
rule_qual
;
bool
nothing
;
}
RewriteInfo
;
extern
List
*
QueryRewrite
(
Query
*
parsetree
);
extern
List
*
QueryRewrite
(
Query
*
parsetree
);
#endif
/* REWRITEHANDLER_H */
#endif
/* REWRITEHANDLER_H */
src/include/rewrite/rewriteManip.h
View file @
bbb7b6f6
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
*
*
* rewriteManip.h
* rewriteManip.h
*
*
Querytree manipulation subroutines for query rewriter.
*
*
*
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: rewriteManip.h,v 1.2
6 2001/03/22 04:01:04 momjian
Exp $
* $Id: rewriteManip.h,v 1.2
7 2001/06/13 18:56:29 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
#ifndef REWRITEMANIP_H
#ifndef REWRITEMANIP_H
#define REWRITEMANIP_H
#define REWRITEMANIP_H
#include "rewrite/rewriteHandler.h"
#include "nodes/parsenodes.h"
/* RewriteManip.c */
extern
void
OffsetVarNodes
(
Node
*
node
,
int
offset
,
int
sublevels_up
);
extern
void
OffsetVarNodes
(
Node
*
node
,
int
offset
,
int
sublevels_up
);
extern
void
ChangeVarNodes
(
Node
*
node
,
int
old_varno
,
int
new_varno
,
extern
void
ChangeVarNodes
(
Node
*
node
,
int
old_varno
,
int
new_varno
,
int
sublevels_up
);
int
sublevels_up
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment