1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

Change CREATE TABLE AS / SELECT INTO to create the new table with OIDs,

for backwards compatibility with pre-7.3 behavior.  Per discussion on
pgsql-general and pgsql-hackers.
This commit is contained in:
Tom Lane
2003-01-23 05:10:57 +00:00
parent d73531209c
commit 01376c215c
3 changed files with 42 additions and 26 deletions

View File

@@ -27,7 +27,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.180 2002/10/14 16:51:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.180.2.1 2003/01/23 05:10:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -450,6 +450,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
{ {
List *rangeTable; List *rangeTable;
Relation intoRelationDesc; Relation intoRelationDesc;
bool do_select_into;
TupleDesc tupType; TupleDesc tupType;
/* /*
@@ -527,6 +528,26 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
estate->es_result_relation_info = NULL; estate->es_result_relation_info = NULL;
} }
/*
* Detect whether we're doing SELECT INTO. If so, set the force_oids
* flag appropriately so that the plan tree will be initialized with
* the correct tuple descriptors.
*/
do_select_into = false;
if (operation == CMD_SELECT &&
!parseTree->isPortal &&
parseTree->into != NULL)
{
do_select_into = true;
/*
* For now, always create OIDs in SELECT INTO; this is for backwards
* compatibility with pre-7.3 behavior. Eventually we might want
* to allow the user to choose.
*/
estate->es_force_oids = true;
}
/* /*
* Have to lock relations selected for update * Have to lock relations selected for update
*/ */
@@ -686,14 +707,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
*/ */
intoRelationDesc = (Relation) NULL; intoRelationDesc = (Relation) NULL;
if (operation == CMD_SELECT) if (do_select_into)
{
if (!parseTree->isPortal)
{
/*
* a select into table --- need to create the "into" table
*/
if (parseTree->into != NULL)
{ {
char *intoName; char *intoName;
Oid namespaceId; Oid namespaceId;
@@ -718,14 +732,6 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
*/ */
tupdesc = CreateTupleDescCopy(tupType); tupdesc = CreateTupleDescCopy(tupType);
/*
* Formerly we forced the output table to have OIDs, but
* as of 7.3 it will not have OIDs, because it's too late
* here to change the tupdescs of the already-initialized
* plan tree. (Perhaps we could recurse and change them
* all, but it's not really worth the trouble IMHO...)
*/
intoRelationId = intoRelationId =
heap_create_with_catalog(intoName, heap_create_with_catalog(intoName,
namespaceId, namespaceId,
@@ -753,8 +759,6 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
intoRelationDesc = heap_open(intoRelationId, intoRelationDesc = heap_open(intoRelationId,
AccessExclusiveLock); AccessExclusiveLock);
} }
}
}
estate->es_into_relation_descriptor = intoRelationDesc; estate->es_into_relation_descriptor = intoRelationDesc;
@@ -1852,6 +1856,7 @@ EvalPlanQual(EState *estate, Index rti, ItemPointer tid)
if (estate->es_origPlan->nParamExec > 0) if (estate->es_origPlan->nParamExec > 0)
memset(epqstate->es_param_exec_vals, 0, memset(epqstate->es_param_exec_vals, 0,
estate->es_origPlan->nParamExec * sizeof(ParamExecData)); estate->es_origPlan->nParamExec * sizeof(ParamExecData));
epqstate->es_force_oids = estate->es_force_oids;
memset(epqstate->es_evTupleNull, false, rtsize * sizeof(bool)); memset(epqstate->es_evTupleNull, false, rtsize * sizeof(bool));
epqstate->es_useEvalPlan = false; epqstate->es_useEvalPlan = false;
Assert(epqstate->es_tupleTable == NULL); Assert(epqstate->es_tupleTable == NULL);

View File

@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.90 2002/09/04 20:31:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.90.2.1 2003/01/23 05:10:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -310,7 +310,15 @@ ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate)
* have to make the decision on a per-relation basis as we initialize * have to make the decision on a per-relation basis as we initialize
* each of the child plans of the topmost Append plan. So, this is * each of the child plans of the topmost Append plan. So, this is
* ugly but it works, for now ... * ugly but it works, for now ...
*
* SELECT INTO is also pretty grotty, because we don't yet have the
* INTO relation's descriptor at this point; we have to look aside
* at a flag set by InitPlan().
*/ */
if (node->state->es_force_oids)
hasoid = true;
else
{
ri = node->state->es_result_relation_info; ri = node->state->es_result_relation_info;
if (ri != NULL) if (ri != NULL)
{ {
@@ -319,6 +327,7 @@ ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate)
if (rel != NULL) if (rel != NULL)
hasoid = rel->rd_rel->relhasoids; hasoid = rel->rd_rel->relhasoids;
} }
}
tupDesc = ExecTypeFromTL(node->targetlist, hasoid); tupDesc = ExecTypeFromTL(node->targetlist, hasoid);
ExecAssignResultType(commonstate, tupDesc, true); ExecAssignResultType(commonstate, tupDesc, true);

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: execnodes.h,v 1.75 2002/09/04 20:31:42 momjian Exp $ * $Id: execnodes.h,v 1.75.2.1 2003/01/23 05:10:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -306,6 +306,8 @@ typedef struct EState
uint32 es_processed; /* # of tuples processed */ uint32 es_processed; /* # of tuples processed */
Oid es_lastoid; /* last oid processed (by INSERT) */ Oid es_lastoid; /* last oid processed (by INSERT) */
List *es_rowMark; /* not good place, but there is no other */ List *es_rowMark; /* not good place, but there is no other */
bool es_force_oids; /* true forces result tuples to have (space
* for) OIDs --- used for SELECT INTO */
MemoryContext es_query_cxt; /* per-query context in which EState lives */ MemoryContext es_query_cxt; /* per-query context in which EState lives */
/* /*