Index: src/backend/access/heap/heapam.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/access/heap/heapam.c,v retrieving revision 1.149 diff -c -r1.149 heapam.c *** src/backend/access/heap/heapam.c 2002/09/26 22:46:29 1.149 --- src/backend/access/heap/heapam.c 2002/11/07 07:23:17 *************** *** 50,55 **** --- 50,56 ---- #include "miscadmin.h" #include "utils/inval.h" #include "utils/relcache.h" + #include "storage/sinval.h" #include "pgstat.h" *************** *** 1298,1303 **** --- 1299,1340 ---- if (result == HeapTupleInvisible) { + TransactionId xwait = HeapTupleHeaderGetXmin(tp.t_data); + TransactionId xmax = HeapTupleHeaderGetXmax(tp.t_data); + if (!(tp.t_data->t_infomask & HEAP_XMIN_INVALID)) { + if (xwait == xmax) { /* deleted by inserted transaction */ + elog(NOTICE, "del by same xact"); + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleSelfUpdated; + } + if (tp.t_data->t_infomask & HEAP_MOVED_OFF) { + elog(NOTICE, "moved off by vacuum"); + /* moved off? - for now ignore */ + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleSelfUpdated; + } + if (tp.t_data->t_infomask & HEAP_XMAX_INVALID) { + /* it's new? */ + if (TransactionIdIsInProgress(xwait)) { + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + elog(NOTICE, "about to wait on %d", xwait); + XactLockTableWait(xwait); + if (TransactionIdDidAbort(xwait)) + return HeapTupleSelfUpdated; + /* It's real */ + LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + goto l1; + } + } + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + ReleaseBuffer(buffer); + elog(ERROR, "heap_delete: (am)invalid tid - xmin valid, xmax valid?"); + } + else { /* why?*/ + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + ReleaseBuffer(buffer); + elog(ERROR, "heap_delete: (am)invalid tid - xmin invalid?"); + } LockBuffer(buffer, BUFFER_LOCK_UNLOCK); ReleaseBuffer(buffer); elog(ERROR, "heap_delete: (am)invalid tid"); *************** *** 1502,1510 **** if (result == HeapTupleInvisible) { LockBuffer(buffer, BUFFER_LOCK_UNLOCK); ReleaseBuffer(buffer); ! elog(ERROR, "heap_update: (am)invalid tid"); } else if (result == HeapTupleBeingUpdated) { --- 1539,1583 ---- if (result == HeapTupleInvisible) { + TransactionId xwait = HeapTupleHeaderGetXmin(oldtup.t_data); + TransactionId xmax = HeapTupleHeaderGetXmax(oldtup.t_data); + if (!(oldtup.t_data->t_infomask & HEAP_XMIN_INVALID)) { + if (xwait == xmax) { /* deleted by inserted transaction */ + elog(NOTICE, "del by same xact"); + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleSelfUpdated; + } + if (oldtup.t_data->t_infomask & HEAP_MOVED_OFF) { + elog(NOTICE, "moved off by vacuum"); + /* moved off? - for now ignore */ + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleSelfUpdated; + } + if (oldtup.t_data->t_infomask & HEAP_XMAX_INVALID) { + /* it's new? */ + if (TransactionIdIsInProgress(xwait)) { + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + elog(NOTICE, "about to wait on %d", xwait); + XactLockTableWait(xwait); + if (TransactionIdDidAbort(xwait)) + return HeapTupleSelfUpdated; + /* It's real */ + LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); + goto l2; + } + } + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + ReleaseBuffer(buffer); + elog(ERROR, "heap_delete: (am)invalid tid - xmin valid, xmax valid?"); + } + else { /* why?*/ + LockBuffer(buffer, BUFFER_LOCK_UNLOCK); + ReleaseBuffer(buffer); + elog(ERROR, "heap_delete: (am)invalid tid - xmin invalid?"); + } LockBuffer(buffer, BUFFER_LOCK_UNLOCK); ReleaseBuffer(buffer); ! elog(ERROR, "heap_delete: (am)invalid tid"); } else if (result == HeapTupleBeingUpdated) { *************** *** 1881,1886 **** --- 1954,2185 ---- WriteNoReleaseBuffer(*buffer); return HeapTupleMayBeUpdated; + } + + /* + * Temporary locking structure + */ + typedef struct mark4fk_lock_row { + ItemPointerData tid; + struct mark4fk_lock_row *next; + } mark4fk_lock_row; + + typedef struct mark4fk_lock_tables { + Oid table; + struct mark4fk_lock_row *head; + struct mark4fk_lock_tables *next; + } mark4fk_lock_tables; + + static mark4fk_lock_tables *mark4fk_lock_head; + static TransactionId mark4fk_lastxid; + + void + heap_mark4fk_lock_acquire(Relation relation, HeapTuple tuple); + bool + heap_mark4fk_lock_check(Relation relation, HeapTuple tuple); + + /* + * heap_mark4fk_lock_acquire - grab the persistent portion + * of our "lock" for FOR FOREIGN KEY statements. + */ + void + heap_mark4fk_lock_acquire(Relation relation, HeapTuple tuple) { + Oid relid = relation->rd_id; + ItemPointerData tid = tuple->t_self; + mark4fk_lock_tables *ptr = mark4fk_lock_head; + mark4fk_lock_tables *oldptr = NULL; + mark4fk_lock_tables *newptr = NULL; + + mark4fk_lock_row *newrowptr = NULL; + if (!TransactionIdEquals(mark4fk_lastxid, GetCurrentTransactionId())) { + mark4fk_lock_head = ptr = NULL; + mark4fk_lastxid = GetCurrentTransactionId(); + } + + /* try to find the list for the table in question */ + while (ptr!=NULL) { + if (relid>ptr->table) { + ptr=ptr->next; + oldptr=ptr; + } + else + break; + } + + if (ptr==NULL || relidtable) { /* we didn't find it */ + newptr = MemoryContextAlloc(TopTransactionContext, sizeof(*newptr)); + newptr->head = NULL; + newptr->next = ptr; + newptr->table = relid; + if (oldptr==NULL) { /* we're the new head */ + mark4fk_lock_head = newptr; + } + else { /* insert between two nodes */ + oldptr->next = newptr; + } + ptr = newptr; + } + + /* okay add the lock info */ + newrowptr = MemoryContextAlloc(TopTransactionContext, sizeof(*newrowptr)); + newrowptr->tid = tid; + newrowptr->next = ptr->head; + ptr->head = newrowptr; + } + + /* + * heap_mark4fk_lock_check - do we have a "lock" on this + * row already + */ + bool + heap_mark4fk_lock_check(Relation relation, HeapTuple tuple) { + Oid relid = relation->rd_id; + ItemPointerData tid = tuple->t_self; + mark4fk_lock_tables *ptr = mark4fk_lock_head; + mark4fk_lock_row *rowptr = NULL; + + /* try to find the list for the table in question */ + while (ptr!=NULL) { + if (relid>ptr->table) { + ptr=ptr->next; + } + else if (relidtable) + return false; + else + break; + } + if (ptr == NULL) + return false; + + rowptr = ptr->head; + while (rowptr != NULL) { + if (ItemPointerEquals(&rowptr->tid, &tid)) + return true; + rowptr = rowptr->next; + } + + return false; + } + + /* + * heap_mark4fk - mark a tuple for foreign key check + */ + int + heap_mark4fk(Relation relation, HeapTuple tuple, Buffer *buffer, + CommandId cid) + { + ItemPointer tid = &(tuple->t_self); + ItemId lp; + PageHeader dp; + int result; + + /* increment access statistics */ + IncrHeapAccessStat(local_mark4update); + IncrHeapAccessStat(global_mark4update); + + *buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); + + if (!BufferIsValid(*buffer)) + elog(ERROR, "heap_mark4fk: failed ReadBuffer"); + + LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); + + dp = (PageHeader) BufferGetPage(*buffer); + lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid)); + tuple->t_datamcxt = NULL; + tuple->t_data = (HeapTupleHeader) PageGetItem((Page) dp, lp); + tuple->t_len = ItemIdGetLength(lp); + + l3: + result = HeapTupleSatisfiesUpdate(tuple, cid); + + elog(NOTICE, "result %d (%d %d)", result, HeapTupleInvisible==result, HeapTupleUpdated==result); + elog(NOTICE, "xs (%d %d) %d", HeapTupleHeaderGetXmin(tuple->t_data), HeapTupleHeaderGetXmax(tuple->t_data), + GetCurrentTransactionId()); + if (result == HeapTupleInvisible) + { + TransactionId xwait = HeapTupleHeaderGetXmin(tuple->t_data); + TransactionId xmax = HeapTupleHeaderGetXmax(tuple->t_data); + if (!(tuple->t_data->t_infomask & HEAP_XMIN_INVALID)) { + if (xwait == xmax) { /* deleted by inserted transaction */ + elog(NOTICE, "del by same xact"); + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleSelfUpdated; + } + if (tuple->t_data->t_infomask & HEAP_MOVED_OFF) { + elog(NOTICE, "moved off by vacuum"); + /* moved off? - for now ignore */ + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleSelfUpdated; + } + if (tuple->t_data->t_infomask & HEAP_XMAX_INVALID) { + /* it's new? */ + if (TransactionIdIsInProgress(xwait)) { + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + elog(NOTICE, "about to wait on %d", xwait); + XactLockTableWait(xwait); + if (TransactionIdDidAbort(xwait)) + return HeapTupleSelfUpdated; + + LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); + goto l3; + } + } + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + ReleaseBuffer(*buffer); + elog(ERROR, "heap_mark4fk: (am)invalid tid - xmin valid, xmax valid?"); + } + else { /* why?*/ + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + ReleaseBuffer(*buffer); + elog(ERROR, "heap_mark4fk: (am)invalid tid - xmin invalid?"); + } + } + else if (result == HeapTupleBeingUpdated) + { + TransactionId xwait = HeapTupleHeaderGetXmax(tuple->t_data); + + if (heap_mark4fk_lock_check(relation,tuple)) { + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + return HeapTupleMayBeUpdated; /* this is wrong */ + } + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + + /* sleep untill concurrent transaction ends */ + XactLockTableWait(xwait); + + LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE); + + if (TransactionIdDidAbort(xwait)) + goto l3; + + /* + * xwait is committed but if xwait had just marked the tuple for + * update then some other xaction could update this tuple before + * we got to this point. + */ + if (!TransactionIdEquals(HeapTupleHeaderGetXmax(tuple->t_data), xwait)) + goto l3; + if (!(tuple->t_data->t_infomask & HEAP_XMAX_COMMITTED)) + { + tuple->t_data->t_infomask |= HEAP_XMAX_COMMITTED; + SetBufferCommitInfoNeedsSave(*buffer); + } + /* if tuple was marked for update but not updated... */ + if (tuple->t_data->t_infomask & HEAP_MARKED_FOR_UPDATE) + result = HeapTupleMayBeUpdated; + else + result = HeapTupleUpdated; + } + heap_mark4fk_lock_acquire(relation, tuple); + if (result != HeapTupleMayBeUpdated) + { + Assert(result == HeapTupleSelfUpdated || result == HeapTupleUpdated); + tuple->t_self = tuple->t_data->t_ctid; + } + + LockBuffer(*buffer, BUFFER_LOCK_UNLOCK); + return result; } /* ---------------- Index: src/backend/commands/tablecmds.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/tablecmds.c,v retrieving revision 1.45 diff -c -r1.45 tablecmds.c *** src/backend/commands/tablecmds.c 2002/09/28 20:00:19 1.45 --- src/backend/commands/tablecmds.c 2002/11/07 07:23:27 *************** *** 1383,1389 **** return RI_TRIGGER_PK; case F_RI_FKEY_CHECK_INS: ! case F_RI_FKEY_CHECK_UPD: return RI_TRIGGER_FK; } --- 1383,1389 ---- return RI_TRIGGER_PK; case F_RI_FKEY_CHECK_INS: ! case F_RI_FKEY_CHECK_UPD_SETDEF: return RI_TRIGGER_FK; } *************** *** 3240,3246 **** fk_trigger = makeNode(CreateTrigStmt); fk_trigger->trigname = fkconstraint->constr_name; fk_trigger->relation = myRel; ! fk_trigger->funcname = SystemFuncName("RI_FKey_check_ins"); fk_trigger->before = false; fk_trigger->row = true; fk_trigger->actions[0] = 'i'; --- 3240,3250 ---- fk_trigger = makeNode(CreateTrigStmt); fk_trigger->trigname = fkconstraint->constr_name; fk_trigger->relation = myRel; ! if (fkconstraint->fk_del_action == FKCONSTR_ACTION_SETDEFAULT || ! fkconstraint->fk_upd_action == FKCONSTR_ACTION_SETDEFAULT) ! fk_trigger->funcname = SystemFuncName("RI_FKey_check_upd_setdef"); ! else ! fk_trigger->funcname = SystemFuncName("RI_FKey_check_ins"); fk_trigger->before = false; fk_trigger->row = true; fk_trigger->actions[0] = 'i'; Index: src/backend/executor/execMain.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/executor/execMain.c,v retrieving revision 1.179 diff -c -r1.179 execMain.c *** src/backend/executor/execMain.c 2002/09/23 22:57:44 1.179 --- src/backend/executor/execMain.c 2002/11/07 07:23:31 *************** *** 531,536 **** --- 531,538 ---- * Have to lock relations selected for update */ estate->es_rowMark = NIL; + estate->hasFkUpdate = parseTree->hasFkUpdate; + if (parseTree->rowMarks != NIL) { List *l; *************** *** 946,957 **** if (estate->es_useEvalPlan) { slot = EvalPlanQualNext(estate); ! if (TupIsNull(slot)) slot = ExecProcNode(plan, NULL); } ! else slot = ExecProcNode(plan, NULL); ! /* * if the tuple is null, then we assume there is nothing more to * process so we just return null... --- 948,960 ---- if (estate->es_useEvalPlan) { slot = EvalPlanQualNext(estate); ! if (TupIsNull(slot)) { slot = ExecProcNode(plan, NULL); + } } ! else { slot = ExecProcNode(plan, NULL); ! } /* * if the tuple is null, then we assume there is nothing more to * process so we just return null... *************** *** 1026,1038 **** erm->resname); tuple.t_self = *((ItemPointer) DatumGetPointer(datum)); ! test = heap_mark4update(erm->relation, &tuple, &buffer, estate->es_snapshot->curcid); ReleaseBuffer(buffer); switch (test) { case HeapTupleSelfUpdated: /* treat it as deleted; do not process */ goto lnext; case HeapTupleMayBeUpdated: --- 1029,1052 ---- erm->resname); tuple.t_self = *((ItemPointer) DatumGetPointer(datum)); ! if (estate->hasFkUpdate) { ! elog(NOTICE, "fk"); ! test = heap_mark4fk(erm->relation, &tuple, &buffer, ! estate->es_snapshot->curcid); ! } ! else { ! elog(NOTICE, "upd"); ! test = heap_mark4update(erm->relation, &tuple, &buffer, estate->es_snapshot->curcid); + } + elog(NOTICE, "A"); ReleaseBuffer(buffer); + elog(NOTICE, "B"); switch (test) { case HeapTupleSelfUpdated: /* treat it as deleted; do not process */ + elog(NOTICE, "C"); goto lnext; case HeapTupleMayBeUpdated: Index: src/backend/nodes/copyfuncs.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/nodes/copyfuncs.c,v retrieving revision 1.213 diff -c -r1.213 copyfuncs.c *** src/backend/nodes/copyfuncs.c 2002/09/22 19:42:51 1.213 --- src/backend/nodes/copyfuncs.c 2002/11/07 07:23:39 *************** *** 1791,1796 **** --- 1791,1797 ---- Node_Copy(from, newnode, jointree); newnode->rowMarks = listCopy(from->rowMarks); + newnode->hasFkUpdate = from->hasFkUpdate; Node_Copy(from, newnode, targetList); *************** *** 1872,1877 **** --- 1873,1880 ---- Node_Copy(from, newnode, limitOffset); Node_Copy(from, newnode, limitCount); Node_Copy(from, newnode, forUpdate); + newnode->forFk = from->forFk; + newnode->op = from->op; newnode->all = from->all; Node_Copy(from, newnode, larg); Index: src/backend/nodes/equalfuncs.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/nodes/equalfuncs.c,v retrieving revision 1.160 diff -c -r1.160 equalfuncs.c *** src/backend/nodes/equalfuncs.c 2002/09/22 19:42:51 1.160 --- src/backend/nodes/equalfuncs.c 2002/11/07 07:23:43 *************** *** 594,599 **** --- 594,601 ---- return false; if (!equali(a->rowMarks, b->rowMarks)) return false; + if (a->hasFkUpdate != b->hasFkUpdate) + return false; if (!equal(a->targetList, b->targetList)) return false; if (!equal(a->groupClause, b->groupClause)) *************** *** 693,698 **** --- 695,702 ---- if (!equal(a->limitCount, b->limitCount)) return false; if (!equal(a->forUpdate, b->forUpdate)) + return false; + if (a->forFk != b->forFk) return false; if (a->op != b->op) return false; Index: src/backend/nodes/outfuncs.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/nodes/outfuncs.c,v retrieving revision 1.175 diff -c -r1.175 outfuncs.c *** src/backend/nodes/outfuncs.c 2002/09/22 19:42:51 1.175 --- src/backend/nodes/outfuncs.c 2002/11/07 07:23:46 *************** *** 273,278 **** --- 273,280 ---- appendStringInfo(str, " :rowMarks "); _outIntList(str, node->rowMarks); + appendStringInfo(str, " :hasFkUpdate %s", booltostr(node->hasFkUpdate)); + appendStringInfo(str, " :targetList "); _outNode(str, node->targetList); *************** *** 299,304 **** --- 301,308 ---- appendStringInfo(str, " :resultRelations "); _outIntList(str, node->resultRelations); + + elog(NOTICE, "%s", str->data); } static void Index: src/backend/nodes/readfuncs.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/nodes/readfuncs.c,v retrieving revision 1.134 diff -c -r1.134 readfuncs.c *** src/backend/nodes/readfuncs.c 2002/09/22 19:42:51 1.134 --- src/backend/nodes/readfuncs.c 2002/11/07 07:23:51 *************** *** 161,166 **** --- 161,170 ---- token = pg_strtok(&length); /* skip :rowMarks */ local_node->rowMarks = toIntList(nodeRead(true)); + token = pg_strtok(&length); /* skip :hasFkUpdate */ + token = pg_strtok(&length); + local_node->hasFkUpdate = strtobool(token); + token = pg_strtok(&length); /* skip :targetlist */ local_node->targetList = nodeRead(true); Index: src/backend/parser/analyze.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/parser/analyze.c,v retrieving revision 1.250 diff -c -r1.250 analyze.c *** src/backend/parser/analyze.c 2002/09/22 00:37:09 1.250 --- src/backend/parser/analyze.c 2002/11/07 07:23:58 *************** *** 1653,1658 **** --- 1653,1660 ---- /* make FOR UPDATE clause available to addRangeTableEntry */ pstate->p_forUpdate = stmt->forUpdate; + qry->hasFkUpdate = stmt->forFk; + /* process the FROM clause */ transformFromClause(pstate, stmt->fromClause); Index: src/backend/parser/gram.y =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/parser/gram.y,v retrieving revision 2.370 diff -c -r2.370 gram.y *** src/backend/parser/gram.y 2002/09/22 21:44:43 2.370 --- src/backend/parser/gram.y 2002/11/07 07:24:15 *************** *** 336,342 **** CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE DATABASE DAY_P DEALLOCATE DEC DECIMAL DECLARE DEFAULT ! DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC DISTINCT DO DOMAIN_P DOUBLE DROP EACH ELSE ENCODING ENCRYPTED END_TRANS ESCAPE EXCEPT --- 336,342 ---- CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE DATABASE DAY_P DEALLOCATE DEC DECIMAL DECLARE DEFAULT ! DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS, DESC DISTINCT DO DOMAIN_P DOUBLE DROP EACH ELSE ENCODING ENCRYPTED END_TRANS ESCAPE EXCEPT *************** *** 4495,4501 **** ; for_update_clause: ! FOR UPDATE update_list { $$ = $3; } | FOR READ ONLY { $$ = NULL; } ; --- 4495,4502 ---- ; for_update_clause: ! FOR UPDATE update_list { $$ = makeList2($3, NULL); } ! | FOR FOREIGN KEY update_list { $$ = makeList2($4, makeInteger(FALSE)); } | FOR READ ONLY { $$ = NULL; } ; *************** *** 7645,7651 **** { if (stmt->forUpdate) elog(ERROR, "Multiple FOR UPDATE clauses not allowed"); ! stmt->forUpdate = forUpdate; } if (limitOffset) { --- 7646,7656 ---- { if (stmt->forUpdate) elog(ERROR, "Multiple FOR UPDATE clauses not allowed"); ! stmt->forUpdate = lfirst(forUpdate); ! if (lsecond(forUpdate)) ! stmt->forFk = true; ! else ! stmt->forFk = false; } if (limitOffset) { Index: src/backend/utils/adt/ri_triggers.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/ri_triggers.c,v retrieving revision 1.42 diff -c -r1.42 ri_triggers.c *** src/backend/utils/adt/ri_triggers.c 2002/09/04 20:31:28 1.42 --- src/backend/utils/adt/ri_triggers.c 2002/11/07 07:24:26 *************** *** 37,42 **** --- 37,43 ---- #include "executor/spi_priv.h" #include "parser/parse_oper.h" #include "utils/lsyscache.h" + #include "access/htup.h" #include "miscadmin.h" *************** *** 155,161 **** * ---------- */ static Datum ! RI_FKey_check(PG_FUNCTION_ARGS) { TriggerData *trigdata = (TriggerData *) fcinfo->context; int tgnargs; --- 156,162 ---- * ---------- */ static Datum ! RI_FKey_check(PG_FUNCTION_ARGS, bool setdefault) { TriggerData *trigdata = (TriggerData *) fcinfo->context; int tgnargs; *************** *** 175,182 **** save_uid = GetUserId(); - ReferentialIntegritySnapshotOverride = true; - /* * Check that this is a valid trigger call on the right time and * event. --- 176,181 ---- *************** *** 264,270 **** * ---------- */ quoteRelationName(pkrelname, pk_rel); ! snprintf(querystr, sizeof(querystr), "SELECT 1 FROM ONLY %s x FOR UPDATE OF x", pkrelname); /* --- 263,269 ---- * ---------- */ quoteRelationName(pkrelname, pk_rel); ! snprintf(querystr, sizeof(querystr), "SELECT 1 FROM ONLY %s x FOR FOREIGN KEY OF x", pkrelname); /* *************** *** 283,291 **** --- 282,294 ---- SetUserId(RelationGetForm(pk_rel)->relowner); + ReferentialIntegritySnapshotOverride = 1; + if (SPI_execp(qplan, check_values, check_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in RI_FKey_check()"); + ReferentialIntegritySnapshotOverride = 0; + SetUserId(save_uid); if (SPI_processed == 0) *************** *** 382,394 **** } /* ! * Note: We cannot avoid the check on UPDATE, even if old and new key * are the same. Otherwise, someone could DELETE the PK that consists * of the DEFAULT values, and if there are any references, a ON DELETE * SET DEFAULT action would update the references to exactly these * values but we wouldn't see that weired case (this is the only place * to see it). */ if (SPI_connect() != SPI_OK_CONNECT) elog(WARNING, "SPI_connect() failed in RI_FKey_check()"); --- 385,410 ---- } /* ! * Note: We can only avoid the check on UPDATE, if we know that this key ! * has not set default action or this, even if old and new key * are the same. Otherwise, someone could DELETE the PK that consists * of the DEFAULT values, and if there are any references, a ON DELETE * SET DEFAULT action would update the references to exactly these * values but we wouldn't see that weired case (this is the only place * to see it). */ + if (!setdefault && old_row) { + /* + * No need to do anything if old and new keys are equal + */ + if (ri_KeysEqual(fk_rel, old_row, new_row, &qkey, + RI_KEYPAIR_FK_IDX)) + { + heap_close(pk_rel, RowShareLock); + return PointerGetDatum(NULL); + } + } + if (SPI_connect() != SPI_OK_CONNECT) elog(WARNING, "SPI_connect() failed in RI_FKey_check()"); *************** *** 427,433 **** queryoids[i] = SPI_gettypeid(fk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_FK_IDX]); } ! strcat(querystr, " FOR UPDATE OF x"); /* * Prepare, save and remember the new plan. --- 443,449 ---- queryoids[i] = SPI_gettypeid(fk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_FK_IDX]); } ! strcat(querystr, " FOR FOREIGN KEY OF x"); /* * Prepare, save and remember the new plan. *************** *** 467,474 **** --- 483,492 ---- SetUserId(RelationGetForm(pk_rel)->relowner); + ReferentialIntegritySnapshotOverride = 1; if (SPI_execp(qplan, check_values, check_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in RI_FKey_check()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 503,509 **** Datum RI_FKey_check_ins(PG_FUNCTION_ARGS) { ! return RI_FKey_check(fcinfo); } --- 521,527 ---- Datum RI_FKey_check_ins(PG_FUNCTION_ARGS) { ! return RI_FKey_check(fcinfo, false); } *************** *** 515,522 **** */ Datum RI_FKey_check_upd(PG_FUNCTION_ARGS) { ! return RI_FKey_check(fcinfo); } --- 533,553 ---- */ Datum RI_FKey_check_upd(PG_FUNCTION_ARGS) + { + return RI_FKey_check(fcinfo, false); + } + + /* ---------- + * RI_FKey_check_upd_sdef - + * + * Check foreign key existence at update event on FK table + * if any of the actions are set default. + * ---------- + */ + Datum + RI_FKey_check_upd_setdef(PG_FUNCTION_ARGS) { ! return RI_FKey_check(fcinfo, true); } *************** *** 632,638 **** queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } ! strcat(querystr, " FOR UPDATE OF x"); /* * Prepare, save and remember the new plan. --- 663,669 ---- queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } ! strcat(querystr, " FOR FOREIGN KEY OF x"); /* * Prepare, save and remember the new plan. *************** *** 665,673 **** --- 696,708 ---- SetUserId(RelationGetForm(pk_rel)->relowner); + ReferentialIntegritySnapshotOverride = 1; + if (SPI_execp(qplan, check_values, check_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in ri_Check_Pk_Match()"); + ReferentialIntegritySnapshotOverride = 0; + SetUserId(save_uid); result = (SPI_processed != 0); *************** *** 701,714 **** Datum del_values[RI_MAX_NUMKEYS]; char del_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; int match_type; Oid save_uid; save_uid = GetUserId(); - ReferentialIntegritySnapshotOverride = true; - /* * Check that this is a valid trigger call on the right time and * event. --- 736,748 ---- Datum del_values[RI_MAX_NUMKEYS]; char del_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; + bool needdirty = true; int i; int match_type; Oid save_uid; save_uid = GetUserId(); /* * Check that this is a valid trigger call on the right time and * event. *************** *** 749,754 **** --- 783,797 ---- pk_rel = trigdata->tg_relation; old_row = trigdata->tg_trigtuple; + /* + * If the old row is new for this transaction, we can do non-dirty checks + * since another transaction won't be referencing this row. This is good + * because it lessens the amount of locking we end up doing in practice. + */ + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]); if (ri_Check_Pk_Match(pk_rel, old_row, trigdata->tg_trigger->tgoid, match_type, tgnargs, tgargs)) *************** *** 835,841 **** queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } ! strcat(querystr, " FOR UPDATE OF x"); /* * Prepare, save and remember the new plan. --- 878,885 ---- queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } ! strcat(querystr, " FOR"); ! strcat(querystr, " FOREIGN KEY OF x"); /* * Prepare, save and remember the new plan. *************** *** 866,875 **** --- 910,923 ---- * Now check for existing references */ SetUserId(RelationGetForm(pk_rel)->relowner); + + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, del_values, del_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in RI_FKey_noaction_del()"); + ReferentialIntegritySnapshotOverride = 0; + SetUserId(save_uid); if (SPI_processed > 0) *************** *** 925,938 **** Datum upd_values[RI_MAX_NUMKEYS]; char upd_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; int i; int match_type; Oid save_uid; save_uid = GetUserId(); - ReferentialIntegritySnapshotOverride = true; - /* * Check that this is a valid trigger call on the right time and * event. --- 973,985 ---- Datum upd_values[RI_MAX_NUMKEYS]; char upd_nulls[RI_MAX_NUMKEYS + 1]; bool isnull; + bool needdirty = true; int i; int match_type; Oid save_uid; save_uid = GetUserId(); /* * Check that this is a valid trigger call on the right time and * event. *************** *** 974,979 **** --- 1021,1035 ---- new_row = trigdata->tg_newtuple; old_row = trigdata->tg_trigtuple; + /* + * If the old row is new for this transaction, we can do non-dirty checks + * since another transaction won't be referencing this row. This is good + * because it lessens the amount of locking we end up doing in practice. + */ + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]); if (ri_Check_Pk_Match(pk_rel, old_row, trigdata->tg_trigger->tgoid, match_type, tgnargs, tgargs)) *************** *** 1070,1076 **** queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } ! strcat(querystr, " FOR UPDATE OF x"); /* * Prepare, save and remember the new plan. --- 1126,1133 ---- queryoids[i] = SPI_gettypeid(pk_rel->rd_att, qkey.keypair[i][RI_KEYPAIR_PK_IDX]); } ! strcat(querystr, " FOR"); ! strcat(querystr, " FOREIGN KEY OF x"); /* * Prepare, save and remember the new plan. *************** *** 1102,1109 **** --- 1159,1168 ---- */ SetUserId(RelationGetForm(pk_rel)->relowner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in RI_FKey_noaction_upd()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 1160,1167 **** int i; Oid save_uid; Oid fk_owner; ! ! ReferentialIntegritySnapshotOverride = true; /* * Check that this is a valid trigger call on the right time and --- 1219,1225 ---- int i; Oid save_uid; Oid fk_owner; ! bool needdirty = true; /* * Check that this is a valid trigger call on the right time and *************** *** 1204,1209 **** --- 1262,1276 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + /* + * If the old row is new for this transaction, we can do non-dirty checks + * since another transaction won't be referencing this row. This is good + * because it lessens the amount of locking we end up doing in practice. + */ + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO])) { /* ---------- *************** *** 1309,1316 **** --- 1376,1385 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, del_values, del_nulls, 0) != SPI_OK_DELETE) elog(ERROR, "SPI_execp() failed in RI_FKey_cascade_del()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 1362,1370 **** int j; Oid save_uid; Oid fk_owner; - ReferentialIntegritySnapshotOverride = true; - /* * Check that this is a valid trigger call on the right time and * event. --- 1431,1438 ---- int j; Oid save_uid; Oid fk_owner; + bool needdirty = true; /* * Check that this is a valid trigger call on the right time and * event. *************** *** 1407,1412 **** --- 1475,1484 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO])) { /* ---------- *************** *** 1542,1549 **** --- 1614,1623 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE) elog(ERROR, "SPI_execp() failed in RI_FKey_cascade_upd()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 1600,1607 **** int i; Oid save_uid; Oid fk_owner; ! ! ReferentialIntegritySnapshotOverride = true; /* * Check that this is a valid trigger call on the right time and --- 1674,1680 ---- int i; Oid save_uid; Oid fk_owner; ! bool needdirty = true; /* * Check that this is a valid trigger call on the right time and *************** *** 1644,1649 **** --- 1717,1726 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO])) { /* ---------- *************** *** 1751,1758 **** --- 1828,1837 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, del_values, del_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in RI_FKey_restrict_del()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 1817,1824 **** int i; Oid save_uid; Oid fk_owner; ! ! ReferentialIntegritySnapshotOverride = true; /* * Check that this is a valid trigger call on the right time and --- 1896,1902 ---- int i; Oid save_uid; Oid fk_owner; ! bool needdirty = true; /* * Check that this is a valid trigger call on the right time and *************** *** 1862,1867 **** --- 1940,1949 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO])) { /* ---------- *************** *** 1981,1988 **** --- 2063,2072 ---- SetUserId(RelationGetForm(pk_rel)->relowner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_execp() failed in RI_FKey_restrict_upd()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 2039,2047 **** int i; Oid save_uid; Oid fk_owner; - ReferentialIntegritySnapshotOverride = true; - /* * Check that this is a valid trigger call on the right time and * event. --- 2123,2130 ---- int i; Oid save_uid; Oid fk_owner; + bool needdirty = true; /* * Check that this is a valid trigger call on the right time and * event. *************** *** 2083,2088 **** --- 2166,2175 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO])) { /* ---------- *************** *** 2198,2205 **** --- 2285,2294 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE) elog(ERROR, "SPI_execp() failed in RI_FKey_setnull_del()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 2252,2259 **** bool use_cached_query; Oid save_uid; Oid fk_owner; ! ! ReferentialIntegritySnapshotOverride = true; /* * Check that this is a valid trigger call on the right time and --- 2341,2347 ---- bool use_cached_query; Oid save_uid; Oid fk_owner; ! bool needdirty = true; /* * Check that this is a valid trigger call on the right time and *************** *** 2298,2303 **** --- 2386,2395 ---- match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]); fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (match_type) { /* ---------- *************** *** 2460,2467 **** --- 2552,2561 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE) elog(ERROR, "SPI_execp() failed in RI_FKey_setnull_upd()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 2511,2518 **** int i; Oid save_uid; Oid fk_owner; ! ! ReferentialIntegritySnapshotOverride = true; /* * Check that this is a valid trigger call on the right time and --- 2605,2611 ---- int i; Oid save_uid; Oid fk_owner; ! bool needdirty = true; /* * Check that this is a valid trigger call on the right time and *************** *** 2555,2560 **** --- 2648,2657 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + switch (ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO])) { /* ---------- *************** *** 2714,2721 **** --- 2811,2820 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE) elog(ERROR, "SPI_execp() failed in RI_FKey_setdefault_del()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); *************** *** 2767,2775 **** int match_type; Oid save_uid; Oid fk_owner; - ReferentialIntegritySnapshotOverride = true; - /* * Check that this is a valid trigger call on the right time and * event. --- 2866,2873 ---- int match_type; Oid save_uid; Oid fk_owner; + bool needdirty = true; /* * Check that this is a valid trigger call on the right time and * event. *************** *** 2812,2817 **** --- 2910,2919 ---- old_row = trigdata->tg_trigtuple; fk_owner = RelationGetForm(fk_rel)->relowner; + if (HeapTupleHeaderGetXmin(old_row->t_data)==GetCurrentTransactionId()) { + needdirty=false; + } + match_type = ri_DetermineMatchType(tgargs[RI_MATCH_TYPE_ARGNO]); switch (match_type) *************** *** 2999,3006 **** --- 3101,3110 ---- save_uid = GetUserId(); SetUserId(fk_owner); + ReferentialIntegritySnapshotOverride = needdirty?2:1; if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE) elog(ERROR, "SPI_execp() failed in RI_FKey_setdefault_upd()"); + ReferentialIntegritySnapshotOverride = 0; SetUserId(save_uid); Index: src/backend/utils/time/tqual.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/time/tqual.c,v retrieving revision 1.60 diff -c -r1.60 tqual.c *** src/backend/utils/time/tqual.c 2002/09/04 20:31:33 1.60 --- src/backend/utils/time/tqual.c 2002/11/07 07:24:29 *************** *** 36,42 **** /* This is updated by GetSnapshotData: */ TransactionId RecentGlobalXmin = InvalidTransactionId; ! bool ReferentialIntegritySnapshotOverride = false; /* --- 36,42 ---- /* This is updated by GetSnapshotData: */ TransactionId RecentGlobalXmin = InvalidTransactionId; ! int ReferentialIntegritySnapshotOverride = 0; /* *************** *** 631,638 **** HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) { /* XXX this is horribly ugly: */ ! if (ReferentialIntegritySnapshotOverride) return HeapTupleSatisfiesNow(tuple); if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED)) { --- 631,640 ---- HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) { /* XXX this is horribly ugly: */ ! if (ReferentialIntegritySnapshotOverride==1) return HeapTupleSatisfiesNow(tuple); + if (ReferentialIntegritySnapshotOverride==2) + return HeapTupleSatisfiesDirty(tuple); if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED)) { Index: src/include/access/heapam.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/access/heapam.h,v retrieving revision 1.79 diff -c -r1.79 heapam.h *** src/include/access/heapam.h 2002/09/04 20:31:36 1.79 --- src/include/access/heapam.h 2002/11/07 07:24:31 *************** *** 167,172 **** --- 167,174 ---- ItemPointer ctid, CommandId cid); extern int heap_mark4update(Relation relation, HeapTuple tup, Buffer *userbuf, CommandId cid); + extern int heap_mark4fk(Relation relation, HeapTuple tup, + Buffer *userbuf, CommandId cid); extern Oid simple_heap_insert(Relation relation, HeapTuple tup); extern void simple_heap_delete(Relation relation, ItemPointer tid); Index: src/include/catalog/pg_proc.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/catalog/pg_proc.h,v retrieving revision 1.273 diff -c -r1.273 pg_proc.h *** src/include/catalog/pg_proc.h 2002/09/22 17:27:23 1.273 --- src/include/catalog/pg_proc.h 2002/11/07 07:24:48 *************** *** 2194,2200 **** /* Generic referential integrity constraint triggers */ DATA(insert OID = 1644 ( RI_FKey_check_ins PGNSP PGUID 12 f f t f v 0 2279 "" RI_FKey_check_ins - _null_ )); DESCR("referential integrity FOREIGN KEY ... REFERENCES"); ! DATA(insert OID = 1645 ( RI_FKey_check_upd PGNSP PGUID 12 f f t f v 0 2279 "" RI_FKey_check_upd - _null_ )); DESCR("referential integrity FOREIGN KEY ... REFERENCES"); DATA(insert OID = 1646 ( RI_FKey_cascade_del PGNSP PGUID 12 f f t f v 0 2279 "" RI_FKey_cascade_del - _null_ )); DESCR("referential integrity ON DELETE CASCADE"); --- 2194,2200 ---- /* Generic referential integrity constraint triggers */ DATA(insert OID = 1644 ( RI_FKey_check_ins PGNSP PGUID 12 f f t f v 0 2279 "" RI_FKey_check_ins - _null_ )); DESCR("referential integrity FOREIGN KEY ... REFERENCES"); ! DATA(insert OID = 1645 ( RI_FKey_check_upd_setdef PGNSP PGUID 12 f f t f v 0 2279 "" RI_FKey_check_upd_setdef - _null_ )); DESCR("referential integrity FOREIGN KEY ... REFERENCES"); DATA(insert OID = 1646 ( RI_FKey_cascade_del PGNSP PGUID 12 f f t f v 0 2279 "" RI_FKey_cascade_del - _null_ )); DESCR("referential integrity ON DELETE CASCADE"); Index: src/include/nodes/execnodes.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/nodes/execnodes.h,v retrieving revision 1.75 diff -c -r1.75 execnodes.h *** src/include/nodes/execnodes.h 2002/09/04 20:31:42 1.75 --- src/include/nodes/execnodes.h 2002/11/07 07:24:50 *************** *** 306,311 **** --- 306,314 ---- uint32 es_processed; /* # of tuples processed */ Oid es_lastoid; /* last oid processed (by INSERT) */ List *es_rowMark; /* not good place, but there is no other */ + bool hasFkUpdate; + bool dirtyFkUpdate; + MemoryContext es_query_cxt; /* per-query context in which EState lives */ /* Index: src/include/nodes/parsenodes.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/nodes/parsenodes.h,v retrieving revision 1.208 diff -c -r1.208 parsenodes.h *** src/include/nodes/parsenodes.h 2002/09/22 19:42:52 1.208 --- src/include/nodes/parsenodes.h 2002/11/07 07:24:54 *************** *** 49,54 **** --- 49,56 ---- bool hasAggs; /* has aggregates in tlist or havingQual */ bool hasSubLinks; /* has subquery SubLink */ + bool hasFkUpdate; /* is part of a FOR FOREIGN KEY */ + bool originalQuery; /* marks original query through rewriting */ List *rtable; /* list of range table entries */ *************** *** 697,703 **** bool binary; /* a binary (internal) portal? */ Node *limitOffset; /* # of result tuples to skip */ Node *limitCount; /* # of result tuples to return */ ! List *forUpdate; /* FOR UPDATE clause */ /* * These fields are used only in upper-level SelectStmts. --- 699,706 ---- bool binary; /* a binary (internal) portal? */ Node *limitOffset; /* # of result tuples to skip */ Node *limitCount; /* # of result tuples to return */ ! List *forUpdate; /* FOR UPDATE/FOREIGN KEY tables */ ! bool forFk; /* FOR FOREIGN KEY specified */ /* * These fields are used only in upper-level SelectStmts. Index: src/include/utils/tqual.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/utils/tqual.h,v retrieving revision 1.43 diff -c -r1.43 tqual.h *** src/include/utils/tqual.h 2002/09/04 20:31:46 1.43 --- src/include/utils/tqual.h 2002/11/07 07:24:55 *************** *** 43,49 **** extern TransactionId RecentGlobalXmin; ! extern bool ReferentialIntegritySnapshotOverride; #define IsSnapshotNow(snapshot) ((Snapshot) (snapshot) == SnapshotNow) #define IsSnapshotSelf(snapshot) ((Snapshot) (snapshot) == SnapshotSelf) --- 43,49 ---- extern TransactionId RecentGlobalXmin; ! extern int ReferentialIntegritySnapshotOverride; #define IsSnapshotNow(snapshot) ((Snapshot) (snapshot) == SnapshotNow) #define IsSnapshotSelf(snapshot) ((Snapshot) (snapshot) == SnapshotSelf)