From 9e0b4634732d089237c5eaecb91ad4b1e943bc0f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 17 Jan 2000 23:57:48 +0000 Subject: [PATCH] setheapoverride() is history. Uses replaced with CommandCounterIncrement() where necessary --- several of them didn't really need it, though. tqual-checking macros simplified accordingly. --- src/backend/access/gist/gist.c | 6 +-- src/backend/catalog/aclchk.c | 6 +-- src/backend/catalog/heap.c | 20 +++------ src/backend/catalog/index.c | 11 ++--- src/backend/catalog/pg_operator.c | 21 ++++----- src/backend/catalog/pg_type.c | 6 +-- src/backend/commands/_deadcode/recipe.c | 9 ++-- src/backend/commands/comment.c | 2 - src/backend/executor/execMain.c | 13 ++---- src/backend/utils/adt/sets.c | 4 +- src/backend/utils/cache/catcache.c | 5 +-- src/backend/utils/time/tqual.c | 29 +------------ src/include/utils/tqual.h | 57 +++++++++---------------- 13 files changed, 59 insertions(+), 130 deletions(-) diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index 6b873ab84a..9c9e8aeee7 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.48 1999/12/10 03:55:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.49 2000/01/17 23:57:41 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -98,9 +98,9 @@ gistbuild(Relation heap, /* no locking is needed */ - setheapoverride(true); /* so we can see the new pg_index tuple */ + CommandCounterIncrement(); /* so we can see the new pg_index tuple */ + initGISTstate(&giststate, index); - setheapoverride(false); pred = predInfo->pred; oldPred = predInfo->oldPred; diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 09aa138cf7..0e1a98d07c 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.35 2000/01/16 20:04:54 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.36 2000/01/17 23:57:43 tgl Exp $ * * NOTES * See acl.h. @@ -149,10 +149,8 @@ ChangeAcl(char *relname, replaces[Anum_pg_class_relacl - 1] = 'r'; values[Anum_pg_class_relacl - 1] = (Datum) new_acl; tuple = heap_modifytuple(tuple, relation, values, nulls, replaces); - /* XXX handle index on pg_class? */ - setheapoverride(true); + heap_update(relation, &tuple->t_self, tuple, NULL); - setheapoverride(false); /* keep the catalog indices up to date */ CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 0476f2c822..d61df6561b 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.116 2000/01/17 02:04:12 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.117 2000/01/17 23:57:43 tgl Exp $ * * * INTERFACE ROUTINES @@ -1065,7 +1065,7 @@ DeleteRelationTuple(Relation rel) pg_class_desc = heap_openr(RelationRelationName, RowExclusiveLock); tup = SearchSysCacheTupleCopy(RELOID, - ObjectIdGetDatum(rel->rd_att->attrs[0]->attrelid), + ObjectIdGetDatum(rel->rd_id), 0, 0, 0); if (!HeapTupleIsValid(tup)) { @@ -1509,31 +1509,25 @@ heap_drop_with_catalog(char *relname) DeleteAttributeTuples(rel); /* ---------------- - * delete comments + * delete comments, statistics, and constraints * ---------------- */ DeleteComments(RelationGetRelid(rel)); - /* ---------------- - * delete statistics - * ---------------- - */ RemoveStatistics(rel); + RemoveConstraints(rel); + /* ---------------- - * delete type tuple. here we want to see the effects - * of the deletions we just did, so we use setheapoverride(). + * delete type tuple * ---------------- */ - setheapoverride(true); DeleteTypeTuple(rel); - setheapoverride(false); /* ---------------- * delete relation tuple * ---------------- */ - /* must delete fake tuple in cache */ DeleteRelationTuple(rel); /* @@ -1541,8 +1535,6 @@ heap_drop_with_catalog(char *relname) */ ReleaseRelationBuffers(rel); - RemoveConstraints(rel); - /* ---------------- * unlink the relation's physical file and finish up. * ---------------- diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 7c7ffa3250..84009d6282 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.101 1999/12/20 10:40:40 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.102 2000/01/17 23:57:43 tgl Exp $ * * * INTERFACE ROUTINES @@ -904,19 +904,16 @@ InitIndexStrategy(int numatts, /* ---------------- * fill in the index strategy structure with information - * from the catalogs. Note: we use heap override mode - * in order to be allowed to see the correct information in the - * catalogs, even though our transaction has not yet committed. + * from the catalogs. First we must advance the command counter + * so that we will see the newly-entered index catalog tuples. * ---------------- */ - setheapoverride(true); + CommandCounterIncrement(); IndexSupportInitialize(strategy, support, attrelid, accessMethodObjectId, amstrategies, amsupport, numatts); - setheapoverride(false); - /* ---------------- * store the strategy information in the index reldesc * ---------------- diff --git a/src/backend/catalog/pg_operator.c b/src/backend/catalog/pg_operator.c index a143c807c7..45c284cd9d 100644 --- a/src/backend/catalog/pg_operator.c +++ b/src/backend/catalog/pg_operator.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.47 2000/01/10 17:14:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.48 2000/01/17 23:57:43 tgl Exp $ * * NOTES * these routines moved here from commands/define.c and somewhat cleaned up. @@ -775,6 +775,9 @@ OperatorDef(char *operatorName, opKey[1].sk_argument = ObjectIdGetDatum(leftTypeId); opKey[2].sk_argument = ObjectIdGetDatum(rightTypeId); + /* Make sure we can see the shell even if it is new in current cmd */ + CommandCounterIncrement(); + pg_operator_scan = heap_beginscan(pg_operator_desc, 0, SnapshotSelf, /* no cache? */ @@ -790,9 +793,7 @@ OperatorDef(char *operatorName, nulls, replaces); - setheapoverride(true); heap_update(pg_operator_desc, &tup->t_self, tup, NULL); - setheapoverride(false); } else elog(ERROR, "OperatorDef: no operator %u", operatorObjectId); @@ -875,7 +876,13 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) pg_operator_desc = heap_openr(OperatorRelationName, RowExclusiveLock); - /* check and update the commutator, if necessary */ + /* + * check and update the commutator & negator, if necessary + * + * First make sure we can see them... + */ + CommandCounterIncrement(); + opKey[0].sk_argument = ObjectIdGetDatum(commId); pg_operator_scan = heap_beginscan(pg_operator_desc, @@ -920,9 +927,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) nulls, replaces); - setheapoverride(true); heap_update(pg_operator_desc, &tup->t_self, tup, NULL); - setheapoverride(false); if (RelationGetForm(pg_operator_desc)->relhasindex) { @@ -954,9 +959,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) nulls, replaces); - setheapoverride(true); heap_update(pg_operator_desc, &tup->t_self, tup, NULL); - setheapoverride(false); if (RelationGetForm(pg_operator_desc)->relhasindex) { @@ -994,9 +997,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) nulls, replaces); - setheapoverride(true); heap_update(pg_operator_desc, &tup->t_self, tup, NULL); - setheapoverride(false); if (RelationGetForm(pg_operator_desc)->relhasindex) { diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index 2b9e9d6ecc..3de8020595 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.46 2000/01/10 20:23:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.47 2000/01/17 23:57:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -481,9 +481,7 @@ TypeCreate(char *typeName, nulls, replaces); - setheapoverride(true); heap_update(pg_type_desc, &tup->t_self, tup, NULL); - setheapoverride(false); typeObjectId = tup->t_data->t_oid; } @@ -558,9 +556,7 @@ TypeRename(char *oldTypeName, char *newTypeName) namestrcpy(&(((Form_pg_type) GETSTRUCT(oldtup))->typname), newTypeName); - setheapoverride(true); heap_update(pg_type_desc, &oldtup->t_self, oldtup, NULL); - setheapoverride(false); /* update the system catalog indices */ CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs); diff --git a/src/backend/commands/_deadcode/recipe.c b/src/backend/commands/_deadcode/recipe.c index dc0928fe97..9a5eda6906 100644 --- a/src/backend/commands/_deadcode/recipe.c +++ b/src/backend/commands/_deadcode/recipe.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/recipe.c,v 1.8 2000/01/10 17:14:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/recipe.c,v 1.9 2000/01/17 23:57:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -211,9 +211,10 @@ beginRecipe(RecipeStmt *stmt) /* * before we plan, we want to see all the changes we did, during * the rewrite phase, such as creating the tee tables, - * setheapoverride() allows us to see the changes + * CommandCounterIncrement() allows us to see the changes */ - setheapoverride(true); + CommandCounterIncrement(); + plan = planner(parsetree); /* ---------------------------------------------------------- @@ -265,8 +266,6 @@ beginRecipe(RecipeStmt *stmt) } /* if (teeInfo) */ - setheapoverride(false); - /* define a portal for this viewer input */ /* for now, eyes can only have one input */ snprintf(portalName, 1024, "%s%d", e->nodeName, 0); diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index 93feb9e805..9ebf207199 100644 --- a/src/backend/commands/comment.c +++ b/src/backend/commands/comment.c @@ -165,9 +165,7 @@ void CreateComments(Oid oid, char *comment) { } else { desctuple = heap_modifytuple(searchtuple, description, values, nulls, replaces); - setheapoverride(true); heap_update(description, &searchtuple->t_self, desctuple, NULL); - setheapoverride(false); modified = TRUE; } diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 352e368d99..fa98950ac1 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.104 2000/01/05 18:23:46 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.105 2000/01/17 23:57:45 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -723,18 +723,13 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) FreeTupleDesc(tupdesc); /* - * XXX rather than having to call setheapoverride(true) - * and then back to false, we should change the arguments - * to heap_open() instead.. - * - * XXX no, we should use commandCounterIncrement... + * Advance command counter so that the newly-created + * relation's catalog tuples will be visible to heap_open. */ - setheapoverride(true); + CommandCounterIncrement(); intoRelationDesc = heap_open(intoRelationId, AccessExclusiveLock); - - setheapoverride(false); } } } diff --git a/src/backend/utils/adt/sets.c b/src/backend/utils/adt/sets.c index ba94496cea..baa4e67b33 100644 --- a/src/backend/utils/adt/sets.c +++ b/src/backend/utils/adt/sets.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.28 1999/11/24 00:44:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.29 2000/01/17 23:57:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -113,9 +113,7 @@ SetDefine(char *querystr, char *typename) replNull, repl); - setheapoverride(true); heap_update(procrel, &tup->t_self, newtup, NULL); - setheapoverride(false); setoid = newtup->t_data->t_oid; } diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index c9f26f38ad..aa76d46862 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.56 2000/01/10 16:13:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.57 2000/01/17 23:57:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1047,8 +1047,7 @@ SearchSysCache(struct catcache * cache, * if this isn't bootstrap (initdb) time, use the index. * ---------------- */ - CACHE2_elog(DEBUG, "SearchSysCache: performing scan (override==%d)", - heapisoverride()); + CACHE1_elog(DEBUG, "SearchSysCache: performing scan"); if ((RelationGetForm(relation))->relhasindex && !IsBootstrapProcessingMode()) diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 4a96c5736c..32479fb278 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.33 1999/12/10 12:34:14 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.34 2000/01/17 23:57:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -26,31 +26,6 @@ Snapshot SerializableSnapshot = NULL; bool ReferentialIntegritySnapshotOverride = false; -/* - * XXX Transaction system override hacks start here - */ -#ifndef GOODAMI - -TransactionId HeapSpecialTransactionId = InvalidTransactionId; -CommandId HeapSpecialCommandId = FirstCommandId; - -void -setheapoverride(bool on) -{ - if (on) - { - TransactionIdStore(GetCurrentTransactionId(), - &HeapSpecialTransactionId); - HeapSpecialCommandId = GetCurrentCommandId(); - } - else - HeapSpecialTransactionId = InvalidTransactionId; -} - -#endif /* !defined(GOODAMI) */ -/* - * XXX Transaction system override hacks end here - */ /* * HeapTupleSatisfiesItself @@ -311,7 +286,7 @@ HeapTupleSatisfiesUpdate(HeapTuple tuple) } else if (TransactionIdIsCurrentTransactionId(th->t_xmin)) { - if (CommandIdGEScanCommandId(th->t_cmin) && !heapisoverride()) + if (CommandIdGEScanCommandId(th->t_cmin)) return HeapTupleInvisible; /* inserted after scan * started */ diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index 89314764ea..311b479a07 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: tqual.h,v 1.26 1999/12/10 12:34:15 wieck Exp $ + * $Id: tqual.h,v 1.27 2000/01/17 23:57:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,13 +17,14 @@ #include "access/htup.h" #include "access/xact.h" + typedef struct SnapshotData { - TransactionId xmin; /* XID < xmin are visible to me */ - TransactionId xmax; /* XID >= xmax are invisible to me */ - uint32 xcnt; /* # of xact below */ - TransactionId *xip; /* array of xacts in progress */ - ItemPointerData tid; /* required for Dirty snapshot -:( */ + TransactionId xmin; /* XID < xmin are visible to me */ + TransactionId xmax; /* XID >= xmax are invisible to me */ + uint32 xcnt; /* # of xact below */ + TransactionId *xip; /* array of xacts in progress */ + ItemPointerData tid; /* required for Dirty snapshot -:( */ } SnapshotData; typedef SnapshotData *Snapshot; @@ -38,20 +39,19 @@ extern Snapshot SerializableSnapshot; extern bool ReferentialIntegritySnapshotOverride; -#define IsSnapshotNow(snapshot) ((Snapshot) snapshot == SnapshotNow) -#define IsSnapshotSelf(snapshot) ((Snapshot) snapshot == SnapshotSelf) -#define IsSnapshotAny(snapshot) ((Snapshot) snapshot == SnapshotAny) -#define IsSnapshotDirty(snapshot) ((Snapshot) snapshot == SnapshotDirty) +#define IsSnapshotNow(snapshot) ((Snapshot) (snapshot) == SnapshotNow) +#define IsSnapshotSelf(snapshot) ((Snapshot) (snapshot) == SnapshotSelf) +#define IsSnapshotAny(snapshot) ((Snapshot) (snapshot) == SnapshotAny) +#define IsSnapshotDirty(snapshot) ((Snapshot) (snapshot) == SnapshotDirty) -extern TransactionId HeapSpecialTransactionId; -extern CommandId HeapSpecialCommandId; /* * HeapTupleSatisfiesVisibility * True iff heap tuple satsifies a time qual. * - * Note: + * Notes: * Assumes heap tuple is valid. + * Beware of multiple evaluations of arguments. */ #define HeapTupleSatisfiesVisibility(tuple, snapshot) \ ( \ @@ -59,16 +59,16 @@ extern CommandId HeapSpecialCommandId; false \ : \ ( \ - (IsSnapshotAny(snapshot) || heapisoverride()) ? \ + IsSnapshotAny(snapshot) ? \ true \ : \ - ((IsSnapshotSelf(snapshot) || heapisoverride()) ? \ + (IsSnapshotSelf(snapshot) ? \ HeapTupleSatisfiesItself((tuple)->t_data) \ : \ - ((IsSnapshotDirty(snapshot)) ? \ + (IsSnapshotDirty(snapshot) ? \ HeapTupleSatisfiesDirty((tuple)->t_data) \ : \ - ((IsSnapshotNow(snapshot)) ? \ + (IsSnapshotNow(snapshot) ? \ HeapTupleSatisfiesNow((tuple)->t_data) \ : \ HeapTupleSatisfiesSnapshot((tuple)->t_data, snapshot) \ @@ -78,24 +78,6 @@ extern CommandId HeapSpecialCommandId; ) \ ) -#define heapisoverride() \ -( \ - (!TransactionIdIsValid(HeapSpecialTransactionId)) ? \ - false \ - : \ - ( \ - (!TransactionIdEquals(GetCurrentTransactionId(), \ - HeapSpecialTransactionId) || \ - GetCurrentCommandId() != HeapSpecialCommandId) ? \ - ( \ - HeapSpecialTransactionId = InvalidTransactionId, \ - false \ - ) \ - : \ - true \ - ) \ -) - #define HeapTupleMayBeUpdated 0 #define HeapTupleInvisible 1 #define HeapTupleSelfUpdated 2 @@ -105,11 +87,10 @@ extern CommandId HeapSpecialCommandId; extern bool HeapTupleSatisfiesItself(HeapTupleHeader tuple); extern bool HeapTupleSatisfiesNow(HeapTupleHeader tuple); extern bool HeapTupleSatisfiesDirty(HeapTupleHeader tuple); -extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot); +extern bool HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, + Snapshot snapshot); extern int HeapTupleSatisfiesUpdate(HeapTuple tuple); -extern void setheapoverride(bool on); - extern Snapshot GetSnapshotData(bool serializable); extern void SetQuerySnapshot(void); extern void FreeXactSnapshot(void);