diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-02-08 18:02:27 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-02-08 18:02:27 +0000 |
commit | 3d02cae310deec7ca48ada68e553bfeedbd0f638 (patch) | |
tree | 231ac03313d6df497cc76c1302c2a9a38fc9c6bf /src/backend/executor/execMain.c | |
parent | 053835d334a6c533e3304e0171c078bc04f9514c (diff) | |
download | postgresql-3d02cae310deec7ca48ada68e553bfeedbd0f638.tar.gz postgresql-3d02cae310deec7ca48ada68e553bfeedbd0f638.zip |
Ensure that INSERT ... SELECT into a table with OIDs never copies row OIDs
from the source table. This could never happen anyway before 8.4 because
the executor invariably applied a "junk filter" to rows due to be inserted;
but now that we skip doing that when it's not necessary, the case can occur.
Problem noted 2008-11-27 by KaiGai Kohei, though I misunderstood what he
was on about at the time (the opacity of the patch he proposed didn't help).
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r-- | src/backend/executor/execMain.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 41b6737049b..2ff4150f601 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.322 2009/02/02 19:31:39 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.323 2009/02/08 18:02:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1766,6 +1766,21 @@ ExecInsert(TupleTableSlot *slot, resultRelInfo = estate->es_result_relation_info; resultRelationDesc = resultRelInfo->ri_RelationDesc; + /* + * If the result relation has OIDs, force the tuple's OID to zero so that + * heap_insert will assign a fresh OID. Usually the OID already will be + * zero at this point, but there are corner cases where the plan tree can + * return a tuple extracted literally from some table with the same + * rowtype. + * + * XXX if we ever wanted to allow users to assign their own OIDs to new + * rows, this'd be the place to do it. For the moment, we make a point + * of doing this before calling triggers, so that a user-supplied trigger + * could hack the OID if desired. + */ + if (resultRelationDesc->rd_rel->relhasoids) + HeapTupleSetOid(tuple, InvalidOid); + /* BEFORE ROW INSERT Triggers */ if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->n_before_row[TRIGGER_EVENT_INSERT] > 0) @@ -3033,6 +3048,12 @@ intorel_receive(TupleTableSlot *slot, DestReceiver *self) */ tuple = ExecMaterializeSlot(slot); + /* + * force assignment of new OID (see comments in ExecInsert) + */ + if (myState->rel->rd_rel->relhasoids) + HeapTupleSetOid(tuple, InvalidOid); + heap_insert(myState->rel, tuple, myState->estate->es_output_cid, |