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
0f413d2d
Commit
0f413d2d
authored
Jan 21, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make subqueries rewrite properly.
parent
7e46348e
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
237 additions
and
106 deletions
+237
-106
src/backend/rewrite/locks.c
src/backend/rewrite/locks.c
+22
-11
src/backend/rewrite/rewriteHandler.c
src/backend/rewrite/rewriteHandler.c
+88
-12
src/backend/rewrite/rewriteManip.c
src/backend/rewrite/rewriteManip.c
+124
-81
src/include/rewrite/rewriteManip.h
src/include/rewrite/rewriteManip.h
+3
-2
No files found.
src/backend/rewrite/locks.c
View file @
0f413d2d
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/Attic/locks.c,v 1.
7 1998/01/15 19:00:06
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/Attic/locks.c,v 1.
8 1998/01/21 04:24:34
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -27,7 +27,8 @@
...
@@ -27,7 +27,8 @@
* otherwise, we return false
* otherwise, we return false
*/
*/
static
bool
static
bool
nodeThisLockWasTriggered
(
Node
*
node
,
int
varno
,
AttrNumber
attnum
)
nodeThisLockWasTriggered
(
Node
*
node
,
int
varno
,
AttrNumber
attnum
,
int
sublevels_up
)
{
{
if
(
node
==
NULL
)
if
(
node
==
NULL
)
return
FALSE
;
return
FALSE
;
...
@@ -46,24 +47,24 @@ nodeThisLockWasTriggered(Node *node, int varno, AttrNumber attnum)
...
@@ -46,24 +47,24 @@ nodeThisLockWasTriggered(Node *node, int varno, AttrNumber attnum)
{
{
Expr
*
expr
=
(
Expr
*
)
node
;
Expr
*
expr
=
(
Expr
*
)
node
;
return
return
nodeThisLockWasTriggered
((
Node
*
)
expr
->
args
,
varno
,
nodeThisLockWasTriggered
((
Node
*
)
expr
->
args
,
varno
,
attnum
);
attnum
,
sublevels_up
);
}
}
break
;
break
;
case
T_TargetEntry
:
case
T_TargetEntry
:
{
{
TargetEntry
*
tle
=
(
TargetEntry
*
)
node
;
TargetEntry
*
tle
=
(
TargetEntry
*
)
node
;
return
return
nodeThisLockWasTriggered
(
tle
->
expr
,
varno
,
attnum
,
nodeThisLockWasTriggered
(
tle
->
expr
,
varno
,
attnum
);
sublevels_up
);
}
}
break
;
break
;
case
T_Aggreg
:
case
T_Aggreg
:
{
{
Aggreg
*
agg
=
(
Aggreg
*
)
node
;
Aggreg
*
agg
=
(
Aggreg
*
)
node
;
return
return
nodeThisLockWasTriggered
(
agg
->
target
,
varno
,
attnum
,
nodeThisLockWasTriggered
(
agg
->
target
,
varno
,
attnum
);
sublevels_up
);
}
}
break
;
break
;
case
T_List
:
case
T_List
:
...
@@ -72,12 +73,22 @@ nodeThisLockWasTriggered(Node *node, int varno, AttrNumber attnum)
...
@@ -72,12 +73,22 @@ nodeThisLockWasTriggered(Node *node, int varno, AttrNumber attnum)
foreach
(
l
,
(
List
*
)
node
)
foreach
(
l
,
(
List
*
)
node
)
{
{
if
(
nodeThisLockWasTriggered
(
lfirst
(
l
),
varno
,
attnum
))
if
(
nodeThisLockWasTriggered
(
lfirst
(
l
),
varno
,
attnum
,
sublevels_up
))
return
TRUE
;
return
TRUE
;
}
}
return
FALSE
;
return
FALSE
;
}
}
break
;
break
;
case
T_SubLink
:
{
SubLink
*
sublink
=
(
SubLink
*
)
node
;
Query
*
query
=
(
Query
*
)
sublink
->
subselect
;
return
nodeThisLockWasTriggered
(
query
->
qual
,
varno
,
attnum
,
sublevels_up
+
1
);
}
break
;
default:
default:
break
;
break
;
}
}
...
@@ -96,10 +107,10 @@ thisLockWasTriggered(int varno,
...
@@ -96,10 +107,10 @@ thisLockWasTriggered(int varno,
Query
*
parsetree
)
Query
*
parsetree
)
{
{
if
(
nodeThisLockWasTriggered
(
parsetree
->
qual
,
varno
,
attnum
))
if
(
nodeThisLockWasTriggered
(
parsetree
->
qual
,
varno
,
attnum
,
0
))
return
true
;
return
true
;
if
(
nodeThisLockWasTriggered
((
Node
*
)
parsetree
->
targetList
,
varno
,
attnum
))
if
(
nodeThisLockWasTriggered
((
Node
*
)
parsetree
->
targetList
,
varno
,
attnum
,
0
))
return
true
;
return
true
;
return
false
;
return
false
;
...
...
src/backend/rewrite/rewriteHandler.c
View file @
0f413d2d
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.1
0 1998/01/09 05:48:17
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.1
1 1998/01/21 04:24:36
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -29,12 +29,12 @@
...
@@ -29,12 +29,12 @@
#include "commands/creatinh.h"
#include "commands/creatinh.h"
#include "access/heapam.h"
#include "access/heapam.h"
static
void
static
void
ApplyRetrieveRule
(
Query
*
parsetree
,
RewriteRule
*
rule
,
ApplyRetrieveRule
(
Query
*
parsetree
,
RewriteRule
*
rule
,
int
rt_index
,
int
relation_level
,
int
*
modified
);
int
rt_index
,
int
relation_level
,
int
*
modified
);
static
List
*
static
List
*
fireRules
(
Query
*
parsetree
,
int
rt_index
,
CmdType
event
,
fireRules
(
Query
*
parsetree
,
int
rt_index
,
CmdType
event
,
bool
*
instead_flag
,
List
*
locks
,
List
**
qual_products
);
bool
*
instead_flag
,
List
*
locks
,
List
**
qual_products
);
static
void
QueryRewriteSubLink
(
Node
*
node
);
static
List
*
QueryRewriteOne
(
Query
*
parsetree
);
static
List
*
deepRewriteQuery
(
Query
*
parsetree
);
static
List
*
deepRewriteQuery
(
Query
*
parsetree
);
/*
/*
...
@@ -77,11 +77,11 @@ gatherRewriteMeta(Query *parsetree,
...
@@ -77,11 +77,11 @@ gatherRewriteMeta(Query *parsetree,
OffsetVarNodes
((
Node
*
)
info
->
rule_action
->
targetList
,
rt_length
);
OffsetVarNodes
((
Node
*
)
info
->
rule_action
->
targetList
,
rt_length
);
OffsetVarNodes
(
info
->
rule_qual
,
rt_length
);
OffsetVarNodes
(
info
->
rule_qual
,
rt_length
);
ChangeVarNodes
((
Node
*
)
info
->
rule_action
->
qual
,
ChangeVarNodes
((
Node
*
)
info
->
rule_action
->
qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
ChangeVarNodes
((
Node
*
)
info
->
rule_action
->
targetList
,
ChangeVarNodes
((
Node
*
)
info
->
rule_action
->
targetList
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
ChangeVarNodes
(
info
->
rule_qual
,
ChangeVarNodes
(
info
->
rule_qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
/*
/*
* bug here about replace CURRENT -- sort of replace current is
* bug here about replace CURRENT -- sort of replace current is
...
@@ -292,10 +292,10 @@ ApplyRetrieveRule(Query *parsetree,
...
@@ -292,10 +292,10 @@ ApplyRetrieveRule(Query *parsetree,
OffsetVarNodes
((
Node
*
)
rule_action
->
targetList
,
rt_length
);
OffsetVarNodes
((
Node
*
)
rule_action
->
targetList
,
rt_length
);
OffsetVarNodes
(
rule_qual
,
rt_length
);
OffsetVarNodes
(
rule_qual
,
rt_length
);
ChangeVarNodes
(
rule_action
->
qual
,
ChangeVarNodes
(
rule_action
->
qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
ChangeVarNodes
((
Node
*
)
rule_action
->
targetList
,
ChangeVarNodes
((
Node
*
)
rule_action
->
targetList
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
ChangeVarNodes
(
rule_qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
ChangeVarNodes
(
rule_qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
if
(
relation_level
)
if
(
relation_level
)
{
{
HandleViewRule
(
parsetree
,
rtable
,
rule_action
->
targetList
,
rt_index
,
HandleViewRule
(
parsetree
,
rtable
,
rule_action
->
targetList
,
rt_index
,
...
@@ -402,7 +402,7 @@ CopyAndAddQual(Query *parsetree,
...
@@ -402,7 +402,7 @@ CopyAndAddQual(Query *parsetree,
rtable
=
append
(
rtable
,
listCopy
(
rule_action
->
rtable
));
rtable
=
append
(
rtable
,
listCopy
(
rule_action
->
rtable
));
new_tree
->
rtable
=
rtable
;
new_tree
->
rtable
=
rtable
;
OffsetVarNodes
(
new_qual
,
rt_length
);
OffsetVarNodes
(
new_qual
,
rt_length
);
ChangeVarNodes
(
new_qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
);
ChangeVarNodes
(
new_qual
,
PRS2_CURRENT_VARNO
+
rt_length
,
rt_index
,
0
);
}
}
/* XXX -- where current doesn't work for instead nothing.... yet */
/* XXX -- where current doesn't work for instead nothing.... yet */
AddNotQual
(
new_tree
,
new_qual
);
AddNotQual
(
new_tree
,
new_qual
);
...
@@ -627,6 +627,82 @@ static int numQueryRewriteInvoked = 0;
...
@@ -627,6 +627,82 @@ static int numQueryRewriteInvoked = 0;
*/
*/
List
*
List
*
QueryRewrite
(
Query
*
parsetree
)
QueryRewrite
(
Query
*
parsetree
)
{
QueryRewriteSubLink
(
parsetree
->
qual
);
return
QueryRewriteOne
(
parsetree
);
}
/*
* QueryRewriteSubLink
*
* This rewrites the SubLink subqueries first, doing the lowest ones first.
* We already have code in the main rewrite loops to process correlated
* variables from upper queries that exist in subqueries.
*/
static
void
QueryRewriteSubLink
(
Node
*
node
)
{
if
(
node
==
NULL
)
return
;
switch
(
nodeTag
(
node
))
{
case
T_TargetEntry
:
break
;
case
T_Aggreg
:
break
;
case
T_Expr
:
{
Expr
*
expr
=
(
Expr
*
)
node
;
QueryRewriteSubLink
((
Node
*
)
expr
->
args
);
}
break
;
case
T_Var
:
break
;
case
T_List
:
{
List
*
l
;
foreach
(
l
,
(
List
*
)
node
)
QueryRewriteSubLink
(
lfirst
(
l
));
}
break
;
case
T_SubLink
:
{
SubLink
*
sublink
=
(
SubLink
*
)
node
;
Query
*
query
=
(
Query
*
)
sublink
->
subselect
;
List
*
ret
;
/*
* Nest down first. We do this so if a rewrite adds a
* SubLink we don't process it as part of this loop.
*/
QueryRewriteSubLink
((
Node
*
)
query
->
qual
);
ret
=
QueryRewriteOne
(
query
);
if
(
!
ret
)
sublink
->
subselect
=
NULL
;
else
if
(
lnext
(
ret
)
==
NIL
)
sublink
->
subselect
=
lfirst
(
ret
);
else
elog
(
ERROR
,
"Don't know how to process subquery that rewrites to multiple queries."
);
}
break
;
default:
/* ignore the others */
break
;
}
return
;
}
/*
* QueryOneRewrite -
* rewrite one query
*/
static
List
*
QueryRewriteOne
(
Query
*
parsetree
)
{
{
numQueryRewriteInvoked
=
0
;
numQueryRewriteInvoked
=
0
;
...
...
src/backend/rewrite/rewriteManip.c
View file @
0f413d2d
This diff is collapsed.
Click to expand it.
src/include/rewrite/rewriteManip.h
View file @
0f413d2d
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
* Copyright (c) 1994, Regents of the University of California
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: rewriteManip.h,v 1.
5 1997/11/26 01:14:25
momjian Exp $
* $Id: rewriteManip.h,v 1.
6 1998/01/21 04:24:46
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -19,7 +19,8 @@
...
@@ -19,7 +19,8 @@
/* RewriteManip.c */
/* RewriteManip.c */
void
OffsetVarNodes
(
Node
*
node
,
int
offset
);
void
OffsetVarNodes
(
Node
*
node
,
int
offset
);
void
ChangeVarNodes
(
Node
*
node
,
int
old_varno
,
int
new_varno
);
void
ChangeVarNodes
(
Node
*
node
,
int
old_varno
,
int
new_varno
,
int
sublevels_up
);
void
AddQual
(
Query
*
parsetree
,
Node
*
qual
);
void
AddQual
(
Query
*
parsetree
,
Node
*
qual
);
void
AddNotQual
(
Query
*
parsetree
,
Node
*
qual
);
void
AddNotQual
(
Query
*
parsetree
,
Node
*
qual
);
void
FixResdomTypes
(
List
*
user_tlist
);
void
FixResdomTypes
(
List
*
user_tlist
);
...
...
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