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
9e964f90
Commit
9e964f90
authored
Jul 15, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix explain for union and inheritance. Rename Append structure
members to be clearer. Fix cost computation for these.
parent
9fdbbdc8
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
185 additions
and
128 deletions
+185
-128
src/backend/commands/explain.c
src/backend/commands/explain.c
+36
-1
src/backend/executor/execTuples.c
src/backend/executor/execTuples.c
+7
-7
src/backend/executor/nodeAppend.c
src/backend/executor/nodeAppend.c
+69
-73
src/backend/nodes/copyfuncs.c
src/backend/nodes/copyfuncs.c
+6
-6
src/backend/nodes/outfuncs.c
src/backend/nodes/outfuncs.c
+8
-8
src/backend/nodes/print.c
src/backend/nodes/print.c
+18
-1
src/backend/nodes/readfuncs.c
src/backend/nodes/readfuncs.c
+10
-10
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/plan/subselect.c
+1
-1
src/backend/optimizer/prep/prepunion.c
src/backend/optimizer/prep/prepunion.c
+17
-14
src/include/nodes/plannodes.h
src/include/nodes/plannodes.h
+13
-7
No files found.
src/backend/commands/explain.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.
19 1998/04/27 16:57:09 scrappy
Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.
20 1998/07/15 14:54:29 momjian
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include <tcop/tcopprot.h>
#include <tcop/tcopprot.h>
#include <lib/stringinfo.h>
#include <lib/stringinfo.h>
#include <commands/explain.h>
#include <commands/explain.h>
#include <parser/parsetree.h>
#include <parser/parse_node.h>
#include <parser/parse_node.h>
#include <optimizer/planner.h>
#include <optimizer/planner.h>
#include <access/xact.h>
#include <access/xact.h>
...
@@ -269,6 +270,40 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
...
@@ -269,6 +270,40 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
}
}
es
->
rtable
=
saved_rtable
;
es
->
rtable
=
saved_rtable
;
}
}
if
(
nodeTag
(
plan
)
==
T_Append
)
{
List
*
saved_rtable
=
es
->
rtable
;
List
*
lst
;
int
whichplan
=
0
;
Append
*
appendplan
=
(
Append
*
)
plan
;
foreach
(
lst
,
appendplan
->
appendplans
)
{
Plan
*
subnode
=
(
Plan
*
)
lfirst
(
lst
);
if
(
appendplan
->
inheritrelid
>
0
)
{
ResTarget
*
rtentry
;
es
->
rtable
=
appendplan
->
inheritrtable
;
rtentry
=
nth
(
whichplan
,
appendplan
->
inheritrtable
);
Assert
(
rtentry
!=
NULL
);
rt_store
(
appendplan
->
inheritrelid
,
es
->
rtable
,
rtentry
);
}
else
es
->
rtable
=
nth
(
whichplan
,
appendplan
->
unionrtables
);
for
(
i
=
0
;
i
<
indent
;
i
++
)
appendStringInfo
(
str
,
" "
);
appendStringInfo
(
str
,
" -> "
);
explain_outNode
(
str
,
subnode
,
indent
+
4
,
es
);
whichplan
++
;
}
es
->
rtable
=
saved_rtable
;
}
return
;
return
;
}
}
...
...
src/backend/executor/execTuples.c
View file @
9e964f90
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.1
8 1998/04/24 14:41:46
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.1
9 1998/07/15 14:54:29
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -712,16 +712,16 @@ NodeGetResultTupleSlot(Plan *node)
...
@@ -712,16 +712,16 @@ NodeGetResultTupleSlot(Plan *node)
case
T_Append
:
case
T_Append
:
{
{
Append
*
n
=
(
Append
*
)
node
;
Append
*
n
=
(
Append
*
)
node
;
AppendState
*
union
state
;
AppendState
*
append
state
;
List
*
union
plans
;
List
*
append
plans
;
int
whichplan
;
int
whichplan
;
Plan
*
subplan
;
Plan
*
subplan
;
unionstate
=
n
->
union
state
;
appendstate
=
n
->
append
state
;
unionplans
=
n
->
union
plans
;
appendplans
=
n
->
append
plans
;
whichplan
=
union
state
->
as_whichplan
;
whichplan
=
append
state
->
as_whichplan
;
subplan
=
(
Plan
*
)
nth
(
whichplan
,
union
plans
);
subplan
=
(
Plan
*
)
nth
(
whichplan
,
append
plans
);
slot
=
NodeGetResultTupleSlot
(
subplan
);
slot
=
NodeGetResultTupleSlot
(
subplan
);
break
;
break
;
}
}
...
...
src/backend/executor/nodeAppend.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.1
2 1998/06/15 19:28:21
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.1
3 1998/07/15 14:54:30
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -79,31 +79,29 @@ static bool
...
@@ -79,31 +79,29 @@ static bool
exec_append_initialize_next
(
Append
*
node
)
exec_append_initialize_next
(
Append
*
node
)
{
{
EState
*
estate
;
EState
*
estate
;
AppendState
*
union
state
;
AppendState
*
append
state
;
TupleTableSlot
*
result_slot
;
TupleTableSlot
*
result_slot
;
List
*
rangeTable
;
List
*
rangeTable
;
int
whichplan
;
int
whichplan
;
int
nplans
;
int
nplans
;
List
*
rts
;
List
*
rt
able
s
;
List
*
rt
entries
;
List
*
rt
able
;
ResTarget
*
rtentry
;
ResTarget
*
rtentry
;
Index
unionrelid
;
/* ----------------
/* ----------------
* get information from the append node
* get information from the append node
* ----------------
* ----------------
*/
*/
estate
=
node
->
plan
.
state
;
estate
=
node
->
plan
.
state
;
unionstate
=
node
->
union
state
;
appendstate
=
node
->
append
state
;
result_slot
=
union
state
->
cstate
.
cs_ResultTupleSlot
;
result_slot
=
append
state
->
cstate
.
cs_ResultTupleSlot
;
rangeTable
=
estate
->
es_range_table
;
rangeTable
=
estate
->
es_range_table
;
whichplan
=
union
state
->
as_whichplan
;
whichplan
=
append
state
->
as_whichplan
;
nplans
=
union
state
->
as_nplans
;
nplans
=
append
state
->
as_nplans
;
rt
s
=
node
->
unionrt
s
;
rt
ables
=
node
->
unionrtable
s
;
rt
entries
=
node
->
unionrtentries
;
rt
able
=
node
->
inheritrtable
;
if
(
whichplan
<
0
)
if
(
whichplan
<
0
)
{
{
...
@@ -115,7 +113,7 @@ exec_append_initialize_next(Append *node)
...
@@ -115,7 +113,7 @@ exec_append_initialize_next(Append *node)
* at the end of the line by returning FALSE
* at the end of the line by returning FALSE
* ----------------
* ----------------
*/
*/
union
state
->
as_whichplan
=
0
;
append
state
->
as_whichplan
=
0
;
return
FALSE
;
return
FALSE
;
}
}
...
@@ -126,7 +124,7 @@ exec_append_initialize_next(Append *node)
...
@@ -126,7 +124,7 @@ exec_append_initialize_next(Append *node)
* the last scan in our list..
* the last scan in our list..
* ----------------
* ----------------
*/
*/
union
state
->
as_whichplan
=
nplans
-
1
;
append
state
->
as_whichplan
=
nplans
-
1
;
return
FALSE
;
return
FALSE
;
}
}
...
@@ -139,29 +137,27 @@ exec_append_initialize_next(Append *node)
...
@@ -139,29 +137,27 @@ exec_append_initialize_next(Append *node)
* of the Append node??? - jolly )
* of the Append node??? - jolly )
* ----------------
* ----------------
*/
*/
if
(
node
->
union
relid
>
0
)
if
(
node
->
inherit
relid
>
0
)
{
{
rtentry
=
nth
(
whichplan
,
rt
entries
);
rtentry
=
nth
(
whichplan
,
rt
able
);
Assert
(
rtentry
!=
NULL
);
Assert
(
rtentry
!=
NULL
);
unionrelid
=
node
->
unionrelid
;
rt_store
(
node
->
inheritrelid
,
rangeTable
,
rtentry
);
rt_store
(
unionrelid
,
rangeTable
,
rtentry
);
}
}
else
else
estate
->
es_range_table
=
nth
(
whichplan
,
rts
);
estate
->
es_range_table
=
nth
(
whichplan
,
rt
able
s
);
if
(
union
state
->
as_junkFilter_list
)
if
(
append
state
->
as_junkFilter_list
)
{
{
estate
->
es_junkFilter
=
estate
->
es_junkFilter
=
(
JunkFilter
*
)
nth
(
whichplan
,
(
JunkFilter
*
)
nth
(
whichplan
,
union
state
->
as_junkFilter_list
);
append
state
->
as_junkFilter_list
);
}
}
if
(
union
state
->
as_result_relation_info_list
)
if
(
append
state
->
as_result_relation_info_list
)
{
{
estate
->
es_result_relation_info
=
estate
->
es_result_relation_info
=
(
RelationInfo
*
)
nth
(
whichplan
,
(
RelationInfo
*
)
nth
(
whichplan
,
union
state
->
as_result_relation_info_list
);
append
state
->
as_result_relation_info_list
);
}
}
result_slot
->
ttc_whichplan
=
whichplan
;
result_slot
->
ttc_whichplan
=
whichplan
;
...
@@ -187,11 +183,11 @@ exec_append_initialize_next(Append *node)
...
@@ -187,11 +183,11 @@ exec_append_initialize_next(Append *node)
bool
bool
ExecInitAppend
(
Append
*
node
,
EState
*
estate
,
Plan
*
parent
)
ExecInitAppend
(
Append
*
node
,
EState
*
estate
,
Plan
*
parent
)
{
{
AppendState
*
union
state
;
AppendState
*
append
state
;
int
nplans
;
int
nplans
;
List
*
resultList
=
NULL
;
List
*
resultList
=
NULL
;
List
*
rt
entries
;
List
*
rt
able
;
List
*
union
plans
;
List
*
append
plans
;
bool
*
initialized
;
bool
*
initialized
;
int
i
;
int
i
;
Plan
*
initNode
;
Plan
*
initNode
;
...
@@ -205,9 +201,9 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -205,9 +201,9 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
*/
*/
node
->
plan
.
state
=
estate
;
node
->
plan
.
state
=
estate
;
unionplans
=
node
->
union
plans
;
appendplans
=
node
->
append
plans
;
nplans
=
length
(
union
plans
);
nplans
=
length
(
append
plans
);
rt
entries
=
node
->
unionrtentries
;
rt
able
=
node
->
inheritrtable
;
CXT1_printf
(
"ExecInitAppend: context is %d
\n
"
,
CurrentMemoryContext
);
CXT1_printf
(
"ExecInitAppend: context is %d
\n
"
,
CurrentMemoryContext
);
initialized
=
(
bool
*
)
palloc
(
nplans
*
sizeof
(
bool
));
initialized
=
(
bool
*
)
palloc
(
nplans
*
sizeof
(
bool
));
...
@@ -216,13 +212,13 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -216,13 +212,13 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* create new AppendState for our append node
* create new AppendState for our append node
* ----------------
* ----------------
*/
*/
union
state
=
makeNode
(
AppendState
);
append
state
=
makeNode
(
AppendState
);
union
state
->
as_whichplan
=
0
;
append
state
->
as_whichplan
=
0
;
union
state
->
as_nplans
=
nplans
;
append
state
->
as_nplans
=
nplans
;
union
state
->
as_initialized
=
initialized
;
append
state
->
as_initialized
=
initialized
;
unionstate
->
as_rtentries
=
rtentries
;
appendstate
->
as_rtentries
=
rtable
;
node
->
unionstate
=
union
state
;
node
->
appendstate
=
append
state
;
/* ----------------
/* ----------------
* Miscellanious initialization
* Miscellanious initialization
...
@@ -234,7 +230,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -234,7 +230,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* never call ExecQual or ExecTargetList.
* never call ExecQual or ExecTargetList.
* ----------------
* ----------------
*/
*/
ExecAssignNodeBaseInfo
(
estate
,
&
union
state
->
cstate
,
parent
);
ExecAssignNodeBaseInfo
(
estate
,
&
append
state
->
cstate
,
parent
);
#define APPEND_NSLOTS 1
#define APPEND_NSLOTS 1
/* ----------------
/* ----------------
...
@@ -242,7 +238,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -242,7 +238,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* to tuples, so we have to initialize them..
* to tuples, so we have to initialize them..
* ----------------
* ----------------
*/
*/
ExecInitResultTupleSlot
(
estate
,
&
union
state
->
cstate
);
ExecInitResultTupleSlot
(
estate
,
&
append
state
->
cstate
);
/*
/*
* If the inherits rtentry is the result relation, we have to make a
* If the inherits rtentry is the result relation, we have to make a
...
@@ -252,12 +248,12 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -252,12 +248,12 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* e.g. replace p (age = p.age + 1) from p in person*
* e.g. replace p (age = p.age + 1) from p in person*
*/
*/
if
((
es_rri
!=
(
RelationInfo
*
)
NULL
)
&&
if
((
es_rri
!=
(
RelationInfo
*
)
NULL
)
&&
(
node
->
union
relid
==
es_rri
->
ri_RangeTableIndex
))
(
node
->
inherit
relid
==
es_rri
->
ri_RangeTableIndex
))
{
{
RelationInfo
*
rri
;
RelationInfo
*
rri
;
List
*
rtentryP
;
List
*
rtentryP
;
foreach
(
rtentryP
,
rt
entries
)
foreach
(
rtentryP
,
rt
able
)
{
{
Oid
reloid
;
Oid
reloid
;
RangeTblEntry
*
rtentry
=
lfirst
(
rtentryP
);
RangeTblEntry
*
rtentry
=
lfirst
(
rtentryP
);
...
@@ -273,7 +269,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -273,7 +269,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
resultList
=
lcons
(
rri
,
resultList
);
resultList
=
lcons
(
rri
,
resultList
);
ExecOpenIndices
(
reloid
,
rri
);
ExecOpenIndices
(
reloid
,
rri
);
}
}
union
state
->
as_result_relation_info_list
=
resultList
;
append
state
->
as_result_relation_info_list
=
resultList
;
}
}
/* ----------------
/* ----------------
* call ExecInitNode on each of the plans in our list
* call ExecInitNode on each of the plans in our list
...
@@ -294,10 +290,10 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -294,10 +290,10 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* since it may use the range table.
* since it may use the range table.
* ----------------
* ----------------
*/
*/
union
state
->
as_whichplan
=
i
;
append
state
->
as_whichplan
=
i
;
exec_append_initialize_next
(
node
);
exec_append_initialize_next
(
node
);
initNode
=
(
Plan
*
)
nth
(
i
,
union
plans
);
initNode
=
(
Plan
*
)
nth
(
i
,
append
plans
);
initialized
[
i
]
=
ExecInitNode
(
initNode
,
estate
,
(
Plan
*
)
node
);
initialized
[
i
]
=
ExecInitNode
(
initNode
,
estate
,
(
Plan
*
)
node
);
/* ---------------
/* ---------------
...
@@ -308,7 +304,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -308,7 +304,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* ---------------
* ---------------
*/
*/
if
((
es_rri
!=
(
RelationInfo
*
)
NULL
)
&&
if
((
es_rri
!=
(
RelationInfo
*
)
NULL
)
&&
(
node
->
union
relid
==
es_rri
->
ri_RangeTableIndex
))
(
node
->
inherit
relid
==
es_rri
->
ri_RangeTableIndex
))
{
{
targetList
=
initNode
->
targetlist
;
targetList
=
initNode
->
targetlist
;
...
@@ -317,7 +313,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -317,7 +313,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
}
}
}
}
union
state
->
as_junkFilter_list
=
junkList
;
append
state
->
as_junkFilter_list
=
junkList
;
if
(
junkList
!=
NIL
)
if
(
junkList
!=
NIL
)
estate
->
es_junkFilter
=
(
JunkFilter
*
)
lfirst
(
junkList
);
estate
->
es_junkFilter
=
(
JunkFilter
*
)
lfirst
(
junkList
);
...
@@ -325,17 +321,17 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
...
@@ -325,17 +321,17 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
* initialize the return type from the appropriate subplan.
* initialize the return type from the appropriate subplan.
* ----------------
* ----------------
*/
*/
initNode
=
(
Plan
*
)
nth
(
0
,
union
plans
);
initNode
=
(
Plan
*
)
nth
(
0
,
append
plans
);
ExecAssignResultType
(
&
union
state
->
cstate
,
ExecAssignResultType
(
&
append
state
->
cstate
,
/* ExecGetExecTupDesc(initNode), */
/* ExecGetExecTupDesc(initNode), */
ExecGetTupType
(
initNode
));
ExecGetTupType
(
initNode
));
union
state
->
cstate
.
cs_ProjInfo
=
NULL
;
append
state
->
cstate
.
cs_ProjInfo
=
NULL
;
/* ----------------
/* ----------------
* return the result from the first subplan's initialization
* return the result from the first subplan's initialization
* ----------------
* ----------------
*/
*/
union
state
->
as_whichplan
=
0
;
append
state
->
as_whichplan
=
0
;
exec_append_initialize_next
(
node
);
exec_append_initialize_next
(
node
);
#if 0
#if 0
result = (List *) initialized[0];
result = (List *) initialized[0];
...
@@ -347,10 +343,10 @@ int
...
@@ -347,10 +343,10 @@ int
ExecCountSlotsAppend
(
Append
*
node
)
ExecCountSlotsAppend
(
Append
*
node
)
{
{
List
*
plan
;
List
*
plan
;
List
*
unionplans
=
node
->
union
plans
;
List
*
appendplans
=
node
->
append
plans
;
int
nSlots
=
0
;
int
nSlots
=
0
;
foreach
(
plan
,
union
plans
)
foreach
(
plan
,
append
plans
)
nSlots
+=
ExecCountSlotsNode
((
Plan
*
)
lfirst
(
plan
));
nSlots
+=
ExecCountSlotsNode
((
Plan
*
)
lfirst
(
plan
));
return
nSlots
+
APPEND_NSLOTS
;
return
nSlots
+
APPEND_NSLOTS
;
}
}
...
@@ -367,10 +363,10 @@ TupleTableSlot *
...
@@ -367,10 +363,10 @@ TupleTableSlot *
ExecProcAppend
(
Append
*
node
)
ExecProcAppend
(
Append
*
node
)
{
{
EState
*
estate
;
EState
*
estate
;
AppendState
*
union
state
;
AppendState
*
append
state
;
int
whichplan
;
int
whichplan
;
List
*
union
plans
;
List
*
append
plans
;
Plan
*
subnode
;
Plan
*
subnode
;
TupleTableSlot
*
result
;
TupleTableSlot
*
result
;
TupleTableSlot
*
result_slot
;
TupleTableSlot
*
result_slot
;
...
@@ -380,19 +376,19 @@ ExecProcAppend(Append *node)
...
@@ -380,19 +376,19 @@ ExecProcAppend(Append *node)
* get information from the node
* get information from the node
* ----------------
* ----------------
*/
*/
unionstate
=
node
->
union
state
;
appendstate
=
node
->
append
state
;
estate
=
node
->
plan
.
state
;
estate
=
node
->
plan
.
state
;
direction
=
estate
->
es_direction
;
direction
=
estate
->
es_direction
;
unionplans
=
node
->
union
plans
;
appendplans
=
node
->
append
plans
;
whichplan
=
union
state
->
as_whichplan
;
whichplan
=
append
state
->
as_whichplan
;
result_slot
=
union
state
->
cstate
.
cs_ResultTupleSlot
;
result_slot
=
append
state
->
cstate
.
cs_ResultTupleSlot
;
/* ----------------
/* ----------------
* figure out which subplan we are currently processing
* figure out which subplan we are currently processing
* ----------------
* ----------------
*/
*/
subnode
=
(
Plan
*
)
nth
(
whichplan
,
union
plans
);
subnode
=
(
Plan
*
)
nth
(
whichplan
,
append
plans
);
if
(
subnode
==
NULL
)
if
(
subnode
==
NULL
)
elog
(
DEBUG
,
"ExecProcAppend: subnode is NULL"
);
elog
(
DEBUG
,
"ExecProcAppend: subnode is NULL"
);
...
@@ -421,12 +417,12 @@ ExecProcAppend(Append *node)
...
@@ -421,12 +417,12 @@ ExecProcAppend(Append *node)
* direction and try processing again (recursively)
* direction and try processing again (recursively)
* ----------------
* ----------------
*/
*/
whichplan
=
union
state
->
as_whichplan
;
whichplan
=
append
state
->
as_whichplan
;
if
(
ScanDirectionIsForward
(
direction
))
if
(
ScanDirectionIsForward
(
direction
))
union
state
->
as_whichplan
=
whichplan
+
1
;
append
state
->
as_whichplan
=
whichplan
+
1
;
else
else
union
state
->
as_whichplan
=
whichplan
-
1
;
append
state
->
as_whichplan
=
whichplan
-
1
;
/* ----------------
/* ----------------
* return something from next node or an empty slot
* return something from next node or an empty slot
...
@@ -454,9 +450,9 @@ ExecProcAppend(Append *node)
...
@@ -454,9 +450,9 @@ ExecProcAppend(Append *node)
void
void
ExecEndAppend
(
Append
*
node
)
ExecEndAppend
(
Append
*
node
)
{
{
AppendState
*
union
state
;
AppendState
*
append
state
;
int
nplans
;
int
nplans
;
List
*
union
plans
;
List
*
append
plans
;
bool
*
initialized
;
bool
*
initialized
;
int
i
;
int
i
;
List
*
resultRelationInfoList
;
List
*
resultRelationInfoList
;
...
@@ -466,10 +462,10 @@ ExecEndAppend(Append *node)
...
@@ -466,10 +462,10 @@ ExecEndAppend(Append *node)
* get information from the node
* get information from the node
* ----------------
* ----------------
*/
*/
unionstate
=
node
->
union
state
;
appendstate
=
node
->
append
state
;
unionplans
=
node
->
union
plans
;
appendplans
=
node
->
append
plans
;
nplans
=
union
state
->
as_nplans
;
nplans
=
append
state
->
as_nplans
;
initialized
=
union
state
->
as_initialized
;
initialized
=
append
state
->
as_initialized
;
/* ----------------
/* ----------------
* shut down each of the subscans
* shut down each of the subscans
...
@@ -478,14 +474,14 @@ ExecEndAppend(Append *node)
...
@@ -478,14 +474,14 @@ ExecEndAppend(Append *node)
for
(
i
=
0
;
i
<
nplans
;
i
++
)
for
(
i
=
0
;
i
<
nplans
;
i
++
)
{
{
if
(
initialized
[
i
]
==
TRUE
)
if
(
initialized
[
i
]
==
TRUE
)
ExecEndNode
((
Plan
*
)
nth
(
i
,
union
plans
),
(
Plan
*
)
node
);
ExecEndNode
((
Plan
*
)
nth
(
i
,
append
plans
),
(
Plan
*
)
node
);
}
}
/* ----------------
/* ----------------
* close out the different result relations
* close out the different result relations
* ----------------
* ----------------
*/
*/
resultRelationInfoList
=
union
state
->
as_result_relation_info_list
;
resultRelationInfoList
=
append
state
->
as_result_relation_info_list
;
while
(
resultRelationInfoList
!=
NIL
)
while
(
resultRelationInfoList
!=
NIL
)
{
{
Relation
resultRelationDesc
;
Relation
resultRelationDesc
;
...
@@ -496,11 +492,11 @@ ExecEndAppend(Append *node)
...
@@ -496,11 +492,11 @@ ExecEndAppend(Append *node)
pfree
(
resultRelationInfo
);
pfree
(
resultRelationInfo
);
resultRelationInfoList
=
lnext
(
resultRelationInfoList
);
resultRelationInfoList
=
lnext
(
resultRelationInfoList
);
}
}
if
(
union
state
->
as_result_relation_info_list
)
if
(
append
state
->
as_result_relation_info_list
)
pfree
(
union
state
->
as_result_relation_info_list
);
pfree
(
append
state
->
as_result_relation_info_list
);
/*
/*
* XXX should free
union
state->as_rtentries and
* XXX should free
append
state->as_rtentries and
*
union
state->as_junkfilter_list here
*
append
state->as_junkfilter_list here
*/
*/
}
}
src/backend/nodes/copyfuncs.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.4
2 1998/06/15 19:28:30
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.4
3 1998/07/15 14:54:31
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -162,11 +162,11 @@ _copyAppend(Append *from)
...
@@ -162,11 +162,11 @@ _copyAppend(Append *from)
* copy remainder of node
* copy remainder of node
* ----------------
* ----------------
*/
*/
Node_Copy
(
from
,
newnode
,
union
plans
);
Node_Copy
(
from
,
newnode
,
append
plans
);
Node_Copy
(
from
,
newnode
,
unionrts
);
Node_Copy
(
from
,
newnode
,
unionrt
able
s
);
newnode
->
unionrelid
=
from
->
union
relid
;
newnode
->
inheritrelid
=
from
->
inherit
relid
;
Node_Copy
(
from
,
newnode
,
unionrtentries
);
Node_Copy
(
from
,
newnode
,
inheritrtable
);
Node_Copy
(
from
,
newnode
,
union
state
);
Node_Copy
(
from
,
newnode
,
append
state
);
return
newnode
;
return
newnode
;
}
}
...
...
src/backend/nodes/outfuncs.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.
39 1998/07/14 01:45:24
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.
40 1998/07/15 14:54:32
momjian Exp $
*
*
* NOTES
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
* Every (plan) node in POSTGRES has an associated "out" routine which
...
@@ -354,17 +354,17 @@ _outAppend(StringInfo str, Append *node)
...
@@ -354,17 +354,17 @@ _outAppend(StringInfo str, Append *node)
appendStringInfo
(
str
,
" APPEND "
);
appendStringInfo
(
str
,
" APPEND "
);
_outPlanInfo
(
str
,
(
Plan
*
)
node
);
_outPlanInfo
(
str
,
(
Plan
*
)
node
);
appendStringInfo
(
str
,
" :
union
plans "
);
appendStringInfo
(
str
,
" :
append
plans "
);
_outNode
(
str
,
node
->
union
plans
);
_outNode
(
str
,
node
->
append
plans
);
appendStringInfo
(
str
,
" :unionrts "
);
appendStringInfo
(
str
,
" :unionrt
able
s "
);
_outNode
(
str
,
node
->
unionrts
);
_outNode
(
str
,
node
->
unionrt
able
s
);
sprintf
(
buf
,
" :
unionrelid %d "
,
node
->
union
relid
);
sprintf
(
buf
,
" :
inheritrelid %d "
,
node
->
inherit
relid
);
appendStringInfo
(
str
,
buf
);
appendStringInfo
(
str
,
buf
);
appendStringInfo
(
str
,
" :
unionrtentries
"
);
appendStringInfo
(
str
,
" :
inheritrtable
"
);
_outNode
(
str
,
node
->
unionrtentries
);
_outNode
(
str
,
node
->
inheritrtable
);
}
}
...
...
src/backend/nodes/print.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.1
5 1998/06/15 19:28:32
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.1
6 1998/07/15 14:54:33
momjian Exp $
*
*
* HISTORY
* HISTORY
* AUTHOR DATE MAJOR EVENT
* AUTHOR DATE MAJOR EVENT
...
@@ -387,6 +387,23 @@ print_plan_recursive(Plan *p, Query *parsetree, int indentLevel, char *label)
...
@@ -387,6 +387,23 @@ print_plan_recursive(Plan *p, Query *parsetree, int indentLevel, char *label)
printf
(
"
\n
"
);
printf
(
"
\n
"
);
print_plan_recursive
(
p
->
lefttree
,
parsetree
,
indentLevel
+
3
,
"l: "
);
print_plan_recursive
(
p
->
lefttree
,
parsetree
,
indentLevel
+
3
,
"l: "
);
print_plan_recursive
(
p
->
righttree
,
parsetree
,
indentLevel
+
3
,
"r: "
);
print_plan_recursive
(
p
->
righttree
,
parsetree
,
indentLevel
+
3
,
"r: "
);
if
(
nodeTag
(
p
)
==
T_Append
)
{
List
*
lst
;
int
whichplan
=
0
;
Append
*
appendplan
=
(
Append
*
)
p
;
foreach
(
lst
,
appendplan
->
appendplans
)
{
Plan
*
subnode
=
(
Plan
*
)
lfirst
(
lst
);
/* I don't think we need to fiddle with the range table here, bjm */
print_plan_recursive
(
subnode
,
parsetree
,
indentLevel
+
3
,
"a: "
);
whichplan
++
;
}
}
}
}
/* print_plan
/* print_plan
...
...
src/backend/nodes/readfuncs.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.3
1 1998/07/14 01:45:2
4 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.3
2 1998/07/15 14:54:3
4 momjian Exp $
*
*
* NOTES
* NOTES
* Most of the read functions for plan nodes are tested. (In fact, they
* Most of the read functions for plan nodes are tested. (In fact, they
...
@@ -322,18 +322,18 @@ _readAppend()
...
@@ -322,18 +322,18 @@ _readAppend()
_getPlan
((
Plan
*
)
local_node
);
_getPlan
((
Plan
*
)
local_node
);
token
=
lsptok
(
NULL
,
&
length
);
/* eat :
union
plans */
token
=
lsptok
(
NULL
,
&
length
);
/* eat :
append
plans */
local_node
->
union
plans
=
nodeRead
(
true
);
/* now read it */
local_node
->
append
plans
=
nodeRead
(
true
);
/* now read it */
token
=
lsptok
(
NULL
,
&
length
);
/* eat :unionrts */
token
=
lsptok
(
NULL
,
&
length
);
/* eat :unionrt
able
s */
local_node
->
unionrts
=
nodeRead
(
true
);
/* now read it */
local_node
->
unionrt
able
s
=
nodeRead
(
true
);
/* now read it */
token
=
lsptok
(
NULL
,
&
length
);
/* eat :
union
relid */
token
=
lsptok
(
NULL
,
&
length
);
/* eat :
inherit
relid */
token
=
lsptok
(
NULL
,
&
length
);
/* get
union
relid */
token
=
lsptok
(
NULL
,
&
length
);
/* get
inherit
relid */
local_node
->
union
relid
=
strtoul
(
token
,
NULL
,
10
);
local_node
->
inherit
relid
=
strtoul
(
token
,
NULL
,
10
);
token
=
lsptok
(
NULL
,
&
length
);
/* eat :
unionrtentries
*/
token
=
lsptok
(
NULL
,
&
length
);
/* eat :
inheritrtable
*/
local_node
->
unionrtentries
=
nodeRead
(
true
);
/* now read it */
local_node
->
inheritrtable
=
nodeRead
(
true
);
/* now read it */
return
(
local_node
);
return
(
local_node
);
}
}
...
...
src/backend/optimizer/plan/subselect.c
View file @
9e964f90
...
@@ -432,7 +432,7 @@ SS_finalize_plan(Plan *plan)
...
@@ -432,7 +432,7 @@ SS_finalize_plan(Plan *plan)
break
;
break
;
case
T_Append
:
case
T_Append
:
foreach
(
lst
,
((
Append
*
)
plan
)
->
union
plans
)
foreach
(
lst
,
((
Append
*
)
plan
)
->
append
plans
)
param_list
=
set_unioni
(
param_list
,
param_list
=
set_unioni
(
param_list
,
SS_finalize_plan
((
Plan
*
)
lfirst
(
lst
)));
SS_finalize_plan
((
Plan
*
)
lfirst
(
lst
)));
break
;
break
;
...
...
src/backend/optimizer/prep/prepunion.c
View file @
9e964f90
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.2
4 1998/06/15 19:28:46
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.2
5 1998/07/15 14:54:37
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -48,8 +48,8 @@ static void
...
@@ -48,8 +48,8 @@ static void
fix_parsetree_attnums
(
Index
rt_index
,
Oid
old_relid
,
fix_parsetree_attnums
(
Index
rt_index
,
Oid
old_relid
,
Oid
new_relid
,
Query
*
parsetree
);
Oid
new_relid
,
Query
*
parsetree
);
static
Append
*
static
Append
*
make_append
(
List
*
unionplans
,
List
*
unionrt
s
,
Index
rt_index
,
make_append
(
List
*
appendplans
,
List
*
unionrtable
s
,
Index
rt_index
,
List
*
union_rt_entries
,
List
*
tlist
);
List
*
inheritrtable
,
List
*
tlist
);
/*
/*
...
@@ -224,7 +224,7 @@ plan_inherit_queries(Query *parse, Index rt_index)
...
@@ -224,7 +224,7 @@ plan_inherit_queries(Query *parse, Index rt_index)
List
*
rangetable
=
parse
->
rtable
;
List
*
rangetable
=
parse
->
rtable
;
RangeTblEntry
*
rt_entry
=
rt_fetch
(
rt_index
,
rangetable
);
RangeTblEntry
*
rt_entry
=
rt_fetch
(
rt_index
,
rangetable
);
List
*
union_rt_entries
=
NIL
;
List
*
inheritrtable
=
NIL
;
List
*
union_relids
=
NIL
;
List
*
union_relids
=
NIL
;
union_relids
=
union_relids
=
...
@@ -239,12 +239,12 @@ plan_inherit_queries(Query *parse, Index rt_index)
...
@@ -239,12 +239,12 @@ plan_inherit_queries(Query *parse, Index rt_index)
rt_fetch
(
rt_index
,
rangetable
)
->
inh
=
false
;
rt_fetch
(
rt_index
,
rangetable
)
->
inh
=
false
;
union_plans
=
plan_inherit_query
(
union_relids
,
rt_index
,
rt_entry
,
union_plans
=
plan_inherit_query
(
union_relids
,
rt_index
,
rt_entry
,
parse
,
&
union_rt_entries
);
parse
,
&
inheritrtable
);
return
(
make_append
(
union_plans
,
return
(
make_append
(
union_plans
,
NULL
,
NULL
,
rt_index
,
rt_index
,
union_rt_entries
,
inheritrtable
,
((
Plan
*
)
lfirst
(
union_plans
))
->
targetlist
));
((
Plan
*
)
lfirst
(
union_plans
))
->
targetlist
));
}
}
...
@@ -494,19 +494,22 @@ fix_parsetree_attnums(Index rt_index,
...
@@ -494,19 +494,22 @@ fix_parsetree_attnums(Index rt_index,
}
}
static
Append
*
static
Append
*
make_append
(
List
*
union
plans
,
make_append
(
List
*
append
plans
,
List
*
unionrts
,
List
*
unionrt
able
s
,
Index
rt_index
,
Index
rt_index
,
List
*
union_rt_entries
,
List
*
inheritrtable
,
List
*
tlist
)
List
*
tlist
)
{
{
Append
*
node
=
makeNode
(
Append
);
Append
*
node
=
makeNode
(
Append
);
List
*
subnode
;
node
->
unionplans
=
unionplans
;
node
->
unionrts
=
unionrts
;
node
->
appendplans
=
appendplans
;
node
->
unionrelid
=
rt_index
;
node
->
unionrtables
=
unionrtables
;
node
->
unionrtentries
=
union_rt_entries
;
node
->
inheritrelid
=
rt_index
;
node
->
inheritrtable
=
inheritrtable
;
node
->
plan
.
cost
=
0
.
0
;
node
->
plan
.
cost
=
0
.
0
;
foreach
(
subnode
,
appendplans
)
node
->
plan
.
cost
+=
((
Plan
*
)
lfirst
(
subnode
))
->
cost
;
node
->
plan
.
state
=
(
EState
*
)
NULL
;
node
->
plan
.
state
=
(
EState
*
)
NULL
;
node
->
plan
.
targetlist
=
tlist
;
node
->
plan
.
targetlist
=
tlist
;
node
->
plan
.
qual
=
NIL
;
node
->
plan
.
qual
=
NIL
;
...
...
src/include/nodes/plannodes.h
View file @
9e964f90
...
@@ -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: plannodes.h,v 1.1
5 1998/02/26 04:42:01
momjian Exp $
* $Id: plannodes.h,v 1.1
6 1998/07/15 14:54:39
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
* control nodes
* control nodes
*
*
* Result ResultState resstate;
* Result ResultState resstate;
* Append AppendState
union
state;
* Append AppendState
append
state;
*
*
* scan nodes
* scan nodes
*
*
...
@@ -138,11 +138,17 @@ typedef struct Result
...
@@ -138,11 +138,17 @@ typedef struct Result
typedef
struct
Append
typedef
struct
Append
{
{
Plan
plan
;
Plan
plan
;
List
*
unionplans
;
List
*
appendplans
;
List
*
unionrts
;
List
*
unionrtables
;
/*
Index
unionrelid
;
* List of range tables, one for each
List
*
unionrtentries
;
* union query.
AppendState
*
unionstate
;
*/
Index
inheritrelid
;
/*
* The range table has to be changed for
* inheritance.
*/
List
*
inheritrtable
;
AppendState
*
appendstate
;
}
Append
;
}
Append
;
/*
/*
...
...
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