Commit 9e964f90 authored by Bruce Momjian's avatar Bruce Momjian

Fix explain for union and inheritance. Rename Append structure

members to be clearer.  Fix cost computation for these.
parent 9fdbbdc8
...@@ -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;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.18 1998/04/24 14:41:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.19 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 *unionstate; AppendState *appendstate;
List *unionplans; List *appendplans;
int whichplan; int whichplan;
Plan *subplan; Plan *subplan;
unionstate = n->unionstate; appendstate = n->appendstate;
unionplans = n->unionplans; appendplans = n->appendplans;
whichplan = unionstate->as_whichplan; whichplan = appendstate->as_whichplan;
subplan = (Plan *) nth(whichplan, unionplans); subplan = (Plan *) nth(whichplan, appendplans);
slot = NodeGetResultTupleSlot(subplan); slot = NodeGetResultTupleSlot(subplan);
break; break;
} }
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.42 1998/06/15 19:28:30 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.43 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, unionplans); Node_Copy(from, newnode, appendplans);
Node_Copy(from, newnode, unionrts); Node_Copy(from, newnode, unionrtables);
newnode->unionrelid = from->unionrelid; newnode->inheritrelid = from->inheritrelid;
Node_Copy(from, newnode, unionrtentries); Node_Copy(from, newnode, inheritrtable);
Node_Copy(from, newnode, unionstate); Node_Copy(from, newnode, appendstate);
return newnode; return newnode;
} }
......
...@@ -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, " :unionplans "); appendStringInfo(str, " :appendplans ");
_outNode(str, node->unionplans); _outNode(str, node->appendplans);
appendStringInfo(str, " :unionrts "); appendStringInfo(str, " :unionrtables ");
_outNode(str, node->unionrts); _outNode(str, node->unionrtables);
sprintf(buf, " :unionrelid %d ", node->unionrelid); sprintf(buf, " :inheritrelid %d ", node->inheritrelid);
appendStringInfo(str, buf); appendStringInfo(str, buf);
appendStringInfo(str, " :unionrtentries "); appendStringInfo(str, " :inheritrtable ");
_outNode(str, node->unionrtentries); _outNode(str, node->inheritrtable);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.15 1998/06/15 19:28:32 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.16 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
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.31 1998/07/14 01:45:24 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.32 1998/07/15 14:54:34 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 :unionplans */ token = lsptok(NULL, &length); /* eat :appendplans */
local_node->unionplans = nodeRead(true); /* now read it */ local_node->appendplans = nodeRead(true); /* now read it */
token = lsptok(NULL, &length); /* eat :unionrts */ token = lsptok(NULL, &length); /* eat :unionrtables */
local_node->unionrts = nodeRead(true); /* now read it */ local_node->unionrtables = nodeRead(true); /* now read it */
token = lsptok(NULL, &length); /* eat :unionrelid */ token = lsptok(NULL, &length); /* eat :inheritrelid */
token = lsptok(NULL, &length); /* get unionrelid */ token = lsptok(NULL, &length); /* get inheritrelid */
local_node->unionrelid = strtoul(token, NULL, 10); local_node->inheritrelid = 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);
} }
......
...@@ -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)->unionplans) foreach(lst, ((Append *) plan)->appendplans)
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;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.24 1998/06/15 19:28:46 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.25 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 *unionrts, Index rt_index, make_append(List *appendplans, List *unionrtables, 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 *unionplans, make_append(List *appendplans,
List *unionrts, List *unionrtables,
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;
......
...@@ -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.15 1998/02/26 04:42:01 momjian Exp $ * $Id: plannodes.h,v 1.16 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 unionstate; * Append AppendState appendstate;
* *
* 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;
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment