1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Revert "Modified files for MERGE"

This reverts commit 354f13855e.
This commit is contained in:
Simon Riggs
2018-04-02 21:34:15 +01:00
parent 354f13855e
commit 7cf8a5c302
82 changed files with 165 additions and 2570 deletions

View File

@ -85,8 +85,7 @@ static HeapTuple GetTupleForTrigger(EState *estate,
ResultRelInfo *relinfo,
ItemPointer tid,
LockTupleMode lockmode,
TupleTableSlot **newSlot,
HeapUpdateFailureData *hufdp);
TupleTableSlot **newSlot);
static bool TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
Trigger *trigger, TriggerEvent event,
Bitmapset *modifiedCols,
@ -2730,8 +2729,7 @@ bool
ExecBRDeleteTriggers(EState *estate, EPQState *epqstate,
ResultRelInfo *relinfo,
ItemPointer tupleid,
HeapTuple fdw_trigtuple,
HeapUpdateFailureData *hufdp)
HeapTuple fdw_trigtuple)
{
TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
bool result = true;
@ -2745,7 +2743,7 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate,
if (fdw_trigtuple == NULL)
{
trigtuple = GetTupleForTrigger(estate, epqstate, relinfo, tupleid,
LockTupleExclusive, &newSlot, hufdp);
LockTupleExclusive, &newSlot);
if (trigtuple == NULL)
return false;
}
@ -2816,7 +2814,6 @@ ExecARDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
relinfo,
tupleid,
LockTupleExclusive,
NULL,
NULL);
else
trigtuple = fdw_trigtuple;
@ -2954,8 +2951,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate,
ResultRelInfo *relinfo,
ItemPointer tupleid,
HeapTuple fdw_trigtuple,
TupleTableSlot *slot,
HeapUpdateFailureData *hufdp)
TupleTableSlot *slot)
{
TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
HeapTuple slottuple = ExecMaterializeSlot(slot);
@ -2976,7 +2972,7 @@ ExecBRUpdateTriggers(EState *estate, EPQState *epqstate,
{
/* get a copy of the on-disk tuple we are planning to update */
trigtuple = GetTupleForTrigger(estate, epqstate, relinfo, tupleid,
lockmode, &newSlot, hufdp);
lockmode, &newSlot);
if (trigtuple == NULL)
return NULL; /* cancel the update action */
}
@ -3096,7 +3092,6 @@ ExecARUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
relinfo,
tupleid,
LockTupleExclusive,
NULL,
NULL);
else
trigtuple = fdw_trigtuple;
@ -3245,8 +3240,7 @@ GetTupleForTrigger(EState *estate,
ResultRelInfo *relinfo,
ItemPointer tid,
LockTupleMode lockmode,
TupleTableSlot **newSlot,
HeapUpdateFailureData *hufdp)
TupleTableSlot **newSlot)
{
Relation relation = relinfo->ri_RelationDesc;
HeapTupleData tuple;
@ -3272,11 +3266,6 @@ ltrmark:;
estate->es_output_cid,
lockmode, LockWaitBlock,
false, &buffer, &hufd);
/* Let the caller know about failure reason, if any. */
if (hufdp)
*hufdp = hufd;
switch (test)
{
case HeapTupleSelfUpdated:
@ -3313,17 +3302,10 @@ ltrmark:;
/* it was updated, so look at the updated version */
TupleTableSlot *epqslot;
/*
* If we're running MERGE then we must install the
* new tuple in the slot of the underlying join query and
* not the result relation itself. If the join does not
* yield any tuple, the caller will take the necessary
* action.
*/
epqslot = EvalPlanQual(estate,
epqstate,
relation,
GetEPQRangeTableIndex(relinfo),
relinfo->ri_RangeTableIndex,
lockmode,
&hufd.ctid,
hufd.xmax);
@ -3846,14 +3828,8 @@ struct AfterTriggersTableData
bool before_trig_done; /* did we already queue BS triggers? */
bool after_trig_done; /* did we already queue AS triggers? */
AfterTriggerEventList after_trig_events; /* if so, saved list pointer */
/* "old" transition table for UPDATE, if any */
Tuplestorestate *old_upd_tuplestore;
/* "new" transition table for UPDATE, if any */
Tuplestorestate *new_upd_tuplestore;
/* "old" transition table for DELETE, if any */
Tuplestorestate *old_del_tuplestore;
/* "new" transition table INSERT, if any */
Tuplestorestate *new_ins_tuplestore;
Tuplestorestate *old_tuplestore; /* "old" transition table, if any */
Tuplestorestate *new_tuplestore; /* "new" transition table, if any */
};
static AfterTriggersData afterTriggers;
@ -4320,19 +4296,13 @@ AfterTriggerExecute(AfterTriggerEvent event,
{
if (LocTriggerData.tg_trigger->tgoldtable)
{
if (TRIGGER_FIRED_BY_UPDATE(evtshared->ats_event))
LocTriggerData.tg_oldtable = evtshared->ats_table->old_upd_tuplestore;
else
LocTriggerData.tg_oldtable = evtshared->ats_table->old_del_tuplestore;
LocTriggerData.tg_oldtable = evtshared->ats_table->old_tuplestore;
evtshared->ats_table->closed = true;
}
if (LocTriggerData.tg_trigger->tgnewtable)
{
if (TRIGGER_FIRED_BY_INSERT(evtshared->ats_event))
LocTriggerData.tg_newtable = evtshared->ats_table->new_ins_tuplestore;
else
LocTriggerData.tg_newtable = evtshared->ats_table->new_upd_tuplestore;
LocTriggerData.tg_newtable = evtshared->ats_table->new_tuplestore;
evtshared->ats_table->closed = true;
}
}
@ -4667,10 +4637,8 @@ TransitionCaptureState *
MakeTransitionCaptureState(TriggerDesc *trigdesc, Oid relid, CmdType cmdType)
{
TransitionCaptureState *state;
bool need_old_upd,
need_new_upd,
need_old_del,
need_new_ins;
bool need_old,
need_new;
AfterTriggersTableData *table;
MemoryContext oldcxt;
ResourceOwner saveResourceOwner;
@ -4682,31 +4650,23 @@ MakeTransitionCaptureState(TriggerDesc *trigdesc, Oid relid, CmdType cmdType)
switch (cmdType)
{
case CMD_INSERT:
need_old_upd = need_old_del = need_new_upd = false;
need_new_ins = trigdesc->trig_insert_new_table;
need_old = false;
need_new = trigdesc->trig_insert_new_table;
break;
case CMD_UPDATE:
need_old_upd = trigdesc->trig_update_old_table;
need_new_upd = trigdesc->trig_update_new_table;
need_old_del = need_new_ins = false;
need_old = trigdesc->trig_update_old_table;
need_new = trigdesc->trig_update_new_table;
break;
case CMD_DELETE:
need_old_del = trigdesc->trig_delete_old_table;
need_old_upd = need_new_upd = need_new_ins = false;
break;
case CMD_MERGE:
need_old_upd = trigdesc->trig_update_old_table;
need_new_upd = trigdesc->trig_update_new_table;
need_old_del = trigdesc->trig_delete_old_table;
need_new_ins = trigdesc->trig_insert_new_table;
need_old = trigdesc->trig_delete_old_table;
need_new = false;
break;
default:
elog(ERROR, "unexpected CmdType: %d", (int) cmdType);
/* keep compiler quiet */
need_old_upd = need_new_upd = need_old_del = need_new_ins = false;
need_old = need_new = false; /* keep compiler quiet */
break;
}
if (!need_old_upd && !need_new_upd && !need_new_ins && !need_old_del)
if (!need_old && !need_new)
return NULL;
/* Check state, like AfterTriggerSaveEvent. */
@ -4736,14 +4696,10 @@ MakeTransitionCaptureState(TriggerDesc *trigdesc, Oid relid, CmdType cmdType)
saveResourceOwner = CurrentResourceOwner;
CurrentResourceOwner = CurTransactionResourceOwner;
if (need_old_upd && table->old_upd_tuplestore == NULL)
table->old_upd_tuplestore = tuplestore_begin_heap(false, false, work_mem);
if (need_new_upd && table->new_upd_tuplestore == NULL)
table->new_upd_tuplestore = tuplestore_begin_heap(false, false, work_mem);
if (need_old_del && table->old_del_tuplestore == NULL)
table->old_del_tuplestore = tuplestore_begin_heap(false, false, work_mem);
if (need_new_ins && table->new_ins_tuplestore == NULL)
table->new_ins_tuplestore = tuplestore_begin_heap(false, false, work_mem);
if (need_old && table->old_tuplestore == NULL)
table->old_tuplestore = tuplestore_begin_heap(false, false, work_mem);
if (need_new && table->new_tuplestore == NULL)
table->new_tuplestore = tuplestore_begin_heap(false, false, work_mem);
CurrentResourceOwner = saveResourceOwner;
MemoryContextSwitchTo(oldcxt);
@ -4932,20 +4888,12 @@ AfterTriggerFreeQuery(AfterTriggersQueryData *qs)
{
AfterTriggersTableData *table = (AfterTriggersTableData *) lfirst(lc);
ts = table->old_upd_tuplestore;
table->old_upd_tuplestore = NULL;
ts = table->old_tuplestore;
table->old_tuplestore = NULL;
if (ts)
tuplestore_end(ts);
ts = table->new_upd_tuplestore;
table->new_upd_tuplestore = NULL;
if (ts)
tuplestore_end(ts);
ts = table->old_del_tuplestore;
table->old_del_tuplestore = NULL;
if (ts)
tuplestore_end(ts);
ts = table->new_ins_tuplestore;
table->new_ins_tuplestore = NULL;
ts = table->new_tuplestore;
table->new_tuplestore = NULL;
if (ts)
tuplestore_end(ts);
}
@ -5796,28 +5744,12 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
newtup == NULL));
if (oldtup != NULL &&
(event == TRIGGER_EVENT_DELETE && delete_old_table))
((event == TRIGGER_EVENT_DELETE && delete_old_table) ||
(event == TRIGGER_EVENT_UPDATE && update_old_table)))
{
Tuplestorestate *old_tuplestore;
old_tuplestore = transition_capture->tcs_private->old_del_tuplestore;
if (map != NULL)
{
HeapTuple converted = do_convert_tuple(oldtup, map);
tuplestore_puttuple(old_tuplestore, converted);
pfree(converted);
}
else
tuplestore_puttuple(old_tuplestore, oldtup);
}
if (oldtup != NULL &&
(event == TRIGGER_EVENT_UPDATE && update_old_table))
{
Tuplestorestate *old_tuplestore;
old_tuplestore = transition_capture->tcs_private->old_upd_tuplestore;
old_tuplestore = transition_capture->tcs_private->old_tuplestore;
if (map != NULL)
{
@ -5830,30 +5762,12 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
tuplestore_puttuple(old_tuplestore, oldtup);
}
if (newtup != NULL &&
(event == TRIGGER_EVENT_INSERT && insert_new_table))
((event == TRIGGER_EVENT_INSERT && insert_new_table) ||
(event == TRIGGER_EVENT_UPDATE && update_new_table)))
{
Tuplestorestate *new_tuplestore;
new_tuplestore = transition_capture->tcs_private->new_ins_tuplestore;
if (original_insert_tuple != NULL)
tuplestore_puttuple(new_tuplestore, original_insert_tuple);
else if (map != NULL)
{
HeapTuple converted = do_convert_tuple(newtup, map);
tuplestore_puttuple(new_tuplestore, converted);
pfree(converted);
}
else
tuplestore_puttuple(new_tuplestore, newtup);
}
if (newtup != NULL &&
(event == TRIGGER_EVENT_UPDATE && update_new_table))
{
Tuplestorestate *new_tuplestore;
new_tuplestore = transition_capture->tcs_private->new_upd_tuplestore;
new_tuplestore = transition_capture->tcs_private->new_tuplestore;
if (original_insert_tuple != NULL)
tuplestore_puttuple(new_tuplestore, original_insert_tuple);