Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 05e3d0e

Browse files
committed
Reimplementation of UNION/INTERSECT/EXCEPT. INTERSECT/EXCEPT now meet the
SQL92 semantics, including support for ALL option. All three can be used in subqueries and views. DISTINCT and ORDER BY work now in views, too. This rewrite fixes many problems with cross-datatype UNIONs and INSERT/SELECT where the SELECT yields different datatypes than the INSERT needs. I did that by making UNION subqueries and SELECT in INSERT be treated like subselects-in-FROM, thereby allowing an extra level of targetlist where the datatype conversions can be inserted safely. INITDB NEEDED!
1 parent 5292637 commit 05e3d0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2588
-1902
lines changed

src/backend/commands/explain.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.59 2000/09/29 18:21:26 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.60 2000/10/05 19:11:26 tgl Exp $
99
*
1010
*/
1111

@@ -197,6 +197,26 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
197197
case T_Unique:
198198
pname = "Unique";
199199
break;
200+
case T_SetOp:
201+
switch (((SetOp *) plan)->cmd)
202+
{
203+
case SETOPCMD_INTERSECT:
204+
pname = "SetOp Intersect";
205+
break;
206+
case SETOPCMD_INTERSECT_ALL:
207+
pname = "SetOp Intersect All";
208+
break;
209+
case SETOPCMD_EXCEPT:
210+
pname = "SetOp Except";
211+
break;
212+
case SETOPCMD_EXCEPT_ALL:
213+
pname = "SetOp Except All";
214+
break;
215+
default:
216+
pname = "SetOp ???";
217+
break;
218+
}
219+
break;
200220
case T_Hash:
201221
pname = "Hash";
202222
break;
@@ -320,8 +340,6 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
320340
Assert(rtentry != NULL);
321341
rt_store(appendplan->inheritrelid, es->rtable, rtentry);
322342
}
323-
else
324-
es->rtable = nth(whichplan, appendplan->unionrtables);
325343

326344
for (i = 0; i < indent; i++)
327345
appendStringInfo(str, " ");

src/backend/executor/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for executor
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/executor/Makefile,v 1.14 2000/09/29 18:21:28 tgl Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/executor/Makefile,v 1.15 2000/10/05 19:11:26 tgl Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -16,7 +16,7 @@ OBJS = execAmi.o execFlatten.o execJunk.o execMain.o \
1616
execProcnode.o execQual.o execScan.o execTuples.o \
1717
execUtils.o functions.o nodeAppend.o nodeAgg.o nodeHash.o \
1818
nodeHashjoin.o nodeIndexscan.o nodeMaterial.o nodeMergejoin.o \
19-
nodeNestloop.o nodeResult.o nodeSeqscan.o nodeSort.o \
19+
nodeNestloop.o nodeResult.o nodeSeqscan.o nodeSetOp.o nodeSort.o \
2020
nodeUnique.o nodeGroup.o spi.o nodeSubplan.o \
2121
nodeSubqueryscan.o nodeTidscan.o
2222

src/backend/executor/execAmi.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: execAmi.c,v 1.52 2000/09/29 18:21:28 tgl Exp $
9+
* $Id: execAmi.c,v 1.53 2000/10/05 19:11:26 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -42,6 +42,7 @@
4242
#include "executor/nodeNestloop.h"
4343
#include "executor/nodeResult.h"
4444
#include "executor/nodeSeqscan.h"
45+
#include "executor/nodeSetOp.h"
4546
#include "executor/nodeSort.h"
4647
#include "executor/nodeSubplan.h"
4748
#include "executor/nodeSubqueryscan.h"
@@ -345,6 +346,10 @@ ExecReScan(Plan *node, ExprContext *exprCtxt, Plan *parent)
345346
ExecReScanUnique((Unique *) node, exprCtxt, parent);
346347
break;
347348

349+
case T_SetOp:
350+
ExecReScanSetOp((SetOp *) node, exprCtxt, parent);
351+
break;
352+
348353
case T_Sort:
349354
ExecReScanSort((Sort *) node, exprCtxt, parent);
350355
break;

src/backend/executor/execMain.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.128 2000/09/29 18:21:28 tgl Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.129 2000/10/05 19:11:26 tgl Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -463,7 +463,6 @@ ExecCheckPlanPerms(Plan *plan, List *rangeTable, CmdType operation)
463463
/* Append implements expansion of inheritance */
464464
ExecCheckRTPerms(app->inheritrtable, operation);
465465

466-
/* Check appended plans w/outer rangetable */
467466
foreach(appendplans, app->appendplans)
468467
{
469468
ExecCheckPlanPerms((Plan *) lfirst(appendplans),
@@ -474,15 +473,11 @@ ExecCheckPlanPerms(Plan *plan, List *rangeTable, CmdType operation)
474473
else
475474
{
476475
/* Append implements UNION, which must be a SELECT */
477-
List *rtables = app->unionrtables;
478-
479-
/* Check appended plans with their rangetables */
480476
foreach(appendplans, app->appendplans)
481477
{
482478
ExecCheckPlanPerms((Plan *) lfirst(appendplans),
483-
(List *) lfirst(rtables),
479+
rangeTable,
484480
CMD_SELECT);
485-
rtables = lnext(rtables);
486481
}
487482
}
488483
break;

src/backend/executor/execProcnode.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.20 2000/09/29 18:21:29 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.21 2000/10/05 19:11:26 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -88,6 +88,7 @@
8888
#include "executor/nodeNestloop.h"
8989
#include "executor/nodeResult.h"
9090
#include "executor/nodeSeqscan.h"
91+
#include "executor/nodeSetOp.h"
9192
#include "executor/nodeSort.h"
9293
#include "executor/nodeSubplan.h"
9394
#include "executor/nodeSubqueryscan.h"
@@ -199,6 +200,10 @@ ExecInitNode(Plan *node, EState *estate, Plan *parent)
199200
result = ExecInitUnique((Unique *) node, estate, parent);
200201
break;
201202

203+
case T_SetOp:
204+
result = ExecInitSetOp((SetOp *) node, estate, parent);
205+
break;
206+
202207
case T_Group:
203208
result = ExecInitGroup((Group *) node, estate, parent);
204209
break;
@@ -322,6 +327,10 @@ ExecProcNode(Plan *node, Plan *parent)
322327
result = ExecUnique((Unique *) node);
323328
break;
324329

330+
case T_SetOp:
331+
result = ExecSetOp((SetOp *) node);
332+
break;
333+
325334
case T_Group:
326335
result = ExecGroup((Group *) node);
327336
break;
@@ -401,6 +410,9 @@ ExecCountSlotsNode(Plan *node)
401410
case T_Unique:
402411
return ExecCountSlotsUnique((Unique *) node);
403412

413+
case T_SetOp:
414+
return ExecCountSlotsSetOp((SetOp *) node);
415+
404416
case T_Group:
405417
return ExecCountSlotsGroup((Group *) node);
406418

@@ -519,6 +531,10 @@ ExecEndNode(Plan *node, Plan *parent)
519531
ExecEndUnique((Unique *) node);
520532
break;
521533

534+
case T_SetOp:
535+
ExecEndSetOp((SetOp *) node);
536+
break;
537+
522538
case T_Group:
523539
ExecEndGroup((Group *) node);
524540
break;

src/backend/executor/execTuples.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.40 2000/09/29 18:21:29 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.41 2000/10/05 19:11:26 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -762,6 +762,14 @@ NodeGetResultTupleSlot(Plan *node)
762762
}
763763
break;
764764

765+
case T_SetOp:
766+
{
767+
SetOpState *setopstate = ((SetOp *) node)->setopstate;
768+
769+
slot = setopstate->cstate.cs_ResultTupleSlot;
770+
}
771+
break;
772+
765773
case T_MergeJoin:
766774
{
767775
MergeJoinState *mergestate = ((MergeJoin *) node)->mergestate;
@@ -783,8 +791,8 @@ NodeGetResultTupleSlot(Plan *node)
783791
* should never get here
784792
* ----------------
785793
*/
786-
elog(ERROR, "NodeGetResultTupleSlot: node not yet supported: %d ",
787-
nodeTag(node));
794+
elog(ERROR, "NodeGetResultTupleSlot: node not yet supported: %d",
795+
(int) nodeTag(node));
788796

789797
return NULL;
790798
}

src/backend/executor/nodeAppend.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.35 2000/07/12 02:37:03 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.36 2000/10/05 19:11:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -80,11 +80,9 @@ exec_append_initialize_next(Append *node)
8080
AppendState *appendstate;
8181
TupleTableSlot *result_slot;
8282
List *rangeTable;
83-
8483
int whichplan;
8584
int nplans;
86-
List *rtables;
87-
List *rtable;
85+
List *inheritrtable;
8886
RangeTblEntry *rtentry;
8987

9088
/* ----------------
@@ -98,8 +96,7 @@ exec_append_initialize_next(Append *node)
9896

9997
whichplan = appendstate->as_whichplan;
10098
nplans = appendstate->as_nplans;
101-
rtables = node->unionrtables;
102-
rtable = node->inheritrtable;
99+
inheritrtable = node->inheritrtable;
103100

104101
if (whichplan < 0)
105102
{
@@ -131,19 +128,17 @@ exec_append_initialize_next(Append *node)
131128
/* ----------------
132129
* initialize the scan
133130
* (and update the range table appropriately)
134-
* (doesn't this leave the range table hosed for anybody upstream
135-
* of the Append node??? - jolly )
131+
*
132+
* (doesn't this leave the range table hosed for anybody upstream
133+
* of the Append node??? - jolly )
136134
* ----------------
137135
*/
138136
if (node->inheritrelid > 0)
139137
{
140-
rtentry = nth(whichplan, rtable);
138+
rtentry = nth(whichplan, inheritrtable);
141139
Assert(rtentry != NULL);
142-
143140
rt_store(node->inheritrelid, rangeTable, rtentry);
144141
}
145-
else
146-
estate->es_range_table = nth(whichplan, rtables);
147142

148143
if (appendstate->as_junkFilter_list)
149144
{
@@ -181,7 +176,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
181176
{
182177
AppendState *appendstate;
183178
int nplans;
184-
List *rtable;
179+
List *inheritrtable;
185180
List *appendplans;
186181
bool *initialized;
187182
int i;
@@ -201,7 +196,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
201196

202197
appendplans = node->appendplans;
203198
nplans = length(appendplans);
204-
rtable = node->inheritrtable;
199+
inheritrtable = node->inheritrtable;
205200

206201
initialized = (bool *) palloc(nplans * sizeof(bool));
207202
MemSet(initialized, 0, nplans * sizeof(bool));
@@ -214,7 +209,6 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
214209
appendstate->as_whichplan = 0;
215210
appendstate->as_nplans = nplans;
216211
appendstate->as_initialized = initialized;
217-
appendstate->as_rtentries = rtable;
218212

219213
node->appendstate = appendstate;
220214

@@ -250,7 +244,7 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
250244

251245
inherited_result_rel = true;
252246

253-
foreach(rtentryP, rtable)
247+
foreach(rtentryP, inheritrtable)
254248
{
255249
RangeTblEntry *rtentry = lfirst(rtentryP);
256250
Oid reloid = rtentry->relid;
@@ -522,8 +516,7 @@ ExecEndAppend(Append *node)
522516
estate->es_result_relation_info = NULL;
523517

524518
/*
525-
* XXX should free appendstate->as_rtentries and
526-
* appendstate->as_junkfilter_list here
519+
* XXX should free appendstate->as_junkfilter_list here
527520
*/
528521
}
529522
void

0 commit comments

Comments
 (0)