Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
7711e40b
Commit
7711e40b
authored
24 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Make application of FOR UPDATE to a view work exactly like the parser's
transformForUpdate does: it should recurse into subqueries.
parent
0a844e84
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/rewrite/rewriteHandler.c
+42
-22
42 additions, 22 deletions
src/backend/rewrite/rewriteHandler.c
with
42 additions
and
22 deletions
src/backend/rewrite/rewriteHandler.c
+
42
−
22
View file @
7711e40b
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.8
5
2000/12/0
6 23:55:18
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.8
6
2000/12/0
7 01:22:25
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -38,6 +38,7 @@ static RewriteInfo *gatherRewriteMeta(Query *parsetree,
CmdType
event
,
bool
instead_flag
);
static
List
*
adjustJoinTreeList
(
Query
*
parsetree
,
int
rt_index
,
bool
*
found
);
static
void
markQueryForUpdate
(
Query
*
qry
,
bool
skipOldNew
);
static
List
*
matchLocks
(
CmdType
event
,
RuleLock
*
rulelocks
,
int
varno
,
Query
*
parsetree
);
static
Query
*
fireRIRrules
(
Query
*
parsetree
);
...
...
@@ -263,7 +264,6 @@ ApplyRetrieveRule(Query *parsetree,
Query
*
rule_action
;
RangeTblEntry
*
rte
,
*
subrte
;
List
*
l
;
if
(
length
(
rule
->
actions
)
!=
1
)
elog
(
ERROR
,
"ApplyRetrieveRule: expected just one rule action"
);
...
...
@@ -308,8 +308,6 @@ ApplyRetrieveRule(Query *parsetree,
*/
if
(
intMember
(
rt_index
,
parsetree
->
rowMarks
))
{
Index
innerrti
=
1
;
/*
* Remove the view from the list of rels that will actually be
* marked FOR UPDATE by the executor. It will still be access-
...
...
@@ -320,29 +318,51 @@ ApplyRetrieveRule(Query *parsetree,
/*
* Set up the view's referenced tables as if FOR UPDATE.
*/
foreach
(
l
,
rule_action
->
rtable
)
{
subrte
=
(
RangeTblEntry
*
)
lfirst
(
l
);
/*
* RTable of VIEW has two entries of VIEW itself - skip them!
* Also keep hands off of sub-subqueries.
*/
if
(
innerrti
!=
PRS2_OLD_VARNO
&&
innerrti
!=
PRS2_NEW_VARNO
&&
subrte
->
relid
!=
InvalidOid
)
{
if
(
!
intMember
(
innerrti
,
rule_action
->
rowMarks
))
rule_action
->
rowMarks
=
lappendi
(
rule_action
->
rowMarks
,
innerrti
);
subrte
->
checkForWrite
=
true
;
}
innerrti
++
;
}
markQueryForUpdate
(
rule_action
,
true
);
}
return
parsetree
;
}
/*
* Recursively mark all relations used by a view as FOR UPDATE.
*
* This may generate an invalid query, eg if some sub-query uses an
* aggregate. We leave it to the planner to detect that.
*
* NB: this must agree with the parser's transformForUpdate() routine.
*/
static
void
markQueryForUpdate
(
Query
*
qry
,
bool
skipOldNew
)
{
Index
rti
=
0
;
List
*
l
;
foreach
(
l
,
qry
->
rtable
)
{
RangeTblEntry
*
rte
=
(
RangeTblEntry
*
)
lfirst
(
l
);
rti
++
;
/* Ignore OLD and NEW entries if we are at top level of view */
if
(
skipOldNew
&&
(
rti
==
PRS2_OLD_VARNO
||
rti
==
PRS2_NEW_VARNO
))
continue
;
if
(
rte
->
subquery
)
{
/* FOR UPDATE of subquery is propagated to subquery's rels */
markQueryForUpdate
(
rte
->
subquery
,
false
);
}
else
{
if
(
!
intMember
(
rti
,
qry
->
rowMarks
))
qry
->
rowMarks
=
lappendi
(
qry
->
rowMarks
,
rti
);
rte
->
checkForWrite
=
true
;
}
}
}
/*
* fireRIRonSubLink -
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment