heap_fetch requires buffer pointer, must be released; heap_getnext

no longer returns buffer pointer, can be gotten from scan;
	descriptor; bootstrap can create multi-key indexes;
pg_procname index now is multi-key index; oidint2, oidint4, oidname
are gone (must be removed from regression tests); use System Cache
rather than sequential scan in many places; heap_modifytuple no
longer takes buffer parameter; remove unused buffer parameter in
a few other functions; oid8 is not index-able; remove some use of
single-character variable names; cleanup Buffer variables usage
and scan descriptor looping; cleaned up allocation and freeing of
tuples; 18k lines of diff;
This commit is contained in:
Bruce Momjian 1998-08-19 02:04:17 +00:00
parent 31de2c9461
commit 7971539020
123 changed files with 2139 additions and 3134 deletions

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.38 1998/06/15 19:27:44 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.39 1998/08/19 02:00:53 momjian Exp $
* *
* NOTES * NOTES
* The old interface functions have been converted to macros * The old interface functions have been converted to macros
@ -736,13 +736,6 @@ heap_copytuple(HeapTuple tuple)
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
return (NULL); return (NULL);
/* XXX For now, just prevent an undetectable executor related error */
if (tuple->t_len > MAXTUPLEN)
{
elog(ERROR, "palloctup: cannot handle length %d tuples",
tuple->t_len);
}
newTuple = (HeapTuple) palloc(tuple->t_len); newTuple = (HeapTuple) palloc(tuple->t_len);
memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len); memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len);
return (newTuple); return (newTuple);
@ -863,11 +856,11 @@ heap_formtuple(TupleDesc tupleDescriptor,
* heap_modifytuple * heap_modifytuple
* *
* forms a new tuple from an old tuple and a set of replacement values. * forms a new tuple from an old tuple and a set of replacement values.
* returns a new palloc'ed tuple.
* ---------------- * ----------------
*/ */
HeapTuple HeapTuple
heap_modifytuple(HeapTuple tuple, heap_modifytuple(HeapTuple tuple,
Buffer buffer,
Relation relation, Relation relation,
Datum replValue[], Datum replValue[],
char replNull[], char replNull[],
@ -879,7 +872,6 @@ heap_modifytuple(HeapTuple tuple,
char *nulls; char *nulls;
bool isNull; bool isNull;
HeapTuple newTuple; HeapTuple newTuple;
int madecopy;
uint8 infomask; uint8 infomask;
/* ---------------- /* ----------------
@ -887,26 +879,11 @@ heap_modifytuple(HeapTuple tuple,
* ---------------- * ----------------
*/ */
Assert(HeapTupleIsValid(tuple)); Assert(HeapTupleIsValid(tuple));
Assert(BufferIsValid(buffer) || RelationIsValid(relation)); Assert(RelationIsValid(relation));
Assert(HeapTupleIsValid(tuple));
Assert(PointerIsValid(replValue)); Assert(PointerIsValid(replValue));
Assert(PointerIsValid(replNull)); Assert(PointerIsValid(replNull));
Assert(PointerIsValid(repl)); Assert(PointerIsValid(repl));
/* ----------------
* if we're pointing to a disk page, then first
* make a copy of our tuple so that all the attributes
* are available. XXX this is inefficient -cim
* ----------------
*/
madecopy = 0;
if (BufferIsValid(buffer) == true)
{
relation = (Relation) BufferGetRelation(buffer);
tuple = heap_copytuple(tuple);
madecopy = 1;
}
numberOfAttributes = RelationGetRelationTupleForm(relation)->relnatts; numberOfAttributes = RelationGetRelationTupleForm(relation)->relnatts;
/* ---------------- /* ----------------
@ -933,10 +910,7 @@ heap_modifytuple(HeapTuple tuple,
} }
else if (repl[attoff] != 'r') else if (repl[attoff] != 'r')
{
elog(ERROR, "heap_modifytuple: repl is \\%3d", repl[attoff]); elog(ERROR, "heap_modifytuple: repl is \\%3d", repl[attoff]);
}
else else
{ /* == 'r' */ { /* == 'r' */
value[attoff] = replValue[attoff]; value[attoff] = replValue[attoff];
@ -961,18 +935,8 @@ heap_modifytuple(HeapTuple tuple,
(char *) &tuple->t_oid, (char *) &tuple->t_oid,
((char *) &tuple->t_hoff - (char *) &tuple->t_oid)); /* XXX */ ((char *) &tuple->t_hoff - (char *) &tuple->t_oid)); /* XXX */
newTuple->t_infomask = infomask; newTuple->t_infomask = infomask;
newTuple->t_natts = numberOfAttributes; /* fix t_natts just in newTuple->t_natts = numberOfAttributes; /* fix t_natts just in case */
* case */ return newTuple;
/* ----------------
* if we made a copy of the tuple, then free it.
* ----------------
*/
if (madecopy)
pfree(tuple);
return
newTuple;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.31 1998/07/26 04:30:16 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.32 1998/08/19 02:00:54 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -46,8 +46,7 @@ typtoout(Oid type)
0, 0, 0); 0, 0, 0);
if (HeapTupleIsValid(typeTuple)) if (HeapTupleIsValid(typeTuple))
return ((Oid) return ((Oid) ((TypeTupleForm) GETSTRUCT(typeTuple))->typoutput);
((TypeTupleForm) GETSTRUCT(typeTuple))->typoutput);
elog(ERROR, "typtoout: Cache lookup of type %d failed", type); elog(ERROR, "typtoout: Cache lookup of type %d failed", type);
return (InvalidOid); return (InvalidOid);
@ -63,8 +62,7 @@ gettypelem(Oid type)
0, 0, 0); 0, 0, 0);
if (HeapTupleIsValid(typeTuple)) if (HeapTupleIsValid(typeTuple))
return ((Oid) return ((Oid) ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
elog(ERROR, "typtoout: Cache lookup of type %d failed", type); elog(ERROR, "typtoout: Cache lookup of type %d failed", type);
return (InvalidOid); return (InvalidOid);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.41 1998/07/12 21:29:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.42 1998/08/19 02:00:56 momjian Exp $
* *
* NOTES * NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be * some of the executor utility code such as "ExecTypeFromTL" should be
@ -327,7 +327,8 @@ TupleDescInitEntry(TupleDesc desc,
* -cim 6/14/90 * -cim 6/14/90
* ---------------- * ----------------
*/ */
tuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(typeid), tuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(typeid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {

View File

@ -87,7 +87,6 @@ gistbuild(Relation heap,
PredInfo *predInfo) PredInfo *predInfo)
{ {
HeapScanDesc scan; HeapScanDesc scan;
Buffer buffer;
AttrNumber i; AttrNumber i;
HeapTuple htup; HeapTuple htup;
IndexTuple itup; IndexTuple itup;
@ -112,14 +111,15 @@ gistbuild(Relation heap,
*oldPred; *oldPred;
GISTSTATE giststate; GISTSTATE giststate;
GISTENTRY tmpcentry; GISTENTRY tmpcentry;
Buffer buffer = InvalidBuffer;
bool *compvec; bool *compvec;
/* GiSTs only know how to do stupid locking now */ /* GiSTs only know how to do stupid locking now */
RelationSetLockForWrite(index); RelationSetLockForWrite(index);
setheapoverride(TRUE); /* so we can see the new pg_index tuple */ setheapoverride(true); /* so we can see the new pg_index tuple */
initGISTstate(&giststate, index); initGISTstate(&giststate, index);
setheapoverride(FALSE); setheapoverride(false);
pred = predInfo->pred; pred = predInfo->pred;
oldPred = predInfo->oldPred; oldPred = predInfo->oldPred;
@ -170,15 +170,13 @@ gistbuild(Relation heap,
econtext = NULL; econtext = NULL;
} }
#endif /* OMIT_PARTIAL_INDEX */ #endif /* OMIT_PARTIAL_INDEX */
scan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
htup = heap_getnext(scan, 0, &buffer);
/* int the tuples as we insert them */ /* int the tuples as we insert them */
nh = ni = 0; nh = ni = 0;
for (; HeapTupleIsValid(htup); htup = heap_getnext(scan, 0, &buffer)) scan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
{
while (HeapTupleIsValid(htup = heap_getnext(scan, 0)))
{
nh++; nh++;
/* /*
@ -240,8 +238,7 @@ gistbuild(Relation heap,
attoff, attoff,
attnum, attnum,
finfo, finfo,
&attnull, &attnull);
buffer);
nulls[attoff] = (attnull ? 'n' : ' '); nulls[attoff] = (attnull ? 'n' : ' ');
} }
@ -302,8 +299,8 @@ gistbuild(Relation heap,
* flushed. We close them to guarantee that they will be. * flushed. We close them to guarantee that they will be.
*/ */
hrelid = heap->rd_id; hrelid = RelationGetRelid(heap);
irelid = index->rd_id; irelid = RelationGetRelid(index);
heap_close(heap); heap_close(heap);
index_close(index); index_close(index);
@ -1165,11 +1162,13 @@ initGISTstate(GISTSTATE *giststate, Relation index)
fmgr_info(equal_proc, &giststate->equalFn); fmgr_info(equal_proc, &giststate->equalFn);
/* see if key type is different from type of attribute being indexed */ /* see if key type is different from type of attribute being indexed */
htup = SearchSysCacheTuple(INDEXRELID, ObjectIdGetDatum(index->rd_id), htup = SearchSysCacheTuple(INDEXRELID,
ObjectIdGetDatum(RelationGetRelid(index)),
0, 0, 0); 0, 0, 0);
itupform = (IndexTupleForm) GETSTRUCT(htup); itupform = (IndexTupleForm) GETSTRUCT(htup);
if (!HeapTupleIsValid(htup)) if (!HeapTupleIsValid(htup))
elog(ERROR, "initGISTstate: index %d not found", index->rd_id); elog(ERROR, "initGISTstate: index %d not found",
RelationGetRelid(index));
giststate->haskeytype = itupform->indhaskeytype; giststate->haskeytype = itupform->indhaskeytype;
if (giststate->haskeytype) if (giststate->haskeytype)
{ {

View File

@ -284,12 +284,12 @@ gistdropscan(IndexScanDesc s)
} }
void void
gistadjscans(Relation r, int op, BlockNumber blkno, OffsetNumber offnum) gistadjscans(Relation rel, int op, BlockNumber blkno, OffsetNumber offnum)
{ {
GISTScanList l; GISTScanList l;
Oid relid; Oid relid;
relid = r->rd_id; relid = RelationGetRelid(rel);
for (l = GISTScans; l != (GISTScanList) NULL; l = l->gsl_next) for (l = GISTScans; l != (GISTScanList) NULL; l = l->gsl_next)
{ {
if (l->gsl_scan->relation->rd_id == relid) if (l->gsl_scan->relation->rd_id == relid)

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.19 1998/07/27 19:37:35 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.20 1998/08/19 02:01:00 momjian Exp $
* *
* NOTES * NOTES
* This file contains only the public interface routines. * This file contains only the public interface routines.
@ -53,7 +53,6 @@ hashbuild(Relation heap,
PredInfo *predInfo) PredInfo *predInfo)
{ {
HeapScanDesc hscan; HeapScanDesc hscan;
Buffer buffer;
HeapTuple htup; HeapTuple htup;
IndexTuple itup; IndexTuple itup;
TupleDesc htupdesc, TupleDesc htupdesc,
@ -65,6 +64,7 @@ hashbuild(Relation heap,
nitups; nitups;
int i; int i;
HashItem hitem; HashItem hitem;
Buffer buffer = InvalidBuffer;
#ifndef OMIT_PARTIAL_INDEX #ifndef OMIT_PARTIAL_INDEX
ExprContext *econtext; ExprContext *econtext;
@ -120,14 +120,13 @@ hashbuild(Relation heap,
} }
#endif /* OMIT_PARTIAL_INDEX */ #endif /* OMIT_PARTIAL_INDEX */
/* start a heap scan */
hscan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
htup = heap_getnext(hscan, 0, &buffer);
/* build the index */ /* build the index */
nhtups = nitups = 0; nhtups = nitups = 0;
for (; HeapTupleIsValid(htup); htup = heap_getnext(hscan, 0, &buffer)) /* start a heap scan */
hscan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
while (HeapTupleIsValid(htup = heap_getnext(hscan, 0)))
{ {
nhtups++; nhtups++;
@ -193,8 +192,7 @@ hashbuild(Relation heap,
attoff, attoff,
attnum, attnum,
finfo, finfo,
&attnull, &attnull);
buffer);
nulls[attoff] = (attnull ? 'n' : ' '); nulls[attoff] = (attnull ? 'n' : ' ');
} }
@ -248,8 +246,8 @@ hashbuild(Relation heap,
*/ */
if (IsNormalProcessingMode()) if (IsNormalProcessingMode())
{ {
hrelid = heap->rd_id; hrelid = RelationGetRelid(heap);
irelid = index->rd_id; irelid = RelationGetRelid(index);
heap_close(heap); heap_close(heap);
index_close(index); index_close(index);
UpdateStats(hrelid, nhtups, true); UpdateStats(hrelid, nhtups, true);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.9 1998/04/26 04:05:08 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.10 1998/08/19 02:01:02 momjian Exp $
* *
* NOTES * NOTES
* These functions are stored in pg_amproc. For each operator class * These functions are stored in pg_amproc. For each operator class
@ -133,6 +133,18 @@ hashoid(Oid key)
return ((uint32) ~key); return ((uint32) ~key);
} }
uint32
hashoid8(Oid key[])
{
int i;
uint32 result = 0;
for (i=0; i < 8; i++)
result = result ^ (~(uint32)key[i]);
return result;
}
#define PRIME1 37 #define PRIME1 37
#define PRIME2 1048583 #define PRIME2 1048583

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashscan.c,v 1.14 1998/06/15 19:27:50 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/hash/hashscan.c,v 1.15 1998/08/19 02:01:04 momjian Exp $
* *
* NOTES * NOTES
* Because we can be doing an index scan on a relation while we * Because we can be doing an index scan on a relation while we
@ -90,7 +90,7 @@ _hash_adjscans(Relation rel, ItemPointer tid)
HashScanList l; HashScanList l;
Oid relid; Oid relid;
relid = rel->rd_id; relid = RelationGetRelid(rel);
for (l = HashScans; l != (HashScanList) NULL; l = l->hashsl_next) for (l = HashScans; l != (HashScanList) NULL; l = l->hashsl_next)
{ {
if (relid == l->hashsl_scan->relation->rd_id) if (relid == l->hashsl_scan->relation->rd_id)

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.31 1998/07/27 19:37:36 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.32 1998/08/19 02:01:05 momjian Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
@ -104,11 +104,11 @@ static bool ImmediateInvalidation;
*/ */
/* ---------------- /* ----------------
* initsdesc - sdesc code common to heap_beginscan and heap_rescan * initscan - scan code common to heap_beginscan and heap_rescan
* ---------------- * ----------------
*/ */
static void static void
initsdesc(HeapScanDesc sdesc, initscan(HeapScanDesc scan,
Relation relation, Relation relation,
int atend, int atend,
unsigned nkeys, unsigned nkeys,
@ -120,8 +120,8 @@ initsdesc(HeapScanDesc sdesc,
* relation is empty * relation is empty
* ---------------- * ----------------
*/ */
sdesc->rs_ntup = sdesc->rs_ctup = sdesc->rs_ptup = NULL; scan->rs_ntup = scan->rs_ctup = scan->rs_ptup = NULL;
sdesc->rs_nbuf = sdesc->rs_cbuf = sdesc->rs_pbuf = InvalidBuffer; scan->rs_nbuf = scan->rs_cbuf = scan->rs_pbuf = InvalidBuffer;
} }
else if (atend) else if (atend)
{ {
@ -129,10 +129,10 @@ initsdesc(HeapScanDesc sdesc,
* reverse scan * reverse scan
* ---------------- * ----------------
*/ */
sdesc->rs_ntup = sdesc->rs_ctup = NULL; scan->rs_ntup = scan->rs_ctup = NULL;
sdesc->rs_nbuf = sdesc->rs_cbuf = InvalidBuffer; scan->rs_nbuf = scan->rs_cbuf = InvalidBuffer;
sdesc->rs_ptup = NULL; scan->rs_ptup = NULL;
sdesc->rs_pbuf = UnknownBuffer; scan->rs_pbuf = UnknownBuffer;
} }
else else
{ {
@ -140,35 +140,35 @@ initsdesc(HeapScanDesc sdesc,
* forward scan * forward scan
* ---------------- * ----------------
*/ */
sdesc->rs_ctup = sdesc->rs_ptup = NULL; scan->rs_ctup = scan->rs_ptup = NULL;
sdesc->rs_cbuf = sdesc->rs_pbuf = InvalidBuffer; scan->rs_cbuf = scan->rs_pbuf = InvalidBuffer;
sdesc->rs_ntup = NULL; scan->rs_ntup = NULL;
sdesc->rs_nbuf = UnknownBuffer; scan->rs_nbuf = UnknownBuffer;
} /* invalid too */ } /* invalid too */
/* we don't have a marked position... */ /* we don't have a marked position... */
ItemPointerSetInvalid(&(sdesc->rs_mptid)); ItemPointerSetInvalid(&(scan->rs_mptid));
ItemPointerSetInvalid(&(sdesc->rs_mctid)); ItemPointerSetInvalid(&(scan->rs_mctid));
ItemPointerSetInvalid(&(sdesc->rs_mntid)); ItemPointerSetInvalid(&(scan->rs_mntid));
ItemPointerSetInvalid(&(sdesc->rs_mcd)); ItemPointerSetInvalid(&(scan->rs_mcd));
/* ---------------- /* ----------------
* copy the scan key, if appropriate * copy the scan key, if appropriate
* ---------------- * ----------------
*/ */
if (key != NULL) if (key != NULL)
memmove(sdesc->rs_key, key, nkeys * sizeof(ScanKeyData)); memmove(scan->rs_key, key, nkeys * sizeof(ScanKeyData));
} }
/* ---------------- /* ----------------
* unpinsdesc - code common to heap_rescan and heap_endscan * unpinscan - code common to heap_rescan and heap_endscan
* ---------------- * ----------------
*/ */
static void static void
unpinsdesc(HeapScanDesc sdesc) unpinscan(HeapScanDesc scan)
{ {
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(sdesc->rs_pbuf); ReleaseBuffer(scan->rs_pbuf);
/* ------------------------------------ /* ------------------------------------
* Scan will pin buffer one for each non-NULL tuple pointer * Scan will pin buffer one for each non-NULL tuple pointer
@ -176,11 +176,11 @@ unpinsdesc(HeapScanDesc sdesc)
* times. * times.
* ------------------------------------ * ------------------------------------
*/ */
if (BufferIsValid(sdesc->rs_cbuf)) if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(sdesc->rs_cbuf); ReleaseBuffer(scan->rs_cbuf);
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(sdesc->rs_nbuf); ReleaseBuffer(scan->rs_nbuf);
} }
/* ------------------------------------------ /* ------------------------------------------
@ -202,13 +202,18 @@ nextpage(int page, int dir)
* *
* routine used by heap_getnext() which does most of the * routine used by heap_getnext() which does most of the
* real work in scanning tuples. * real work in scanning tuples.
*
* The scan routines handle their own buffer lock/unlocking, so
* there is no reason to request the buffer number unless
* to want to perform some other operation with the result,
* like pass it to another function.
* ---------------- * ----------------
*/ */
static HeapTuple static HeapTuple
heapgettup(Relation relation, heapgettup(Relation relation,
ItemPointer tid, ItemPointer tid,
int dir, int dir,
Buffer *b, Buffer *buf,
Snapshot snapshot, Snapshot snapshot,
int nkeys, int nkeys,
ScanKey key) ScanKey key)
@ -248,7 +253,7 @@ heapgettup(Relation relation,
elog(DEBUG, "heapgettup(%s, tid=0x%x, dir=%d, ...)", elog(DEBUG, "heapgettup(%s, tid=0x%x, dir=%d, ...)",
RelationGetRelationName(relation), tid, dir); RelationGetRelationName(relation), tid, dir);
} }
elog(DEBUG, "heapgettup(..., b=0x%x, nkeys=%d, key=0x%x", b, nkeys, key); elog(DEBUG, "heapgettup(..., b=0x%x, nkeys=%d, key=0x%x", buf, nkeys, key);
elog(DEBUG, "heapgettup: relation(%c)=`%s', %p", elog(DEBUG, "heapgettup: relation(%c)=`%s', %p",
relation->rd_rel->relkind, &relation->rd_rel->relname, relation->rd_rel->relkind, &relation->rd_rel->relname,
@ -278,19 +283,19 @@ heapgettup(Relation relation,
/* assume it is a valid TID XXX */ /* assume it is a valid TID XXX */
if (ItemPointerIsValid(tid) == false) if (ItemPointerIsValid(tid) == false)
{ {
*b = InvalidBuffer; *buf= InvalidBuffer;
return (NULL); return (NULL);
} }
*b = RelationGetBufferWithBuffer(relation, *buf = RelationGetBufferWithBuffer(relation,
ItemPointerGetBlockNumber(tid), ItemPointerGetBlockNumber(tid),
*b); *buf);
#ifndef NO_BUFFERISVALID #ifndef NO_BUFFERISVALID
if (!BufferIsValid(*b)) if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer"); elog(ERROR, "heapgettup: failed ReadBuffer");
#endif #endif
dp = (Page) BufferGetPage(*b); dp = (Page) BufferGetPage(*buf);
lineoff = ItemPointerGetOffsetNumber(tid); lineoff = ItemPointerGetOffsetNumber(tid);
lpp = PageGetItemId(dp, lineoff); lpp = PageGetItemId(dp, lineoff);
@ -316,17 +321,17 @@ heapgettup(Relation relation,
} }
if (page < 0) if (page < 0)
{ {
*b = InvalidBuffer; *buf = InvalidBuffer;
return (NULL); return (NULL);
} }
*b = RelationGetBufferWithBuffer(relation, page, *b); *buf = RelationGetBufferWithBuffer(relation, page, *buf);
#ifndef NO_BUFFERISVALID #ifndef NO_BUFFERISVALID
if (!BufferIsValid(*b)) if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer"); elog(ERROR, "heapgettup: failed ReadBuffer");
#endif #endif
dp = (Page) BufferGetPage(*b); dp = (Page) BufferGetPage(*buf);
lines = PageGetMaxOffsetNumber(dp); lines = PageGetMaxOffsetNumber(dp);
if (tid == NULL) if (tid == NULL)
{ {
@ -360,18 +365,18 @@ heapgettup(Relation relation,
if (page >= pages) if (page >= pages)
{ {
*b = InvalidBuffer; *buf = InvalidBuffer;
return (NULL); return (NULL);
} }
/* page and lineoff now reference the physically next tid */ /* page and lineoff now reference the physically next tid */
*b = RelationGetBufferWithBuffer(relation, page, *b); *buf = RelationGetBufferWithBuffer(relation, page, *buf);
#ifndef NO_BUFFERISVALID #ifndef NO_BUFFERISVALID
if (!BufferIsValid(*b)) if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer"); elog(ERROR, "heapgettup: failed ReadBuffer");
#endif #endif
dp = (Page) BufferGetPage(*b); dp = (Page) BufferGetPage(*buf);
lines = PageGetMaxOffsetNumber(dp); lines = PageGetMaxOffsetNumber(dp);
} }
@ -401,7 +406,7 @@ heapgettup(Relation relation,
* if current tuple qualifies, return it. * if current tuple qualifies, return it.
* ---------------- * ----------------
*/ */
HeapTupleSatisfies(lpp, relation, *b, (PageHeader) dp, HeapTupleSatisfies(lpp, relation, *buf, (PageHeader) dp,
snapshot, nkeys, key, rtup); snapshot, nkeys, key, rtup);
if (rtup != NULL) if (rtup != NULL)
{ {
@ -409,7 +414,6 @@ heapgettup(Relation relation,
if (ItemPointerGetBlockNumber(iptr) != page) if (ItemPointerGetBlockNumber(iptr) != page)
{ {
/* /*
* set block id to the correct page number --- this is * set block id to the correct page number --- this is
* a hack to support the virtual fragment concept * a hack to support the virtual fragment concept
@ -448,19 +452,19 @@ heapgettup(Relation relation,
*/ */
if (page < 0 || page >= pages) if (page < 0 || page >= pages)
{ {
if (BufferIsValid(*b)) if (BufferIsValid(*buf))
ReleaseBuffer(*b); ReleaseBuffer(*buf);
*b = InvalidBuffer; *buf = InvalidBuffer;
return (NULL); return (NULL);
} }
*b = ReleaseAndReadBuffer(*b, relation, page); *buf = ReleaseAndReadBuffer(*buf, relation, page);
#ifndef NO_BUFFERISVALID #ifndef NO_BUFFERISVALID
if (!BufferIsValid(*b)) if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer"); elog(ERROR, "heapgettup: failed ReadBuffer");
#endif #endif
dp = (Page) BufferGetPage(*b); dp = (Page) BufferGetPage(*buf);
lines = lineoff = PageGetMaxOffsetNumber((Page) dp); lines = lineoff = PageGetMaxOffsetNumber((Page) dp);
linesleft = lines - 1; linesleft = lines - 1;
if (dir < 0) if (dir < 0)
@ -584,7 +588,7 @@ heap_beginscan(Relation relation,
unsigned nkeys, unsigned nkeys,
ScanKey key) ScanKey key)
{ {
HeapScanDesc sdesc; HeapScanDesc scan;
/* ---------------- /* ----------------
* increment access statistics * increment access statistics
@ -620,29 +624,29 @@ heap_beginscan(Relation relation,
* allocate and initialize scan descriptor * allocate and initialize scan descriptor
* ---------------- * ----------------
*/ */
sdesc = (HeapScanDesc) palloc(sizeof(HeapScanDescData)); scan = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
relation->rd_nblocks = smgrnblocks(DEFAULT_SMGR, relation); relation->rd_nblocks = smgrnblocks(DEFAULT_SMGR, relation);
sdesc->rs_rd = relation; scan->rs_rd = relation;
if (nkeys) if (nkeys)
/* /*
* we do this here instead of in initsdesc() because heap_rescan * we do this here instead of in initscan() because heap_rescan
* also calls initsdesc() and we don't want to allocate memory * also calls initscan() and we don't want to allocate memory
* again * again
*/ */
sdesc->rs_key = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys); scan->rs_key = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys);
else else
sdesc->rs_key = NULL; scan->rs_key = NULL;
initsdesc(sdesc, relation, atend, nkeys, key); initscan(scan, relation, atend, nkeys, key);
sdesc->rs_atend = atend; scan->rs_atend = atend;
sdesc->rs_snapshot = snapshot; scan->rs_snapshot = snapshot;
sdesc->rs_nkeys = (short) nkeys; scan->rs_nkeys = (short) nkeys;
return (sdesc); return (scan);
} }
/* ---------------- /* ----------------
@ -650,7 +654,7 @@ heap_beginscan(Relation relation,
* ---------------- * ----------------
*/ */
void void
heap_rescan(HeapScanDesc sdesc, heap_rescan(HeapScanDesc scan,
bool scanFromEnd, bool scanFromEnd,
ScanKey key) ScanKey key)
{ {
@ -667,14 +671,14 @@ heap_rescan(HeapScanDesc sdesc,
* unpin scan buffers * unpin scan buffers
* ---------------- * ----------------
*/ */
unpinsdesc(sdesc); unpinscan(scan);
/* ---------------- /* ----------------
* reinitialize scan descriptor * reinitialize scan descriptor
* ---------------- * ----------------
*/ */
initsdesc(sdesc, sdesc->rs_rd, scanFromEnd, sdesc->rs_nkeys, key); initscan(scan, scan->rs_rd, scanFromEnd, scan->rs_nkeys, key);
sdesc->rs_atend = (bool) scanFromEnd; scan->rs_atend = (bool) scanFromEnd;
} }
/* ---------------- /* ----------------
@ -685,7 +689,7 @@ heap_rescan(HeapScanDesc sdesc,
* ---------------- * ----------------
*/ */
void void
heap_endscan(HeapScanDesc sdesc) heap_endscan(HeapScanDesc scan)
{ {
/* ---------------- /* ----------------
* increment access statistics * increment access statistics
@ -700,36 +704,38 @@ heap_endscan(HeapScanDesc sdesc)
* unpin scan buffers * unpin scan buffers
* ---------------- * ----------------
*/ */
unpinsdesc(sdesc); unpinscan(scan);
/* ---------------- /* ----------------
* decrement relation reference count and free scan descriptor storage * decrement relation reference count and free scan descriptor storage
* ---------------- * ----------------
*/ */
RelationDecrementReferenceCount(sdesc->rs_rd); RelationDecrementReferenceCount(scan->rs_rd);
/* ---------------- /* ----------------
* Non 2-phase read locks on catalog relations * Non 2-phase read locks on catalog relations
* ---------------- * ----------------
*/ */
if (IsSystemRelationName(RelationGetRelationName(sdesc->rs_rd)->data)) if (IsSystemRelationName(RelationGetRelationName(scan->rs_rd)->data))
RelationUnsetLockForRead(sdesc->rs_rd); RelationUnsetLockForRead(scan->rs_rd);
pfree(sdesc); /* XXX */ pfree(scan); /* XXX */
} }
/* ---------------- /* ----------------
* heap_getnext - retrieve next tuple in scan * heap_getnext - retrieve next tuple in scan
* *
* Fix to work with index relations. * Fix to work with index relations.
* We don't return the buffer anymore, but you can get it from the
* returned HeapTuple.
* ---------------- * ----------------
*/ */
#ifdef HEAPDEBUGALL #ifdef HEAPDEBUGALL
#define HEAPDEBUG_1 \ #define HEAPDEBUG_1 \
elog(DEBUG, "heap_getnext([%s,nkeys=%d],backw=%d,0x%x) called", \ elog(DEBUG, "heap_getnext([%s,nkeys=%d],backw=%d) called", \
sdesc->rs_rd->rd_rel->relname.data, sdesc->rs_nkeys, backw, b) scan->rs_rd->rd_rel->relname.data, scan->rs_nkeys, backw)
#define HEAPDEBUG_2 \ #define HEAPDEBUG_2 \
elog(DEBUG, "heap_getnext called with backw (no tracing yet)") elog(DEBUG, "heap_getnext called with backw (no tracing yet)")
@ -760,12 +766,9 @@ elog(DEBUG, "heap_getnext([%s,nkeys=%d],backw=%d,0x%x) called", \
HeapTuple HeapTuple
heap_getnext(HeapScanDesc scandesc, heap_getnext(HeapScanDesc scandesc, int backw)
int backw,
Buffer *b)
{ {
HeapScanDesc sdesc = scandesc; HeapScanDesc scan = scandesc;
Buffer localb;
/* ---------------- /* ----------------
* increment access statistics * increment access statistics
@ -780,16 +783,13 @@ heap_getnext(HeapScanDesc scandesc,
* argument checks * argument checks
* ---------------- * ----------------
*/ */
if (sdesc == NULL) if (scan == NULL)
elog(ERROR, "heap_getnext: NULL relscan"); elog(ERROR, "heap_getnext: NULL relscan");
/* ---------------- /* ----------------
* initialize return buffer to InvalidBuffer * initialize return buffer to InvalidBuffer
* ---------------- * ----------------
*/ */
if (!PointerIsValid(b))
b = &localb;
(*b) = InvalidBuffer;
HEAPDEBUG_1; /* heap_getnext( info ) */ HEAPDEBUG_1; /* heap_getnext( info ) */
@ -801,11 +801,11 @@ heap_getnext(HeapScanDesc scandesc,
*/ */
HEAPDEBUG_2; /* heap_getnext called with backw */ HEAPDEBUG_2; /* heap_getnext called with backw */
if (sdesc->rs_ptup == sdesc->rs_ctup && if (scan->rs_ptup == scan->rs_ctup &&
BufferIsInvalid(sdesc->rs_pbuf)) BufferIsInvalid(scan->rs_pbuf))
{ {
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(sdesc->rs_nbuf); ReleaseBuffer(scan->rs_nbuf);
return (NULL); return (NULL);
} }
@ -813,37 +813,37 @@ heap_getnext(HeapScanDesc scandesc,
* Copy the "current" tuple/buffer to "next". Pin/unpin the * Copy the "current" tuple/buffer to "next". Pin/unpin the
* buffers accordingly * buffers accordingly
*/ */
if (sdesc->rs_nbuf != sdesc->rs_cbuf) if (scan->rs_nbuf != scan->rs_cbuf)
{ {
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(sdesc->rs_nbuf); ReleaseBuffer(scan->rs_nbuf);
if (BufferIsValid(sdesc->rs_cbuf)) if (BufferIsValid(scan->rs_cbuf))
IncrBufferRefCount(sdesc->rs_cbuf); IncrBufferRefCount(scan->rs_cbuf);
} }
sdesc->rs_ntup = sdesc->rs_ctup; scan->rs_ntup = scan->rs_ctup;
sdesc->rs_nbuf = sdesc->rs_cbuf; scan->rs_nbuf = scan->rs_cbuf;
if (sdesc->rs_ptup != NULL) if (scan->rs_ptup != NULL)
{ {
if (sdesc->rs_cbuf != sdesc->rs_pbuf) if (scan->rs_cbuf != scan->rs_pbuf)
{ {
if (BufferIsValid(sdesc->rs_cbuf)) if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(sdesc->rs_cbuf); ReleaseBuffer(scan->rs_cbuf);
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
IncrBufferRefCount(sdesc->rs_pbuf); IncrBufferRefCount(scan->rs_pbuf);
} }
sdesc->rs_ctup = sdesc->rs_ptup; scan->rs_ctup = scan->rs_ptup;
sdesc->rs_cbuf = sdesc->rs_pbuf; scan->rs_cbuf = scan->rs_pbuf;
} }
else else
{ /* NONTUP */ { /* NONTUP */
ItemPointer iptr; ItemPointer iptr;
iptr = (sdesc->rs_ctup != NULL) ? iptr = (scan->rs_ctup != NULL) ?
&(sdesc->rs_ctup->t_ctid) : (ItemPointer) NULL; &(scan->rs_ctup->t_ctid) : (ItemPointer) NULL;
/* /*
* Don't release sdesc->rs_cbuf at this point, because * Don't release scan->rs_cbuf at this point, because
* heapgettup doesn't increase PrivateRefCount if it is * heapgettup doesn't increase PrivateRefCount if it is
* already set. On a backward scan, both rs_ctup and rs_ntup * already set. On a backward scan, both rs_ctup and rs_ntup
* usually point to the same buffer page, so * usually point to the same buffer page, so
@ -851,33 +851,33 @@ heap_getnext(HeapScanDesc scandesc,
* instance ctup is stored in a TupleTableSlot). - 01/09/94 * instance ctup is stored in a TupleTableSlot). - 01/09/94
*/ */
sdesc->rs_ctup = (HeapTuple) scan->rs_ctup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
iptr, iptr,
-1, -1,
&(sdesc->rs_cbuf), &(scan->rs_cbuf),
sdesc->rs_snapshot, scan->rs_snapshot,
sdesc->rs_nkeys, scan->rs_nkeys,
sdesc->rs_key); scan->rs_key);
} }
if (sdesc->rs_ctup == NULL && !BufferIsValid(sdesc->rs_cbuf)) if (scan->rs_ctup == NULL && !BufferIsValid(scan->rs_cbuf))
{ {
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(sdesc->rs_pbuf); ReleaseBuffer(scan->rs_pbuf);
sdesc->rs_ptup = NULL; scan->rs_ptup = NULL;
sdesc->rs_pbuf = InvalidBuffer; scan->rs_pbuf = InvalidBuffer;
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(sdesc->rs_nbuf); ReleaseBuffer(scan->rs_nbuf);
sdesc->rs_ntup = NULL; scan->rs_ntup = NULL;
sdesc->rs_nbuf = InvalidBuffer; scan->rs_nbuf = InvalidBuffer;
return (NULL); return (NULL);
} }
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(sdesc->rs_pbuf); ReleaseBuffer(scan->rs_pbuf);
sdesc->rs_ptup = NULL; scan->rs_ptup = NULL;
sdesc->rs_pbuf = UnknownBuffer; scan->rs_pbuf = UnknownBuffer;
} }
else else
@ -886,11 +886,11 @@ heap_getnext(HeapScanDesc scandesc,
* handle forward scan * handle forward scan
* ---------------- * ----------------
*/ */
if (sdesc->rs_ctup == sdesc->rs_ntup && if (scan->rs_ctup == scan->rs_ntup &&
BufferIsInvalid(sdesc->rs_nbuf)) BufferIsInvalid(scan->rs_nbuf))
{ {
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(sdesc->rs_pbuf); ReleaseBuffer(scan->rs_pbuf);
HEAPDEBUG_3; /* heap_getnext returns NULL at end */ HEAPDEBUG_3; /* heap_getnext returns NULL at end */
return (NULL); return (NULL);
} }
@ -899,38 +899,38 @@ heap_getnext(HeapScanDesc scandesc,
* Copy the "current" tuple/buffer to "previous". Pin/unpin the * Copy the "current" tuple/buffer to "previous". Pin/unpin the
* buffers accordingly * buffers accordingly
*/ */
if (sdesc->rs_pbuf != sdesc->rs_cbuf) if (scan->rs_pbuf != scan->rs_cbuf)
{ {
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(sdesc->rs_pbuf); ReleaseBuffer(scan->rs_pbuf);
if (BufferIsValid(sdesc->rs_cbuf)) if (BufferIsValid(scan->rs_cbuf))
IncrBufferRefCount(sdesc->rs_cbuf); IncrBufferRefCount(scan->rs_cbuf);
} }
sdesc->rs_ptup = sdesc->rs_ctup; scan->rs_ptup = scan->rs_ctup;
sdesc->rs_pbuf = sdesc->rs_cbuf; scan->rs_pbuf = scan->rs_cbuf;
if (sdesc->rs_ntup != NULL) if (scan->rs_ntup != NULL)
{ {
if (sdesc->rs_cbuf != sdesc->rs_nbuf) if (scan->rs_cbuf != scan->rs_nbuf)
{ {
if (BufferIsValid(sdesc->rs_cbuf)) if (BufferIsValid(scan->rs_cbuf))
ReleaseBuffer(sdesc->rs_cbuf); ReleaseBuffer(scan->rs_cbuf);
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
IncrBufferRefCount(sdesc->rs_nbuf); IncrBufferRefCount(scan->rs_nbuf);
} }
sdesc->rs_ctup = sdesc->rs_ntup; scan->rs_ctup = scan->rs_ntup;
sdesc->rs_cbuf = sdesc->rs_nbuf; scan->rs_cbuf = scan->rs_nbuf;
HEAPDEBUG_5; /* heap_getnext next tuple was cached */ HEAPDEBUG_5; /* heap_getnext next tuple was cached */
} }
else else
{ /* NONTUP */ { /* NONTUP */
ItemPointer iptr; ItemPointer iptr;
iptr = (sdesc->rs_ctup != NULL) ? iptr = (scan->rs_ctup != NULL) ?
&sdesc->rs_ctup->t_ctid : (ItemPointer) NULL; &scan->rs_ctup->t_ctid : (ItemPointer) NULL;
/* /*
* Don't release sdesc->rs_cbuf at this point, because * Don't release scan->rs_cbuf at this point, because
* heapgettup doesn't increase PrivateRefCount if it is * heapgettup doesn't increase PrivateRefCount if it is
* already set. On a forward scan, both rs_ctup and rs_ptup * already set. On a forward scan, both rs_ctup and rs_ptup
* usually point to the same buffer page, so * usually point to the same buffer page, so
@ -938,34 +938,34 @@ heap_getnext(HeapScanDesc scandesc,
* instance ctup is stored in a TupleTableSlot). - 01/09/93 * instance ctup is stored in a TupleTableSlot). - 01/09/93
*/ */
sdesc->rs_ctup = (HeapTuple) scan->rs_ctup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
iptr, iptr,
1, 1,
&sdesc->rs_cbuf, &scan->rs_cbuf,
sdesc->rs_snapshot, scan->rs_snapshot,
sdesc->rs_nkeys, scan->rs_nkeys,
sdesc->rs_key); scan->rs_key);
} }
if (sdesc->rs_ctup == NULL && !BufferIsValid(sdesc->rs_cbuf)) if (scan->rs_ctup == NULL && !BufferIsValid(scan->rs_cbuf))
{ {
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(sdesc->rs_nbuf); ReleaseBuffer(scan->rs_nbuf);
sdesc->rs_ntup = NULL; scan->rs_ntup = NULL;
sdesc->rs_nbuf = InvalidBuffer; scan->rs_nbuf = InvalidBuffer;
if (BufferIsValid(sdesc->rs_pbuf)) if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(sdesc->rs_pbuf); ReleaseBuffer(scan->rs_pbuf);
sdesc->rs_ptup = NULL; scan->rs_ptup = NULL;
sdesc->rs_pbuf = InvalidBuffer; scan->rs_pbuf = InvalidBuffer;
HEAPDEBUG_6; /* heap_getnext returning EOS */ HEAPDEBUG_6; /* heap_getnext returning EOS */
return (NULL); return (NULL);
} }
if (BufferIsValid(sdesc->rs_nbuf)) if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(sdesc->rs_nbuf); ReleaseBuffer(scan->rs_nbuf);
sdesc->rs_ntup = NULL; scan->rs_ntup = NULL;
sdesc->rs_nbuf = UnknownBuffer; scan->rs_nbuf = UnknownBuffer;
} }
/* ---------------- /* ----------------
@ -973,24 +973,31 @@ heap_getnext(HeapScanDesc scandesc,
* point to the proper return buffer and return the tuple. * point to the proper return buffer and return the tuple.
* ---------------- * ----------------
*/ */
(*b) = sdesc->rs_cbuf;
HEAPDEBUG_7; /* heap_getnext returning tuple */ HEAPDEBUG_7; /* heap_getnext returning tuple */
return (sdesc->rs_ctup); return scan->rs_ctup;
} }
/* ---------------- /* ----------------
* heap_fetch - retrive tuple with tid * heap_fetch - retrive tuple with tid
* *
* Currently ignores LP_IVALID during processing! * Currently ignores LP_IVALID during processing!
*
* Because this is not part of a scan, there is no way to
* automatically lock/unlock the shared buffers.
* For this reason, we require that the user retrieve the buffer
* value, and they are required to BuffferRelease() it when they
* are done. If they want to make a copy of it before releasing it,
* they can call heap_copytyple().
* ---------------- * ----------------
*/ */
HeapTuple HeapTuple
heap_fetch(Relation relation, heap_fetch(Relation relation,
Snapshot snapshot, Snapshot snapshot,
ItemPointer tid, ItemPointer tid,
Buffer *b) Buffer *userbuf)
{ {
ItemId lp; ItemId lp;
Buffer buffer; Buffer buffer;
@ -998,6 +1005,8 @@ heap_fetch(Relation relation,
HeapTuple tuple; HeapTuple tuple;
OffsetNumber offnum; OffsetNumber offnum;
AssertMacro(PointerIsValid(userbuf)); /* see comments above */
/* ---------------- /* ----------------
* increment access statistics * increment access statistics
* ---------------- * ----------------
@ -1061,17 +1070,12 @@ heap_fetch(Relation relation,
/* ---------------- /* ----------------
* all checks passed, now either return a copy of the tuple * all checks passed, now either return a copy of the tuple
* or pin the buffer page and return a pointer, depending on * or pin the buffer page and return a pointer, depending on
* whether caller gave us a valid b. * whether caller gave us a valid buf.
* ---------------- * ----------------
*/ */
if (PointerIsValid(b)) *userbuf = buffer; /* user is required to ReleaseBuffer() this */
*b = buffer;
else
{
tuple = heap_copytuple(tuple);
ReleaseBuffer(buffer);
}
return (tuple); return (tuple);
} }
@ -1161,7 +1165,7 @@ heap_delete(Relation relation, ItemPointer tid)
ItemId lp; ItemId lp;
HeapTuple tp; HeapTuple tp;
PageHeader dp; PageHeader dp;
Buffer b; Buffer buf;
/* ---------------- /* ----------------
* increment access statistics * increment access statistics
@ -1182,16 +1186,16 @@ heap_delete(Relation relation, ItemPointer tid)
*/ */
RelationSetLockForWrite(relation); RelationSetLockForWrite(relation);
b = ReadBuffer(relation, ItemPointerGetBlockNumber(tid)); buf = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
#ifndef NO_BUFFERISVALID #ifndef NO_BUFFERISVALID
if (!BufferIsValid(b)) if (!BufferIsValid(buf))
{ /* XXX L_SH better ??? */ { /* XXX L_SH better ??? */
elog(ERROR, "heap_delete: failed ReadBuffer"); elog(ERROR, "heap_delete: failed ReadBuffer");
} }
#endif /* NO_BUFFERISVALID */ #endif /* NO_BUFFERISVALID */
dp = (PageHeader) BufferGetPage(b); dp = (PageHeader) BufferGetPage(buf);
lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid)); lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid));
/* /*
@ -1208,20 +1212,20 @@ heap_delete(Relation relation, ItemPointer tid)
*/ */
if (IsSystemRelationName(RelationGetRelationName(relation)->data)) if (IsSystemRelationName(RelationGetRelationName(relation)->data))
RelationUnsetLockForWrite(relation); RelationUnsetLockForWrite(relation);
ReleaseBuffer(b); ReleaseBuffer(buf);
return (1); return (1);
} }
/* ---------------- /* ----------------
* check that we're deleteing a valid item * check that we're deleteing a valid item
* ---------------- * ----------------
*/ */
HeapTupleSatisfies(lp, relation, b, dp, HeapTupleSatisfies(lp, relation, buf, dp,
false, 0, (ScanKey) NULL, tp); false, 0, (ScanKey) NULL, tp);
if (!tp) if (!tp)
{ {
/* XXX call something else */ /* XXX call something else */
ReleaseBuffer(b); ReleaseBuffer(buf);
elog(ERROR, "heap_delete: (am)invalid tid"); elog(ERROR, "heap_delete: (am)invalid tid");
} }
@ -1248,7 +1252,7 @@ heap_delete(Relation relation, ItemPointer tid)
RelationInvalidateHeapTuple(relation, tp); RelationInvalidateHeapTuple(relation, tp);
SetRefreshWhenInvalidate((bool) !ImmediateInvalidation); SetRefreshWhenInvalidate((bool) !ImmediateInvalidation);
WriteBuffer(b); WriteBuffer(buf);
if (IsSystemRelationName(RelationGetRelationName(relation)->data)) if (IsSystemRelationName(RelationGetRelationName(relation)->data))
RelationUnsetLockForWrite(relation); RelationUnsetLockForWrite(relation);
@ -1426,7 +1430,7 @@ heap_replace(Relation relation, ItemPointer otid, HeapTuple tup)
* ---------------- * ----------------
*/ */
void void
heap_markpos(HeapScanDesc sdesc) heap_markpos(HeapScanDesc scan)
{ {
/* ---------------- /* ----------------
@ -1438,50 +1442,50 @@ heap_markpos(HeapScanDesc sdesc)
/* Note: no locking manipulations needed */ /* Note: no locking manipulations needed */
if (sdesc->rs_ptup == NULL && if (scan->rs_ptup == NULL &&
BufferIsUnknown(sdesc->rs_pbuf)) BufferIsUnknown(scan->rs_pbuf))
{ /* == NONTUP */ { /* == NONTUP */
sdesc->rs_ptup = (HeapTuple) scan->rs_ptup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
(sdesc->rs_ctup == NULL) ? (scan->rs_ctup == NULL) ?
(ItemPointer) NULL : &sdesc->rs_ctup->t_ctid, (ItemPointer) NULL : &scan->rs_ctup->t_ctid,
-1, -1,
&sdesc->rs_pbuf, &scan->rs_pbuf,
sdesc->rs_snapshot, scan->rs_snapshot,
sdesc->rs_nkeys, scan->rs_nkeys,
sdesc->rs_key); scan->rs_key);
} }
else if (sdesc->rs_ntup == NULL && else if (scan->rs_ntup == NULL &&
BufferIsUnknown(sdesc->rs_nbuf)) BufferIsUnknown(scan->rs_nbuf))
{ /* == NONTUP */ { /* == NONTUP */
sdesc->rs_ntup = (HeapTuple) scan->rs_ntup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
(sdesc->rs_ctup == NULL) ? (scan->rs_ctup == NULL) ?
(ItemPointer) NULL : &sdesc->rs_ctup->t_ctid, (ItemPointer) NULL : &scan->rs_ctup->t_ctid,
1, 1,
&sdesc->rs_nbuf, &scan->rs_nbuf,
sdesc->rs_snapshot, scan->rs_snapshot,
sdesc->rs_nkeys, scan->rs_nkeys,
sdesc->rs_key); scan->rs_key);
} }
/* ---------------- /* ----------------
* Should not unpin the buffer pages. They may still be in use. * Should not unpin the buffer pages. They may still be in use.
* ---------------- * ----------------
*/ */
if (sdesc->rs_ptup != NULL) if (scan->rs_ptup != NULL)
sdesc->rs_mptid = sdesc->rs_ptup->t_ctid; scan->rs_mptid = scan->rs_ptup->t_ctid;
else else
ItemPointerSetInvalid(&sdesc->rs_mptid); ItemPointerSetInvalid(&scan->rs_mptid);
if (sdesc->rs_ctup != NULL) if (scan->rs_ctup != NULL)
sdesc->rs_mctid = sdesc->rs_ctup->t_ctid; scan->rs_mctid = scan->rs_ctup->t_ctid;
else else
ItemPointerSetInvalid(&sdesc->rs_mctid); ItemPointerSetInvalid(&scan->rs_mctid);
if (sdesc->rs_ntup != NULL) if (scan->rs_ntup != NULL)
sdesc->rs_mntid = sdesc->rs_ntup->t_ctid; scan->rs_mntid = scan->rs_ntup->t_ctid;
else else
ItemPointerSetInvalid(&sdesc->rs_mntid); ItemPointerSetInvalid(&scan->rs_mntid);
} }
/* ---------------- /* ----------------
@ -1506,7 +1510,7 @@ heap_markpos(HeapScanDesc sdesc)
* ---------------- * ----------------
*/ */
void void
heap_restrpos(HeapScanDesc sdesc) heap_restrpos(HeapScanDesc scan)
{ {
/* ---------------- /* ----------------
* increment access statistics * increment access statistics
@ -1519,50 +1523,50 @@ heap_restrpos(HeapScanDesc sdesc)
/* Note: no locking manipulations needed */ /* Note: no locking manipulations needed */
unpinsdesc(sdesc); unpinscan(scan);
/* force heapgettup to pin buffer for each loaded tuple */ /* force heapgettup to pin buffer for each loaded tuple */
sdesc->rs_pbuf = InvalidBuffer; scan->rs_pbuf = InvalidBuffer;
sdesc->rs_cbuf = InvalidBuffer; scan->rs_cbuf = InvalidBuffer;
sdesc->rs_nbuf = InvalidBuffer; scan->rs_nbuf = InvalidBuffer;
if (!ItemPointerIsValid(&sdesc->rs_mptid)) if (!ItemPointerIsValid(&scan->rs_mptid))
sdesc->rs_ptup = NULL; scan->rs_ptup = NULL;
else else
{ {
sdesc->rs_ptup = (HeapTuple) scan->rs_ptup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
&sdesc->rs_mptid, &scan->rs_mptid,
0, 0,
&sdesc->rs_pbuf, &scan->rs_pbuf,
false, false,
0, 0,
(ScanKey) NULL); (ScanKey) NULL);
} }
if (!ItemPointerIsValid(&sdesc->rs_mctid)) if (!ItemPointerIsValid(&scan->rs_mctid))
sdesc->rs_ctup = NULL; scan->rs_ctup = NULL;
else else
{ {
sdesc->rs_ctup = (HeapTuple) scan->rs_ctup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
&sdesc->rs_mctid, &scan->rs_mctid,
0, 0,
&sdesc->rs_cbuf, &scan->rs_cbuf,
false, false,
0, 0,
(ScanKey) NULL); (ScanKey) NULL);
} }
if (!ItemPointerIsValid(&sdesc->rs_mntid)) if (!ItemPointerIsValid(&scan->rs_mntid))
sdesc->rs_ntup = NULL; scan->rs_ntup = NULL;
else else
{ {
sdesc->rs_ntup = (HeapTuple) scan->rs_ntup = (HeapTuple)
heapgettup(sdesc->rs_rd, heapgettup(scan->rs_rd,
&sdesc->rs_mntid, &scan->rs_mntid,
0, 0,
&sdesc->rs_nbuf, &scan->rs_nbuf,
false, false,
0, 0,
(ScanKey) NULL); (ScanKey) NULL);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.12 1998/06/15 19:27:53 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.13 1998/08/19 02:01:09 momjian Exp $
* *
* NOTES * NOTES
* many of the old access method routines have been turned into * many of the old access method routines have been turned into
@ -216,14 +216,15 @@ IndexScanMarkPosition(IndexScanDesc scan)
if (scan->flags & ScanUncheckedPrevious) if (scan->flags & ScanUncheckedPrevious)
{ {
result = result = index_getnext(scan, BackwardScanDirection);
index_getnext(scan, BackwardScanDirection);
if (result != NULL) if (result != NULL)
{
scan->previousItemData = result->index_iptr; scan->previousItemData = result->index_iptr;
pfree(result);
}
else else
ItemPointerSetInvalid(&scan->previousItemData); ItemPointerSetInvalid(&scan->previousItemData);
} }
else if (scan->flags & ScanUncheckedNext) else if (scan->flags & ScanUncheckedNext)
{ {
@ -231,7 +232,10 @@ IndexScanMarkPosition(IndexScanDesc scan)
index_getnext(scan, ForwardScanDirection); index_getnext(scan, ForwardScanDirection);
if (result != NULL) if (result != NULL)
{
scan->nextItemData = result->index_iptr; scan->nextItemData = result->index_iptr;
pfree(result);
}
else else
ItemPointerSetInvalid(&scan->nextItemData); ItemPointerSetInvalid(&scan->nextItemData);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.22 1998/06/15 18:39:23 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.23 1998/08/19 02:01:10 momjian Exp $
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
* index_open - open an index relation by relationId * index_open - open an index relation by relationId
@ -331,8 +331,7 @@ index_getnext(IndexScanDesc scan,
* have the am's gettuple proc do all the work. * have the am's gettuple proc do all the work.
* ---------------- * ----------------
*/ */
result = (RetrieveIndexResult) result = (RetrieveIndexResult)fmgr(procedure, scan, direction);
fmgr(procedure, scan, direction);
return result; return result;
} }
@ -376,8 +375,7 @@ GetIndexValue(HeapTuple tuple,
int attOff, int attOff,
AttrNumber attrNums[], AttrNumber attrNums[],
FuncIndexInfo *fInfo, FuncIndexInfo *fInfo,
bool *attNull, bool *attNull)
Buffer buffer)
{ {
Datum returnVal; Datum returnVal;
bool isNull; bool isNull;

View File

@ -8,13 +8,14 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.25 1998/08/11 22:39:32 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.26 1998/08/19 02:01:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "access/istrat.h" #include "access/istrat.h"
#include "catalog/catname.h" #include "catalog/catname.h"
@ -22,6 +23,7 @@
#include "catalog/pg_amproc.h" #include "catalog/pg_amproc.h"
#include "catalog/pg_index.h" #include "catalog/pg_index.h"
#include "catalog/pg_operator.h" #include "catalog/pg_operator.h"
#include "utils/syscache.h"
#include "fmgr.h" #include "fmgr.h"
#include "utils/memutils.h" /* could have been access/itup.h */ #include "utils/memutils.h" /* could have been access/itup.h */
@ -30,8 +32,7 @@ static bool StrategyEvaluationIsValid(StrategyEvaluation evaluation);
static bool static bool
StrategyExpressionIsValid(StrategyExpression expression, StrategyExpressionIsValid(StrategyExpression expression,
StrategyNumber maxStrategy); StrategyNumber maxStrategy);
static ScanKey static ScanKey StrategyMapGetScanKeyEntry(StrategyMap map,
StrategyMapGetScanKeyEntry(StrategyMap map,
StrategyNumber strategyNumber); StrategyNumber strategyNumber);
static bool static bool
StrategyOperatorIsValid(StrategyOperator operator, StrategyOperatorIsValid(StrategyOperator operator,
@ -95,8 +96,7 @@ IndexStrategyGetStrategyMap(IndexStrategy indexStrategy,
Assert(AttributeNumberIsValid(attrNum)); Assert(AttributeNumberIsValid(attrNum));
maxStrategyNum = AMStrategies(maxStrategyNum); /* XXX */ maxStrategyNum = AMStrategies(maxStrategyNum); /* XXX */
return return &indexStrategy->strategyMapData[maxStrategyNum * (attrNum - 1)];
&indexStrategy->strategyMapData[maxStrategyNum * (attrNum - 1)];
} }
/* /*
@ -108,8 +108,7 @@ AttributeNumberGetIndexStrategySize(AttrNumber maxAttributeNumber,
StrategyNumber maxStrategyNumber) StrategyNumber maxStrategyNumber)
{ {
maxStrategyNumber = AMStrategies(maxStrategyNumber); /* XXX */ maxStrategyNumber = AMStrategies(maxStrategyNumber); /* XXX */
return return maxAttributeNumber * maxStrategyNumber * sizeof(ScanKeyData);
maxAttributeNumber * maxStrategyNumber * sizeof(ScanKeyData);
} }
#ifdef USE_ASSERT_CHECKING #ifdef USE_ASSERT_CHECKING
@ -483,39 +482,52 @@ OperatorRelationFillScanKeyEntry(Relation operatorRelation,
Oid operatorObjectId, Oid operatorObjectId,
ScanKey entry) ScanKey entry)
{ {
HeapScanDesc scan;
ScanKeyData scanKeyData;
HeapTuple tuple; HeapTuple tuple;
HeapScanDesc scan = NULL;
ScanKeyEntryInitialize(&scanKeyData, 0, if (!IsBootstrapProcessingMode())
ObjectIdAttributeNumber, {
F_OIDEQ, tuple = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(operatorObjectId)); ObjectIdGetDatum(operatorObjectId),
0, 0, 0);
}
else
{
ScanKeyData scanKeyData;
ScanKeyEntryInitialize(&scanKeyData, 0,
ObjectIdAttributeNumber,
F_OIDEQ,
ObjectIdGetDatum(operatorObjectId));
scan = heap_beginscan(operatorRelation, false, SnapshotNow, scan = heap_beginscan(operatorRelation, false, SnapshotNow,
1, &scanKeyData); 1, &scanKeyData);
tuple = heap_getnext(scan, 0);
}
tuple = heap_getnext(scan, false, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
if (IsBootstrapProcessingMode())
heap_endscan(scan);
elog(ERROR, "OperatorObjectIdFillScanKeyEntry: unknown operator %lu", elog(ERROR, "OperatorObjectIdFillScanKeyEntry: unknown operator %lu",
(uint32) operatorObjectId); (uint32) operatorObjectId);
} }
entry->sk_flags = 0; entry->sk_flags = 0;
entry->sk_procedure = entry->sk_procedure = ((OperatorTupleForm) GETSTRUCT(tuple))->oprcode;
((OperatorTupleForm) GETSTRUCT(tuple))->oprcode;
fmgr_info(entry->sk_procedure, &entry->sk_func); fmgr_info(entry->sk_procedure, &entry->sk_func);
entry->sk_nargs = entry->sk_func.fn_nargs; entry->sk_nargs = entry->sk_func.fn_nargs;
if (IsBootstrapProcessingMode())
heap_endscan(scan);
if (!RegProcedureIsValid(entry->sk_procedure)) if (!RegProcedureIsValid(entry->sk_procedure))
{ {
elog(ERROR, elog(ERROR,
"OperatorObjectIdFillScanKeyEntry: no procedure for operator %lu", "OperatorObjectIdFillScanKeyEntry: no procedure for operator %lu",
(uint32) operatorObjectId); (uint32) operatorObjectId);
} }
heap_endscan(scan);
} }
@ -532,28 +544,38 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
StrategyNumber maxSupportNumber, StrategyNumber maxSupportNumber,
AttrNumber maxAttributeNumber) AttrNumber maxAttributeNumber)
{ {
Relation relation; Relation relation = NULL;
Relation operatorRelation; HeapScanDesc scan = NULL;
HeapScanDesc scan;
HeapTuple tuple;
ScanKeyData entry[2]; ScanKeyData entry[2];
Relation operatorRelation;
HeapTuple tuple;
StrategyMap map; StrategyMap map;
AttrNumber attributeNumber; AttrNumber attributeNumber;
int attributeIndex; int attributeIndex;
Oid operatorClassObjectId[MaxIndexAttributeNumber]; Oid operatorClassObjectId[MaxIndexAttributeNumber];
maxStrategyNumber = AMStrategies(maxStrategyNumber); if (!IsBootstrapProcessingMode())
{
tuple = SearchSysCacheTuple(INDEXRELID,
ObjectIdGetDatum(indexObjectId),
0, 0, 0);
}
else
{
ScanKeyEntryInitialize(&entry[0], 0, Anum_pg_index_indexrelid,
F_OIDEQ,
ObjectIdGetDatum(indexObjectId));
relation = heap_openr(IndexRelationName);
scan = heap_beginscan(relation, false, SnapshotNow, 1, entry);
tuple = heap_getnext(scan, 0);
}
ScanKeyEntryInitialize(&entry[0], 0, Anum_pg_index_indexrelid,
F_OIDEQ,
ObjectIdGetDatum(indexObjectId));
relation = heap_openr(IndexRelationName);
scan = heap_beginscan(relation, false, SnapshotNow, 1, entry);
tuple = heap_getnext(scan, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "IndexSupportInitialize: corrupted catalogs"); elog(ERROR, "IndexSupportInitialize: corrupted catalogs");
maxStrategyNumber = AMStrategies(maxStrategyNumber);
/* /*
* XXX note that the following assumes the INDEX tuple is well formed * XXX note that the following assumes the INDEX tuple is well formed
* and that the key[] and class[] are 0 terminated. * and that the key[] and class[] are 0 terminated.
@ -574,9 +596,12 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
operatorClassObjectId[attributeIndex] = iform->indclass[attributeIndex]; operatorClassObjectId[attributeIndex] = iform->indclass[attributeIndex];
} }
heap_endscan(scan); if (IsBootstrapProcessingMode())
heap_close(relation); {
heap_endscan(scan);
heap_close(relation);
}
/* if support routines exist for this access method, load them */ /* if support routines exist for this access method, load them */
if (maxSupportNumber > 0) if (maxSupportNumber > 0)
{ {
@ -606,8 +631,7 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry); scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
while (tuple = heap_getnext(scan, 0, (Buffer *) NULL), while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
HeapTupleIsValid(tuple))
{ {
form = (Form_pg_amproc) GETSTRUCT(tuple); form = (Form_pg_amproc) GETSTRUCT(tuple);
loc[(form->amprocnum - 1)] = form->amproc; loc[(form->amprocnum - 1)] = form->amproc;
@ -647,8 +671,7 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry); scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
while (tuple = heap_getnext(scan, 0, (Buffer *) NULL), while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
HeapTupleIsValid(tuple))
{ {
Form_pg_amop form; Form_pg_amop form;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.16 1998/04/26 04:05:19 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.17 1998/08/19 02:01:13 momjian Exp $
* *
* NOTES * NOTES
* These functions are stored in pg_amproc. For each operator class * These functions are stored in pg_amproc. For each operator class
@ -30,81 +30,96 @@
int32 int32
btint2cmp(int16 a, int16 b) btint2cmp(int16 a, int16 b)
{ {
return ((int32) (a - b)); return (int32) (a - b);
} }
int32 int32
btint4cmp(int32 a, int32 b) btint4cmp(int32 a, int32 b)
{ {
return (a - b); return a - b;
} }
int32 int32
btint24cmp(int16 a, int32 b) btint24cmp(int16 a, int32 b)
{ {
return (((int32) a) - b); return ((int32) a) - b;
} }
int32 int32
btint42cmp(int32 a, int16 b) btint42cmp(int32 a, int16 b)
{ {
return (a - ((int32) b)); return a - ((int32) b);
} }
int32 int32
btfloat4cmp(float32 a, float32 b) btfloat4cmp(float32 a, float32 b)
{ {
if (*a > *b) if (*a > *b)
return (1); return 1;
else if (*a == *b) else if (*a == *b)
return (0); return 0;
else else
return (-1); return -1;
} }
int32 int32
btfloat8cmp(float64 a, float64 b) btfloat8cmp(float64 a, float64 b)
{ {
if (*a > *b) if (*a > *b)
return (1); return 1;
else if (*a == *b) else if (*a == *b)
return (0); return 0;
else else
return (-1); return -1;
} }
int32 int32
btoidcmp(Oid a, Oid b) btoidcmp(Oid a, Oid b)
{ {
if (a > b) if (a > b)
return (1); return 1;
else if (a == b) else if (a == b)
return (0); return 0;
else else
return (-1); return -1;
} }
int32
btoid8cmp(Oid a[], Oid b[])
{
int i;
for (i=0; i < 8; i++)
/* we use this because we need the int4gt, etc */
if (!int4eq(a[i], b[i]))
if (int4gt(a[i], b[i]))
return 1;
else
return -1;
return 0;
}
int32 int32
btabstimecmp(AbsoluteTime a, AbsoluteTime b) btabstimecmp(AbsoluteTime a, AbsoluteTime b)
{ {
if (AbsoluteTimeIsBefore(a, b)) if (AbsoluteTimeIsBefore(a, b))
return (-1); return -1;
else if (AbsoluteTimeIsBefore(b, a)) else if (AbsoluteTimeIsBefore(b, a))
return (1); return 1;
else else
return (0); return 0;
} }
int32 int32
btcharcmp(char a, char b) btcharcmp(char a, char b)
{ {
return ((int32) ((uint8) a - (uint8) b)); return (int32) ((uint8) a - (uint8) b);
} }
int32 int32
btnamecmp(NameData *a, NameData *b) btnamecmp(NameData *a, NameData *b)
{ {
return (strncmp(a->data, b->data, NAMEDATALEN)); return strncmp(a->data, b->data, NAMEDATALEN);
} }
int32 int32
@ -162,7 +177,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
#endif #endif
if (res != 0 || VARSIZE(a) == VARSIZE(b)) if (res != 0 || VARSIZE(a) == VARSIZE(b))
return (res); return res;
/* /*
* The two strings are the same in the first len bytes, and they are * The two strings are the same in the first len bytes, and they are
@ -170,7 +185,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
*/ */
if (VARSIZE(a) < VARSIZE(b)) if (VARSIZE(a) < VARSIZE(b))
return (-1); return -1;
else else
return (1); return 1;
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.27 1998/07/27 19:37:39 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.28 1998/08/19 02:01:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -53,7 +53,8 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, Relation heapRel
BlockNumber blkno; BlockNumber blkno;
int natts = rel->rd_rel->relnatts; int natts = rel->rd_rel->relnatts;
InsertIndexResult res; InsertIndexResult res;
Buffer buffer;
itup = &(btitem->bti_itup); itup = &(btitem->bti_itup);
/* we need a scan key to do our search, so build one */ /* we need a scan key to do our search, so build one */
@ -120,11 +121,12 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, Relation heapRel
{ /* they're equal */ { /* they're equal */
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offset)); btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offset));
itup = &(btitem->bti_itup); itup = &(btitem->bti_itup);
htup = heap_fetch(heapRel, SnapshotSelf, &(itup->t_tid), NULL); htup = heap_fetch(heapRel, SnapshotSelf, &(itup->t_tid), &buffer);
if (htup != (HeapTuple) NULL) if (htup != (HeapTuple) NULL)
{ /* it is a duplicate */ { /* it is a duplicate */
elog(ERROR, "Cannot insert a duplicate key into a unique index"); elog(ERROR, "Cannot insert a duplicate key into a unique index");
} }
/* htup null so no buffer to release */
/* get next offnum */ /* get next offnum */
if (offset < maxoff) if (offset < maxoff)
offset = OffsetNumberNext(offset); offset = OffsetNumberNext(offset);

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.28 1998/07/30 05:04:49 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.29 1998/08/19 02:01:16 momjian Exp $
* *
* NOTES * NOTES
* This file contains only the public interface routines. * This file contains only the public interface routines.
@ -66,7 +66,6 @@ btbuild(Relation heap,
PredInfo *predInfo) PredInfo *predInfo)
{ {
HeapScanDesc hscan; HeapScanDesc hscan;
Buffer buffer;
HeapTuple htup; HeapTuple htup;
IndexTuple itup; IndexTuple itup;
TupleDesc htupdesc, TupleDesc htupdesc,
@ -113,7 +112,7 @@ btbuild(Relation heap,
#endif #endif
/* see if index is unique */ /* see if index is unique */
isunique = IndexIsUniqueNoCache(RelationGetRelationId(index)); isunique = IndexIsUniqueNoCache(RelationGetRelid(index));
/* initialize the btree index metadata page (if this is a new index) */ /* initialize the btree index metadata page (if this is a new index) */
if (oldPred == NULL) if (oldPred == NULL)
@ -155,9 +154,6 @@ btbuild(Relation heap,
#endif /* OMIT_PARTIAL_INDEX */ #endif /* OMIT_PARTIAL_INDEX */
/* start a heap scan */ /* start a heap scan */
hscan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
htup = heap_getnext(hscan, 0, &buffer);
/* build the index */ /* build the index */
nhtups = nitups = 0; nhtups = nitups = 0;
@ -167,9 +163,10 @@ btbuild(Relation heap,
res = (InsertIndexResult) NULL; res = (InsertIndexResult) NULL;
} }
for (; HeapTupleIsValid(htup); htup = heap_getnext(hscan, 0, &buffer)) hscan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
{
while (HeapTupleIsValid(htup = heap_getnext(hscan, 0)))
{
nhtups++; nhtups++;
/* /*
@ -228,8 +225,7 @@ btbuild(Relation heap,
attoff, attoff,
attnum, attnum,
finfo, finfo,
&attnull, &attnull);
buffer);
nulls[attoff] = (attnull ? 'n' : ' '); nulls[attoff] = (attnull ? 'n' : ' ');
} }
@ -323,8 +319,8 @@ btbuild(Relation heap,
*/ */
if (IsNormalProcessingMode()) if (IsNormalProcessingMode())
{ {
hrelid = heap->rd_id; hrelid = RelationGetRelid(heap);
irelid = index->rd_id; irelid = RelationGetRelid(index);
heap_close(heap); heap_close(heap);
index_close(index); index_close(index);
UpdateStats(hrelid, nhtups, true); UpdateStats(hrelid, nhtups, true);
@ -371,7 +367,7 @@ btinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid, Relation
btitem = _bt_formitem(itup); btitem = _bt_formitem(itup);
res = _bt_doinsert(rel, btitem, res = _bt_doinsert(rel, btitem,
IndexIsUnique(RelationGetRelationId(rel)), heapRel); IndexIsUnique(RelationGetRelid(rel)), heapRel);
pfree(btitem); pfree(btitem);
pfree(itup); pfree(itup);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/Attic/nbtscan.c,v 1.15 1998/07/30 05:04:50 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/Attic/nbtscan.c,v 1.16 1998/08/19 02:01:17 momjian Exp $
* *
* *
* NOTES * NOTES
@ -96,10 +96,10 @@ _bt_adjscans(Relation rel, ItemPointer tid, int op)
BTScanList l; BTScanList l;
Oid relid; Oid relid;
relid = rel->rd_id; relid = RelationGetRelid(rel);
for (l = BTScans; l != (BTScanList) NULL; l = l->btsl_next) for (l = BTScans; l != (BTScanList) NULL; l = l->btsl_next)
{ {
if (relid == l->btsl_scan->relation->rd_id) if (relid == RelationGetRelid(l->btsl_scan->relation))
_bt_scandel(l->btsl_scan, op, _bt_scandel(l->btsl_scan, op,
ItemPointerGetBlockNumber(tid), ItemPointerGetBlockNumber(tid),
ItemPointerGetOffsetNumber(tid)); ItemPointerGetOffsetNumber(tid));

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.20 1998/06/15 19:27:59 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.21 1998/08/19 02:01:18 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -61,8 +61,7 @@ _bt_mkscankey(Relation rel, IndexTuple itup)
proc = index_getprocid(rel, i + 1, BTORDER_PROC); proc = index_getprocid(rel, i + 1, BTORDER_PROC);
flag = 0x0; flag = 0x0;
} }
ScanKeyEntryInitialize(&skey[i], ScanKeyEntryInitialize(&skey[i], flag, (AttrNumber) (i + 1), proc, arg);
flag, (AttrNumber) (i + 1), proc, arg);
} }
return (skey); return (skey);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.25 1998/07/27 19:37:41 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.26 1998/08/19 02:01:20 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -86,7 +86,6 @@ rtbuild(Relation heap,
PredInfo *predInfo) PredInfo *predInfo)
{ {
HeapScanDesc scan; HeapScanDesc scan;
Buffer buffer;
AttrNumber i; AttrNumber i;
HeapTuple htup; HeapTuple htup;
IndexTuple itup; IndexTuple itup;
@ -95,6 +94,7 @@ rtbuild(Relation heap,
InsertIndexResult res; InsertIndexResult res;
Datum *d; Datum *d;
bool *nulls; bool *nulls;
Buffer buffer = InvalidBuffer;
int nb, int nb,
nh, nh,
ni; ni;
@ -164,15 +164,14 @@ rtbuild(Relation heap,
slot = NULL; slot = NULL;
} }
#endif /* OMIT_PARTIAL_INDEX */ #endif /* OMIT_PARTIAL_INDEX */
scan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
htup = heap_getnext(scan, 0, &buffer);
/* count the tuples as we insert them */ /* count the tuples as we insert them */
nh = ni = 0; nh = ni = 0;
for (; HeapTupleIsValid(htup); htup = heap_getnext(scan, 0, &buffer)) scan = heap_beginscan(heap, 0, SnapshotNow, 0, (ScanKey) NULL);
{
while (HeapTupleIsValid(htup = heap_getnext(scan, 0)))
{
nh++; nh++;
/* /*
@ -234,8 +233,7 @@ rtbuild(Relation heap,
attoff, attoff,
attnum, attnum,
finfo, finfo,
&attnull, &attnull);
buffer);
nulls[attoff] = (attnull ? 'n' : ' '); nulls[attoff] = (attnull ? 'n' : ' ');
} }
@ -278,8 +276,8 @@ rtbuild(Relation heap,
* flushed. We close them to guarantee that they will be. * flushed. We close them to guarantee that they will be.
*/ */
hrelid = heap->rd_id; hrelid = RelationGetRelid(heap);
irelid = index->rd_id; irelid = RelationGetRelid(index);
heap_close(heap); heap_close(heap);
index_close(index); index_close(index);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtscan.c,v 1.16 1998/06/15 19:28:01 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtscan.c,v 1.17 1998/08/19 02:01:21 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -290,10 +290,10 @@ rtadjscans(Relation r, int op, BlockNumber blkno, OffsetNumber offnum)
RTScanList l; RTScanList l;
Oid relid; Oid relid;
relid = r->rd_id; relid = RelationGetRelid(r);
for (l = RTScans; l != (RTScanList) NULL; l = l->rtsl_next) for (l = RTScans; l != (RTScanList) NULL; l = l->rtsl_next)
{ {
if (l->rtsl_scan->relation->rd_id == relid) if (RelationGetRelid(l->rtsl_scan->relation) == relid)
rtadjone(l->rtsl_scan, op, blkno, offnum); rtadjone(l->rtsl_scan, op, blkno, offnum);
} }
} }

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.19 1998/08/06 05:12:16 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.20 1998/08/19 02:01:23 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -78,8 +78,8 @@ static Oid objectid;
int ival; int ival;
} }
%type <list> boot_arg_list %type <list> boot_index_params
%type <ielem> boot_index_params boot_index_on %type <ielem> boot_index_param
%type <ival> boot_const boot_ident %type <ival> boot_const boot_ident
%type <ival> optbootstrap optoideq boot_tuple boot_tuplelist %type <ival> optbootstrap optoideq boot_tuple boot_tuplelist
@ -225,15 +225,12 @@ Boot_InsertStmt:
Boot_DeclareIndexStmt: Boot_DeclareIndexStmt:
XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN XDECLARE INDEX boot_ident ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{ {
List *params;
DO_START; DO_START;
params = lappend(NIL, (List*)$9);
DefineIndex(LexIDStr($5), DefineIndex(LexIDStr($5),
LexIDStr($3), LexIDStr($3),
LexIDStr($7), LexIDStr($7),
params, NIL, 0, 0, NIL); $9, NIL, 0, 0, NIL);
DO_END; DO_END;
} }
; ;
@ -241,39 +238,21 @@ Boot_DeclareIndexStmt:
Boot_BuildIndsStmt: Boot_BuildIndsStmt:
XBUILD INDICES { build_indices(); } XBUILD INDICES { build_indices(); }
boot_index_params: boot_index_params:
boot_index_on boot_ident boot_index_params COMMA boot_index_param { $$ = lappend($1, $3); }
| boot_index_param { $$ = lcons($1, NIL); }
;
boot_index_param:
boot_ident boot_ident
{ {
IndexElem *n = (IndexElem*)$1; IndexElem *n = makeNode(IndexElem);
n->name = LexIDStr($1);
n->class = LexIDStr($2); n->class = LexIDStr($2);
$$ = n; $$ = n;
} }
boot_index_on:
boot_ident
{
IndexElem *n = makeNode(IndexElem);
n->name = LexIDStr($1);
$$ = n;
}
| boot_ident LPAREN boot_arg_list RPAREN
{
IndexElem *n = makeNode(IndexElem);
n->name = LexIDStr($1);
n->args = (List*)$3;
$$ = n;
}
boot_arg_list:
boot_ident
{
$$ = lappend(NIL, makeString(LexIDStr($1)));
}
| boot_arg_list COMMA boot_ident
{
$$ = lappend((List*)$1, makeString(LexIDStr($3)));
}
optbootstrap: optbootstrap:
XBOOTSTRAP { $$ = 1; } XBOOTSTRAP { $$ = 1; }
| { $$ = 0; } | { $$ = 0; }

View File

@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.47 1998/07/27 19:37:43 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.48 1998/08/19 02:01:26 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -448,8 +448,8 @@ boot_openrel(char *relname)
{ {
int i; int i;
struct typmap **app; struct typmap **app;
Relation rdesc; Relation rel;
HeapScanDesc sdesc; HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
if (strlen(relname) >= NAMEDATALEN - 1) if (strlen(relname) >= NAMEDATALEN - 1)
@ -458,25 +458,27 @@ boot_openrel(char *relname)
if (Typ == (struct typmap **) NULL) if (Typ == (struct typmap **) NULL)
{ {
StartPortalAllocMode(DefaultAllocMode, 0); StartPortalAllocMode(DefaultAllocMode, 0);
rdesc = heap_openr(TypeRelationName); rel = heap_openr(TypeRelationName);
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 0, (ScanKey) NULL); scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
for (i = 0; PointerIsValid(tup = heap_getnext(sdesc, 0, (Buffer *) NULL)); ++i); i = 0;
heap_endscan(sdesc); while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
++i;
heap_endscan(scan);
app = Typ = ALLOC(struct typmap *, i + 1); app = Typ = ALLOC(struct typmap *, i + 1);
while (i-- > 0) while (i-- > 0)
*app++ = ALLOC(struct typmap, 1); *app++ = ALLOC(struct typmap, 1);
*app = (struct typmap *) NULL; *app = (struct typmap *) NULL;
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 0, (ScanKey) NULL); scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
app = Typ; app = Typ;
while (PointerIsValid(tup = heap_getnext(sdesc, 0, (Buffer *) NULL))) while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
{ {
(*app)->am_oid = tup->t_oid; (*app)->am_oid = tup->t_oid;
memmove((char *) &(*app++)->am_typ, memmove((char *) &(*app++)->am_typ,
(char *) GETSTRUCT(tup), (char *) GETSTRUCT(tup),
sizeof((*app)->am_typ)); sizeof((*app)->am_typ));
} }
heap_endscan(sdesc); heap_endscan(scan);
heap_close(rdesc); heap_close(rel);
EndPortalAllocMode(); EndPortalAllocMode();
} }
@ -505,7 +507,7 @@ boot_openrel(char *relname)
* defined yet. * defined yet.
*/ */
if (namestrcmp(&attrtypes[i]->attname, "attisset") == 0) if (namestrcmp(&attrtypes[i]->attname, "attisset") == 0)
attrtypes[i]->attisset = get_attisset(reldesc->rd_id, attrtypes[i]->attisset = get_attisset(RelationGetRelid(reldesc),
attrtypes[i]->attname.data); attrtypes[i]->attname.data);
else else
attrtypes[i]->attisset = false; attrtypes[i]->attisset = false;
@ -786,8 +788,8 @@ static int
gettype(char *type) gettype(char *type)
{ {
int i; int i;
Relation rdesc; Relation rel;
HeapScanDesc sdesc; HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
struct typmap **app; struct typmap **app;
@ -811,27 +813,27 @@ gettype(char *type)
} }
if (DebugMode) if (DebugMode)
printf("bootstrap.c: External Type: %s\n", type); printf("bootstrap.c: External Type: %s\n", type);
rdesc = heap_openr(TypeRelationName); rel = heap_openr(TypeRelationName);
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 0, (ScanKey) NULL); scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
i = 0; i = 0;
while (PointerIsValid(tup = heap_getnext(sdesc, 0, (Buffer *) NULL))) while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
++i; ++i;
heap_endscan(sdesc); heap_endscan(scan);
app = Typ = ALLOC(struct typmap *, i + 1); app = Typ = ALLOC(struct typmap *, i + 1);
while (i-- > 0) while (i-- > 0)
*app++ = ALLOC(struct typmap, 1); *app++ = ALLOC(struct typmap, 1);
*app = (struct typmap *) NULL; *app = (struct typmap *) NULL;
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 0, (ScanKey) NULL); scan = heap_beginscan(rel, 0, SnapshotNow, 0, (ScanKey) NULL);
app = Typ; app = Typ;
while (PointerIsValid(tup = heap_getnext(sdesc, 0, (Buffer *) NULL))) while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
{ {
(*app)->am_oid = tup->t_oid; (*app)->am_oid = tup->t_oid;
memmove((char *) &(*app++)->am_typ, memmove((char *) &(*app++)->am_typ,
(char *) GETSTRUCT(tup), (char *) GETSTRUCT(tup),
sizeof((*app)->am_typ)); sizeof((*app)->am_typ));
} }
heap_endscan(sdesc); heap_endscan(scan);
heap_close(rdesc); heap_close(rel);
return (gettype(type)); return (gettype(type));
} }
elog(ERROR, "Error: unknown type '%s'.\n", type); elog(ERROR, "Error: unknown type '%s'.\n", type);
@ -1167,7 +1169,7 @@ build_indices()
*/ */
heap = heap_openr(ILHead->il_heap); heap = heap_openr(ILHead->il_heap);
if (!BootstrapAlreadySeen(heap->rd_id)) if (!BootstrapAlreadySeen(RelationGetRelid(heap)))
UpdateStats(heap->rd_id, 0, true); UpdateStats(RelationGetRelid(heap), 0, true);
} }
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.13 1998/08/11 18:28:11 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.14 1998/08/19 02:01:27 momjian Exp $
* *
* NOTES * NOTES
* See acl.h. * See acl.h.
@ -33,6 +33,7 @@
#include "fmgr.h" #include "fmgr.h"
#include "parser/parse_agg.h" #include "parser/parse_agg.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "storage/bufmgr.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/memutils.h" #include "utils/memutils.h"
#include "utils/syscache.h" #include "utils/syscache.h"
@ -97,16 +98,10 @@ ChangeAcl(char *relname,
Acl *old_acl = (Acl *) NULL, Acl *old_acl = (Acl *) NULL,
*new_acl; *new_acl;
Relation relation; Relation relation;
static ScanKeyData relkey[1] = { HeapTuple tuple;
{0, Anum_pg_class_relname, F_NAMEEQ}
};
HeapScanDesc hsdp;
HeapTuple htp;
Buffer buffer;
Datum values[Natts_pg_class]; Datum values[Natts_pg_class];
char nulls[Natts_pg_class]; char nulls[Natts_pg_class];
char replaces[Natts_pg_class]; char replaces[Natts_pg_class];
ItemPointerData tmp_ipd;
Relation idescs[Num_pg_class_indices]; Relation idescs[Num_pg_class_indices];
int free_old_acl = 0; int free_old_acl = 0;
@ -115,40 +110,34 @@ ChangeAcl(char *relname,
* there's no ACL, create a default using the pg_class.relowner field. * there's no ACL, create a default using the pg_class.relowner field.
* *
* We can't use the syscache here, since we need to do a heap_replace on * We can't use the syscache here, since we need to do a heap_replace on
* the tuple we find. Feh. * the tuple we find.
*/ */
relation = heap_openr(RelationRelationName); relation = heap_openr(RelationRelationName);
if (!RelationIsValid(relation)) if (!RelationIsValid(relation))
elog(ERROR, "ChangeAcl: could not open '%s'??", elog(ERROR, "ChangeAcl: could not open '%s'??",
RelationRelationName); RelationRelationName);
fmgr_info(F_NAMEEQ, &relkey[0].sk_func); tuple = SearchSysCacheTuple(RELNAME,
relkey[0].sk_nargs = relkey[0].sk_func.fn_nargs; PointerGetDatum(relname),
relkey[0].sk_argument = NameGetDatum(relname); 0, 0, 0);
hsdp = heap_beginscan(relation, if (!HeapTupleIsValid(tuple))
0,
SnapshotNow,
(unsigned) 1,
relkey);
htp = heap_getnext(hsdp, 0, &buffer);
if (!HeapTupleIsValid(htp))
{ {
heap_endscan(hsdp);
heap_close(relation); heap_close(relation);
elog(ERROR, "ChangeAcl: class \"%s\" not found", elog(ERROR, "ChangeAcl: class \"%s\" not found",
relname); relname);
return; return;
} }
if (!heap_attisnull(htp, Anum_pg_class_relacl))
old_acl = (Acl *) heap_getattr(htp, if (!heap_attisnull(tuple, Anum_pg_class_relacl))
old_acl = (Acl *) heap_getattr(tuple,
Anum_pg_class_relacl, Anum_pg_class_relacl,
RelationGetTupleDescriptor(relation), RelationGetTupleDescriptor(relation),
(bool *) NULL); (bool *) NULL);
if (!old_acl || ACL_NUM(old_acl) < 1) if (!old_acl || ACL_NUM(old_acl) < 1)
{ {
#ifdef ACLDEBUG_TRACE #ifdef ACLDEBUG_TRACE
elog(DEBUG, "ChangeAcl: using default ACL"); elog(DEBUG, "ChangeAcl: using default ACL");
#endif #endif
/* old_acl = acldefault(((Form_pg_class) GETSTRUCT(htp))->relowner); */ /* old_acl = acldefault(((Form_pg_class) GETSTRUCT(tuple))->relowner); */
old_acl = acldefault(relname); old_acl = acldefault(relname);
free_old_acl = 1; free_old_acl = 1;
} }
@ -170,19 +159,16 @@ ChangeAcl(char *relname,
} }
replaces[Anum_pg_class_relacl - 1] = 'r'; replaces[Anum_pg_class_relacl - 1] = 'r';
values[Anum_pg_class_relacl - 1] = (Datum) new_acl; values[Anum_pg_class_relacl - 1] = (Datum) new_acl;
htp = heap_modifytuple(htp, buffer, relation, values, nulls, replaces); tuple = heap_modifytuple(tuple, relation, values, nulls, replaces);
/* XXX is this necessary? */
ItemPointerCopy(&htp->t_ctid, &tmp_ipd);
/* XXX handle index on pg_class? */ /* XXX handle index on pg_class? */
setheapoverride(true); setheapoverride(true);
heap_replace(relation, &tmp_ipd, htp); heap_replace(relation, &tuple->t_ctid, tuple);
setheapoverride(false); setheapoverride(false);
heap_endscan(hsdp);
/* keep the catalog indices up to date */ /* keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
idescs); idescs);
CatalogIndexInsert(idescs, Num_pg_class_indices, relation, htp); CatalogIndexInsert(idescs, Num_pg_class_indices, relation, tuple);
CatalogCloseIndices(Num_pg_class_indices, idescs); CatalogCloseIndices(Num_pg_class_indices, idescs);
heap_close(relation); heap_close(relation);
@ -194,13 +180,14 @@ ChangeAcl(char *relname,
AclId AclId
get_grosysid(char *groname) get_grosysid(char *groname)
{ {
HeapTuple htp; HeapTuple tuple;
AclId id = 0; AclId id = 0;
htp = SearchSysCacheTuple(GRONAME, PointerGetDatum(groname), tuple = SearchSysCacheTuple(GRONAME,
0, 0, 0); PointerGetDatum(groname),
if (HeapTupleIsValid(htp)) 0, 0, 0);
id = ((Form_pg_group) GETSTRUCT(htp))->grosysid; if (HeapTupleIsValid(tuple))
id = ((Form_pg_group) GETSTRUCT(tuple))->grosysid;
else else
elog(ERROR, "non-existent group \"%s\"", groname); elog(ERROR, "non-existent group \"%s\"", groname);
return (id); return (id);
@ -209,13 +196,14 @@ get_grosysid(char *groname)
char * char *
get_groname(AclId grosysid) get_groname(AclId grosysid)
{ {
HeapTuple htp; HeapTuple tuple;
char *name = NULL; char *name = NULL;
htp = SearchSysCacheTuple(GROSYSID, PointerGetDatum(grosysid), tuple = SearchSysCacheTuple(GROSYSID,
0, 0, 0); ObjectIdGetDatum(grosysid),
if (HeapTupleIsValid(htp)) 0, 0, 0);
name = (((Form_pg_group) GETSTRUCT(htp))->groname).data; if (HeapTupleIsValid(tuple))
name = (((Form_pg_group) GETSTRUCT(tuple))->groname).data;
else else
elog(NOTICE, "get_groname: group %d not found", grosysid); elog(NOTICE, "get_groname: group %d not found", grosysid);
return (name); return (name);
@ -225,7 +213,7 @@ static int32
in_group(AclId uid, AclId gid) in_group(AclId uid, AclId gid)
{ {
Relation relation; Relation relation;
HeapTuple htp; HeapTuple tuple;
Acl *tmp; Acl *tmp;
unsigned i, unsigned i,
num; num;
@ -239,12 +227,13 @@ in_group(AclId uid, AclId gid)
GroupRelationName); GroupRelationName);
return (0); return (0);
} }
htp = SearchSysCacheTuple(GROSYSID, ObjectIdGetDatum(gid), tuple = SearchSysCacheTuple(GROSYSID,
0, 0, 0); ObjectIdGetDatum(gid),
if (HeapTupleIsValid(htp) && 0, 0, 0);
!heap_attisnull(htp, Anum_pg_group_grolist)) if (HeapTupleIsValid(tuple) &&
!heap_attisnull(tuple, Anum_pg_group_grolist))
{ {
tmp = (IdList *) heap_getattr(htp, tmp = (IdList *) heap_getattr(tuple,
Anum_pg_group_grolist, Anum_pg_group_grolist,
RelationGetTupleDescriptor(relation), RelationGetTupleDescriptor(relation),
(bool *) NULL); (bool *) NULL);
@ -371,26 +360,27 @@ aclcheck(char *relname, Acl *acl, AclId id, AclIdType idtype, AclMode mode)
int32 int32
pg_aclcheck(char *relname, char *usename, AclMode mode) pg_aclcheck(char *relname, char *usename, AclMode mode)
{ {
HeapTuple htp; HeapTuple tuple;
AclId id; AclId id;
Acl *acl = (Acl *) NULL, Acl *acl = (Acl *) NULL,
*tmp; *tmp;
int32 result; int32 result;
Relation relation; Relation relation;
htp = SearchSysCacheTuple(USENAME, PointerGetDatum(usename), tuple = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(usename),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_aclcheck: user \"%s\" not found", elog(ERROR, "pg_aclcheck: user \"%s\" not found",
usename); usename);
id = (AclId) ((Form_pg_shadow) GETSTRUCT(htp))->usesysid; id = (AclId) ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
/* /*
* for the 'pg_database' relation, check the usecreatedb field before * for the 'pg_database' relation, check the usecreatedb field before
* checking normal permissions * checking normal permissions
*/ */
if (strcmp(DatabaseRelationName, relname) == 0 && if (strcmp(DatabaseRelationName, relname) == 0 &&
(((Form_pg_shadow) GETSTRUCT(htp))->usecreatedb)) (((Form_pg_shadow) GETSTRUCT(tuple))->usecreatedb))
{ {
/* /*
@ -409,7 +399,7 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
*/ */
if (((mode & ACL_WR) || (mode & ACL_AP)) && if (((mode & ACL_WR) || (mode & ACL_AP)) &&
IsSystemRelationName(relname) && IsSystemRelationName(relname) &&
!((Form_pg_shadow) GETSTRUCT(htp))->usecatupd) !((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{ {
elog(DEBUG, "pg_aclcheck: catalog update to \"%s\": permission denied", elog(DEBUG, "pg_aclcheck: catalog update to \"%s\": permission denied",
relname); relname);
@ -419,7 +409,7 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
/* /*
* Otherwise, superusers bypass all permission-checking. * Otherwise, superusers bypass all permission-checking.
*/ */
if (((Form_pg_shadow) GETSTRUCT(htp))->usesuper) if (((Form_pg_shadow) GETSTRUCT(tuple))->usesuper)
{ {
#ifdef ACLDEBUG_TRACE #ifdef ACLDEBUG_TRACE
elog(DEBUG, "pg_aclcheck: \"%s\" is superuser", elog(DEBUG, "pg_aclcheck: \"%s\" is superuser",
@ -429,18 +419,19 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
} }
#ifndef ACLDEBUG #ifndef ACLDEBUG
htp = SearchSysCacheTuple(RELNAME, PointerGetDatum(relname), tuple = SearchSysCacheTuple(RELNAME,
0, 0, 0); PointerGetDatum(relname),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(tuple))
{ {
elog(ERROR, "pg_aclcheck: class \"%s\" not found", elog(ERROR, "pg_aclcheck: class \"%s\" not found",
relname); relname);
/* an elog(ERROR) kills us, so no need to return anything. */ /* an elog(ERROR) kills us, so no need to return anything. */
} }
if (!heap_attisnull(htp, Anum_pg_class_relacl)) if (!heap_attisnull(tuple, Anum_pg_class_relacl))
{ {
relation = heap_openr(RelationRelationName); relation = heap_openr(RelationRelationName);
tmp = (Acl *) heap_getattr(htp, tmp = (Acl *) heap_getattr(tuple,
Anum_pg_class_relacl, Anum_pg_class_relacl,
RelationGetTupleDescriptor(relation), RelationGetTupleDescriptor(relation),
(bool *) NULL); (bool *) NULL);
@ -458,7 +449,7 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
int4 ownerId; int4 ownerId;
relation = heap_openr(RelationRelationName); relation = heap_openr(RelationRelationName);
ownerId = (int4) heap_getattr(htp, ownerId = (int4) heap_getattr(tuple,
Anum_pg_class_relowner, Anum_pg_class_relowner,
RelationGetTupleDescriptor(relation), RelationGetTupleDescriptor(relation),
(bool *) NULL); (bool *) NULL);
@ -469,7 +460,6 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
static ScanKeyData relkey[1] = { static ScanKeyData relkey[1] = {
{0, Anum_pg_class_relname, F_NAMEEQ} {0, Anum_pg_class_relname, F_NAMEEQ}
}; };
HeapScanDesc hsdp;
relation = heap_openr(RelationRelationName); relation = heap_openr(RelationRelationName);
if (!RelationIsValid(relation)) if (!RelationIsValid(relation))
@ -478,23 +468,19 @@ pg_aclcheck(char *relname, char *usename, AclMode mode)
RelationRelationName); RelationRelationName);
return ACLCHECK_NO_CLASS; return ACLCHECK_NO_CLASS;
} }
fmgr_info(F_NAMEEQ, tuple = SearchSysCacheTuple(RELNAME,
&relkey[0].sk_func, PointerGetDatum(relname),
&relkey[0].sk_nargs); 0, 0, 0);
relkey[0].sk_argument = NameGetDatum(relname); if (HeapTupleIsValid(tuple) &&
hsdp = heap_beginscan(relation, 0, SnapshotNow, 1, relkey); !heap_attisnull(tuple, Anum_pg_class_relacl))
htp = heap_getnext(hsdp, 0, (Buffer *) 0);
if (HeapTupleIsValid(htp) &&
!heap_attisnull(htp, Anum_pg_class_relacl))
{ {
tmp = (Acl *) heap_getattr(htp, tmp = (Acl *) heap_getattr(tuple,
Anum_pg_class_relacl, Anum_pg_class_relacl,
RelationGetTupleDescriptor(relation), RelationGetTupleDescriptor(relation),
(bool *) NULL); (bool *) NULL);
acl = makeacl(ACL_NUM(tmp)); acl = makeacl(ACL_NUM(tmp));
memmove((char *) acl, (char *) tmp, ACL_SIZE(tmp)); memmove((char *) acl, (char *) tmp, ACL_SIZE(tmp));
} }
heap_endscan(hsdp);
heap_close(relation); heap_close(relation);
} }
#endif #endif
@ -509,21 +495,22 @@ pg_ownercheck(char *usename,
char *value, char *value,
int cacheid) int cacheid)
{ {
HeapTuple htp; HeapTuple tuple;
AclId user_id, AclId user_id,
owner_id = 0; owner_id = 0;
htp = SearchSysCacheTuple(USENAME, PointerGetDatum(usename), tuple = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(usename),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_ownercheck: user \"%s\" not found", elog(ERROR, "pg_ownercheck: user \"%s\" not found",
usename); usename);
user_id = (AclId) ((Form_pg_shadow) GETSTRUCT(htp))->usesysid; user_id = (AclId) ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
/* /*
* Superusers bypass all permission-checking. * Superusers bypass all permission-checking.
*/ */
if (((Form_pg_shadow) GETSTRUCT(htp))->usesuper) if (((Form_pg_shadow) GETSTRUCT(tuple))->usesuper)
{ {
#ifdef ACLDEBUG_TRACE #ifdef ACLDEBUG_TRACE
elog(DEBUG, "pg_ownercheck: user \"%s\" is superuser", elog(DEBUG, "pg_ownercheck: user \"%s\" is superuser",
@ -532,33 +519,33 @@ pg_ownercheck(char *usename,
return (1); return (1);
} }
htp = SearchSysCacheTuple(cacheid, PointerGetDatum(value), tuple = SearchSysCacheTuple(cacheid, PointerGetDatum(value),
0, 0, 0); 0, 0, 0);
switch (cacheid) switch (cacheid)
{ {
case OPROID: case OPROID:
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_ownercheck: operator %ld not found", elog(ERROR, "pg_ownercheck: operator %ld not found",
PointerGetDatum(value)); PointerGetDatum(value));
owner_id = ((OperatorTupleForm) GETSTRUCT(htp))->oprowner; owner_id = ((OperatorTupleForm) GETSTRUCT(tuple))->oprowner;
break; break;
case PRONAME: case PRONAME:
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_ownercheck: function \"%s\" not found", elog(ERROR, "pg_ownercheck: function \"%s\" not found",
value); value);
owner_id = ((Form_pg_proc) GETSTRUCT(htp))->proowner; owner_id = ((Form_pg_proc) GETSTRUCT(tuple))->proowner;
break; break;
case RELNAME: case RELNAME:
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_ownercheck: class \"%s\" not found", elog(ERROR, "pg_ownercheck: class \"%s\" not found",
value); value);
owner_id = ((Form_pg_class) GETSTRUCT(htp))->relowner; owner_id = ((Form_pg_class) GETSTRUCT(tuple))->relowner;
break; break;
case TYPNAME: case TYPNAME:
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_ownercheck: type \"%s\" not found", elog(ERROR, "pg_ownercheck: type \"%s\" not found",
value); value);
owner_id = ((TypeTupleForm) GETSTRUCT(htp))->typowner; owner_id = ((TypeTupleForm) GETSTRUCT(tuple))->typowner;
break; break;
default: default:
elog(ERROR, "pg_ownercheck: invalid cache id: %d", elog(ERROR, "pg_ownercheck: invalid cache id: %d",
@ -575,21 +562,22 @@ pg_func_ownercheck(char *usename,
int nargs, int nargs,
Oid *arglist) Oid *arglist)
{ {
HeapTuple htp; HeapTuple tuple;
AclId user_id, AclId user_id,
owner_id; owner_id;
htp = SearchSysCacheTuple(USENAME, PointerGetDatum(usename), tuple = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(usename),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_func_ownercheck: user \"%s\" not found", elog(ERROR, "pg_func_ownercheck: user \"%s\" not found",
usename); usename);
user_id = (AclId) ((Form_pg_shadow) GETSTRUCT(htp))->usesysid; user_id = (AclId) ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
/* /*
* Superusers bypass all permission-checking. * Superusers bypass all permission-checking.
*/ */
if (((Form_pg_shadow) GETSTRUCT(htp))->usesuper) if (((Form_pg_shadow) GETSTRUCT(tuple))->usesuper)
{ {
#ifdef ACLDEBUG_TRACE #ifdef ACLDEBUG_TRACE
elog(DEBUG, "pg_ownercheck: user \"%s\" is superuser", elog(DEBUG, "pg_ownercheck: user \"%s\" is superuser",
@ -598,15 +586,15 @@ pg_func_ownercheck(char *usename,
return (1); return (1);
} }
htp = SearchSysCacheTuple(PRONAME, tuple = SearchSysCacheTuple(PRONAME,
PointerGetDatum(funcname), PointerGetDatum(funcname),
PointerGetDatum(nargs), Int32GetDatum(nargs),
PointerGetDatum(arglist), PointerGetDatum(arglist),
0); 0);
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(tuple))
func_error("pg_func_ownercheck", funcname, nargs, arglist, NULL); func_error("pg_func_ownercheck", funcname, nargs, arglist, NULL);
owner_id = ((Form_pg_proc) GETSTRUCT(htp))->proowner; owner_id = ((Form_pg_proc) GETSTRUCT(tuple))->proowner;
return (user_id == owner_id); return (user_id == owner_id);
} }
@ -616,21 +604,22 @@ pg_aggr_ownercheck(char *usename,
char *aggname, char *aggname,
Oid basetypeID) Oid basetypeID)
{ {
HeapTuple htp; HeapTuple tuple;
AclId user_id, AclId user_id,
owner_id; owner_id;
htp = SearchSysCacheTuple(USENAME, PointerGetDatum(usename), tuple = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(usename),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "pg_aggr_ownercheck: user \"%s\" not found", elog(ERROR, "pg_aggr_ownercheck: user \"%s\" not found",
usename); usename);
user_id = (AclId) ((Form_pg_shadow) GETSTRUCT(htp))->usesysid; user_id = (AclId) ((Form_pg_shadow) GETSTRUCT(tuple))->usesysid;
/* /*
* Superusers bypass all permission-checking. * Superusers bypass all permission-checking.
*/ */
if (((Form_pg_shadow) GETSTRUCT(htp))->usesuper) if (((Form_pg_shadow) GETSTRUCT(tuple))->usesuper)
{ {
#ifdef ACLDEBUG_TRACE #ifdef ACLDEBUG_TRACE
elog(DEBUG, "pg_aggr_ownercheck: user \"%s\" is superuser", elog(DEBUG, "pg_aggr_ownercheck: user \"%s\" is superuser",
@ -639,16 +628,15 @@ pg_aggr_ownercheck(char *usename,
return (1); return (1);
} }
htp = SearchSysCacheTuple(AGGNAME, tuple = SearchSysCacheTuple(AGGNAME,
PointerGetDatum(aggname), PointerGetDatum(aggname),
PointerGetDatum(basetypeID), ObjectIdGetDatum(basetypeID),
0, 0, 0);
0);
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(tuple))
agg_error("pg_aggr_ownercheck", aggname, basetypeID); agg_error("pg_aggr_ownercheck", aggname, basetypeID);
owner_id = ((Form_pg_aggregate) GETSTRUCT(htp))->aggowner; owner_id = ((Form_pg_aggregate) GETSTRUCT(tuple))->aggowner;
return (user_id == owner_id); return (user_id == owner_id);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.15 1998/02/26 04:30:31 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.16 1998/08/19 02:01:29 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -174,7 +174,7 @@ fillatt(TupleDesc tupleDesc)
for (i = 0; i < natts;) for (i = 0; i < natts;)
{ {
tuple = SearchSysCacheTuple(TYPOID, tuple = SearchSysCacheTuple(TYPOID,
Int32GetDatum((*attributeP)->atttypid), ObjectIdGetDatum((*attributeP)->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.57 1998/08/17 16:03:31 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.58 1998/08/19 02:01:30 momjian Exp $
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
* heap_create() - Create an uncataloged heap relation * heap_create() - Create an uncataloged heap relation
@ -56,6 +56,7 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/mcxt.h" #include "utils/mcxt.h"
#include "utils/relcache.h" #include "utils/relcache.h"
#include "utils/syscache.h"
#include "utils/tqual.h" #include "utils/tqual.h"
#ifndef HAVE_MEMMOVE #ifndef HAVE_MEMMOVE
@ -69,9 +70,9 @@ AddPgRelationTuple(Relation pg_class_desc,
Relation new_rel_desc, Oid new_rel_oid, unsigned natts, Relation new_rel_desc, Oid new_rel_oid, unsigned natts,
char relkind); char relkind);
static void AddToTempRelList(Relation r); static void AddToTempRelList(Relation r);
static void DeletePgAttributeTuples(Relation rdesc); static void DeletePgAttributeTuples(Relation rel);
static void DeletePgRelationTuple(Relation rdesc); static void DeletePgRelationTuple(Relation rel);
static void DeletePgTypeTuple(Relation rdesc); static void DeletePgTypeTuple(Relation rel);
static int RelationAlreadyExists(Relation pg_class_desc, char relname[]); static int RelationAlreadyExists(Relation pg_class_desc, char relname[]);
static void RelationRemoveIndexes(Relation relation); static void RelationRemoveIndexes(Relation relation);
static void RelationRemoveInheritance(Relation relation); static void RelationRemoveInheritance(Relation relation);
@ -157,7 +158,7 @@ static TempRelList *tempRels = NULL;
* heap_create - Create an uncataloged heap relation * heap_create - Create an uncataloged heap relation
* *
* Fields relpages, reltuples, reltuples, relkeys, relhistory, * Fields relpages, reltuples, reltuples, relkeys, relhistory,
* relisindexed, and relkind of rdesc->rd_rel are initialized * relisindexed, and relkind of rel->rd_rel are initialized
* to all zeros, as are rd_last and rd_hook. Rd_refcnt is set to 1. * to all zeros, as are rd_last and rd_hook. Rd_refcnt is set to 1.
* *
* Remove the system relation specific code to elsewhere eventually. * Remove the system relation specific code to elsewhere eventually.
@ -176,7 +177,7 @@ heap_create(char *name,
{ {
unsigned i; unsigned i;
Oid relid; Oid relid;
Relation rdesc; Relation rel;
int len; int len;
bool nailme = false; bool nailme = false;
char *relname = name; char *relname = name;
@ -259,13 +260,13 @@ heap_create(char *name,
*/ */
len = sizeof(RelationData); len = sizeof(RelationData);
rdesc = (Relation) palloc(len); rel = (Relation) palloc(len);
MemSet((char *) rdesc, 0, len); MemSet((char *) rel, 0, len);
/* ---------- /* ----------
create a new tuple descriptor from the one passed in create a new tuple descriptor from the one passed in
*/ */
rdesc->rd_att = CreateTupleDescCopyConstr(tupDesc); rel->rd_att = CreateTupleDescCopyConstr(tupDesc);
/* ---------------- /* ----------------
* initialize the fields of our new relation descriptor * initialize the fields of our new relation descriptor
@ -279,29 +280,29 @@ heap_create(char *name,
* ---------------- * ----------------
*/ */
if (nailme) if (nailme)
rdesc->rd_isnailed = true; rel->rd_isnailed = true;
RelationSetReferenceCount(rdesc, 1); RelationSetReferenceCount(rel, 1);
rdesc->rd_rel = (Form_pg_class) palloc(sizeof *rdesc->rd_rel); rel->rd_rel = (Form_pg_class) palloc(sizeof *rel->rd_rel);
MemSet((char *) rdesc->rd_rel, 0, MemSet((char *) rel->rd_rel, 0,
sizeof *rdesc->rd_rel); sizeof *rel->rd_rel);
namestrcpy(&(rdesc->rd_rel->relname), relname); namestrcpy(&(rel->rd_rel->relname), relname);
rdesc->rd_rel->relkind = RELKIND_UNCATALOGED; rel->rd_rel->relkind = RELKIND_UNCATALOGED;
rdesc->rd_rel->relnatts = natts; rel->rd_rel->relnatts = natts;
if (tupDesc->constr) if (tupDesc->constr)
rdesc->rd_rel->relchecks = tupDesc->constr->num_check; rel->rd_rel->relchecks = tupDesc->constr->num_check;
for (i = 0; i < natts; i++) for (i = 0; i < natts; i++)
rdesc->rd_att->attrs[i]->attrelid = relid; rel->rd_att->attrs[i]->attrelid = relid;
rdesc->rd_id = relid; RelationGetRelid(rel) = relid;
if (nailme) if (nailme)
{ {
/* for system relations, set the reltype field here */ /* for system relations, set the reltype field here */
rdesc->rd_rel->reltype = relid; rel->rd_rel->reltype = relid;
} }
/* ---------------- /* ----------------
@ -309,18 +310,18 @@ heap_create(char *name,
* ---------------- * ----------------
*/ */
rdesc->rd_istemp = isTemp; rel->rd_istemp = isTemp;
/* ---------------- /* ----------------
* have the storage manager create the relation. * have the storage manager create the relation.
* ---------------- * ----------------
*/ */
rdesc->rd_tmpunlinked = TRUE; /* change once table is created */ rel->rd_tmpunlinked = TRUE; /* change once table is created */
rdesc->rd_fd = (File) smgrcreate(DEFAULT_SMGR, rdesc); rel->rd_fd = (File) smgrcreate(DEFAULT_SMGR, rel);
rdesc->rd_tmpunlinked = FALSE; rel->rd_tmpunlinked = FALSE;
RelationRegisterRelation(rdesc); RelationRegisterRelation(rel);
MemoryContextSwitchTo(oldcxt); MemoryContextSwitchTo(oldcxt);
@ -329,9 +330,9 @@ heap_create(char *name,
* properly disposed of at the end of transaction * properly disposed of at the end of transaction
*/ */
if (isTemp) if (isTemp)
AddToTempRelList(rdesc); AddToTempRelList(rel);
return (rdesc); return (rel);
} }
@ -477,14 +478,13 @@ RelationAlreadyExists(Relation pg_class_desc, char relname[])
if (!IsBootstrapProcessingMode()) if (!IsBootstrapProcessingMode())
{ {
tup = ClassNameIndexScan(pg_class_desc, relname); tup = SearchSysCacheTuple(RELNAME,
PointerGetDatum(relname),
0, 0, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ return true;
pfree(tup);
return ((int) true);
}
else else
return ((int) false); return false;
} }
/* ---------------- /* ----------------
@ -513,7 +513,7 @@ RelationAlreadyExists(Relation pg_class_desc, char relname[])
* didn't find an existing relation. * didn't find an existing relation.
* ---------------- * ----------------
*/ */
tup = heap_getnext(pg_class_scan, 0, (Buffer *) NULL); tup = heap_getnext(pg_class_scan, 0);
/* ---------------- /* ----------------
* end the scan and return existance of relation. * end the scan and return existance of relation.
@ -521,8 +521,7 @@ RelationAlreadyExists(Relation pg_class_desc, char relname[])
*/ */
heap_endscan(pg_class_scan); heap_endscan(pg_class_scan);
return return HeapTupleIsValid(tup);
(PointerIsValid(tup) == true);
} }
/* -------------------------------- /* --------------------------------
@ -539,7 +538,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
AttributeTupleForm *dpp; AttributeTupleForm *dpp;
unsigned i; unsigned i;
HeapTuple tup; HeapTuple tup;
Relation rdesc; Relation rel;
bool hasindex; bool hasindex;
Relation idescs[Num_pg_attr_indices]; Relation idescs[Num_pg_attr_indices];
int natts = tupdesc->natts; int natts = tupdesc->natts;
@ -548,15 +547,15 @@ AddNewAttributeTuples(Oid new_rel_oid,
* open pg_attribute * open pg_attribute
* ---------------- * ----------------
*/ */
rdesc = heap_openr(AttributeRelationName); rel = heap_openr(AttributeRelationName);
/* ----------------- /* -----------------
* Check if we have any indices defined on pg_attribute. * Check if we have any indices defined on pg_attribute.
* ----------------- * -----------------
*/ */
Assert(rdesc); Assert(rel);
Assert(rdesc->rd_rel); Assert(rel->rd_rel);
hasindex = RelationGetRelationTupleForm(rdesc)->relhasindex; hasindex = RelationGetRelationTupleForm(rel)->relhasindex;
if (hasindex) if (hasindex)
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs); CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
@ -584,9 +583,9 @@ AddNewAttributeTuples(Oid new_rel_oid,
ATTRIBUTE_TUPLE_SIZE, ATTRIBUTE_TUPLE_SIZE,
(char *) *dpp); (char *) *dpp);
heap_insert(rdesc, tup); heap_insert(rel, tup);
if (hasindex) if (hasindex)
CatalogIndexInsert(idescs, Num_pg_attr_indices, rdesc, tup); CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
pfree(tup); pfree(tup);
dpp++; dpp++;
@ -606,16 +605,16 @@ AddNewAttributeTuples(Oid new_rel_oid,
ATTRIBUTE_TUPLE_SIZE, ATTRIBUTE_TUPLE_SIZE,
(char *) *dpp); (char *) *dpp);
heap_insert(rdesc, tup); heap_insert(rel, tup);
if (hasindex) if (hasindex)
CatalogIndexInsert(idescs, Num_pg_attr_indices, rdesc, tup); CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
pfree(tup); pfree(tup);
dpp++; dpp++;
} }
heap_close(rdesc); heap_close(rel);
/* /*
* close pg_attribute indices * close pg_attribute indices
@ -878,7 +877,8 @@ RelationRemoveInheritance(Relation relation)
HeapTuple tuple; HeapTuple tuple;
HeapScanDesc scan; HeapScanDesc scan;
ScanKeyData entry; ScanKeyData entry;
bool found = false;
/* ---------------- /* ----------------
* open pg_inherits * open pg_inherits
* ---------------- * ----------------
@ -892,7 +892,7 @@ RelationRemoveInheritance(Relation relation)
*/ */
ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_inherits_inhparent, ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_inherits_inhparent,
F_OIDEQ, F_OIDEQ,
ObjectIdGetDatum(RelationGetRelationId(relation))); ObjectIdGetDatum(RelationGetRelid(relation)));
scan = heap_beginscan(catalogRelation, scan = heap_beginscan(catalogRelation,
false, false,
@ -904,7 +904,7 @@ RelationRemoveInheritance(Relation relation)
* if any subclasses exist, then we disallow the deletion. * if any subclasses exist, then we disallow the deletion.
* ---------------- * ----------------
*/ */
tuple = heap_getnext(scan, 0, (Buffer *) NULL); tuple = heap_getnext(scan, 0);
if (HeapTupleIsValid(tuple)) if (HeapTupleIsValid(tuple))
{ {
heap_endscan(scan); heap_endscan(scan);
@ -928,12 +928,10 @@ RelationRemoveInheritance(Relation relation)
1, 1,
&entry); &entry);
for (;;) while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{ {
tuple = heap_getnext(scan, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
break;
heap_delete(catalogRelation, &tuple->t_ctid); heap_delete(catalogRelation, &tuple->t_ctid);
found = true;
} }
heap_endscan(scan); heap_endscan(scan);
@ -943,8 +941,7 @@ RelationRemoveInheritance(Relation relation)
* now remove dead IPL tuples * now remove dead IPL tuples
* ---------------- * ----------------
*/ */
catalogRelation = catalogRelation = heap_openr(InheritancePrecidenceListRelationName);
heap_openr(InheritancePrecidenceListRelationName);
entry.sk_attno = Anum_pg_ipl_iplrel; entry.sk_attno = Anum_pg_ipl_iplrel;
@ -954,13 +951,8 @@ RelationRemoveInheritance(Relation relation)
1, 1,
&entry); &entry);
for (;;) while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{
tuple = heap_getnext(scan, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
break;
heap_delete(catalogRelation, &tuple->t_ctid); heap_delete(catalogRelation, &tuple->t_ctid);
}
heap_endscan(scan); heap_endscan(scan);
heap_close(catalogRelation); heap_close(catalogRelation);
@ -980,10 +972,10 @@ RelationRemoveIndexes(Relation relation)
ScanKeyData entry; ScanKeyData entry;
indexRelation = heap_openr(IndexRelationName); indexRelation = heap_openr(IndexRelationName);
ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_index_indrelid, ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_index_indrelid,
F_OIDEQ, F_OIDEQ,
ObjectIdGetDatum(RelationGetRelationId(relation))); ObjectIdGetDatum(RelationGetRelid(relation)));
scan = heap_beginscan(indexRelation, scan = heap_beginscan(indexRelation,
false, false,
@ -991,14 +983,8 @@ RelationRemoveIndexes(Relation relation)
1, 1,
&entry); &entry);
for (;;) while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{
tuple = heap_getnext(scan, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
break;
index_destroy(((IndexTupleForm) GETSTRUCT(tuple))->indexrelid); index_destroy(((IndexTupleForm) GETSTRUCT(tuple))->indexrelid);
}
heap_endscan(scan); heap_endscan(scan);
heap_close(indexRelation); heap_close(indexRelation);
@ -1010,11 +996,9 @@ RelationRemoveIndexes(Relation relation)
* -------------------------------- * --------------------------------
*/ */
static void static void
DeletePgRelationTuple(Relation rdesc) DeletePgRelationTuple(Relation rel)
{ {
Relation pg_class_desc; Relation pg_class_desc;
HeapScanDesc pg_class_scan;
ScanKeyData key;
HeapTuple tup; HeapTuple tup;
/* ---------------- /* ----------------
@ -1023,42 +1007,23 @@ DeletePgRelationTuple(Relation rdesc)
*/ */
pg_class_desc = heap_openr(RelationRelationName); pg_class_desc = heap_openr(RelationRelationName);
/* ---------------- tup = SearchSysCacheTupleCopy(RELOID,
* create a scan key to locate the relation oid of the ObjectIdGetDatum(rel->rd_att->attrs[0]->attrelid),
* relation to delete 0, 0, 0);
* ---------------- if (!HeapTupleIsValid(tup))
*/
ScanKeyEntryInitialize(&key, 0, ObjectIdAttributeNumber,
F_INT4EQ, rdesc->rd_att->attrs[0]->attrelid);
pg_class_scan = heap_beginscan(pg_class_desc,
0,
SnapshotNow,
1,
&key);
/* ----------------
* use heap_getnext() to fetch the pg_class tuple. If this
* tuple is not valid then something's wrong.
* ----------------
*/
tup = heap_getnext(pg_class_scan, 0, (Buffer *) NULL);
if (!PointerIsValid(tup))
{ {
heap_endscan(pg_class_scan);
heap_close(pg_class_desc); heap_close(pg_class_desc);
elog(ERROR, "DeletePgRelationTuple: %s relation nonexistent", elog(ERROR, "DeletePgRelationTuple: %s relation nonexistent",
&rdesc->rd_rel->relname); &rel->rd_rel->relname);
} }
/* ---------------- /* ----------------
* delete the relation tuple from pg_class, and finish up. * delete the relation tuple from pg_class, and finish up.
* ---------------- * ----------------
*/ */
heap_endscan(pg_class_scan);
heap_delete(pg_class_desc, &tup->t_ctid); heap_delete(pg_class_desc, &tup->t_ctid);
pfree(tup);
heap_close(pg_class_desc); heap_close(pg_class_desc);
} }
@ -1068,57 +1033,36 @@ DeletePgRelationTuple(Relation rdesc)
* -------------------------------- * --------------------------------
*/ */
static void static void
DeletePgAttributeTuples(Relation rdesc) DeletePgAttributeTuples(Relation rel)
{ {
Relation pg_attribute_desc; Relation pg_attribute_desc;
HeapScanDesc pg_attribute_scan;
ScanKeyData key;
HeapTuple tup; HeapTuple tup;
int2 attnum;
/* ---------------- /* ----------------
* open pg_attribute * open pg_attribute
* ---------------- * ----------------
*/ */
pg_attribute_desc = heap_openr(AttributeRelationName); pg_attribute_desc = heap_openr(AttributeRelationName);
/* ----------------
* create a scan key to locate the attribute tuples to delete
* and begin the scan.
* ----------------
*/
ScanKeyEntryInitialize(&key, 0, Anum_pg_attribute_attrelid,
F_INT4EQ, rdesc->rd_att->attrs[0]->attrelid);
/* ----------------- /* -----------------
* Get a write lock _before_ getting the read lock in the scan * Get a write lock _before_ getting the read lock in the scan
* ---------------- * ----------------
*/ */
RelationSetLockForWrite(pg_attribute_desc); RelationSetLockForWrite(pg_attribute_desc);
pg_attribute_scan = heap_beginscan(pg_attribute_desc, attnum = FirstLowInvalidHeapAttributeNumber + 1; /* cmax */
0,
SnapshotNow,
1,
&key);
/* ---------------- while (HeapTupleIsValid(tup = SearchSysCacheTupleCopy(ATTNUM,
* use heap_getnext() / amdelete() until all attribute tuples ObjectIdGetDatum(rel->rd_att->attrs[0]->attrelid),
* have been deleted. Int16GetDatum(attnum),
* ---------------- 0, 0)))
*/
while (tup = heap_getnext(pg_attribute_scan, 0, (Buffer *) NULL),
PointerIsValid(tup))
{ {
heap_delete(pg_attribute_desc, &tup->t_ctid); heap_delete(pg_attribute_desc, &tup->t_ctid);
pfree(tup);
attnum++;
} }
/* ----------------
* finish up.
* ----------------
*/
heap_endscan(pg_attribute_scan);
/* ---------------- /* ----------------
* Release the write lock * Release the write lock
* ---------------- * ----------------
@ -1127,7 +1071,6 @@ DeletePgAttributeTuples(Relation rdesc)
heap_close(pg_attribute_desc); heap_close(pg_attribute_desc);
} }
/* -------------------------------- /* --------------------------------
* DeletePgTypeTuple * DeletePgTypeTuple
* *
@ -1138,7 +1081,7 @@ DeletePgAttributeTuples(Relation rdesc)
* -------------------------------- * --------------------------------
*/ */
static void static void
DeletePgTypeTuple(Relation rdesc) DeletePgTypeTuple(Relation rel)
{ {
Relation pg_type_desc; Relation pg_type_desc;
HeapScanDesc pg_type_scan; HeapScanDesc pg_type_scan;
@ -1162,7 +1105,7 @@ DeletePgTypeTuple(Relation rdesc)
* ---------------- * ----------------
*/ */
ScanKeyEntryInitialize(&key, 0, Anum_pg_type_typrelid, F_INT4EQ, ScanKeyEntryInitialize(&key, 0, Anum_pg_type_typrelid, F_INT4EQ,
rdesc->rd_att->attrs[0]->attrelid); rel->rd_att->attrs[0]->attrelid);
pg_type_scan = heap_beginscan(pg_type_desc, pg_type_scan = heap_beginscan(pg_type_desc,
0, 0,
@ -1175,14 +1118,14 @@ DeletePgTypeTuple(Relation rdesc)
* tuple is not valid then something's wrong. * tuple is not valid then something's wrong.
* ---------------- * ----------------
*/ */
tup = heap_getnext(pg_type_scan, 0, (Buffer *) NULL); tup = heap_getnext(pg_type_scan, 0);
if (!PointerIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {
heap_endscan(pg_type_scan); heap_endscan(pg_type_scan);
heap_close(pg_type_desc); heap_close(pg_type_desc);
elog(ERROR, "DeletePgTypeTuple: %s type nonexistent", elog(ERROR, "DeletePgTypeTuple: %s type nonexistent",
&rdesc->rd_rel->relname); &rel->rd_rel->relname);
} }
/* ---------------- /* ----------------
@ -1212,7 +1155,7 @@ DeletePgTypeTuple(Relation rdesc)
* the schema. * the schema.
* ---------------- * ----------------
*/ */
atttup = heap_getnext(pg_attribute_scan, 0, (Buffer *) NULL); atttup = heap_getnext(pg_attribute_scan, 0);
if (PointerIsValid(atttup)) if (PointerIsValid(atttup))
{ {
@ -1224,7 +1167,7 @@ DeletePgTypeTuple(Relation rdesc)
heap_close(pg_attribute_desc); heap_close(pg_attribute_desc);
elog(ERROR, "DeletePgTypeTuple: att of type %s exists in relation %d", elog(ERROR, "DeletePgTypeTuple: att of type %s exists in relation %d",
&rdesc->rd_rel->relname, relid); &rel->rd_rel->relname, relid);
} }
heap_endscan(pg_attribute_scan); heap_endscan(pg_attribute_scan);
heap_close(pg_attribute_desc); heap_close(pg_attribute_desc);
@ -1235,9 +1178,9 @@ DeletePgTypeTuple(Relation rdesc)
* we release the read lock on pg_type. -mer 13 Aug 1991 * we release the read lock on pg_type. -mer 13 Aug 1991
* ---------------- * ----------------
*/ */
heap_endscan(pg_type_scan);
heap_delete(pg_type_desc, &tup->t_ctid); heap_delete(pg_type_desc, &tup->t_ctid);
heap_endscan(pg_type_scan);
heap_close(pg_type_desc); heap_close(pg_type_desc);
} }
@ -1249,7 +1192,7 @@ DeletePgTypeTuple(Relation rdesc)
void void
heap_destroy_with_catalog(char *relname) heap_destroy_with_catalog(char *relname)
{ {
Relation rdesc; Relation rel;
Oid rid; Oid rid;
/* ---------------- /* ----------------
@ -1257,50 +1200,50 @@ heap_destroy_with_catalog(char *relname)
* heap_openr() returns NULL. * heap_openr() returns NULL.
* ---------------- * ----------------
*/ */
rdesc = heap_openr(relname); rel = heap_openr(relname);
if (rdesc == NULL) if (rel == NULL)
elog(ERROR, "Relation %s Does Not Exist!", relname); elog(ERROR, "Relation %s Does Not Exist!", relname);
RelationSetLockForWrite(rdesc); RelationSetLockForWrite(rel);
rid = rdesc->rd_id; rid = rel->rd_id;
/* ---------------- /* ----------------
* prevent deletion of system relations * prevent deletion of system relations
* ---------------- * ----------------
*/ */
if (IsSystemRelationName(RelationGetRelationName(rdesc)->data)) if (IsSystemRelationName(RelationGetRelationName(rel)->data))
elog(ERROR, "amdestroy: cannot destroy %s relation", elog(ERROR, "amdestroy: cannot destroy %s relation",
&rdesc->rd_rel->relname); &rel->rd_rel->relname);
/* ---------------- /* ----------------
* remove inheritance information * remove inheritance information
* ---------------- * ----------------
*/ */
RelationRemoveInheritance(rdesc); RelationRemoveInheritance(rel);
/* ---------------- /* ----------------
* remove indexes if necessary * remove indexes if necessary
* ---------------- * ----------------
*/ */
if (rdesc->rd_rel->relhasindex) if (rel->rd_rel->relhasindex)
RelationRemoveIndexes(rdesc); RelationRemoveIndexes(rel);
/* ---------------- /* ----------------
* remove rules if necessary * remove rules if necessary
* ---------------- * ----------------
*/ */
if (rdesc->rd_rules != NULL) if (rel->rd_rules != NULL)
RelationRemoveRules(rid); RelationRemoveRules(rid);
/* triggers */ /* triggers */
if (rdesc->rd_rel->reltriggers > 0) if (rel->rd_rel->reltriggers > 0)
RelationRemoveTriggers(rdesc); RelationRemoveTriggers(rel);
/* ---------------- /* ----------------
* delete attribute tuples * delete attribute tuples
* ---------------- * ----------------
*/ */
DeletePgAttributeTuples(rdesc); DeletePgAttributeTuples(rel);
/* ---------------- /* ----------------
* delete type tuple. here we want to see the effects * delete type tuple. here we want to see the effects
@ -1308,41 +1251,41 @@ heap_destroy_with_catalog(char *relname)
* ---------------- * ----------------
*/ */
setheapoverride(true); setheapoverride(true);
DeletePgTypeTuple(rdesc); DeletePgTypeTuple(rel);
setheapoverride(false); setheapoverride(false);
/* ---------------- /* ----------------
* delete relation tuple * delete relation tuple
* ---------------- * ----------------
*/ */
DeletePgRelationTuple(rdesc); DeletePgRelationTuple(rel);
/* /*
* release dirty buffers of this relation * release dirty buffers of this relation
*/ */
ReleaseRelationBuffers(rdesc); ReleaseRelationBuffers(rel);
/* ---------------- /* ----------------
* flush the relation from the relcache * flush the relation from the relcache
* ---------------- * ----------------
* Does nothing!!! Flushing moved below. - vadim 06/04/97 * Does nothing!!! Flushing moved below. - vadim 06/04/97
RelationIdInvalidateRelationCacheByRelationId(rdesc->rd_id); RelationIdInvalidateRelationCacheByRelationId(rel->rd_id);
*/ */
RemoveConstraints(rdesc); RemoveConstraints(rel);
/* ---------------- /* ----------------
* unlink the relation and finish up. * unlink the relation and finish up.
* ---------------- * ----------------
*/ */
if (!(rdesc->rd_istemp) || !(rdesc->rd_tmpunlinked)) if (!(rel->rd_istemp) || !(rel->rd_tmpunlinked))
smgrunlink(DEFAULT_SMGR, rdesc); smgrunlink(DEFAULT_SMGR, rel);
rdesc->rd_tmpunlinked = TRUE; rel->rd_tmpunlinked = TRUE;
RelationUnsetLockForWrite(rdesc); RelationUnsetLockForWrite(rel);
heap_close(rdesc); heap_close(rel);
/* ok - flush the relation from the relcache */ /* ok - flush the relation from the relcache */
RelationForgetRelation(rid); RelationForgetRelation(rid);
@ -1355,14 +1298,14 @@ heap_destroy_with_catalog(char *relname)
*/ */
void void
heap_destroy(Relation rdesc) heap_destroy(Relation rel)
{ {
ReleaseRelationBuffers(rdesc); ReleaseRelationBuffers(rel);
if (!(rdesc->rd_istemp) || !(rdesc->rd_tmpunlinked)) if (!(rel->rd_istemp) || !(rel->rd_tmpunlinked))
smgrunlink(DEFAULT_SMGR, rdesc); smgrunlink(DEFAULT_SMGR, rel);
rdesc->rd_tmpunlinked = TRUE; rel->rd_tmpunlinked = TRUE;
heap_close(rdesc); heap_close(rel);
RemoveFromTempRelList(rdesc); RemoveFromTempRelList(rel);
} }
@ -1456,17 +1399,17 @@ void
DestroyTempRels(void) DestroyTempRels(void)
{ {
int i; int i;
Relation rdesc; Relation rel;
if (!tempRels) if (!tempRels)
return; return;
for (i = 0; i < tempRels->num; i++) for (i = 0; i < tempRels->num; i++)
{ {
rdesc = tempRels->rels[i]; rel = tempRels->rels[i];
/* rdesc may be NULL if it has been removed from the list already */ /* rel may be NULL if it has been removed from the list already */
if (rdesc) if (rel)
heap_destroy(rdesc); heap_destroy(rel);
} }
free(tempRels->rels); free(tempRels->rels);
free(tempRels); free(tempRels);
@ -1649,7 +1592,7 @@ RemoveAttrDefault(Relation rel)
adscan = heap_beginscan(adrel, 0, SnapshotNow, 1, &key); adscan = heap_beginscan(adrel, 0, SnapshotNow, 1, &key);
while (tup = heap_getnext(adscan, 0, (Buffer *) NULL), PointerIsValid(tup)) while (HeapTupleIsValid(tup = heap_getnext(adscan, 0)))
heap_delete(adrel, &tup->t_ctid); heap_delete(adrel, &tup->t_ctid);
heap_endscan(adscan); heap_endscan(adscan);
@ -1676,7 +1619,7 @@ RemoveRelCheck(Relation rel)
rcscan = heap_beginscan(rcrel, 0, SnapshotNow, 1, &key); rcscan = heap_beginscan(rcrel, 0, SnapshotNow, 1, &key);
while (tup = heap_getnext(rcscan, 0, (Buffer *) NULL), PointerIsValid(tup)) while (HeapTupleIsValid(tup = heap_getnext(rcscan, 0)))
heap_delete(rcrel, &tup->t_ctid); heap_delete(rcrel, &tup->t_ctid);
heap_endscan(rcscan); heap_endscan(rcscan);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.47 1998/07/27 19:37:47 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.48 1998/08/19 02:01:32 momjian Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
@ -65,8 +65,7 @@
/* non-export function prototypes */ /* non-export function prototypes */
static Oid static Oid
RelationNameGetObjectId(char *relationName, Relation pg_class, RelationNameGetObjectId(char *relationName, Relation pg_class);
bool setHasIndexAttribute);
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName); static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName);
static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo); static TupleDesc BuildFuncTupleDesc(FuncIndexInfo *funcInfo);
static TupleDesc static TupleDesc
@ -130,26 +129,15 @@ static FormData_pg_attribute sysatts[] = {
* RelationNameGetObjectId -- * RelationNameGetObjectId --
* Returns the object identifier for a relation given its name. * Returns the object identifier for a relation given its name.
* *
* > The HASINDEX attribute for the relation with this name will
* > be set if it exists and if it is indicated by the call argument.
* What a load of bull. This setHasIndexAttribute is totally ignored.
* This is yet another silly routine to scan the catalogs which should
* probably be replaced by SearchSysCacheTuple. -cim 1/19/91
*
* Note:
* Assumes relation name is valid.
* Assumes relation descriptor is valid.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
static Oid static Oid
RelationNameGetObjectId(char *relationName, RelationNameGetObjectId(char *relationName,
Relation pg_class, Relation pg_class)
bool setHasIndexAttribute)
{ {
HeapScanDesc pg_class_scan; HeapScanDesc pg_class_scan;
HeapTuple pg_class_tuple; HeapTuple pg_class_tuple;
Oid relationObjectId; Oid relationObjectId;
Buffer buffer;
ScanKeyData key; ScanKeyData key;
/* /*
@ -159,20 +147,20 @@ RelationNameGetObjectId(char *relationName,
if (!IsBootstrapProcessingMode()) if (!IsBootstrapProcessingMode())
{ {
pg_class_tuple = ClassNameIndexScan(pg_class, relationName); HeapTuple tuple;
if (HeapTupleIsValid(pg_class_tuple))
{ tuple = SearchSysCacheTuple(RELNAME,
relationObjectId = pg_class_tuple->t_oid; PointerGetDatum(relationName),
pfree(pg_class_tuple); 0, 0, 0);
}
if (HeapTupleIsValid(tuple))
return tuple->t_oid;
else else
relationObjectId = InvalidOid; return InvalidOid;
return (relationObjectId);
} }
/* ---------------- /* ----------------
* Bootstrap time, do this the hard way. * BOOTSTRAP TIME, do this the hard way.
* begin a scan of pg_class for the named relation * begin a scan of pg_class for the named relation
* ---------------- * ----------------
*/ */
@ -187,15 +175,12 @@ RelationNameGetObjectId(char *relationName,
* (the oid of the tuple we found). * (the oid of the tuple we found).
* ---------------- * ----------------
*/ */
pg_class_tuple = heap_getnext(pg_class_scan, 0, &buffer); pg_class_tuple = heap_getnext(pg_class_scan, 0);
if (!HeapTupleIsValid(pg_class_tuple)) if (!HeapTupleIsValid(pg_class_tuple))
relationObjectId = InvalidOid; relationObjectId = InvalidOid;
else else
{
relationObjectId = pg_class_tuple->t_oid; relationObjectId = pg_class_tuple->t_oid;
ReleaseBuffer(buffer);
}
/* ---------------- /* ----------------
* cleanup and return results * cleanup and return results
@ -203,8 +188,7 @@ RelationNameGetObjectId(char *relationName,
*/ */
heap_endscan(pg_class_scan); heap_endscan(pg_class_scan);
return return relationObjectId;
relationObjectId;
} }
@ -219,10 +203,6 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName)
Oid indoid; Oid indoid;
Oid heapoid; Oid heapoid;
/* ----------------
* XXX ADD INDEXING HERE
* ----------------
*/
/* ---------------- /* ----------------
* open pg_class and get the oid of the relation * open pg_class and get the oid of the relation
* corresponding to the name of the index relation. * corresponding to the name of the index relation.
@ -230,34 +210,18 @@ GetHeapRelationOid(char *heapRelationName, char *indexRelationName)
*/ */
pg_class = heap_openr(RelationRelationName); pg_class = heap_openr(RelationRelationName);
indoid = RelationNameGetObjectId(indexRelationName, indoid = RelationNameGetObjectId(indexRelationName, pg_class);
pg_class,
false);
if (OidIsValid(indoid)) if (OidIsValid(indoid))
elog(ERROR, "Cannot create index: '%s' already exists", elog(ERROR, "Cannot create index: '%s' already exists",
indexRelationName); indexRelationName);
/* ---------------- heapoid = RelationNameGetObjectId(heapRelationName, pg_class);
* get the object id of the heap relation
* ----------------
*/
heapoid = RelationNameGetObjectId(heapRelationName,
pg_class,
true);
/* ----------------
* check that the heap relation exists..
* ----------------
*/
if (!OidIsValid(heapoid)) if (!OidIsValid(heapoid))
elog(ERROR, "Cannot create index on '%s': relation does not exist", elog(ERROR, "Cannot create index on '%s': relation does not exist",
heapRelationName); heapRelationName);
/* ----------------
* close pg_class and return the heap relation oid
* ----------------
*/
heap_close(pg_class); heap_close(pg_class);
return heapoid; return heapoid;
@ -508,7 +472,7 @@ AccessMethodObjectIdGetAccessMethodTupleForm(Oid accessMethodObjectId)
pg_am_desc = heap_openr(AccessMethodRelationName); pg_am_desc = heap_openr(AccessMethodRelationName);
pg_am_scan = heap_beginscan(pg_am_desc, 0, SnapshotNow, 1, &key); pg_am_scan = heap_beginscan(pg_am_desc, 0, SnapshotNow, 1, &key);
pg_am_tuple = heap_getnext(pg_am_scan, 0, (Buffer *) NULL); pg_am_tuple = heap_getnext(pg_am_scan, 0);
/* ---------------- /* ----------------
* return NULL if not found * return NULL if not found
@ -597,7 +561,7 @@ UpdateRelationRelation(Relation indexRelation)
* company. * company.
* ---------------- * ----------------
*/ */
tuple->t_oid = indexRelation->rd_id; tuple->t_oid = RelationGetRelid(indexRelation);
heap_insert(pg_class, tuple); heap_insert(pg_class, tuple);
/* /*
@ -649,8 +613,7 @@ static void
AppendAttributeTuples(Relation indexRelation, int numatts) AppendAttributeTuples(Relation indexRelation, int numatts)
{ {
Relation pg_attribute; Relation pg_attribute;
HeapTuple tuple; HeapTuple init_tuple, cur_tuple = NULL, new_tuple;
HeapTuple newtuple;
bool hasind; bool hasind;
Relation idescs[Num_pg_attr_indices]; Relation idescs[Num_pg_attr_indices];
@ -686,7 +649,7 @@ AppendAttributeTuples(Relation indexRelation, int numatts)
value[Anum_pg_attribute_attnum - 1] = Int16GetDatum(1); value[Anum_pg_attribute_attnum - 1] = Int16GetDatum(1);
value[Anum_pg_attribute_attcacheoff - 1] = Int32GetDatum(-1); value[Anum_pg_attribute_attcacheoff - 1] = Int32GetDatum(-1);
tuple = heap_addheader(Natts_pg_attribute, init_tuple = heap_addheader(Natts_pg_attribute,
sizeof *(indexRelation->rd_att->attrs[0]), sizeof *(indexRelation->rd_att->attrs[0]),
(char *) (indexRelation->rd_att->attrs[0])); (char *) (indexRelation->rd_att->attrs[0]));
@ -701,19 +664,19 @@ AppendAttributeTuples(Relation indexRelation, int numatts)
* insert the first attribute tuple. * insert the first attribute tuple.
* ---------------- * ----------------
*/ */
tuple = heap_modifytuple(tuple, cur_tuple = heap_modifytuple(init_tuple,
InvalidBuffer,
pg_attribute, pg_attribute,
value, value,
nullv, nullv,
replace); replace);
pfree(init_tuple);
heap_insert(pg_attribute, tuple);
heap_insert(pg_attribute, cur_tuple);
if (hasind) if (hasind)
CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, tuple); CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, cur_tuple);
/* ---------------- /* ----------------
* now we use the information in the index tuple * now we use the information in the index cur_tuple
* descriptor to form the remaining attribute tuples. * descriptor to form the remaining attribute tuples.
* ---------------- * ----------------
*/ */
@ -725,42 +688,37 @@ AppendAttributeTuples(Relation indexRelation, int numatts)
* process the remaining attributes... * process the remaining attributes...
* ---------------- * ----------------
*/ */
memmove(GETSTRUCT(tuple), memmove(GETSTRUCT(cur_tuple),
(char *) indexTupDesc->attrs[i], (char *) indexTupDesc->attrs[i],
sizeof(FormData_pg_attribute)); sizeof(FormData_pg_attribute));
value[Anum_pg_attribute_attnum - 1] = Int16GetDatum(i + 1); value[Anum_pg_attribute_attnum - 1] = Int16GetDatum(i + 1);
newtuple = heap_modifytuple(tuple, new_tuple = heap_modifytuple(cur_tuple,
InvalidBuffer,
pg_attribute, pg_attribute,
value, value,
nullv, nullv,
replace); replace);
pfree(cur_tuple);
heap_insert(pg_attribute, newtuple); heap_insert(pg_attribute,new_tuple);
if (hasind) if (hasind)
CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, newtuple); CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, new_tuple);
/* ---------------- /* ----------------
* ModifyHeapTuple returns a new copy of a tuple * ModifyHeapTuple returns a new copy of a cur_tuple
* so we free the original and use the copy.. * so we free the original and use the copy..
* ---------------- * ----------------
*/ */
pfree(tuple); cur_tuple = new_tuple;
tuple = newtuple;
} }
/* ---------------- if (cur_tuple)
* close the attribute relation and free the tuple pfree(cur_tuple);
* ----------------
*/
heap_close(pg_attribute); heap_close(pg_attribute);
if (hasind) if (hasind)
CatalogCloseIndices(Num_pg_attr_indices, idescs); CatalogCloseIndices(Num_pg_attr_indices, idescs);
pfree(tuple);
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -899,9 +857,6 @@ UpdateIndexPredicate(Oid indexoid, Node *oldPred, Node *predicate)
Relation pg_index; Relation pg_index;
HeapTuple tuple; HeapTuple tuple;
HeapTuple newtup; HeapTuple newtup;
ScanKeyData entry;
HeapScanDesc scan;
Buffer buffer;
int i; int i;
Datum values[Natts_pg_index]; Datum values[Natts_pg_index];
char nulls[Natts_pg_index]; char nulls[Natts_pg_index];
@ -941,14 +896,11 @@ UpdateIndexPredicate(Oid indexoid, Node *oldPred, Node *predicate)
/* open the index system catalog relation */ /* open the index system catalog relation */
pg_index = heap_openr(IndexRelationName); pg_index = heap_openr(IndexRelationName);
ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_index_indexrelid, tuple = SearchSysCacheTuple(INDEXRELID,
F_OIDEQ, ObjectIdGetDatum(indexoid),
ObjectIdGetDatum(indexoid)); 0, 0, 0);
Assert(HeapTupleIsValid(tuple));
scan = heap_beginscan(pg_index, 0, SnapshotNow, 1, &entry);
tuple = heap_getnext(scan, 0, &buffer);
heap_endscan(scan);
for (i = 0; i < Natts_pg_index; i++) for (i = 0; i < Natts_pg_index; i++)
{ {
nulls[i] = heap_attisnull(tuple, i + 1) ? 'n' : ' '; nulls[i] = heap_attisnull(tuple, i + 1) ? 'n' : ' ';
@ -959,10 +911,11 @@ UpdateIndexPredicate(Oid indexoid, Node *oldPred, Node *predicate)
replace[Anum_pg_index_indpred - 1] = 'r'; replace[Anum_pg_index_indpred - 1] = 'r';
values[Anum_pg_index_indpred - 1] = (Datum) predText; values[Anum_pg_index_indpred - 1] = (Datum) predText;
newtup = heap_modifytuple(tuple, buffer, pg_index, values, nulls, replace); newtup = heap_modifytuple(tuple, pg_index, values, nulls, replace);
heap_replace(pg_index, &(newtup->t_ctid), newtup); heap_replace(pg_index, &newtup->t_ctid, newtup);
pfree(newtup);
heap_close(pg_index); heap_close(pg_index);
pfree(predText); pfree(predText);
} }
@ -1028,13 +981,13 @@ InitIndexStrategy(int numatts,
* catalogs, even though our transaction has not yet committed. * catalogs, even though our transaction has not yet committed.
* ---------------- * ----------------
*/ */
setheapoverride(1); setheapoverride(true);
IndexSupportInitialize(strategy, support, IndexSupportInitialize(strategy, support,
attrelid, accessMethodObjectId, attrelid, accessMethodObjectId,
amstrategies, amsupport, numatts); amstrategies, amsupport, numatts);
setheapoverride(0); setheapoverride(false);
/* ---------------- /* ----------------
* store the strategy information in the index reldesc * store the strategy information in the index reldesc
@ -1221,9 +1174,8 @@ index_destroy(Oid indexId)
Relation indexRelation; Relation indexRelation;
Relation catalogRelation; Relation catalogRelation;
HeapTuple tuple; HeapTuple tuple;
HeapScanDesc scan; int16 attnum;
ScanKeyData entry;
Assert(OidIsValid(indexId)); Assert(OidIsValid(indexId));
indexRelation = index_open(indexId); indexRelation = index_open(indexId);
@ -1234,17 +1186,14 @@ index_destroy(Oid indexId)
*/ */
catalogRelation = heap_openr(RelationRelationName); catalogRelation = heap_openr(RelationRelationName);
ScanKeyEntryInitialize(&entry, 0x0, ObjectIdAttributeNumber, tuple = SearchSysCacheTupleCopy(RELOID,
F_OIDEQ, ObjectIdGetDatum(indexId),
ObjectIdGetDatum(indexId));; 0, 0, 0);
scan = heap_beginscan(catalogRelation, 0, SnapshotNow, 1, &entry);
tuple = heap_getnext(scan, 0, (Buffer *) NULL);
AssertState(HeapTupleIsValid(tuple)); AssertState(HeapTupleIsValid(tuple));
heap_delete(catalogRelation, &tuple->t_ctid); heap_delete(catalogRelation, &tuple->t_ctid);
heap_endscan(scan); pfree(tuple);
heap_close(catalogRelation); heap_close(catalogRelation);
/* ---------------- /* ----------------
@ -1253,33 +1202,35 @@ index_destroy(Oid indexId)
*/ */
catalogRelation = heap_openr(AttributeRelationName); catalogRelation = heap_openr(AttributeRelationName);
entry.sk_attno = Anum_pg_attribute_attrelid; attnum = 1; /* indexes start at 1 */
scan = heap_beginscan(catalogRelation, 0, SnapshotNow, 1, &entry); while (HeapTupleIsValid(tuple = SearchSysCacheTupleCopy(ATTNUM,
ObjectIdGetDatum(indexId),
while (tuple = heap_getnext(scan, 0, (Buffer *) NULL), Int16GetDatum(attnum),
HeapTupleIsValid(tuple)) 0, 0)))
{
heap_delete(catalogRelation, &tuple->t_ctid); heap_delete(catalogRelation, &tuple->t_ctid);
heap_endscan(scan); pfree(tuple);
attnum++;
}
heap_close(catalogRelation); heap_close(catalogRelation);
/* ---------------- /* ----------------
* fix INDEX relation * fix INDEX relation
* ---------------- * ----------------
*/ */
catalogRelation = heap_openr(IndexRelationName); tuple = SearchSysCacheTupleCopy(INDEXRELID,
ObjectIdGetDatum(indexId),
0, 0, 0);
entry.sk_attno = Anum_pg_index_indexrelid;
scan = heap_beginscan(catalogRelation, 0, SnapshotNow, 1, &entry);
tuple = heap_getnext(scan, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
elog(NOTICE, "IndexRelationDestroy: %s's INDEX tuple missing", elog(NOTICE, "IndexRelationDestroy: %s's INDEX tuple missing",
RelationGetRelationName(indexRelation)); RelationGetRelationName(indexRelation));
} }
heap_delete(catalogRelation, &tuple->t_ctid); heap_delete(catalogRelation, &tuple->t_ctid);
heap_endscan(scan); pfree(tuple);
heap_close(catalogRelation); heap_close(catalogRelation);
/* /*
@ -1291,7 +1242,7 @@ index_destroy(Oid indexId)
elog(ERROR, "amdestroyr: unlink: %m"); elog(ERROR, "amdestroyr: unlink: %m");
index_close(indexRelation); index_close(indexRelation);
RelationForgetRelation(indexRelation->rd_id); RelationForgetRelation(RelationGetRelid(indexRelation));
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -1307,7 +1258,6 @@ FormIndexDatum(int numberOfAttributes,
AttrNumber attributeNumber[], AttrNumber attributeNumber[],
HeapTuple heapTuple, HeapTuple heapTuple,
TupleDesc heapDescriptor, TupleDesc heapDescriptor,
Buffer buffer,
Datum *datum, Datum *datum,
char *nullv, char *nullv,
FuncIndexInfoPtr fInfo) FuncIndexInfoPtr fInfo)
@ -1333,8 +1283,7 @@ FormIndexDatum(int numberOfAttributes,
offset, offset,
attributeNumber, attributeNumber,
fInfo, fInfo,
&isNull, &isNull));
buffer));
nullv[offset] = (isNull) ? 'n' : ' '; nullv[offset] = (isNull) ? 'n' : ' ';
} }
@ -1350,25 +1299,16 @@ UpdateStats(Oid relid, long reltuples, bool hasindex)
{ {
Relation whichRel; Relation whichRel;
Relation pg_class; Relation pg_class;
HeapScanDesc pg_class_scan; HeapTuple tuple;
HeapTuple htup;
HeapTuple newtup; HeapTuple newtup;
long relpages; long relpages;
Buffer buffer;
int i; int i;
Form_pg_class rd_rel; Form_pg_class rd_rel;
Relation idescs[Num_pg_class_indices]; Relation idescs[Num_pg_class_indices];
static ScanKeyData key[1] = {
{0, ObjectIdAttributeNumber, F_OIDEQ}
};
Datum values[Natts_pg_class]; Datum values[Natts_pg_class];
char nulls[Natts_pg_class]; char nulls[Natts_pg_class];
char replace[Natts_pg_class]; char replace[Natts_pg_class];
fmgr_info(F_OIDEQ, &key[0].sk_func);
key[0].sk_nargs = key[0].sk_func.fn_nargs;
/* ---------------- /* ----------------
* This routine handles updates for both the heap and index relation * This routine handles updates for both the heap and index relation
* statistics. In order to guarantee that we're able to *see* the index * statistics. In order to guarantee that we're able to *see* the index
@ -1399,21 +1339,16 @@ UpdateStats(Oid relid, long reltuples, bool hasindex)
pg_class = heap_openr(RelationRelationName); pg_class = heap_openr(RelationRelationName);
if (!RelationIsValid(pg_class)) if (!RelationIsValid(pg_class))
elog(ERROR, "UpdateStats: could not open RELATION relation"); elog(ERROR, "UpdateStats: could not open RELATION relation");
key[0].sk_argument = ObjectIdGetDatum(relid);
pg_class_scan = tuple = SearchSysCacheTupleCopy(RELOID,
heap_beginscan(pg_class, 0, SnapshotNow, 1, key); ObjectIdGetDatum(relid),
0, 0, 0);
if (!HeapScanIsValid(pg_class_scan)) if (!HeapTupleIsValid(tuple))
{ {
heap_close(pg_class); heap_close(pg_class);
elog(ERROR, "UpdateStats: cannot scan RELATION relation"); elog(ERROR, "UpdateStats: cannot scan RELATION relation");
} }
/* if the heap_open above succeeded, then so will this heap_getnext() */
htup = heap_getnext(pg_class_scan, 0, &buffer);
heap_endscan(pg_class_scan);
/* ---------------- /* ----------------
* update statistics * update statistics
* ---------------- * ----------------
@ -1432,7 +1367,7 @@ UpdateStats(Oid relid, long reltuples, bool hasindex)
for (i = 0; i < Natts_pg_class; i++) for (i = 0; i < Natts_pg_class; i++)
{ {
nulls[i] = heap_attisnull(htup, i + 1) ? 'n' : ' '; nulls[i] = heap_attisnull(tuple, i + 1) ? 'n' : ' ';
replace[i] = ' '; replace[i] = ' ';
values[i] = (Datum) NULL; values[i] = (Datum) NULL;
} }
@ -1451,7 +1386,7 @@ UpdateStats(Oid relid, long reltuples, bool hasindex)
* visibility of changes, so we cheat. * visibility of changes, so we cheat.
*/ */
rd_rel = (Form_pg_class) GETSTRUCT(htup); rd_rel = (Form_pg_class) GETSTRUCT(tuple);
rd_rel->relpages = relpages; rd_rel->relpages = relpages;
rd_rel->reltuples = reltuples; rd_rel->reltuples = reltuples;
rd_rel->relhasindex = hasindex; rd_rel->relhasindex = hasindex;
@ -1466,14 +1401,15 @@ UpdateStats(Oid relid, long reltuples, bool hasindex)
replace[Anum_pg_class_relhasindex - 1] = 'r'; replace[Anum_pg_class_relhasindex - 1] = 'r';
values[Anum_pg_class_relhasindex - 1] = CharGetDatum(hasindex); values[Anum_pg_class_relhasindex - 1] = CharGetDatum(hasindex);
newtup = heap_modifytuple(htup, buffer, pg_class, values, newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
nulls, replace); heap_replace(pg_class, &newtup->t_ctid, newtup);
heap_replace(pg_class, &(newtup->t_ctid), newtup); pfree(newtup);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, newtup); CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, newtup);
CatalogCloseIndices(Num_pg_class_indices, idescs); CatalogCloseIndices(Num_pg_class_indices, idescs);
} }
pfree(tuple);
heap_close(pg_class); heap_close(pg_class);
heap_close(whichRel); heap_close(whichRel);
} }
@ -1521,8 +1457,6 @@ DefaultBuild(Relation heapRelation,
{ {
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple heapTuple; HeapTuple heapTuple;
Buffer buffer;
IndexTuple indexTuple; IndexTuple indexTuple;
TupleDesc heapDescriptor; TupleDesc heapDescriptor;
TupleDesc indexDescriptor; TupleDesc indexDescriptor;
@ -1582,7 +1516,8 @@ DefaultBuild(Relation heapRelation,
tupleTable = ExecCreateTupleTable(1); tupleTable = ExecCreateTupleTable(1);
slot = ExecAllocTableSlot(tupleTable); slot = ExecAllocTableSlot(tupleTable);
econtext = makeNode(ExprContext); econtext = makeNode(ExprContext);
FillDummyExprContext(econtext, slot, heapDescriptor, buffer); /* last parameter was junk being sent bjm 1998/08/17 */
FillDummyExprContext(econtext, slot, heapDescriptor, InvalidBuffer);
} }
else else
{ {
@ -1611,10 +1546,8 @@ DefaultBuild(Relation heapRelation,
* with correct statistics when we're done building the index. * with correct statistics when we're done building the index.
* ---------------- * ----------------
*/ */
while (heapTuple = heap_getnext(scan, 0, &buffer), while (HeapTupleIsValid(heapTuple = heap_getnext(scan, 0)))
HeapTupleIsValid(heapTuple))
{ {
reltuples++; reltuples++;
/* /*
@ -1659,7 +1592,6 @@ DefaultBuild(Relation heapRelation,
attributeNumber, /* array of att nums to extract */ attributeNumber, /* array of att nums to extract */
heapTuple, /* tuple from base relation */ heapTuple, /* tuple from base relation */
heapDescriptor, /* heap tuple's descriptor */ heapDescriptor, /* heap tuple's descriptor */
buffer, /* buffer used in the scan */
datum, /* return: array of attributes */ datum, /* return: array of attributes */
nullv, /* return: array of char's */ nullv, /* return: array of char's */
funcInfo); funcInfo);
@ -1697,13 +1629,14 @@ DefaultBuild(Relation heapRelation,
* the vacuum daemon, but we update them here to make the index useful * the vacuum daemon, but we update them here to make the index useful
* as soon as possible. * as soon as possible.
*/ */
UpdateStats(heapRelation->rd_id, reltuples, true); UpdateStats(RelationGetRelid(heapRelation), reltuples, true);
UpdateStats(indexRelation->rd_id, indtuples, false); UpdateStats(RelationGetRelid(indexRelation), indtuples, false);
if (oldPred != NULL) if (oldPred != NULL)
{ {
if (indtuples == reltuples) if (indtuples == reltuples)
predicate = NULL; predicate = NULL;
UpdateIndexPredicate(indexRelation->rd_id, oldPred, predicate); UpdateIndexPredicate(RelationGetRelid(indexRelation),
oldPred, predicate);
} }
} }
@ -1814,12 +1747,11 @@ IndexIsUniqueNoCache(Oid indexId)
scandesc = heap_beginscan(pg_index, 0, SnapshotSelf, 1, skey); scandesc = heap_beginscan(pg_index, 0, SnapshotSelf, 1, skey);
tuple = heap_getnext(scandesc, 0, NULL); /* NO CACHE */
tuple = heap_getnext(scandesc, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ elog(ERROR, "IndexIsUniqueNoCache: can't find index id %d", indexId);
elog(ERROR, "IndexIsUniqueNoCache: can't find index id %d",
indexId);
}
index = (IndexTupleForm) GETSTRUCT(tuple); index = (IndexTupleForm) GETSTRUCT(tuple);
Assert(index->indexrelid == indexId); Assert(index->indexrelid == indexId);
isunique = index->indisunique; isunique = index->indisunique;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.19 1998/07/27 19:37:48 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.20 1998/08/19 02:01:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -29,7 +29,6 @@
#include "nodes/execnodes.h" #include "nodes/execnodes.h"
#include "storage/bufmgr.h" #include "storage/bufmgr.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/oidcompos.h"
#include "utils/syscache.h" #include "utils/syscache.h"
/* /*
@ -62,10 +61,10 @@ char *Name_pg_relcheck_indices[Num_pg_relcheck_indices] = {RelCheckIndex};
char *Name_pg_trigger_indices[Num_pg_trigger_indices] = {TriggerRelidIndex}; char *Name_pg_trigger_indices[Num_pg_trigger_indices] = {TriggerRelidIndex};
static HeapTuple static HeapTuple CatalogIndexFetchTuple(Relation heapRelation,
CatalogIndexFetchTuple(Relation heapRelation,
Relation idesc, Relation idesc,
ScanKey skey); ScanKey skey,
int16 num_keys);
/* /*
@ -127,7 +126,7 @@ CatalogIndexInsert(Relation *idescs,
indexDescriptor = RelationGetTupleDescriptor(idescs[i]); indexDescriptor = RelationGetTupleDescriptor(idescs[i]);
pgIndexTup = SearchSysCacheTuple(INDEXRELID, pgIndexTup = SearchSysCacheTuple(INDEXRELID,
Int32GetDatum(idescs[i]->rd_id), ObjectIdGetDatum(idescs[i]->rd_id),
0, 0, 0); 0, 0, 0);
Assert(pgIndexTup); Assert(pgIndexTup);
pgIndexP = (IndexTupleForm) GETSTRUCT(pgIndexTup); pgIndexP = (IndexTupleForm) GETSTRUCT(pgIndexTup);
@ -156,13 +155,12 @@ CatalogIndexInsert(Relation *idescs,
(AttrNumber *) &pgIndexP->indkey[0], (AttrNumber *) &pgIndexP->indkey[0],
heapTuple, heapTuple,
heapDescriptor, heapDescriptor,
InvalidBuffer,
&datum, &datum,
nulls, nulls,
finfoP); finfoP);
indexRes = index_insert(idescs[i], &datum, nulls, indexRes = index_insert(idescs[i], &datum, nulls,
&(heapTuple->t_ctid), heapRelation); &heapTuple->t_ctid, heapRelation);
if (indexRes) if (indexRes)
pfree(indexRes); pfree(indexRes);
} }
@ -223,16 +221,16 @@ CatalogHasIndex(char *catName, Oid catId)
static HeapTuple static HeapTuple
CatalogIndexFetchTuple(Relation heapRelation, CatalogIndexFetchTuple(Relation heapRelation,
Relation idesc, Relation idesc,
ScanKey skey) ScanKey skey,
int16 num_keys)
{ {
IndexScanDesc sd; IndexScanDesc sd;
RetrieveIndexResult indexRes; RetrieveIndexResult indexRes;
HeapTuple tuple; HeapTuple tuple;
Buffer buffer; Buffer buffer;
sd = index_beginscan(idesc, false, 1, skey); sd = index_beginscan(idesc, false, num_keys, skey);
tuple = (HeapTuple) NULL; tuple = (HeapTuple) NULL;
do do
{ {
indexRes = index_getnext(sd, ForwardScanDirection); indexRes = index_getnext(sd, ForwardScanDirection);
@ -249,10 +247,10 @@ CatalogIndexFetchTuple(Relation heapRelation,
} while (!HeapTupleIsValid(tuple)); } while (!HeapTupleIsValid(tuple));
if (HeapTupleIsValid(tuple)) if (HeapTupleIsValid(tuple))
{
tuple = heap_copytuple(tuple); tuple = heap_copytuple(tuple);
if (BufferIsValid(buffer))
ReleaseBuffer(buffer); ReleaseBuffer(buffer);
}
index_endscan(sd); index_endscan(sd);
pfree(sd); pfree(sd);
@ -271,22 +269,25 @@ AttributeNameIndexScan(Relation heapRelation,
char *attname) char *attname)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[2];
OidName keyarg;
HeapTuple tuple; HeapTuple tuple;
keyarg = mkoidname(relid, attname); ScanKeyEntryInitialize(&skey[0],
ScanKeyEntryInitialize(&skey,
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDNAMEEQ, (RegProcedure)F_OIDEQ,
(Datum) keyarg); Int32GetDatum(relid));
ScanKeyEntryInitialize(&skey[1],
(bits16) 0x0,
(AttrNumber) 2,
(RegProcedure)F_NAMEEQ,
NameGetDatum(attname));
idesc = index_openr(AttributeNameIndex); idesc = index_openr(AttributeNameIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 2);
index_close(idesc); index_close(idesc);
pfree(keyarg);
return tuple; return tuple;
} }
@ -297,22 +298,25 @@ AttributeNumIndexScan(Relation heapRelation,
AttrNumber attnum) AttrNumber attnum)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[2];
OidInt2 keyarg;
HeapTuple tuple; HeapTuple tuple;
keyarg = mkoidint2(relid, (uint16) attnum); ScanKeyEntryInitialize(&skey[0],
ScanKeyEntryInitialize(&skey,
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDINT2EQ, (RegProcedure)F_OIDEQ,
(Datum) keyarg); Int32GetDatum(relid));
ScanKeyEntryInitialize(&skey[1],
(bits16) 0x0,
(AttrNumber) 2,
(RegProcedure)F_INT2EQ,
Int16GetDatum(attnum));
idesc = index_openr(AttributeNumIndex); idesc = index_openr(AttributeNumIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 2);
index_close(idesc); index_close(idesc);
pfree(keyarg);
return tuple; return tuple;
} }
@ -321,17 +325,17 @@ HeapTuple
ProcedureOidIndexScan(Relation heapRelation, Oid procId) ProcedureOidIndexScan(Relation heapRelation, Oid procId)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[1];
HeapTuple tuple; HeapTuple tuple;
ScanKeyEntryInitialize(&skey, ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDEQ, (RegProcedure) F_OIDEQ,
(Datum) procId); (Datum) procId);
idesc = index_openr(ProcedureOidIndex); idesc = index_openr(ProcedureOidIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1);
index_close(idesc); index_close(idesc);
@ -343,92 +347,37 @@ ProcedureOidIndexScan(Relation heapRelation, Oid procId)
HeapTuple HeapTuple
ProcedureNameIndexScan(Relation heapRelation, ProcedureNameIndexScan(Relation heapRelation,
char *procName, char *procName,
int nargs, int2 nargs,
Oid *argTypes) Oid *argTypes)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[3];
HeapTuple tuple; /* tuple being tested */ HeapTuple tuple;
HeapTuple return_tuple; /* The tuple pointer we eventually return */
IndexScanDesc sd;
RetrieveIndexResult indexRes;
Buffer buffer;
Form_pg_proc pgProcP;
bool ScanComplete;
/* ScanKeyEntryInitialize(&skey[0],
* The index scan is complete, i.e. we've scanned everything there is
* to scan.
*/
bool FoundMatch;
/*
* In scanning pg_proc, we have found a row that meets our search
* criteria.
*/
ScanKeyEntryInitialize(&skey,
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_NAMEEQ, (RegProcedure) F_NAMEEQ,
(Datum) procName); (Datum) procName);
ScanKeyEntryInitialize(&skey[1],
(bits16) 0x0,
(AttrNumber) 2,
(RegProcedure) F_INT2EQ,
Int16GetDatum(nargs));
ScanKeyEntryInitialize(&skey[2],
(bits16) 0x0,
(AttrNumber) 3,
(RegProcedure) F_OID8EQ,
(Datum) argTypes);
idesc = index_openr(ProcedureNameIndex); idesc = index_openr(ProcedureNameIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 3);
sd = index_beginscan(idesc, false, 1, &skey);
/*
* for now, we do the work usually done by CatalogIndexFetchTuple by
* hand, so that we can check that the other keys match. when
* multi-key indices are added, they will be used here.
*/
tuple = (HeapTuple) NULL; /* initial value */
ScanComplete = false; /* Scan hasn't begun yet */
FoundMatch = false; /* No match yet; haven't even looked. */
while (!FoundMatch && !ScanComplete)
{
indexRes = index_getnext(sd, ForwardScanDirection);
if (indexRes)
{
ItemPointer iptr;
iptr = &indexRes->heap_iptr;
tuple = heap_fetch(heapRelation, SnapshotNow, iptr, &buffer);
pfree(indexRes);
if (HeapTupleIsValid(tuple))
{
/*
* Here's a row for a procedure that has the sought
* procedure name. To be a match, though, we need it to
* have the right number and type of arguments too, so we
* check that now.
*/
pgProcP = (Form_pg_proc) GETSTRUCT(tuple);
if (pgProcP->pronargs == nargs &&
oid8eq(&(pgProcP->proargtypes[0]), argTypes))
FoundMatch = true;
else
ReleaseBuffer(buffer);
}
}
else
ScanComplete = true;
}
if (FoundMatch)
{
Assert(HeapTupleIsValid(tuple));
return_tuple = heap_copytuple(tuple);
ReleaseBuffer(buffer);
}
else
return_tuple = (HeapTuple) NULL;
index_endscan(sd);
index_close(idesc); index_close(idesc);
return return_tuple; return tuple;
} }
@ -437,40 +386,19 @@ HeapTuple
ProcedureSrcIndexScan(Relation heapRelation, text *procSrc) ProcedureSrcIndexScan(Relation heapRelation, text *procSrc)
{ {
Relation idesc; Relation idesc;
IndexScanDesc sd; ScanKeyData skey[1];
ScanKeyData skey;
RetrieveIndexResult indexRes;
HeapTuple tuple; HeapTuple tuple;
Buffer buffer;
ScanKeyEntryInitialize(&skey, ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) Anum_pg_proc_prosrc, (AttrNumber) 1,
(RegProcedure) F_TEXTEQ, (RegProcedure) F_TEXTEQ,
(Datum) procSrc); (Datum) procSrc);
idesc = index_openr(ProcedureSrcIndex); idesc = index_openr(ProcedureSrcIndex);
sd = index_beginscan(idesc, false, 1, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1);
indexRes = index_getnext(sd, ForwardScanDirection); index_close(idesc);
if (indexRes)
{
ItemPointer iptr;
iptr = &indexRes->heap_iptr;
tuple = heap_fetch(heapRelation, SnapshotNow, iptr, &buffer);
pfree(indexRes);
}
else
tuple = (HeapTuple) NULL;
if (HeapTupleIsValid(tuple))
{
tuple = heap_copytuple(tuple);
ReleaseBuffer(buffer);
}
index_endscan(sd);
return tuple; return tuple;
} }
@ -479,17 +407,17 @@ HeapTuple
TypeOidIndexScan(Relation heapRelation, Oid typeId) TypeOidIndexScan(Relation heapRelation, Oid typeId)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[1];
HeapTuple tuple; HeapTuple tuple;
ScanKeyEntryInitialize(&skey, ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDEQ, (RegProcedure) F_OIDEQ,
(Datum) typeId); (Datum) typeId);
idesc = index_openr(TypeOidIndex); idesc = index_openr(TypeOidIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1);
index_close(idesc); index_close(idesc);
@ -500,17 +428,17 @@ HeapTuple
TypeNameIndexScan(Relation heapRelation, char *typeName) TypeNameIndexScan(Relation heapRelation, char *typeName)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[1];
HeapTuple tuple; HeapTuple tuple;
ScanKeyEntryInitialize(&skey, ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_NAMEEQ, (RegProcedure) F_NAMEEQ,
(Datum) typeName); (Datum) typeName);
idesc = index_openr(TypeNameIndex); idesc = index_openr(TypeNameIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1);
index_close(idesc); index_close(idesc);
@ -521,18 +449,17 @@ HeapTuple
ClassNameIndexScan(Relation heapRelation, char *relName) ClassNameIndexScan(Relation heapRelation, char *relName)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[1];
HeapTuple tuple; HeapTuple tuple;
ScanKeyEntryInitialize(&skey, ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_NAMEEQ, (RegProcedure) F_NAMEEQ,
(Datum) relName); (Datum) relName);
idesc = index_openr(ClassNameIndex); idesc = index_openr(ClassNameIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey);
index_close(idesc); index_close(idesc);
return tuple; return tuple;
@ -542,17 +469,17 @@ HeapTuple
ClassOidIndexScan(Relation heapRelation, Oid relId) ClassOidIndexScan(Relation heapRelation, Oid relId)
{ {
Relation idesc; Relation idesc;
ScanKeyData skey; ScanKeyData skey[1];
HeapTuple tuple; HeapTuple tuple;
ScanKeyEntryInitialize(&skey, ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDEQ, (RegProcedure) F_OIDEQ,
(Datum) relId); (Datum) relId);
idesc = index_openr(ClassOidIndex); idesc = index_openr(ClassOidIndex);
tuple = CatalogIndexFetchTuple(heapRelation, idesc, &skey); tuple = CatalogIndexFetchTuple(heapRelation, idesc, skey, 1);
index_close(idesc); index_close(idesc);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.14 1998/04/01 15:35:01 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.15 1998/08/19 02:01:34 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -155,7 +155,8 @@ AggregateCreate(char *aggName,
elog(ERROR, "AggregateCreate: bogus function '%s'", aggfinalfnName); elog(ERROR, "AggregateCreate: bogus function '%s'", aggfinalfnName);
} }
tup = SearchSysCacheTuple(AGGNAME, PointerGetDatum(aggName), tup = SearchSysCacheTuple(AGGNAME,
PointerGetDatum(aggName),
ObjectIdGetDatum(xbase), ObjectIdGetDatum(xbase),
0, 0); 0, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
@ -286,7 +287,7 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
tup = SearchSysCacheTuple(AGGNAME, tup = SearchSysCacheTuple(AGGNAME,
PointerGetDatum(aggName), PointerGetDatum(aggName),
PointerGetDatum(basetype), ObjectIdGetDatum(basetype),
0, 0); 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "AggNameGetInitVal: cache lookup failed for aggregate '%s'", elog(ERROR, "AggNameGetInitVal: cache lookup failed for aggregate '%s'",
@ -325,7 +326,8 @@ AggNameGetInitVal(char *aggName, Oid basetype, int xfuncno, bool *isNull)
strInitVal = textout(textInitVal); strInitVal = textout(textInitVal);
heap_close(aggRel); heap_close(aggRel);
tup = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(transtype), tup = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(transtype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.26 1998/07/27 19:37:49 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.27 1998/08/19 02:01:36 momjian Exp $
* *
* NOTES * NOTES
* these routines moved here from commands/define.c and somewhat cleaned up. * these routines moved here from commands/define.c and somewhat cleaned up.
@ -120,7 +120,7 @@ OperatorGetWithOpenRelation(Relation pg_operator_desc,
*/ */
pg_operator_scan = heap_beginscan(pg_operator_desc, pg_operator_scan = heap_beginscan(pg_operator_desc,
0, 0,
SnapshotSelf, SnapshotSelf, /* no cache? */
3, 3,
opKey); opKey);
@ -129,7 +129,7 @@ OperatorGetWithOpenRelation(Relation pg_operator_desc,
* the proper return oid value. * the proper return oid value.
* ---------------- * ----------------
*/ */
tup = heap_getnext(pg_operator_scan, 0, (Buffer *) 0); tup = heap_getnext(pg_operator_scan, 0);
operatorObjectId = HeapTupleIsValid(tup) ? tup->t_oid : InvalidOid; operatorObjectId = HeapTupleIsValid(tup) ? tup->t_oid : InvalidOid;
/* ---------------- /* ----------------
@ -138,8 +138,7 @@ OperatorGetWithOpenRelation(Relation pg_operator_desc,
*/ */
heap_endscan(pg_operator_scan); heap_endscan(pg_operator_scan);
return return operatorObjectId;
operatorObjectId;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -462,8 +461,6 @@ OperatorDef(char *operatorName,
HeapScanDesc pg_operator_scan; HeapScanDesc pg_operator_scan;
HeapTuple tup; HeapTuple tup;
Buffer buffer;
ItemPointerData itemPointerData;
char nulls[Natts_pg_operator]; char nulls[Natts_pg_operator];
char replaces[Natts_pg_operator]; char replaces[Natts_pg_operator];
Datum values[Natts_pg_operator]; Datum values[Natts_pg_operator];
@ -549,7 +546,7 @@ OperatorDef(char *operatorName,
PointerGetDatum(typeId), PointerGetDatum(typeId),
0); 0);
if (!PointerIsValid(tup)) if (!HeapTupleIsValid(tup))
func_error("OperatorDef", procedureName, nargs, typeId, NULL); func_error("OperatorDef", procedureName, nargs, typeId, NULL);
values[Anum_pg_operator_oprcode - 1] = ObjectIdGetDatum(tup->t_oid); values[Anum_pg_operator_oprcode - 1] = ObjectIdGetDatum(tup->t_oid);
@ -693,7 +690,7 @@ OperatorDef(char *operatorName,
/* last three fields were filled in first */ /* last three fields were filled in first */
/* /*
* If we are adding to an operator shell, get its t_ctid and a buffer. * If we are adding to an operator shell, get its t_ctid
*/ */
pg_operator_desc = heap_openr(OperatorRelationName); pg_operator_desc = heap_openr(OperatorRelationName);
@ -705,30 +702,27 @@ OperatorDef(char *operatorName,
pg_operator_scan = heap_beginscan(pg_operator_desc, pg_operator_scan = heap_beginscan(pg_operator_desc,
0, 0,
SnapshotSelf, SnapshotSelf, /* no cache? */
3, 3,
opKey); opKey);
tup = heap_getnext(pg_operator_scan, 0, &buffer); tup = heap_getnext(pg_operator_scan, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
tup = heap_modifytuple(tup, tup = heap_modifytuple(tup,
buffer,
pg_operator_desc, pg_operator_desc,
values, values,
nulls, nulls,
replaces); replaces);
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
setheapoverride(true); setheapoverride(true);
heap_replace(pg_operator_desc, &itemPointerData, tup); heap_replace(pg_operator_desc, &tup->t_ctid, tup);
setheapoverride(false); setheapoverride(false);
} }
else else
elog(ERROR, "OperatorDef: no operator %d", other_oid); elog(ERROR, "OperatorDef: no operator %d", other_oid);
heap_endscan(pg_operator_scan); heap_endscan(pg_operator_scan);
} }
else else
{ {
@ -777,8 +771,6 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
Relation pg_operator_desc; Relation pg_operator_desc;
HeapScanDesc pg_operator_scan; HeapScanDesc pg_operator_scan;
HeapTuple tup; HeapTuple tup;
Buffer buffer;
ItemPointerData itemPointerData;
char nulls[Natts_pg_operator]; char nulls[Natts_pg_operator];
char replaces[Natts_pg_operator]; char replaces[Natts_pg_operator];
Datum values[Natts_pg_operator]; Datum values[Natts_pg_operator];
@ -804,11 +796,11 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
pg_operator_scan = heap_beginscan(pg_operator_desc, pg_operator_scan = heap_beginscan(pg_operator_desc,
0, 0,
SnapshotSelf, SnapshotSelf, /* no cache? */
1, 1,
opKey); opKey);
tup = heap_getnext(pg_operator_scan, 0, &buffer); tup = heap_getnext(pg_operator_scan, 0);
/* if the commutator and negator are the same operator, do one update */ /* if the commutator and negator are the same operator, do one update */
if (commId == negId) if (commId == negId)
@ -837,16 +829,13 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
} }
tup = heap_modifytuple(tup, tup = heap_modifytuple(tup,
buffer,
pg_operator_desc, pg_operator_desc,
values, values,
nulls, nulls,
replaces); replaces);
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
setheapoverride(true); setheapoverride(true);
heap_replace(pg_operator_desc, &itemPointerData, tup); heap_replace(pg_operator_desc, &tup->t_ctid, tup);
setheapoverride(false); setheapoverride(false);
} }
@ -855,10 +844,6 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
heap_close(pg_operator_desc); heap_close(pg_operator_desc);
/* release the buffer properly */
if (BufferIsValid(buffer))
ReleaseBuffer(buffer);
return; return;
} }
@ -869,24 +854,17 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
values[Anum_pg_operator_oprcom - 1] = ObjectIdGetDatum(baseId); values[Anum_pg_operator_oprcom - 1] = ObjectIdGetDatum(baseId);
replaces[Anum_pg_operator_oprcom - 1] = 'r'; replaces[Anum_pg_operator_oprcom - 1] = 'r';
tup = heap_modifytuple(tup, tup = heap_modifytuple(tup,
buffer,
pg_operator_desc, pg_operator_desc,
values, values,
nulls, nulls,
replaces); replaces);
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
setheapoverride(true); setheapoverride(true);
heap_replace(pg_operator_desc, &itemPointerData, tup); heap_replace(pg_operator_desc, &tup->t_ctid, tup);
setheapoverride(false); setheapoverride(false);
values[Anum_pg_operator_oprcom - 1] = (Datum) NULL; values[Anum_pg_operator_oprcom - 1] = (Datum) NULL;
replaces[Anum_pg_operator_oprcom - 1] = ' '; replaces[Anum_pg_operator_oprcom - 1] = ' ';
/* release the buffer properly */
if (BufferIsValid(buffer))
ReleaseBuffer(buffer);
} }
/* check and update the negator, if necessary */ /* check and update the negator, if necessary */
@ -894,34 +872,27 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
pg_operator_scan = heap_beginscan(pg_operator_desc, pg_operator_scan = heap_beginscan(pg_operator_desc,
0, 0,
SnapshotSelf, SnapshotSelf, /* no cache? */
1, 1,
opKey); opKey);
tup = heap_getnext(pg_operator_scan, 0, &buffer); tup = heap_getnext(pg_operator_scan, 0);
if (HeapTupleIsValid(tup) && if (HeapTupleIsValid(tup) &&
!(OidIsValid(((OperatorTupleForm) GETSTRUCT(tup))->oprnegate))) !(OidIsValid(((OperatorTupleForm) GETSTRUCT(tup))->oprnegate)))
{ {
values[Anum_pg_operator_oprnegate - 1] = ObjectIdGetDatum(baseId); values[Anum_pg_operator_oprnegate - 1] = ObjectIdGetDatum(baseId);
replaces[Anum_pg_operator_oprnegate - 1] = 'r'; replaces[Anum_pg_operator_oprnegate - 1] = 'r';
tup = heap_modifytuple(tup, tup = heap_modifytuple(tup,
buffer,
pg_operator_desc, pg_operator_desc,
values, values,
nulls, nulls,
replaces); replaces);
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
setheapoverride(true); setheapoverride(true);
heap_replace(pg_operator_desc, &itemPointerData, tup); heap_replace(pg_operator_desc, &tup->t_ctid, tup);
setheapoverride(false); setheapoverride(false);
} }
/* release the buffer properly */
if (BufferIsValid(buffer))
ReleaseBuffer(buffer);
heap_endscan(pg_operator_scan); heap_endscan(pg_operator_scan);
heap_close(pg_operator_desc); heap_close(pg_operator_desc);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.18 1998/06/15 19:28:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.19 1998/08/19 02:01:37 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -57,7 +57,7 @@ ProcedureCreate(char *procedureName,
CommandDest dest) CommandDest dest)
{ {
int i; int i;
Relation rdesc; Relation rel;
HeapTuple tup; HeapTuple tup;
bool defined; bool defined;
uint16 parameterCount; uint16 parameterCount;
@ -258,23 +258,23 @@ ProcedureCreate(char *procedureName,
values[i++] = (Datum) fmgr(F_TEXTIN, prosrc); /* prosrc */ values[i++] = (Datum) fmgr(F_TEXTIN, prosrc); /* prosrc */
values[i++] = (Datum) fmgr(F_TEXTIN, probin); /* probin */ values[i++] = (Datum) fmgr(F_TEXTIN, probin); /* probin */
rdesc = heap_openr(ProcedureRelationName); rel = heap_openr(ProcedureRelationName);
tupDesc = rdesc->rd_att; tupDesc = rel->rd_att;
tup = heap_formtuple(tupDesc, tup = heap_formtuple(tupDesc,
values, values,
nulls); nulls);
heap_insert(rdesc, tup); heap_insert(rel, tup);
if (RelationGetRelationTupleForm(rdesc)->relhasindex) if (RelationGetRelationTupleForm(rel)->relhasindex)
{ {
Relation idescs[Num_pg_proc_indices]; Relation idescs[Num_pg_proc_indices];
CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices, idescs); CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_proc_indices, rdesc, tup); CatalogIndexInsert(idescs, Num_pg_proc_indices, rel, tup);
CatalogCloseIndices(Num_pg_proc_indices, idescs); CatalogCloseIndices(Num_pg_proc_indices, idescs);
} }
heap_close(rdesc); heap_close(rel);
return tup->t_oid; return tup->t_oid;
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.26 1998/07/27 19:37:49 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.27 1998/08/19 02:01:38 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -21,6 +21,7 @@
#include "fmgr.h" #include "fmgr.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "storage/bufmgr.h"
#include "storage/lmgr.h" #include "storage/lmgr.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/syscache.h" #include "utils/syscache.h"
@ -68,7 +69,7 @@ TypeGetWithOpenRelation(Relation pg_type_desc,
scan = heap_beginscan(pg_type_desc, scan = heap_beginscan(pg_type_desc,
0, 0,
SnapshotSelf, SnapshotSelf, /* cache? */
1, 1,
typeKey); typeKey);
@ -76,7 +77,7 @@ TypeGetWithOpenRelation(Relation pg_type_desc,
* get the type tuple, if it exists. * get the type tuple, if it exists.
* ---------------- * ----------------
*/ */
tup = heap_getnext(scan, 0, (Buffer *) 0); tup = heap_getnext(scan, 0);
/* ---------------- /* ----------------
* if no type tuple exists for the given type name, then * if no type tuple exists for the given type name, then
@ -99,8 +100,7 @@ TypeGetWithOpenRelation(Relation pg_type_desc,
heap_endscan(scan); heap_endscan(scan);
*defined = (bool) ((TypeTupleForm) GETSTRUCT(tup))->typisdefined; *defined = (bool) ((TypeTupleForm) GETSTRUCT(tup))->typisdefined;
return return tup->t_oid;
tup->t_oid;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -143,8 +143,7 @@ TypeGet(char *typeName, /* name of type to be fetched */
*/ */
heap_close(pg_type_desc); heap_close(pg_type_desc);
return return typeoid;
typeoid;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -312,11 +311,9 @@ TypeCreate(char *typeName,
char replaces[Natts_pg_type]; char replaces[Natts_pg_type];
Datum values[Natts_pg_type]; Datum values[Natts_pg_type];
Buffer buffer;
char *procname; char *procname;
char *procs[4]; char *procs[4];
bool defined; bool defined;
ItemPointerData itemPointerData;
NameData name; NameData name;
TupleDesc tupDesc; TupleDesc tupDesc;
Oid argList[8]; Oid argList[8];
@ -353,9 +350,7 @@ TypeCreate(char *typeName,
* ---------------- * ----------------
*/ */
if (externalSize == 0) if (externalSize == 0)
{
externalSize = -1; /* variable length */ externalSize = -1; /* variable length */
}
/* ---------------- /* ----------------
* initialize arrays needed by FormHeapTuple * initialize arrays needed by FormHeapTuple
@ -470,7 +465,7 @@ TypeCreate(char *typeName,
typeKey[0].sk_argument = PointerGetDatum(typeName); typeKey[0].sk_argument = PointerGetDatum(typeName);
pg_type_scan = heap_beginscan(pg_type_desc, pg_type_scan = heap_beginscan(pg_type_desc,
0, 0,
SnapshotSelf, SnapshotSelf, /* cache? */
1, 1,
typeKey); typeKey);
@ -480,21 +475,17 @@ TypeCreate(char *typeName,
* already there. * already there.
* ---------------- * ----------------
*/ */
tup = heap_getnext(pg_type_scan, 0, &buffer); tup = heap_getnext(pg_type_scan, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
tup = heap_modifytuple(tup, tup = heap_modifytuple(tup,
buffer,
pg_type_desc, pg_type_desc,
values, values,
nulls, nulls,
replaces); replaces);
/* XXX may not be necessary */
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
setheapoverride(true); setheapoverride(true);
heap_replace(pg_type_desc, &itemPointerData, tup); heap_replace(pg_type_desc, &tup->t_ctid, tup);
setheapoverride(false); setheapoverride(false);
typeObjectId = tup->t_oid; typeObjectId = tup->t_oid;
@ -529,9 +520,7 @@ TypeCreate(char *typeName,
RelationUnsetLockForWrite(pg_type_desc); RelationUnsetLockForWrite(pg_type_desc);
heap_close(pg_type_desc); heap_close(pg_type_desc);
return typeObjectId;
return
typeObjectId;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -545,48 +534,42 @@ TypeRename(char *oldTypeName, char *newTypeName)
{ {
Relation pg_type_desc; Relation pg_type_desc;
Relation idescs[Num_pg_type_indices]; Relation idescs[Num_pg_type_indices];
Oid type_oid; HeapTuple oldtup, newtup;
HeapTuple tup;
bool defined;
ItemPointerData itemPointerData;
/* check that that the new type is not already defined */
type_oid = TypeGet(newTypeName, &defined);
if (OidIsValid(type_oid) && defined)
elog(ERROR, "TypeRename: type %s already defined", newTypeName);
/* get the type tuple from the catalog index scan manager */
pg_type_desc = heap_openr(TypeRelationName); pg_type_desc = heap_openr(TypeRelationName);
tup = TypeNameIndexScan(pg_type_desc, oldTypeName);
/* ---------------- oldtup = SearchSysCacheTupleCopy(TYPNAME,
* change the name of the type PointerGetDatum(oldTypeName),
* ---------------- 0, 0, 0);
*/
if (HeapTupleIsValid(tup)) if (!HeapTupleIsValid(oldtup))
{ {
heap_close(pg_type_desc);
namestrcpy(&(((TypeTupleForm) GETSTRUCT(tup))->typname), newTypeName);
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
setheapoverride(true);
heap_replace(pg_type_desc, &itemPointerData, tup);
setheapoverride(false);
/* update the system catalog indices */
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
CatalogCloseIndices(Num_pg_type_indices, idescs);
/* all done */
pfree(tup);
}
else
elog(ERROR, "TypeRename: type %s not defined", oldTypeName); elog(ERROR, "TypeRename: type %s not defined", oldTypeName);
}
newtup = SearchSysCacheTuple(TYPNAME,
PointerGetDatum(newTypeName),
0, 0, 0);
if (HeapTupleIsValid(newtup))
{
pfree(oldtup);
heap_close(pg_type_desc);
elog(ERROR, "TypeRename: type %s already defined", newTypeName);
}
namestrcpy(&(((TypeTupleForm) GETSTRUCT(oldtup))->typname), newTypeName);
/* finish up */ setheapoverride(true);
heap_replace(pg_type_desc, &oldtup->t_ctid, oldtup);
setheapoverride(false);
/* update the system catalog indices */
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, oldtup);
CatalogCloseIndices(Num_pg_type_indices, idescs);
pfree(oldtup);
heap_close(pg_type_desc); heap_close(pg_type_desc);
} }

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.13 1998/06/15 19:28:17 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/_deadcode/Attic/version.c,v 1.14 1998/08/19 02:01:58 momjian Exp $
* *
* NOTES * NOTES
* At the point the version is defined, 2 physical relations are created * At the point the version is defined, 2 physical relations are created
@ -185,26 +185,26 @@ VersionCreate(char *vname, char *bname)
static void static void
setAttrList(char *bname) setAttrList(char *bname)
{ {
Relation rdesc; Relation rel;
int i = 0; int i = 0;
int maxattrs = 0; int maxattrs = 0;
char *attrname; char *attrname;
char temp_buf[512]; char temp_buf[512];
int notfirst = 0; int notfirst = 0;
rdesc = heap_openr(bname); rel = heap_openr(bname);
if (rdesc == NULL) if (rel == NULL)
{ {
elog(ERROR, "Unable to expand all -- amopenr failed "); elog(ERROR, "Unable to expand all -- amopenr failed ");
return; return;
} }
maxattrs = RelationGetNumberOfAttributes(rdesc); maxattrs = RelationGetNumberOfAttributes(rel);
attr_list[0] = '\0'; attr_list[0] = '\0';
for (i = maxattrs - 1; i > -1; --i) for (i = maxattrs - 1; i > -1; --i)
{ {
attrname = (rdesc->rd_att->attrs[i]->attname).data; attrname = (rel->rd_att->attrs[i]->attname).data;
if (notfirst == 1) if (notfirst == 1)
sprintf(temp_buf, ", %s = new.%s", attrname, attrname); sprintf(temp_buf, ", %s = new.%s", attrname, attrname);
@ -216,7 +216,7 @@ setAttrList(char *bname)
strcat(attr_list, temp_buf); strcat(attr_list, temp_buf);
} }
heap_close(rdesc); heap_close(rel);
return; return;
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.36 1998/07/27 19:37:50 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.37 1998/08/19 02:01:39 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -172,7 +172,6 @@ Async_Notify(char *relname)
HeapScanDesc sRel; HeapScanDesc sRel;
TupleDesc tdesc; TupleDesc tdesc;
ScanKeyData key; ScanKeyData key;
Buffer b;
Datum d, Datum d,
value[3]; value[3];
bool isnull; bool isnull;
@ -211,16 +210,14 @@ Async_Notify(char *relname)
value[0] = value[1] = value[2] = (Datum) 0; value[0] = value[1] = value[2] = (Datum) 0;
value[Anum_pg_listener_notify - 1] = Int32GetDatum(1); value[Anum_pg_listener_notify - 1] = Int32GetDatum(1);
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0, &b))) while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
{ {
d = heap_getattr(lTuple, Anum_pg_listener_notify, d = heap_getattr(lTuple, Anum_pg_listener_notify, tdesc, &isnull);
tdesc, &isnull);
if (!DatumGetInt32(d)) if (!DatumGetInt32(d))
{ {
rTuple = heap_modifytuple(lTuple, b, lRel, value, nulls, repl); rTuple = heap_modifytuple(lTuple, lRel, value, nulls, repl);
heap_replace(lRel, &lTuple->t_ctid, rTuple); heap_replace(lRel, &lTuple->t_ctid, rTuple);
} }
ReleaseBuffer(b);
} }
heap_endscan(sRel); heap_endscan(sRel);
RelationUnsetLockForWrite(lRel); RelationUnsetLockForWrite(lRel);
@ -260,7 +257,6 @@ Async_NotifyAtCommit()
ScanKeyData key; ScanKeyData key;
Datum d; Datum d;
bool isnull; bool isnull;
Buffer b;
extern TransactionState CurrentTransactionState; extern TransactionState CurrentTransactionState;
if (!pendingNotifies) if (!pendingNotifies)
@ -286,7 +282,7 @@ Async_NotifyAtCommit()
sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, &key); sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, &key);
tdesc = RelationGetTupleDescriptor(lRel); tdesc = RelationGetTupleDescriptor(lRel);
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0, &b))) while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
{ {
d = heap_getattr(lTuple, Anum_pg_listener_relname, d = heap_getattr(lTuple, Anum_pg_listener_relname,
tdesc, &isnull); tdesc, &isnull);
@ -317,7 +313,6 @@ Async_NotifyAtCommit()
#endif #endif
} }
} }
ReleaseBuffer(b);
} }
heap_endscan(sRel); heap_endscan(sRel);
RelationUnsetLockForWrite(lRel); RelationUnsetLockForWrite(lRel);
@ -400,11 +395,10 @@ Async_Listen(char *relname, int pid)
Datum values[Natts_pg_listener]; Datum values[Natts_pg_listener];
char nulls[Natts_pg_listener]; char nulls[Natts_pg_listener];
TupleDesc tdesc; TupleDesc tdesc;
HeapScanDesc s; HeapScanDesc scan;
HeapTuple htup, HeapTuple tuple,
tup; newtup;
Relation lDesc; Relation lDesc;
Buffer b;
Datum d; Datum d;
int i; int i;
bool isnull; bool isnull;
@ -431,22 +425,21 @@ Async_Listen(char *relname, int pid)
/* is someone already listening. One listener per relation */ /* is someone already listening. One listener per relation */
tdesc = RelationGetTupleDescriptor(lDesc); tdesc = RelationGetTupleDescriptor(lDesc);
s = heap_beginscan(lDesc, 0, SnapshotNow, 0, (ScanKey) NULL); scan = heap_beginscan(lDesc, 0, SnapshotNow, 0, (ScanKey) NULL);
while (HeapTupleIsValid(htup = heap_getnext(s, 0, &b))) while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{ {
d = heap_getattr(htup, Anum_pg_listener_relname, tdesc, d = heap_getattr(tuple, Anum_pg_listener_relname, tdesc,
&isnull); &isnull);
relnamei = DatumGetPointer(d); relnamei = DatumGetPointer(d);
if (!strncmp(relnamei, relname, NAMEDATALEN)) if (!strncmp(relnamei, relname, NAMEDATALEN))
{ {
d = heap_getattr(htup, Anum_pg_listener_pid, tdesc, &isnull); d = heap_getattr(tuple, Anum_pg_listener_pid, tdesc, &isnull);
pid = DatumGetInt32(d); pid = DatumGetInt32(d);
if (pid == MyProcPid) if (pid == MyProcPid)
alreadyListener = 1; alreadyListener = 1;
} }
ReleaseBuffer(b);
} }
heap_endscan(s); heap_endscan(scan);
if (alreadyListener) if (alreadyListener)
{ {
@ -456,12 +449,12 @@ Async_Listen(char *relname, int pid)
} }
tupDesc = lDesc->rd_att; tupDesc = lDesc->rd_att;
tup = heap_formtuple(tupDesc, newtup = heap_formtuple(tupDesc,
values, values,
nulls); nulls);
heap_insert(lDesc, tup); heap_insert(lDesc, newtup);
pfree(tup); pfree(newtup);
/* /*
* if (alreadyListener) { elog(NOTICE,"Async_Listen: already one * if (alreadyListener) { elog(NOTICE,"Async_Listen: already one
@ -504,7 +497,8 @@ Async_Unlisten(char *relname, int pid)
Relation lDesc; Relation lDesc;
HeapTuple lTuple; HeapTuple lTuple;
lTuple = SearchSysCacheTuple(LISTENREL, PointerGetDatum(relname), lTuple = SearchSysCacheTuple(LISTENREL,
PointerGetDatum(relname),
Int32GetDatum(pid), Int32GetDatum(pid),
0, 0); 0, 0);
lDesc = heap_openr(ListenerRelationName); lDesc = heap_openr(ListenerRelationName);
@ -556,7 +550,6 @@ Async_NotifyFrontEnd()
value[3]; value[3];
char repl[3], char repl[3],
nulls[3]; nulls[3];
Buffer b;
bool isnull; bool isnull;
notifyFrontEndPending = 0; notifyFrontEndPending = 0;
@ -585,11 +578,10 @@ Async_NotifyFrontEnd()
value[0] = value[1] = value[2] = (Datum) 0; value[0] = value[1] = value[2] = (Datum) 0;
value[Anum_pg_listener_notify - 1] = Int32GetDatum(0); value[Anum_pg_listener_notify - 1] = Int32GetDatum(0);
while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0, &b))) while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0)))
{ {
d = heap_getattr(lTuple, Anum_pg_listener_relname, d = heap_getattr(lTuple, Anum_pg_listener_relname, tdesc, &isnull);
tdesc, &isnull); rTuple = heap_modifytuple(lTuple, lRel, value, nulls, repl);
rTuple = heap_modifytuple(lTuple, b, lRel, value, nulls, repl);
heap_replace(lRel, &lTuple->t_ctid, rTuple); heap_replace(lRel, &lTuple->t_ctid, rTuple);
/* notifying the front end */ /* notifying the front end */
@ -603,8 +595,9 @@ Async_NotifyFrontEnd()
} }
else else
elog(NOTICE, "Async_NotifyFrontEnd: no asynchronous notification to frontend on interactive sessions"); elog(NOTICE, "Async_NotifyFrontEnd: no asynchronous notification to frontend on interactive sessions");
ReleaseBuffer(b);
} }
heap_endscan(sRel);
heap_close(lRel);
CommitTransactionCommand(); CommitTransactionCommand();
} }

View File

@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.27 1998/08/06 05:12:22 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.28 1998/08/19 02:01:41 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -128,7 +128,7 @@ cluster(char oldrelname[], char oldindexname[])
elog(ERROR, "cluster: unknown relation: \"%s\"", elog(ERROR, "cluster: unknown relation: \"%s\"",
oldrelname); oldrelname);
} }
OIDOldHeap = OldHeap->rd_id;/* Get OID for the index scan */ OIDOldHeap = RelationGetRelid(OldHeap);/* Get OID for the index scan */
OldIndex = index_openr(oldindexname); /* Open old index relation */ OldIndex = index_openr(oldindexname); /* Open old index relation */
if (!RelationIsValid(OldIndex)) if (!RelationIsValid(OldIndex))
@ -136,7 +136,7 @@ cluster(char oldrelname[], char oldindexname[])
elog(ERROR, "cluster: unknown index: \"%s\"", elog(ERROR, "cluster: unknown index: \"%s\"",
oldindexname); oldindexname);
} }
OIDOldIndex = OldIndex->rd_id; /* OID for the index scan */ OIDOldIndex = RelationGetRelid(OldIndex); /* OID for the index scan */
heap_close(OldHeap); heap_close(OldHeap);
index_close(OldIndex); index_close(OldIndex);
@ -150,7 +150,7 @@ cluster(char oldrelname[], char oldindexname[])
* with a pg_vlock. * with a pg_vlock.
*/ */
NewHeap = copy_heap(OIDOldHeap); NewHeap = copy_heap(OIDOldHeap);
OIDNewHeap = NewHeap->rd_id; OIDNewHeap = RelationGetRelid(NewHeap);
strcpy(NewHeapName, NewHeap->rd_rel->relname.data); strcpy(NewHeapName, NewHeap->rd_rel->relname.data);
@ -257,7 +257,7 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
*/ */
Old_pg_index_Tuple = Old_pg_index_Tuple =
SearchSysCacheTuple(INDEXRELID, SearchSysCacheTuple(INDEXRELID,
ObjectIdGetDatum(OldIndex->rd_id), ObjectIdGetDatum(RelationGetRelid(OldIndex)),
0, 0, 0); 0, 0, 0);
Assert(Old_pg_index_Tuple); Assert(Old_pg_index_Tuple);
@ -265,7 +265,7 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
Old_pg_index_relation_Tuple = Old_pg_index_relation_Tuple =
SearchSysCacheTuple(RELOID, SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(OldIndex->rd_id), ObjectIdGetDatum(RelationGetRelid(OldIndex)),
0, 0, 0); 0, 0, 0);
Assert(Old_pg_index_relation_Tuple); Assert(Old_pg_index_relation_Tuple);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.29 1998/07/27 19:37:51 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.30 1998/08/19 02:01:42 momjian Exp $
* *
* NOTES * NOTES
* The PortalExecutorHeapMemory crap needs to be eliminated * The PortalExecutorHeapMemory crap needs to be eliminated
@ -272,7 +272,6 @@ PerformAddAttribute(char *relationName,
{ {
Relation relrdesc, Relation relrdesc,
attrdesc; attrdesc;
HeapScanDesc attsdesc;
HeapTuple reltup; HeapTuple reltup;
HeapTuple attributeTuple; HeapTuple attributeTuple;
AttributeTupleForm attribute; AttributeTupleForm attribute;
@ -281,8 +280,6 @@ PerformAddAttribute(char *relationName,
int minattnum, int minattnum,
maxatts; maxatts;
HeapTuple tup; HeapTuple tup;
ScanKeyData key[2];
ItemPointerData oldTID;
Relation idescs[Num_pg_attr_indices]; Relation idescs[Num_pg_attr_indices];
Relation ridescs[Num_pg_class_indices]; Relation ridescs[Num_pg_class_indices];
bool hasindex; bool hasindex;
@ -334,7 +331,7 @@ PerformAddAttribute(char *relationName,
elog(ERROR, "PerformAddAttribute: unknown relation: \"%s\"", elog(ERROR, "PerformAddAttribute: unknown relation: \"%s\"",
relationName); relationName);
} }
myrelid = relrdesc->rd_id; myrelid = RelationGetRelid(relrdesc);
heap_close(relrdesc); heap_close(relrdesc);
/* this routine is actually in the planner */ /* this routine is actually in the planner */
@ -364,9 +361,12 @@ PerformAddAttribute(char *relationName,
} }
relrdesc = heap_openr(RelationRelationName); relrdesc = heap_openr(RelationRelationName);
reltup = ClassNameIndexScan(relrdesc, relationName);
if (!PointerIsValid(reltup)) reltup = SearchSysCacheTupleCopy(RELNAME,
PointerGetDatum(relationName),
0, 0, 0);
if (!HeapTupleIsValid(reltup))
{ {
heap_close(relrdesc); heap_close(relrdesc);
elog(ERROR, "PerformAddAttribute: relation \"%s\" not found", elog(ERROR, "PerformAddAttribute: relation \"%s\" not found",
@ -387,11 +387,10 @@ PerformAddAttribute(char *relationName,
maxatts = minattnum + 1; maxatts = minattnum + 1;
if (maxatts > MaxHeapAttributeNumber) if (maxatts > MaxHeapAttributeNumber)
{ {
pfree(reltup); /* XXX temp */ pfree(reltup);
heap_close(relrdesc); /* XXX temp */ heap_close(relrdesc);
elog(ERROR, "PerformAddAttribute: relations limited to %d attributes", elog(ERROR, "PerformAddAttribute: relations limited to %d attributes",
MaxHeapAttributeNumber); MaxHeapAttributeNumber);
return;
} }
attrdesc = heap_openr(AttributeRelationName); attrdesc = heap_openr(AttributeRelationName);
@ -406,18 +405,6 @@ PerformAddAttribute(char *relationName,
if (hasindex) if (hasindex)
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs); CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
ScanKeyEntryInitialize(&key[0],
(bits16) NULL,
(AttrNumber) Anum_pg_attribute_attrelid,
(RegProcedure) F_OIDEQ,
(Datum) reltup->t_oid);
ScanKeyEntryInitialize(&key[1],
(bits16) NULL,
(AttrNumber) Anum_pg_attribute_attname,
(RegProcedure) F_NAMEEQ,
(Datum) NULL);
attributeD.attrelid = reltup->t_oid; attributeD.attrelid = reltup->t_oid;
attributeTuple = heap_addheader(Natts_pg_attribute, attributeTuple = heap_addheader(Natts_pg_attribute,
@ -431,53 +418,44 @@ PerformAddAttribute(char *relationName,
{ {
HeapTuple typeTuple; HeapTuple typeTuple;
TypeTupleForm form; TypeTupleForm form;
char *p; char *typename;
int attnelems; int attnelems;
/* tup = SearchSysCacheTuple(ATTNAME,
* XXX use syscache here as an optimization ObjectIdGetDatum(reltup->t_oid),
*/ PointerGetDatum(colDef->colname),
key[1].sk_argument = (Datum) colDef->colname; 0, 0);
attsdesc = heap_beginscan(attrdesc, 0, SnapshotNow, 2, key);
tup = heap_getnext(attsdesc, 0, (Buffer *) NULL);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
pfree(reltup); /* XXX temp */ heap_close(attrdesc);
heap_endscan(attsdesc); /* XXX temp */ heap_close(relrdesc);
heap_close(attrdesc); /* XXX temp */
heap_close(relrdesc); /* XXX temp */
elog(ERROR, "PerformAddAttribute: attribute \"%s\" already exists in class \"%s\"", elog(ERROR, "PerformAddAttribute: attribute \"%s\" already exists in class \"%s\"",
key[1].sk_argument, colDef->colname, relationName);
relationName);
return;
} }
heap_endscan(attsdesc);
/* /*
* check to see if it is an array attribute. * check to see if it is an array attribute.
*/ */
p = colDef->typename->name; typename = colDef->typename->name;
if (colDef->typename->arrayBounds) if (colDef->typename->arrayBounds)
{ {
attnelems = length(colDef->typename->arrayBounds); attnelems = length(colDef->typename->arrayBounds);
p = makeArrayTypeName(colDef->typename->name); typename = makeArrayTypeName(colDef->typename->name);
} }
else else
attnelems = 0; attnelems = 0;
typeTuple = SearchSysCacheTuple(TYPNAME, typeTuple = SearchSysCacheTuple(TYPNAME,
PointerGetDatum(p), PointerGetDatum(typename),
0, 0, 0); 0, 0, 0);
form = (TypeTupleForm) GETSTRUCT(typeTuple); form = (TypeTupleForm) GETSTRUCT(typeTuple);
if (!HeapTupleIsValid(typeTuple)) if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "Add: type \"%s\" nonexistent", p); elog(ERROR, "Add: type \"%s\" nonexistent", typename);
namestrcpy(&(attribute->attname), (char *) key[1].sk_argument); namestrcpy(&(attribute->attname), colDef->colname);
attribute->atttypid = typeTuple->t_oid; attribute->atttypid = typeTuple->t_oid;
attribute->attlen = form->typlen; attribute->attlen = form->typlen;
attributeD.attdisbursion = 0; attributeD.attdisbursion = 0;
@ -504,8 +482,7 @@ PerformAddAttribute(char *relationName,
heap_close(attrdesc); heap_close(attrdesc);
((Form_pg_class) GETSTRUCT(reltup))->relnatts = maxatts; ((Form_pg_class) GETSTRUCT(reltup))->relnatts = maxatts;
oldTID = reltup->t_ctid; heap_replace(relrdesc, &reltup->t_ctid, reltup);
heap_replace(relrdesc, &oldTID, reltup);
/* keep catalog indices current */ /* keep catalog indices current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);

View File

@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.52 1998/07/27 19:37:51 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.53 1998/08/19 02:01:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -257,9 +257,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
fwrite(&ntuples, sizeof(int32), 1, fp); fwrite(&ntuples, sizeof(int32), 1, fp);
} }
for (tuple = heap_getnext(scandesc, 0, NULL); while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))
tuple != NULL;
tuple = heap_getnext(scandesc, 0, NULL))
{ {
if (oids && !binary) if (oids && !binary)
@ -417,7 +415,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
if (rel->rd_rel->relhasindex) if (rel->rd_rel->relhasindex)
{ {
GetIndexRelations(rel->rd_id, &n_indices, &index_rels); GetIndexRelations(RelationGetRelid(rel), &n_indices, &index_rels);
if (n_indices > 0) if (n_indices > 0)
{ {
has_index = true; has_index = true;
@ -435,7 +433,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
itupdescArr[i] = RelationGetTupleDescriptor(index_rels[i]); itupdescArr[i] = RelationGetTupleDescriptor(index_rels[i]);
pgIndexTup = pgIndexTup =
SearchSysCacheTuple(INDEXRELID, SearchSysCacheTuple(INDEXRELID,
ObjectIdGetDatum(index_rels[i]->rd_id), ObjectIdGetDatum(RelationGetRelid(index_rels[i])),
0, 0, 0); 0, 0, 0);
Assert(pgIndexTup); Assert(pgIndexTup);
pgIndexP[i] = (IndexTupleForm) GETSTRUCT(pgIndexTup); pgIndexP[i] = (IndexTupleForm) GETSTRUCT(pgIndexTup);
@ -758,7 +756,6 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
(AttrNumber *) &(pgIndexP[i]->indkey[0]), (AttrNumber *) &(pgIndexP[i]->indkey[0]),
tuple, tuple,
tupDesc, tupDesc,
InvalidBuffer,
idatum, idatum,
index_nulls, index_nulls,
finfoP[i]); finfoP[i]);
@ -833,7 +830,6 @@ GetTypeElement(Oid type)
ObjectIdGetDatum(type), ObjectIdGetDatum(type),
0, 0, 0); 0, 0, 0);
if (HeapTupleIsValid(typeTuple)) if (HeapTupleIsValid(typeTuple))
return ((int) ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem); return ((int) ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
@ -913,9 +909,7 @@ GetIndexRelations(Oid main_relation_oid,
scan = head; scan = head;
head->next = NULL; head->next = NULL;
for (tuple = heap_getnext(scandesc, 0, NULL); while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))
tuple != NULL;
tuple = heap_getnext(scandesc, 0, NULL))
{ {
index_relation_oid = index_relation_oid =
@ -1168,10 +1162,9 @@ CountTuples(Relation relation)
scandesc = heap_beginscan(relation, 0, SnapshotNow, 0, NULL); scandesc = heap_beginscan(relation, 0, SnapshotNow, 0, NULL);
for (tuple = heap_getnext(scandesc, 0, NULL), i = 0; i = 0;
tuple != NULL; while (HeapTupleIsValid(tuple = heap_getnext(scandesc, 0)))
tuple = heap_getnext(scandesc, 0, NULL), i++) i++;
;
heap_endscan(scandesc); heap_endscan(scandesc);
return (i); return (i);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.31 1998/08/06 05:12:24 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.32 1998/08/19 02:01:45 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -404,7 +404,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
char nullarr[Natts_pg_inherits]; char nullarr[Natts_pg_inherits];
tuple = SearchSysCacheTuple(RELNAME, tuple = SearchSysCacheTuple(RELNAME,
PointerGetDatum(strVal(lfirst(entry))), PointerGetDatum(strVal(lfirst(entry))),
0, 0, 0); 0, 0, 0);
AssertArg(HeapTupleIsValid(tuple)); AssertArg(HeapTupleIsValid(tuple));

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.19 1998/08/11 18:28:13 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.20 1998/08/19 02:01:46 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -148,7 +148,6 @@ get_pg_dbtup(char *command, char *dbname, Relation dbrel)
{ {
HeapTuple dbtup; HeapTuple dbtup;
HeapTuple tup; HeapTuple tup;
Buffer buf;
HeapScanDesc scan; HeapScanDesc scan;
ScanKeyData scanKey; ScanKeyData scanKey;
@ -163,13 +162,10 @@ get_pg_dbtup(char *command, char *dbname, Relation dbrel)
* since we want to return the tuple out of this proc, and we're going * since we want to return the tuple out of this proc, and we're going
* to close the relation, copy the tuple and return the copy. * to close the relation, copy the tuple and return the copy.
*/ */
tup = heap_getnext(scan, 0, &buf); tup = heap_getnext(scan, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{
dbtup = heap_copytuple(tup); dbtup = heap_copytuple(tup);
ReleaseBuffer(buf);
}
else else
dbtup = tup; dbtup = tup;
@ -205,8 +201,9 @@ check_permissions(char *command,
char path[MAXPGPATH + 1]; char path[MAXPGPATH + 1];
userName = GetPgUserName(); userName = GetPgUserName();
utup = SearchSysCacheTuple(USENAME, PointerGetDatum(userName), utup = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(userName),
0, 0, 0);
*userIdP = ((Form_pg_shadow) GETSTRUCT(utup))->usesysid; *userIdP = ((Form_pg_shadow) GETSTRUCT(utup))->usesysid;
use_super = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper; use_super = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
use_createdb = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb; use_createdb = ((Form_pg_shadow) GETSTRUCT(utup))->usecreatedb;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.21 1998/06/15 19:28:15 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.22 1998/08/19 02:01:48 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -118,7 +118,8 @@ DefineIndex(char *heapRelationName,
/* /*
* compute access method id * compute access method id
*/ */
tuple = SearchSysCacheTuple(AMNAME, PointerGetDatum(accessMethodName), tuple = SearchSysCacheTuple(AMNAME,
PointerGetDatum(accessMethodName),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
@ -244,7 +245,8 @@ ExtendIndex(char *indexRelationName, Expr *predicate, List *rangetable)
/* /*
* compute index relation id and access method id * compute index relation id and access method id
*/ */
tuple = SearchSysCacheTuple(RELNAME, PointerGetDatum(indexRelationName), tuple = SearchSysCacheTuple(RELNAME,
PointerGetDatum(indexRelationName),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {

View File

@ -53,7 +53,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
Oid typev[8]; Oid typev[8];
char nulls[Natts_pg_language]; char nulls[Natts_pg_language];
Datum values[Natts_pg_language]; Datum values[Natts_pg_language];
Relation rdesc; Relation rel;
HeapTuple tup; HeapTuple tup;
TupleDesc tupDesc; TupleDesc tupDesc;
@ -90,7 +90,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
memset(typev, 0, sizeof(typev)); memset(typev, 0, sizeof(typev));
procTup = SearchSysCacheTuple(PRONAME, procTup = SearchSysCacheTuple(PRONAME,
PointerGetDatum(stmt->plhandler), PointerGetDatum(stmt->plhandler),
UInt16GetDatum(0), Int32GetDatum(0),
PointerGetDatum(typev), PointerGetDatum(typev),
0); 0);
if (!HeapTupleIsValid(procTup)) if (!HeapTupleIsValid(procTup))
@ -121,14 +121,14 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
values[i++] = ObjectIdGetDatum(procTup->t_oid); values[i++] = ObjectIdGetDatum(procTup->t_oid);
values[i++] = (Datum) fmgr(F_TEXTIN, stmt->plcompiler); values[i++] = (Datum) fmgr(F_TEXTIN, stmt->plcompiler);
rdesc = heap_openr(LanguageRelationName); rel = heap_openr(LanguageRelationName);
tupDesc = rdesc->rd_att; tupDesc = rel->rd_att;
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
heap_insert(rdesc, tup); heap_insert(rel, tup);
heap_close(rdesc); heap_close(rel);
return; return;
} }
@ -142,11 +142,7 @@ DropProceduralLanguage(DropPLangStmt *stmt)
{ {
char languageName[NAMEDATALEN]; char languageName[NAMEDATALEN];
HeapTuple langTup; HeapTuple langTup;
Relation rel;
Relation rdesc;
HeapScanDesc scanDesc;
ScanKeyData scanKeyData;
HeapTuple tup;
/* ---------------- /* ----------------
* Check permission * Check permission
@ -165,7 +161,7 @@ DropProceduralLanguage(DropPLangStmt *stmt)
*/ */
case_translate_language_name(stmt->plname, languageName); case_translate_language_name(stmt->plname, languageName);
langTup = SearchSysCacheTuple(LANNAME, langTup = SearchSysCacheTupleCopy(LANNAME,
PointerGetDatum(languageName), PointerGetDatum(languageName),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(langTup)) if (!HeapTupleIsValid(langTup))
@ -177,24 +173,9 @@ DropProceduralLanguage(DropPLangStmt *stmt)
languageName); languageName);
} }
/* ---------------- rel = heap_openr(LanguageRelationName);
* Now scan pg_language and delete the PL tuple heap_delete(rel, &langTup->t_ctid);
* ----------------
*/
rdesc = heap_openr(LanguageRelationName);
ScanKeyEntryInitialize(&scanKeyData, 0, Anum_pg_language_lanname, pfree(langTup);
F_NAMEEQ, PointerGetDatum(languageName)); heap_close(rel);
scanDesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, &scanKeyData);
tup = heap_getnext(scanDesc, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tup))
elog(ERROR, "Language with name '%s' not found", languageName);
heap_delete(rdesc, &(tup->t_ctid));
heap_endscan(scanDesc);
heap_close(rdesc);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.26 1998/07/27 19:37:53 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.27 1998/08/19 02:01:50 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -51,16 +51,13 @@ RemoveOperator(char *operatorName, /* operator name */
char *typeName2) /* optional second type name */ char *typeName2) /* optional second type name */
{ {
Relation relation; Relation relation;
HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
Oid typeId1 = InvalidOid; Oid typeId1 = InvalidOid;
Oid typeId2 = InvalidOid; Oid typeId2 = InvalidOid;
bool defined; bool defined;
ItemPointerData itemPointerData;
Buffer buffer;
ScanKeyData operatorKey[3];
char *userName; char *userName;
char oprtype;
if (typeName1) if (typeName1)
{ {
typeId1 = TypeGet(typeName1, &defined); typeId1 = TypeGet(typeName1, &defined);
@ -81,24 +78,20 @@ RemoveOperator(char *operatorName, /* operator name */
} }
} }
ScanKeyEntryInitialize(&operatorKey[0], 0x0, if (OidIsValid(typeId1) && OidIsValid(typeId2))
Anum_pg_operator_oprname, oprtype = 'b';
F_NAMEEQ, else if (OidIsValid(typeId1))
PointerGetDatum(operatorName)); oprtype = 'l';
else
ScanKeyEntryInitialize(&operatorKey[1], 0x0, oprtype = 'r';
Anum_pg_operator_oprleft,
F_OIDEQ,
ObjectIdGetDatum(typeId1));
ScanKeyEntryInitialize(&operatorKey[2], 0x0,
Anum_pg_operator_oprright,
F_OIDEQ,
ObjectIdGetDatum(typeId2));
tup = SearchSysCacheTupleCopy(OPRNAME,
PointerGetDatum(operatorName),
ObjectIdGetDatum(typeId1),
ObjectIdGetDatum(typeId2),
CharGetDatum(oprtype));
relation = heap_openr(OperatorRelationName); relation = heap_openr(OperatorRelationName);
scan = heap_beginscan(relation, 0, SnapshotNow, 3, operatorKey);
tup = heap_getnext(scan, 0, &buffer);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
#ifndef NO_SECURITY #ifndef NO_SECURITY
@ -109,8 +102,7 @@ RemoveOperator(char *operatorName, /* operator name */
elog(ERROR, "RemoveOperator: operator '%s': permission denied", elog(ERROR, "RemoveOperator: operator '%s': permission denied",
operatorName); operatorName);
#endif #endif
ItemPointerCopy(&tup->t_ctid, &itemPointerData); heap_delete(relation, &tup->t_ctid);
heap_delete(relation, &itemPointerData);
} }
else else
{ {
@ -134,7 +126,7 @@ RemoveOperator(char *operatorName, /* operator name */
typeName2); typeName2);
} }
} }
heap_endscan(scan); pfree(tup);
heap_close(relation); heap_close(relation);
} }
@ -150,31 +142,25 @@ RemoveOperator(char *operatorName, /* operator name */
static void static void
SingleOpOperatorRemove(Oid typeOid) SingleOpOperatorRemove(Oid typeOid)
{ {
Relation rdesc; Relation rel;
ScanKeyData key[3]; ScanKeyData key[3];
HeapScanDesc sdesc; HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
ItemPointerData itemPointerData;
Buffer buffer;
static attnums[3] = {7, 8, 9}; /* left, right, return */ static attnums[3] = {7, 8, 9}; /* left, right, return */
int i; int i;
ScanKeyEntryInitialize(&key[0], ScanKeyEntryInitialize(&key[0],
0, 0, F_OIDEQ, (Datum) typeOid); 0, 0, F_OIDEQ, (Datum) typeOid);
rdesc = heap_openr(OperatorRelationName); rel = heap_openr(OperatorRelationName);
for (i = 0; i < 3; ++i) for (i = 0; i < 3; ++i)
{ {
key[0].sk_attno = attnums[i]; key[0].sk_attno = attnums[i];
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, key); scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
while (PointerIsValid(tup = heap_getnext(sdesc, 0, &buffer))) while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
{ heap_delete(rel, &tup->t_ctid);
ItemPointerCopy(&tup->t_ctid, &itemPointerData); heap_endscan(scan);
/* XXX LOCK not being passed */
heap_delete(rdesc, &itemPointerData);
}
heap_endscan(sdesc);
} }
heap_close(rdesc); heap_close(rel);
} }
/* /*
@ -193,12 +179,10 @@ AttributeAndRelationRemove(Oid typeOid)
}; };
struct oidlist *oidptr, struct oidlist *oidptr,
*optr; *optr;
Relation rdesc; Relation rel;
ScanKeyData key[1]; ScanKeyData key[1];
HeapScanDesc sdesc; HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
ItemPointerData itemPointerData;
Buffer buffer;
/* /*
* Get the oid's of the relations to be removed by scanning the entire * Get the oid's of the relations to be removed by scanning the entire
@ -213,31 +197,30 @@ AttributeAndRelationRemove(Oid typeOid)
oidptr = (struct oidlist *) palloc(sizeof(*oidptr)); oidptr = (struct oidlist *) palloc(sizeof(*oidptr));
oidptr->next = NULL; oidptr->next = NULL;
optr = oidptr; optr = oidptr;
rdesc = heap_openr(AttributeRelationName); rel = heap_openr(AttributeRelationName);
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, key); scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
while (PointerIsValid(tup = heap_getnext(sdesc, 0, &buffer))) while (HeapTupleIsValid(tup = heap_getnext(scan, 0)))
{ {
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
optr->reloid = ((AttributeTupleForm) GETSTRUCT(tup))->attrelid; optr->reloid = ((AttributeTupleForm) GETSTRUCT(tup))->attrelid;
optr->next = (struct oidlist *) palloc(sizeof(*oidptr)); optr->next = (struct oidlist *) palloc(sizeof(*oidptr));
optr = optr->next; optr = optr->next;
} }
optr->next = NULL; optr->next = NULL;
heap_endscan(sdesc); heap_endscan(scan);
heap_close(rdesc); heap_close(rel);
ScanKeyEntryInitialize(&key[0], 0, ScanKeyEntryInitialize(&key[0], 0,
ObjectIdAttributeNumber, ObjectIdAttributeNumber,
F_OIDEQ, (Datum) 0); F_OIDEQ, (Datum) 0);
optr = oidptr; optr = oidptr;
rdesc = heap_openr(RelationRelationName); rel = heap_openr(RelationRelationName);
while (PointerIsValid((char *) optr->next)) while (PointerIsValid((char *) optr->next))
{ {
key[0].sk_argument = (Datum) (optr++)->reloid; key[0].sk_argument = (Datum) (optr++)->reloid;
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 1, key); scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
tup = heap_getnext(sdesc, 0, &buffer); tup = heap_getnext(scan, 0);
if (PointerIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
char *name; char *name;
@ -245,11 +228,11 @@ AttributeAndRelationRemove(Oid typeOid)
heap_destroy_with_catalog(name); heap_destroy_with_catalog(name);
} }
} }
heap_endscan(sdesc); heap_endscan(scan);
heap_close(rdesc); heap_close(rel);
} }
#endif /* NOTYET */ #endif /* NOTYET */
/* /*
* TypeRemove * TypeRemove
@ -260,13 +243,8 @@ void
RemoveType(char *typeName) /* type name to be removed */ RemoveType(char *typeName) /* type name to be removed */
{ {
Relation relation; Relation relation;
HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
Oid typeOid; Oid typeOid;
ItemPointerData itemPointerData;
static ScanKeyData typeKey[1] = {
{0, Anum_pg_type_typname, F_NAMEEQ}
};
char *shadow_type; char *shadow_type;
char *userName; char *userName;
@ -278,44 +256,33 @@ RemoveType(char *typeName) /* type name to be removed */
#endif #endif
relation = heap_openr(TypeRelationName); relation = heap_openr(TypeRelationName);
fmgr_info(typeKey[0].sk_procedure, &typeKey[0].sk_func); tup = SearchSysCacheTuple(TYPNAME,
typeKey[0].sk_nargs = typeKey[0].sk_func.fn_nargs; PointerGetDatum(typeName),
0, 0, 0);
/* Delete the primary type */
typeKey[0].sk_argument = PointerGetDatum(typeName);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, typeKey);
tup = heap_getnext(scan, 0, (Buffer *) 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {
heap_endscan(scan);
heap_close(relation); heap_close(relation);
elog(ERROR, "RemoveType: type '%s' does not exist", elog(ERROR, "RemoveType: type '%s' does not exist", typeName);
typeName);
} }
relation = heap_openr(TypeRelationName);
typeOid = tup->t_oid; typeOid = tup->t_oid;
ItemPointerCopy(&tup->t_ctid, &itemPointerData); heap_delete(relation, &tup->t_ctid);
heap_delete(relation, &itemPointerData);
heap_endscan(scan);
/* Now, Delete the "array of" that type */ /* Now, Delete the "array of" that type */
shadow_type = makeArrayTypeName(typeName); shadow_type = makeArrayTypeName(typeName);
typeKey[0].sk_argument = NameGetDatum(shadow_type); tup = SearchSysCacheTuple(TYPNAME,
PointerGetDatum(shadow_type),
scan = heap_beginscan(relation, 0, SnapshotNow, 0, 0, 0);
1, (ScanKey) typeKey);
tup = heap_getnext(scan, 0, (Buffer *) 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {
elog(ERROR, "RemoveType: type '%s': array stub not found", heap_close(relation);
typeName); elog(ERROR, "RemoveType: type '%s' does not exist", typeName);
} }
typeOid = tup->t_oid; typeOid = tup->t_oid;
ItemPointerCopy(&tup->t_ctid, &itemPointerData); heap_delete(relation, &tup->t_ctid);
heap_delete(relation, &itemPointerData);
heap_endscan(scan);
heap_close(relation); heap_close(relation);
} }
@ -335,24 +302,16 @@ RemoveFunction(char *functionName, /* function name to be removed */
List *argNameList /* list of TypeNames */ ) List *argNameList /* list of TypeNames */ )
{ {
Relation relation; Relation relation;
HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
Buffer buffer = InvalidBuffer;
bool bufferUsed = FALSE;
Oid argList[8]; Oid argList[8];
Form_pg_proc the_proc = NULL;
ItemPointerData itemPointerData;
static ScanKeyData key[3] = {
{0, Anum_pg_proc_proname, F_NAMEEQ}
};
char *userName; char *userName;
char *typename; char *typename;
int i; int i;
MemSet(argList, 0, 8 * sizeof(Oid)); MemSet(argList, 0, 8 * sizeof(Oid));
for (i = 0; i < nargs; i++) for (i = 0; i < nargs; i++)
{ {
/* typename = ((TypeName*)(lfirst(argNameList)))->name; */
typename = strVal(lfirst(argNameList)); typename = strVal(lfirst(argNameList));
argNameList = lnext(argNameList); argNameList = lnext(argNameList);
@ -360,7 +319,8 @@ RemoveFunction(char *functionName, /* function name to be removed */
argList[i] = 0; argList[i] = 0;
else else
{ {
tup = SearchSysCacheTuple(TYPNAME, PointerGetDatum(typename), tup = SearchSysCacheTuple(TYPNAME,
PointerGetDatum(typename),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
@ -369,12 +329,6 @@ RemoveFunction(char *functionName, /* function name to be removed */
} }
} }
tup = SearchSysCacheTuple(PRONAME, PointerGetDatum(functionName),
Int32GetDatum(nargs),
PointerGetDatum(argList), 0);
if (!HeapTupleIsValid(tup))
func_error("RemoveFunction", functionName, nargs, argList, NULL);
#ifndef NO_SECURITY #ifndef NO_SECURITY
userName = GetPgUserName(); userName = GetPgUserName();
if (!pg_func_ownercheck(userName, functionName, nargs, argList)) if (!pg_func_ownercheck(userName, functionName, nargs, argList))
@ -384,48 +338,27 @@ RemoveFunction(char *functionName, /* function name to be removed */
} }
#endif #endif
key[0].sk_argument = PointerGetDatum(functionName);
fmgr_info(key[0].sk_procedure, &key[0].sk_func);
key[0].sk_nargs = key[0].sk_func.fn_nargs;
relation = heap_openr(ProcedureRelationName); relation = heap_openr(ProcedureRelationName);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key); tup = SearchSysCacheTuple(PRONAME,
PointerGetDatum(functionName),
Int32GetDatum(nargs),
PointerGetDatum(argList),
0);
do if (!HeapTupleIsValid(tup))
{ /* hope this is ok because it's indexed */
if (bufferUsed)
{
ReleaseBuffer(buffer);
bufferUsed = FALSE;
}
tup = heap_getnext(scan, 0, (Buffer *) &buffer);
if (!HeapTupleIsValid(tup))
break;
bufferUsed = TRUE;
the_proc = (Form_pg_proc) GETSTRUCT(tup);
} while ((namestrcmp(&(the_proc->proname), functionName) == 0) &&
(the_proc->pronargs != nargs ||
!oid8eq(&(the_proc->proargtypes[0]), &argList[0])));
if (!HeapTupleIsValid(tup) || namestrcmp(&(the_proc->proname),
functionName) != 0)
{ {
heap_endscan(scan);
heap_close(relation); heap_close(relation);
func_error("RemoveFunction", functionName, nargs, argList, NULL); func_error("RemoveFunction", functionName, nargs, argList, NULL);
} }
/* ok, function has been found */ if ((((Form_pg_proc) GETSTRUCT(tup))->prolang) == INTERNALlanguageId)
{
heap_close(relation);
elog(ERROR, "RemoveFunction: function \"%s\" is built-in",functionName);
}
if (the_proc->prolang == INTERNALlanguageId) heap_delete(relation, &tup->t_ctid);
elog(ERROR, "RemoveFunction: function \"%s\" is built-in",
functionName);
ItemPointerCopy(&tup->t_ctid, &itemPointerData);
heap_delete(relation, &itemPointerData);
heap_endscan(scan);
heap_close(relation); heap_close(relation);
} }
@ -433,13 +366,10 @@ void
RemoveAggregate(char *aggName, char *aggType) RemoveAggregate(char *aggName, char *aggType)
{ {
Relation relation; Relation relation;
HeapScanDesc scan;
HeapTuple tup; HeapTuple tup;
ItemPointerData itemPointerData;
char *userName; char *userName;
Oid basetypeID = InvalidOid; Oid basetypeID = InvalidOid;
bool defined; bool defined;
ScanKeyData aggregateKey[3];
/* /*
@ -461,9 +391,7 @@ RemoveAggregate(char *aggName, char *aggType)
else else
basetypeID = 0; basetypeID = 0;
/*
#ifndef NO_SECURITY #ifndef NO_SECURITY
*/
userName = GetPgUserName(); userName = GetPgUserName();
if (!pg_aggr_ownercheck(userName, aggName, basetypeID)) if (!pg_aggr_ownercheck(userName, aggName, basetypeID))
{ {
@ -478,26 +406,16 @@ RemoveAggregate(char *aggName, char *aggType)
aggName); aggName);
} }
} }
/*
#endif #endif
*/
ScanKeyEntryInitialize(&aggregateKey[0], 0x0,
Anum_pg_aggregate_aggname,
F_NAMEEQ,
PointerGetDatum(aggName));
ScanKeyEntryInitialize(&aggregateKey[1], 0x0,
Anum_pg_aggregate_aggbasetype,
F_OIDEQ,
ObjectIdGetDatum(basetypeID));
relation = heap_openr(AggregateRelationName); relation = heap_openr(AggregateRelationName);
scan = heap_beginscan(relation, 0, SnapshotNow, 2, aggregateKey); tup = SearchSysCacheTuple(AGGNAME,
tup = heap_getnext(scan, 0, (Buffer *) 0); PointerGetDatum(aggName),
ObjectIdGetDatum(basetypeID),
0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {
heap_endscan(scan);
heap_close(relation); heap_close(relation);
if (aggType) if (aggType)
{ {
@ -510,8 +428,7 @@ RemoveAggregate(char *aggName, char *aggType)
aggName); aggName);
} }
} }
ItemPointerCopy(&tup->t_ctid, &itemPointerData); heap_delete(relation, &tup->t_ctid);
heap_delete(relation, &itemPointerData);
heap_endscan(scan);
heap_close(relation); heap_close(relation);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.13 1998/07/26 04:30:24 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.14 1998/08/19 02:01:52 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -27,6 +27,7 @@
#include <utils/portal.h> #include <utils/portal.h>
#include <tcop/dest.h> #include <tcop/dest.h>
#include <commands/command.h> #include <commands/command.h>
#include <storage/bufmgr.h>
#include <utils/excid.h> #include <utils/excid.h>
#include <utils/mcxt.h> #include <utils/mcxt.h>
#include <catalog/pg_proc.h> #include <catalog/pg_proc.h>
@ -52,7 +53,7 @@
* Attname attribute is changed in attribute catalog. * Attname attribute is changed in attribute catalog.
* No record of the previous attname is kept (correct?). * No record of the previous attname is kept (correct?).
* *
* get proper reldesc from relation catalog (if not arg) * get proper relrelation from relation catalog (if not arg)
* scan attribute catalog * scan attribute catalog
* for name conflict (within rel) * for name conflict (within rel)
* for original attribute (if not arg) * for original attribute (if not arg)
@ -70,14 +71,13 @@ renameatt(char *relname,
char *userName, char *userName,
int recurse) int recurse)
{ {
Relation relrdesc, Relation attrelation;
attrdesc;
HeapTuple reltup, HeapTuple reltup,
oldatttup, oldatttup,
newatttup; newatttup;
ItemPointerData oldTID; Relation irelations[Num_pg_attr_indices];
Relation idescs[Num_pg_attr_indices]; Oid relid;
/* /*
* permissions checking. this would normally be done in utility.c, * permissions checking. this would normally be done in utility.c,
* but this particular routine is recursive. * but this particular routine is recursive.
@ -110,19 +110,20 @@ renameatt(char *relname,
List *child, List *child,
*children; *children;
relrdesc = heap_openr(relname); reltup = SearchSysCacheTuple(RELNAME,
if (!RelationIsValid(relrdesc)) PointerGetDatum(relname),
{ 0, 0, 0);
elog(ERROR, "renameatt: unknown relation: \"%s\"",
relname);
}
myrelid = relrdesc->rd_id;
heap_close(relrdesc);
if (!HeapTupleIsValid(reltup))
{
elog(ERROR, "renameatt: unknown relation: \"%s\"", relname);
}
myrelid = reltup->t_oid;
/* this routine is actually in the planner */ /* this routine is actually in the planner */
children = find_all_inheritors(lconsi(myrelid, NIL), NIL); children = find_all_inheritors(lconsi(myrelid, NIL), NIL);
/* /*
* find_all_inheritors does the recursive search of the * find_all_inheritors does the recursive search of the
* inheritance hierarchy, so all we have to do is process all of * inheritance hierarchy, so all we have to do is process all of
@ -130,72 +131,70 @@ renameatt(char *relname,
*/ */
foreach(child, children) foreach(child, children)
{ {
char *childname; char childname[NAMEDATALEN];
childrelid = lfirsti(child); childrelid = lfirsti(child);
if (childrelid == myrelid) if (childrelid == myrelid)
continue; continue;
relrdesc = heap_open(childrelid); reltup = SearchSysCacheTuple(RELOID,
if (!RelationIsValid(relrdesc)) ObjectIdGetDatum(childrelid),
0, 0, 0);
if (!HeapTupleIsValid(reltup))
{ {
elog(ERROR, "renameatt: can't find catalog entry for inheriting class with oid %d", elog(ERROR, "renameatt: can't find catalog entry for inheriting class with oid %d",
childrelid); childrelid);
} }
childname = (relrdesc->rd_rel->relname).data; /* make copy of cache value, could disappear in call */
heap_close(relrdesc); StrNCpy(childname,
renameatt(childname, oldattname, newattname, ((Form_pg_class) GETSTRUCT(reltup))->relname.data,
userName, 0); /* no more recursion! */ NAMEDATALEN);
/* no more recursion! */
renameatt(childname, oldattname, newattname, userName, 0);
} }
} }
relrdesc = heap_openr(RelationRelationName); reltup = SearchSysCacheTuple(RELNAME,
reltup = ClassNameIndexScan(relrdesc, relname); PointerGetDatum(relname),
if (!PointerIsValid(reltup)) 0, 0, 0);
{ if (!HeapTupleIsValid(reltup))
heap_close(relrdesc); elog(ERROR, "renameatt: relation \"%s\" nonexistent", relname);
elog(ERROR, "renameatt: relation \"%s\" nonexistent",
relname); relid = reltup->t_oid;
return;
} oldatttup = SearchSysCacheTupleCopy(ATTNAME,
heap_close(relrdesc); ObjectIdGetDatum(relid),
PointerGetDatum(oldattname),
0, 0);
if (!HeapTupleIsValid(oldatttup))
elog(ERROR, "renameatt: attribute \"%s\" nonexistent", oldattname);
attrdesc = heap_openr(AttributeRelationName);
oldatttup = AttributeNameIndexScan(attrdesc, reltup->t_oid, oldattname);
if (!PointerIsValid(oldatttup))
{
heap_close(attrdesc);
elog(ERROR, "renameatt: attribute \"%s\" nonexistent",
oldattname);
}
if (((AttributeTupleForm) GETSTRUCT(oldatttup))->attnum < 0) if (((AttributeTupleForm) GETSTRUCT(oldatttup))->attnum < 0)
{ elog(ERROR, "renameatt: system attribute \"%s\" not renamed", oldattname);
elog(ERROR, "renameatt: system attribute \"%s\" not renamed",
oldattname);
}
newatttup = AttributeNameIndexScan(attrdesc, reltup->t_oid, newattname); newatttup = SearchSysCacheTuple(ATTNAME,
if (PointerIsValid(newatttup)) ObjectIdGetDatum(relid),
PointerGetDatum(newattname),
0, 0);
/* should not already exist */
if (HeapTupleIsValid(newatttup))
{ {
pfree(oldatttup); pfree(oldatttup);
heap_close(attrdesc); elog(ERROR, "renameatt: attribute \"%s\" exists", newattname);
elog(ERROR, "renameatt: attribute \"%s\" exists",
newattname);
} }
namestrcpy(&(((AttributeTupleForm) (GETSTRUCT(oldatttup)))->attname), StrNCpy((((AttributeTupleForm) (GETSTRUCT(oldatttup)))->attname.data),
newattname); newattname, NAMEDATALEN);
oldTID = oldatttup->t_ctid;
/* insert "fixed" tuple */ attrelation = heap_openr(AttributeRelationName);
heap_replace(attrdesc, &oldTID, oldatttup); heap_replace(attrelation, &oldatttup->t_ctid, oldatttup);
/* keep system catalog indices current */ /* keep system catalog indices current */
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs); CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
CatalogIndexInsert(idescs, Num_pg_attr_indices, attrdesc, oldatttup); CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, oldatttup);
CatalogCloseIndices(Num_pg_attr_indices, idescs); CatalogCloseIndices(Num_pg_attr_indices, irelations);
heap_close(attrdesc);
pfree(oldatttup); pfree(oldatttup);
heap_close(attrelation);
} }
/* /*
@ -215,67 +214,52 @@ renameatt(char *relname,
* properly replace the new relation tuple. * properly replace the new relation tuple.
*/ */
void void
renamerel(char oldrelname[], char newrelname[]) renamerel(char *oldrelname, char *newrelname)
{ {
Relation relrdesc; /* for RELATION relation */ Relation relrelation; /* for RELATION relation */
HeapTuple oldreltup, HeapTuple oldreltup,
newreltup; newreltup;
ItemPointerData oldTID;
char oldpath[MAXPGPATH], char oldpath[MAXPGPATH],
newpath[MAXPGPATH]; newpath[MAXPGPATH];
Relation idescs[Num_pg_class_indices]; Relation irelations[Num_pg_class_indices];
if (IsSystemRelationName(oldrelname)) if (IsSystemRelationName(oldrelname))
{
elog(ERROR, "renamerel: system relation \"%s\" not renamed", elog(ERROR, "renamerel: system relation \"%s\" not renamed",
oldrelname); oldrelname);
return;
}
if (IsSystemRelationName(newrelname)) if (IsSystemRelationName(newrelname))
{
elog(ERROR, "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs", elog(ERROR, "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs",
newrelname); newrelname);
return;
}
relrdesc = heap_openr(RelationRelationName); oldreltup = SearchSysCacheTupleCopy(RELNAME,
oldreltup = ClassNameIndexScan(relrdesc, oldrelname); PointerGetDatum(oldrelname),
0, 0, 0);
if (!HeapTupleIsValid(oldreltup))
elog(ERROR, "renamerel: relation \"%s\" does not exist", oldrelname);
if (!PointerIsValid(oldreltup)) newreltup = SearchSysCacheTuple(RELNAME,
{ PointerGetDatum(newrelname),
heap_close(relrdesc); 0, 0, 0);
elog(ERROR, "renamerel: relation \"%s\" does not exist", if (HeapTupleIsValid(newreltup))
oldrelname); elog(ERROR, "renamerel: relation \"%s\" exists", newrelname);
}
newreltup = ClassNameIndexScan(relrdesc, newrelname); /* rename the path first, so if this fails the rename's not done */
if (PointerIsValid(newreltup))
{
pfree(oldreltup);
heap_close(relrdesc);
elog(ERROR, "renamerel: relation \"%s\" exists",
newrelname);
}
/* rename the directory first, so if this fails the rename's not done */
strcpy(oldpath, relpath(oldrelname)); strcpy(oldpath, relpath(oldrelname));
strcpy(newpath, relpath(newrelname)); strcpy(newpath, relpath(newrelname));
if (rename(oldpath, newpath) < 0) if (rename(oldpath, newpath) < 0)
elog(ERROR, "renamerel: unable to rename file: %m"); elog(ERROR, "renamerel: unable to rename file: %s", oldpath);
memmove((char *) (((Form_pg_class) GETSTRUCT(oldreltup))->relname.data), StrNCpy((((Form_pg_class) GETSTRUCT(oldreltup))->relname.data),
newrelname, newrelname, NAMEDATALEN);
NAMEDATALEN);
oldTID = oldreltup->t_ctid;
/* insert fixed rel tuple */ /* insert fixed rel tuple */
heap_replace(relrdesc, &oldTID, oldreltup); relrelation = heap_openr(RelationRelationName);
heap_replace(relrelation, &oldreltup->t_ctid, oldreltup);
/* keep the system catalog indices current */ /* keep the system catalog indices current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations);
CatalogIndexInsert(idescs, Num_pg_class_indices, relrdesc, oldreltup); CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, oldreltup);
CatalogCloseIndices(Num_pg_class_indices, idescs); CatalogCloseIndices(Num_pg_class_indices, irelations);
pfree(oldreltup); heap_close(relrelation);
heap_close(relrdesc);
} }

View File

@ -395,18 +395,18 @@ init_sequence(char *caller, char *name)
if (elm != (SeqTable) NULL) /* we opened sequence from our */ if (elm != (SeqTable) NULL) /* we opened sequence from our */
{ /* SeqTable - check relid ! */ { /* SeqTable - check relid ! */
if (RelationGetRelationId(elm->rel) != elm->relid) if (RelationGetRelid(elm->rel) != elm->relid)
{ {
elog(NOTICE, "%s.%s: sequence was re-created", elog(NOTICE, "%s.%s: sequence was re-created",
name, caller, name); name, caller, name);
elm->cached = elm->last = elm->increment = 0; elm->cached = elm->last = elm->increment = 0;
elm->relid = RelationGetRelationId(elm->rel); elm->relid = RelationGetRelid(elm->rel);
} }
} }
else else
{ {
elm = temp; elm = temp;
elm->relid = RelationGetRelationId(elm->rel); elm->relid = RelationGetRelid(elm->rel);
if (seqtab == (SeqTable) NULL) if (seqtab == (SeqTable) NULL)
seqtab = elm; seqtab = elm;
else else

View File

@ -59,7 +59,6 @@ CreateTrigger(CreateTrigStmt *stmt)
ScanKeyData key; ScanKeyData key;
Relation relrdesc; Relation relrdesc;
HeapTuple tuple; HeapTuple tuple;
ItemPointerData oldTID;
Relation idescs[Num_pg_trigger_indices]; Relation idescs[Num_pg_trigger_indices];
Relation ridescs[Num_pg_class_indices]; Relation ridescs[Num_pg_class_indices];
MemoryContext oldcxt; MemoryContext oldcxt;
@ -118,9 +117,9 @@ CreateTrigger(CreateTrigStmt *stmt)
tgrel = heap_openr(TriggerRelationName); tgrel = heap_openr(TriggerRelationName);
RelationSetLockForWrite(tgrel); RelationSetLockForWrite(tgrel);
ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid, ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid,
F_OIDEQ, rel->rd_id); F_OIDEQ, RelationGetRelid(rel));
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key); tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
while (tuple = heap_getnext(tgscan, 0, (Buffer *) NULL), PointerIsValid(tuple)) while (HeapTupleIsValid(tuple = heap_getnext(tgscan, 0)))
{ {
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple); Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
@ -135,7 +134,9 @@ CreateTrigger(CreateTrigStmt *stmt)
MemSet(fargtypes, 0, 8 * sizeof(Oid)); MemSet(fargtypes, 0, 8 * sizeof(Oid));
tuple = SearchSysCacheTuple(PRONAME, tuple = SearchSysCacheTuple(PRONAME,
PointerGetDatum(stmt->funcname), PointerGetDatum(stmt->funcname),
0, PointerGetDatum(fargtypes), 0); Int32GetDatum(0),
PointerGetDatum(fargtypes),
0);
if (!HeapTupleIsValid(tuple) || if (!HeapTupleIsValid(tuple) ||
((Form_pg_proc) GETSTRUCT(tuple))->prorettype != 0 || ((Form_pg_proc) GETSTRUCT(tuple))->prorettype != 0 ||
((Form_pg_proc) GETSTRUCT(tuple))->pronargs != 0) ((Form_pg_proc) GETSTRUCT(tuple))->pronargs != 0)
@ -157,7 +158,7 @@ CreateTrigger(CreateTrigStmt *stmt)
MemSet(nulls, ' ', Natts_pg_trigger * sizeof(char)); MemSet(nulls, ' ', Natts_pg_trigger * sizeof(char));
values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(rel->rd_id); values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(RelationGetRelid(rel));
values[Anum_pg_trigger_tgname - 1] = NameGetDatum(namein(stmt->trigname)); values[Anum_pg_trigger_tgname - 1] = NameGetDatum(namein(stmt->trigname));
values[Anum_pg_trigger_tgfoid - 1] = ObjectIdGetDatum(tuple->t_oid); values[Anum_pg_trigger_tgfoid - 1] = ObjectIdGetDatum(tuple->t_oid);
values[Anum_pg_trigger_tgtype - 1] = Int16GetDatum(tgtype); values[Anum_pg_trigger_tgtype - 1] = Int16GetDatum(tgtype);
@ -218,17 +219,16 @@ CreateTrigger(CreateTrigStmt *stmt)
pfree(DatumGetPointer(values[Anum_pg_trigger_tgargs - 1])); pfree(DatumGetPointer(values[Anum_pg_trigger_tgargs - 1]));
/* update pg_class */ /* update pg_class */
relrdesc = heap_openr(RelationRelationName); tuple = SearchSysCacheTupleCopy(RELNAME,
tuple = ClassNameIndexScan(relrdesc, stmt->relname); PointerGetDatum(stmt->relname),
if (!PointerIsValid(tuple)) 0, 0, 0);
{ if (!HeapTupleIsValid(tuple))
heap_close(relrdesc);
elog(ERROR, "CreateTrigger: relation %s not found in pg_class", stmt->relname); elog(ERROR, "CreateTrigger: relation %s not found in pg_class", stmt->relname);
}
relrdesc = heap_openr(RelationRelationName);
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found + 1; ((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found + 1;
RelationInvalidateHeapTuple(relrdesc, tuple); RelationInvalidateHeapTuple(relrdesc, tuple);
oldTID = tuple->t_ctid; heap_replace(relrdesc, &tuple->t_ctid, tuple);
heap_replace(relrdesc, &oldTID, tuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
CatalogIndexInsert(ridescs, Num_pg_class_indices, relrdesc, tuple); CatalogIndexInsert(ridescs, Num_pg_class_indices, relrdesc, tuple);
CatalogCloseIndices(Num_pg_class_indices, ridescs); CatalogCloseIndices(Num_pg_class_indices, ridescs);
@ -254,12 +254,11 @@ DropTrigger(DropTrigStmt *stmt)
ScanKeyData key; ScanKeyData key;
Relation relrdesc; Relation relrdesc;
HeapTuple tuple; HeapTuple tuple;
ItemPointerData oldTID;
Relation ridescs[Num_pg_class_indices]; Relation ridescs[Num_pg_class_indices];
MemoryContext oldcxt; MemoryContext oldcxt;
int found = 0; int found = 0;
int tgfound = 0; int tgfound = 0;
#ifndef NO_SECURITY #ifndef NO_SECURITY
if (!pg_ownercheck(GetPgUserName(), stmt->relname, RELNAME)) if (!pg_ownercheck(GetPgUserName(), stmt->relname, RELNAME))
elog(ERROR, "%s: %s", stmt->relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]); elog(ERROR, "%s: %s", stmt->relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
@ -274,9 +273,9 @@ DropTrigger(DropTrigStmt *stmt)
tgrel = heap_openr(TriggerRelationName); tgrel = heap_openr(TriggerRelationName);
RelationSetLockForWrite(tgrel); RelationSetLockForWrite(tgrel);
ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid, ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid,
F_OIDEQ, rel->rd_id); F_OIDEQ, RelationGetRelid(rel));
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key); tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
while (tuple = heap_getnext(tgscan, 0, (Buffer *) NULL), PointerIsValid(tuple)) while (HeapTupleIsValid(tuple = heap_getnext(tgscan, 0)))
{ {
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple); Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
@ -298,18 +297,17 @@ DropTrigger(DropTrigStmt *stmt)
RelationUnsetLockForWrite(tgrel); RelationUnsetLockForWrite(tgrel);
heap_close(tgrel); heap_close(tgrel);
tuple = SearchSysCacheTupleCopy(RELNAME,
PointerGetDatum(stmt->relname),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "DropTrigger: relation %s not found in pg_class", stmt->relname);
/* update pg_class */ /* update pg_class */
relrdesc = heap_openr(RelationRelationName); relrdesc = heap_openr(RelationRelationName);
tuple = ClassNameIndexScan(relrdesc, stmt->relname);
if (!PointerIsValid(tuple))
{
heap_close(relrdesc);
elog(ERROR, "DropTrigger: relation %s not found in pg_class", stmt->relname);
}
((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found; ((Form_pg_class) GETSTRUCT(tuple))->reltriggers = found;
RelationInvalidateHeapTuple(relrdesc, tuple); RelationInvalidateHeapTuple(relrdesc, tuple);
oldTID = tuple->t_ctid; heap_replace(relrdesc, &tuple->t_ctid, tuple);
heap_replace(relrdesc, &oldTID, tuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
CatalogIndexInsert(ridescs, Num_pg_class_indices, relrdesc, tuple); CatalogIndexInsert(ridescs, Num_pg_class_indices, relrdesc, tuple);
CatalogCloseIndices(Num_pg_class_indices, ridescs); CatalogCloseIndices(Num_pg_class_indices, ridescs);
@ -338,11 +336,11 @@ RelationRemoveTriggers(Relation rel)
tgrel = heap_openr(TriggerRelationName); tgrel = heap_openr(TriggerRelationName);
RelationSetLockForWrite(tgrel); RelationSetLockForWrite(tgrel);
ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid, ScanKeyEntryInitialize(&key, 0, Anum_pg_trigger_tgrelid,
F_OIDEQ, rel->rd_id); F_OIDEQ, RelationGetRelid(rel));
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key); tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
while (tup = heap_getnext(tgscan, 0, (Buffer *) NULL), PointerIsValid(tup)) while (HeapTupleIsValid(tup = heap_getnext(tgscan, 0)))
heap_delete(tgrel, &tup->t_ctid); heap_delete(tgrel, &tup->t_ctid);
heap_endscan(tgscan); heap_endscan(tgscan);
@ -377,7 +375,7 @@ RelationBuildTriggers(Relation relation)
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDEQ, (RegProcedure) F_OIDEQ,
ObjectIdGetDatum(relation->rd_id)); ObjectIdGetDatum(RelationGetRelid(relation)));
tgrel = heap_openr(TriggerRelationName); tgrel = heap_openr(TriggerRelationName);
RelationSetLockForRead(tgrel); RelationSetLockForRead(tgrel);

View File

@ -95,7 +95,6 @@ DefineUser(CreateUserStmt *stmt)
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple tuple; HeapTuple tuple;
Datum datum; Datum datum;
Buffer buffer;
char sql[512]; char sql[512];
char *sql_end; char *sql_end;
bool exists = false, bool exists = false,
@ -135,7 +134,7 @@ DefineUser(CreateUserStmt *stmt)
RelationSetLockForWrite(pg_shadow_rel); RelationSetLockForWrite(pg_shadow_rel);
scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL); scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{ {
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n); datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
@ -145,8 +144,6 @@ DefineUser(CreateUserStmt *stmt)
datum = heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_shadow_dsc, &n); datum = heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_shadow_dsc, &n);
if ((int) datum > max_id) if ((int) datum > max_id)
max_id = (int) datum; max_id = (int) datum;
ReleaseBuffer(buffer);
} }
heap_endscan(scan); heap_endscan(scan);
@ -223,15 +220,10 @@ AlterUser(AlterUserStmt *stmt)
char *pg_shadow; char *pg_shadow;
Relation pg_shadow_rel; Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc; TupleDesc pg_shadow_dsc;
HeapScanDesc scan;
HeapTuple tuple; HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512]; char sql[512];
char *sql_end; char *sql_end;
bool exists = false, bool inblock;
n,
inblock;
if (stmt->password) if (stmt->password)
CheckPgUserAclNotNull(); CheckPgUserAclNotNull();
@ -264,25 +256,14 @@ AlterUser(AlterUserStmt *stmt)
*/ */
RelationSetLockForWrite(pg_shadow_rel); RelationSetLockForWrite(pg_shadow_rel);
scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL); tuple = SearchSysCacheTuple(USENAME,
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) PointerGetDatum(stmt->user),
{ 0, 0, 0);
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n); if (!HeapTupleIsValid(tuple))
if (!strncmp((char *) datum, stmt->user, strlen(stmt->user)))
{
exists = true;
ReleaseBuffer(buffer);
break;
}
}
heap_endscan(scan);
if (!exists)
{ {
RelationUnsetLockForWrite(pg_shadow_rel); RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel); heap_close(pg_shadow_rel);
UserAbortTransactionBlock(); UserAbortTransactionBlock(); /* needed? */
elog(ERROR, "alterUser: user \"%s\" does not exist", stmt->user); elog(ERROR, "alterUser: user \"%s\" does not exist", stmt->user);
return; return;
} }
@ -354,12 +335,11 @@ RemoveUser(char *user)
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple tuple; HeapTuple tuple;
Datum datum; Datum datum;
Buffer buffer;
char sql[512]; char sql[512];
bool n, bool n,
inblock; inblock;
int usesysid = -1, int32 usesysid;
ndbase = 0; int ndbase = 0;
char **dbase = NULL; char **dbase = NULL;
if (!(inblock = IsTransactionBlock())) if (!(inblock = IsTransactionBlock()))
@ -375,7 +355,6 @@ RemoveUser(char *user)
UserAbortTransactionBlock(); UserAbortTransactionBlock();
elog(ERROR, "removeUser: user \"%s\" does not have SELECT and DELETE privilege for \"%s\"", elog(ERROR, "removeUser: user \"%s\" does not have SELECT and DELETE privilege for \"%s\"",
pg_shadow, ShadowRelationName); pg_shadow, ShadowRelationName);
return;
} }
/* /*
@ -393,30 +372,19 @@ RemoveUser(char *user)
*/ */
RelationSetLockForWrite(pg_shadow_rel); RelationSetLockForWrite(pg_shadow_rel);
scan = heap_beginscan(pg_shadow_rel, false, SnapshotNow, 0, NULL); tuple = SearchSysCacheTuple(USENAME,
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) PointerGetDatum(user),
{ 0, 0, 0);
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_dsc, &n); if (!HeapTupleIsValid(tuple))
if (!strncmp((char *) datum, user, strlen(user)))
{
usesysid = (int) heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_dsc, &n);
ReleaseBuffer(buffer);
break;
}
ReleaseBuffer(buffer);
}
heap_endscan(scan);
if (usesysid == -1)
{ {
RelationUnsetLockForWrite(pg_shadow_rel); RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel); heap_close(pg_shadow_rel);
UserAbortTransactionBlock(); UserAbortTransactionBlock();
elog(ERROR, "removeUser: user \"%s\" does not exist", user); elog(ERROR, "removeUser: user \"%s\" does not exist", user);
return;
} }
usesysid = (int32) heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_dsc, &n);
/* /*
* Perform a scan of the pg_database relation to find the databases * Perform a scan of the pg_database relation to find the databases
* owned by usesysid. Then drop them. * owned by usesysid. Then drop them.
@ -425,7 +393,7 @@ RemoveUser(char *user)
pg_dsc = RelationGetTupleDescriptor(pg_rel); pg_dsc = RelationGetTupleDescriptor(pg_rel);
scan = heap_beginscan(pg_rel, false, SnapshotNow, 0, NULL); scan = heap_beginscan(pg_rel, false, SnapshotNow, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{ {
datum = heap_getattr(tuple, Anum_pg_database_datdba, pg_dsc, &n); datum = heap_getattr(tuple, Anum_pg_database_datdba, pg_dsc, &n);
@ -440,7 +408,6 @@ RemoveUser(char *user)
dbase[ndbase++][NAMEDATALEN] = '\0'; dbase[ndbase++][NAMEDATALEN] = '\0';
} }
} }
ReleaseBuffer(buffer);
} }
heap_endscan(scan); heap_endscan(scan);
heap_close(pg_rel); heap_close(pg_rel);
@ -496,17 +463,18 @@ RemoveUser(char *user)
static void static void
CheckPgUserAclNotNull() CheckPgUserAclNotNull()
{ {
HeapTuple htp; HeapTuple htup;
htp = SearchSysCacheTuple(RELNAME, PointerGetDatum(ShadowRelationName), htup = SearchSysCacheTuple(RELNAME,
PointerGetDatum(ShadowRelationName),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(htup))
{ {
elog(ERROR, "IsPgUserAclNull: class \"%s\" not found", elog(ERROR, "IsPgUserAclNull: class \"%s\" not found",
ShadowRelationName); ShadowRelationName);
} }
if (heap_attisnull(htp, Anum_pg_class_relacl)) if (heap_attisnull(htup, Anum_pg_class_relacl))
{ {
elog(NOTICE, "To use passwords, you have to revoke permissions on pg_shadow"); elog(NOTICE, "To use passwords, you have to revoke permissions on pg_shadow");
elog(NOTICE, "so normal users can not read the passwords."); elog(NOTICE, "so normal users can not read the passwords.");

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.69 1998/07/27 19:37:53 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.70 1998/08/19 02:01:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -55,7 +55,7 @@
/* #include <port-protos.h> *//* Why? */ /* #include <port-protos.h> *//* Why? */
extern int BlowawayRelationBuffers(Relation rdesc, BlockNumber block); extern int BlowawayRelationBuffers(Relation rel, BlockNumber block);
bool VacuumRunning = false; bool VacuumRunning = false;
@ -84,7 +84,7 @@ static void vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList vpl);
static void vc_vacpage(Page page, VPageDescr vpd); static void vc_vacpage(Page page, VPageDescr vpd);
static void vc_vaconeind(VPageList vpl, Relation indrel, int nhtups); static void vc_vaconeind(VPageList vpl, Relation indrel, int nhtups);
static void vc_scanoneind(Relation indrel, int nhtups); static void vc_scanoneind(Relation indrel, int nhtups);
static void vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup); static void vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tuple);
static void vc_bucketcpy(AttributeTupleForm attr, Datum value, Datum *bucket, int16 *bucket_len); static void vc_bucketcpy(AttributeTupleForm attr, Datum value, Datum *bucket, int16 *bucket_len);
static void vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelstats); static void vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelstats);
static void vc_delhilowstats(Oid relid, int attcnt, int *attnums); static void vc_delhilowstats(Oid relid, int attcnt, int *attnums);
@ -261,7 +261,6 @@ vc_getrels(NameData *VacRelP)
TupleDesc pgcdesc; TupleDesc pgcdesc;
HeapScanDesc pgcscan; HeapScanDesc pgcscan;
HeapTuple pgctup; HeapTuple pgctup;
Buffer buf;
PortalVariableMemory portalmem; PortalVariableMemory portalmem;
MemoryContext old; MemoryContext old;
VRelList vrl, VRelList vrl,
@ -270,8 +269,8 @@ vc_getrels(NameData *VacRelP)
char *rname; char *rname;
char rkind; char rkind;
bool n; bool n;
ScanKeyData pgckey;
bool found = false; bool found = false;
ScanKeyData pgckey;
StartTransactionCommand(); StartTransactionCommand();
@ -295,9 +294,8 @@ vc_getrels(NameData *VacRelP)
pgcscan = heap_beginscan(pgclass, false, SnapshotNow, 1, &pgckey); pgcscan = heap_beginscan(pgclass, false, SnapshotNow, 1, &pgckey);
while (HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0, &buf))) while (HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0)))
{ {
found = true; found = true;
d = heap_getattr(pgctup, Anum_pg_class_relname, pgcdesc, &n); d = heap_getattr(pgctup, Anum_pg_class_relname, pgcdesc, &n);
@ -314,7 +312,6 @@ vc_getrels(NameData *VacRelP)
{ {
elog(NOTICE, "Rel %s: can't vacuum LargeObjects now", elog(NOTICE, "Rel %s: can't vacuum LargeObjects now",
rname); rname);
ReleaseBuffer(buf);
continue; continue;
} }
@ -325,7 +322,6 @@ vc_getrels(NameData *VacRelP)
/* skip system relations */ /* skip system relations */
if (rkind != 'r') if (rkind != 'r')
{ {
ReleaseBuffer(buf);
elog(NOTICE, "Vacuum: can not process index and certain system tables"); elog(NOTICE, "Vacuum: can not process index and certain system tables");
continue; continue;
} }
@ -343,9 +339,6 @@ vc_getrels(NameData *VacRelP)
cur->vrl_relid = pgctup->t_oid; cur->vrl_relid = pgctup->t_oid;
cur->vrl_next = (VRelList) NULL; cur->vrl_next = (VRelList) NULL;
/* wei hates it if you forget to do this */
ReleaseBuffer(buf);
} }
if (found == false) if (found == false)
elog(NOTICE, "Vacuum: table not found"); elog(NOTICE, "Vacuum: table not found");
@ -378,10 +371,7 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
TupleDesc pgcdesc; TupleDesc pgcdesc;
HeapTuple pgctup, HeapTuple pgctup,
pgttup; pgttup;
Buffer pgcbuf;
HeapScanDesc pgcscan;
Relation onerel; Relation onerel;
ScanKeyData pgckey;
VPageListData Vvpl; /* List of pages to vacuum and/or clean VPageListData Vvpl; /* List of pages to vacuum and/or clean
* indices */ * indices */
VPageListData Fvpl; /* List of pages with space enough for VPageListData Fvpl; /* List of pages with space enough for
@ -394,22 +384,18 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
StartTransactionCommand(); StartTransactionCommand();
ScanKeyEntryInitialize(&pgckey, 0x0, ObjectIdAttributeNumber,
F_OIDEQ,
ObjectIdGetDatum(relid));
pgclass = heap_openr(RelationRelationName); pgclass = heap_openr(RelationRelationName);
pgcdesc = RelationGetTupleDescriptor(pgclass); pgcdesc = RelationGetTupleDescriptor(pgclass);
pgcscan = heap_beginscan(pgclass, false, SnapshotNow, 1, &pgckey);
/* /*
* Race condition -- if the pg_class tuple has gone away since the * Race condition -- if the pg_class tuple has gone away since the
* last time we saw it, we don't need to vacuum it. * last time we saw it, we don't need to vacuum it.
*/ */
pgctup = SearchSysCacheTuple(RELOID,
if (!HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0, &pgcbuf))) ObjectIdGetDatum(relid),
0, 0, 0);
if (!HeapTupleIsValid(pgctup))
{ {
heap_endscan(pgcscan);
heap_close(pgclass); heap_close(pgclass);
CommitTransactionCommand(); CommitTransactionCommand();
return; return;
@ -508,7 +494,7 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
stats->f_cmpgt.fn_addr = NULL; stats->f_cmpgt.fn_addr = NULL;
pgttup = SearchSysCacheTuple(TYPOID, pgttup = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(stats->attr->atttypid), ObjectIdGetDatum(stats->attr->atttypid),
0, 0, 0); 0, 0, 0);
if (HeapTupleIsValid(pgttup)) if (HeapTupleIsValid(pgttup))
stats->outfunc = ((TypeTupleForm) GETSTRUCT(pgttup))->typoutput; stats->outfunc = ((TypeTupleForm) GETSTRUCT(pgttup))->typoutput;
@ -581,7 +567,6 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
/* all done with this class */ /* all done with this class */
heap_close(onerel); heap_close(onerel);
heap_endscan(pgcscan);
heap_close(pgclass); heap_close(pgclass);
/* update statistics in pg_class */ /* update statistics in pg_class */
@ -610,8 +595,8 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
blkno; blkno;
ItemId itemid; ItemId itemid;
ItemPointer itemptr; ItemPointer itemptr;
HeapTuple htup;
Buffer buf; Buffer buf;
HeapTuple tuple;
Page page, Page page,
tempPage = NULL; tempPage = NULL;
OffsetNumber offnum, OffsetNumber offnum,
@ -706,23 +691,23 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
continue; continue;
} }
htup = (HeapTuple) PageGetItem(page, itemid); tuple = (HeapTuple) PageGetItem(page, itemid);
tupgone = false; tupgone = false;
if (!(htup->t_infomask & HEAP_XMIN_COMMITTED)) if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
{ {
if (htup->t_infomask & HEAP_XMIN_INVALID) if (tuple->t_infomask & HEAP_XMIN_INVALID)
tupgone = true; tupgone = true;
else else
{ {
if (TransactionIdDidAbort(htup->t_xmin)) if (TransactionIdDidAbort(tuple->t_xmin))
tupgone = true; tupgone = true;
else if (TransactionIdDidCommit(htup->t_xmin)) else if (TransactionIdDidCommit(tuple->t_xmin))
{ {
htup->t_infomask |= HEAP_XMIN_COMMITTED; tuple->t_infomask |= HEAP_XMIN_COMMITTED;
pgchanged = true; pgchanged = true;
} }
else if (!TransactionIdIsInProgress(htup->t_xmin)) else if (!TransactionIdIsInProgress(tuple->t_xmin))
{ {
/* /*
@ -735,7 +720,7 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
else else
{ {
elog(NOTICE, "Rel %s: TID %u/%u: InsertTransactionInProgress %u - can't shrink relation", elog(NOTICE, "Rel %s: TID %u/%u: InsertTransactionInProgress %u - can't shrink relation",
relname, blkno, offnum, htup->t_xmin); relname, blkno, offnum, tuple->t_xmin);
do_shrinking = false; do_shrinking = false;
} }
} }
@ -745,32 +730,32 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
* here we are concerned about tuples with xmin committed and * here we are concerned about tuples with xmin committed and
* xmax unknown or committed * xmax unknown or committed
*/ */
if (htup->t_infomask & HEAP_XMIN_COMMITTED && if (tuple->t_infomask & HEAP_XMIN_COMMITTED &&
!(htup->t_infomask & HEAP_XMAX_INVALID)) !(tuple->t_infomask & HEAP_XMAX_INVALID))
{ {
if (htup->t_infomask & HEAP_XMAX_COMMITTED) if (tuple->t_infomask & HEAP_XMAX_COMMITTED)
tupgone = true; tupgone = true;
else if (TransactionIdDidAbort(htup->t_xmax)) else if (TransactionIdDidAbort(tuple->t_xmax))
{ {
htup->t_infomask |= HEAP_XMAX_INVALID; tuple->t_infomask |= HEAP_XMAX_INVALID;
pgchanged = true; pgchanged = true;
} }
else if (TransactionIdDidCommit(htup->t_xmax)) else if (TransactionIdDidCommit(tuple->t_xmax))
tupgone = true; tupgone = true;
else if (!TransactionIdIsInProgress(htup->t_xmax)) else if (!TransactionIdIsInProgress(tuple->t_xmax))
{ {
/* /*
* Not Aborted, Not Committed, Not in Progress - so it * Not Aborted, Not Committed, Not in Progress - so it
* from crashed process. - vadim 06/02/97 * from crashed process. - vadim 06/02/97
*/ */
htup->t_infomask |= HEAP_XMAX_INVALID;; tuple->t_infomask |= HEAP_XMAX_INVALID;;
pgchanged = true; pgchanged = true;
} }
else else
{ {
elog(NOTICE, "Rel %s: TID %u/%u: DeleteTransactionInProgress %u - can't shrink relation", elog(NOTICE, "Rel %s: TID %u/%u: DeleteTransactionInProgress %u - can't shrink relation",
relname, blkno, offnum, htup->t_xmax); relname, blkno, offnum, tuple->t_xmax);
do_shrinking = false; do_shrinking = false;
} }
} }
@ -779,7 +764,7 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
* It's possibly! But from where it comes ? And should we fix * It's possibly! But from where it comes ? And should we fix
* it ? - vadim 11/28/96 * it ? - vadim 11/28/96
*/ */
itemptr = &(htup->t_ctid); itemptr = &(tuple->t_ctid);
if (!ItemPointerIsValid(itemptr) || if (!ItemPointerIsValid(itemptr) ||
BlockIdGetBlockNumber(&(itemptr->ip_blkid)) != blkno) BlockIdGetBlockNumber(&(itemptr->ip_blkid)) != blkno)
{ {
@ -792,13 +777,13 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
/* /*
* Other checks... * Other checks...
*/ */
if (htup->t_len != itemid->lp_len) if (tuple->t_len != itemid->lp_len)
{ {
elog(NOTICE, "Rel %s: TID %u/%u: TUPLE_LEN IN PAGEHEADER %u IS NOT THE SAME AS IN TUPLEHEADER %u. TUPGONE %d.", elog(NOTICE, "Rel %s: TID %u/%u: TUPLE_LEN IN PAGEHEADER %u IS NOT THE SAME AS IN TUPLEHEADER %u. TUPGONE %d.",
relname, blkno, offnum, relname, blkno, offnum,
itemid->lp_len, htup->t_len, tupgone); itemid->lp_len, tuple->t_len, tupgone);
} }
if (!OidIsValid(htup->t_oid)) if (!OidIsValid(tuple->t_oid))
{ {
elog(NOTICE, "Rel %s: TID %u/%u: OID IS INVALID. TUPGONE %d.", elog(NOTICE, "Rel %s: TID %u/%u: OID IS INVALID. TUPGONE %d.",
relname, blkno, offnum, tupgone); relname, blkno, offnum, tupgone);
@ -830,11 +815,11 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
{ {
ntups++; ntups++;
notup = false; notup = false;
if (htup->t_len < min_tlen) if (tuple->t_len < min_tlen)
min_tlen = htup->t_len; min_tlen = tuple->t_len;
if (htup->t_len > max_tlen) if (tuple->t_len > max_tlen)
max_tlen = htup->t_len; max_tlen = tuple->t_len;
vc_attrstats(onerel, vacrelstats, htup); vc_attrstats(onerel, vacrelstats, tuple);
} }
} }
@ -947,7 +932,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
moff; moff;
ItemId itemid, ItemId itemid,
newitemid; newitemid;
HeapTuple htup, HeapTuple tuple,
newtup; newtup;
TupleDesc tupdesc = NULL; TupleDesc tupdesc = NULL;
Datum *idatum = NULL; Datum *idatum = NULL;
@ -1064,8 +1049,8 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
if (!ItemIdIsUsed(itemid)) if (!ItemIdIsUsed(itemid))
continue; continue;
htup = (HeapTuple) PageGetItem(page, itemid); tuple = (HeapTuple) PageGetItem(page, itemid);
tlen = htup->t_len; tlen = tuple->t_len;
/* try to find new page for this tuple */ /* try to find new page for this tuple */
if (ToBuf == InvalidBuffer || if (ToBuf == InvalidBuffer ||
@ -1112,7 +1097,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
/* copy tuple */ /* copy tuple */
newtup = (HeapTuple) palloc(tlen); newtup = (HeapTuple) palloc(tlen);
memmove((char *) newtup, (char *) htup, tlen); memmove((char *) newtup, (char *) tuple, tlen);
/* store transaction information */ /* store transaction information */
TransactionIdStore(myXID, &(newtup->t_xmin)); TransactionIdStore(myXID, &(newtup->t_xmin));
@ -1138,10 +1123,10 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
ItemPointerSet(&(newtup->t_ctid), ToVpd->vpd_blkno, newoff); ItemPointerSet(&(newtup->t_ctid), ToVpd->vpd_blkno, newoff);
/* now logically delete end-tuple */ /* now logically delete end-tuple */
TransactionIdStore(myXID, &(htup->t_xmax)); TransactionIdStore(myXID, &(tuple->t_xmax));
htup->t_cmax = myCID; tuple->t_cmax = myCID;
/* set xmax to unknown */ /* set xmax to unknown */
htup->t_infomask &= ~(HEAP_XMAX_INVALID | HEAP_XMAX_COMMITTED); tuple->t_infomask &= ~(HEAP_XMAX_INVALID | HEAP_XMAX_COMMITTED);
ToVpd->vpd_nusd++; ToVpd->vpd_nusd++;
nmoved++; nmoved++;
@ -1158,7 +1143,6 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
(AttrNumber *) &(idcur->tform->indkey[0]), (AttrNumber *) &(idcur->tform->indkey[0]),
newtup, newtup,
tupdesc, tupdesc,
InvalidBuffer,
idatum, idatum,
inulls, inulls,
idcur->finfoP); idcur->finfoP);
@ -1244,10 +1228,10 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
itemid = PageGetItemId(page, newoff); itemid = PageGetItemId(page, newoff);
if (!ItemIdIsUsed(itemid)) if (!ItemIdIsUsed(itemid))
continue; continue;
htup = (HeapTuple) PageGetItem(page, itemid); tuple = (HeapTuple) PageGetItem(page, itemid);
if (TransactionIdEquals((TransactionId) htup->t_xmin, myXID)) if (TransactionIdEquals((TransactionId) tuple->t_xmin, myXID))
{ {
htup->t_infomask |= HEAP_XMIN_COMMITTED; tuple->t_infomask |= HEAP_XMIN_COMMITTED;
ntups++; ntups++;
} }
} }
@ -1307,8 +1291,8 @@ Elapsed %u/%u sec.",
itemid = PageGetItemId(page, offnum); itemid = PageGetItemId(page, offnum);
if (!ItemIdIsUsed(itemid)) if (!ItemIdIsUsed(itemid))
continue; continue;
htup = (HeapTuple) PageGetItem(page, itemid); tuple = (HeapTuple) PageGetItem(page, itemid);
Assert(TransactionIdEquals((TransactionId) htup->t_xmax, myXID)); Assert(TransactionIdEquals((TransactionId) tuple->t_xmax, myXID));
itemid->lp_flags &= ~LP_USED; itemid->lp_flags &= ~LP_USED;
ntups++; ntups++;
} }
@ -1453,7 +1437,7 @@ vc_scanoneind(Relation indrel, int nhtups)
/* now update statistics in pg_class */ /* now update statistics in pg_class */
nipages = RelationGetNumberOfBlocks(indrel); nipages = RelationGetNumberOfBlocks(indrel);
vc_updstats(indrel->rd_id, nipages, nitups, false, NULL); vc_updstats(RelationGetRelid(indrel), nipages, nitups, false, NULL);
getrusage(RUSAGE_SELF, &ru1); getrusage(RUSAGE_SELF, &ru1);
@ -1526,7 +1510,6 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
else else
nitups++; nitups++;
/* be tidy */
pfree(res); pfree(res);
} }
@ -1534,7 +1517,7 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
/* now update statistics in pg_class */ /* now update statistics in pg_class */
nipages = RelationGetNumberOfBlocks(indrel); nipages = RelationGetNumberOfBlocks(indrel);
vc_updstats(indrel->rd_id, nipages, nitups, false, NULL); vc_updstats(RelationGetRelid(indrel), nipages, nitups, false, NULL);
getrusage(RUSAGE_SELF, &ru1); getrusage(RUSAGE_SELF, &ru1);
@ -1615,7 +1598,7 @@ vc_tidreapped(ItemPointer itemptr, VPageList vpl)
* *
*/ */
static void static void
vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup) vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple tuple)
{ {
int i, int i,
attr_cnt = vacrelstats->va_natts; attr_cnt = vacrelstats->va_natts;
@ -1629,7 +1612,7 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup)
VacAttrStats *stats = &vacattrstats[i]; VacAttrStats *stats = &vacattrstats[i];
bool value_hit = true; bool value_hit = true;
value = heap_getattr(htup, value = heap_getattr(tuple,
stats->attr->attnum, tupDesc, &isnull); stats->attr->attnum, tupDesc, &isnull);
if (!VacAttrStatsEqValid(stats)) if (!VacAttrStatsEqValid(stats))
@ -1751,35 +1734,28 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
Relation rd, Relation rd,
ad, ad,
sd; sd;
HeapScanDesc rsdesc, HeapScanDesc scan;
asdesc;
TupleDesc sdesc;
HeapTuple rtup, HeapTuple rtup,
atup, atup,
stup; stup;
Buffer rbuf,
abuf;
Form_pg_class pgcform; Form_pg_class pgcform;
ScanKeyData rskey, ScanKeyData askey;
askey;
AttributeTupleForm attp; AttributeTupleForm attp;
/* /*
* update number of tuples and number of pages in pg_class * update number of tuples and number of pages in pg_class
*/ */
ScanKeyEntryInitialize(&rskey, 0x0, ObjectIdAttributeNumber, rtup = SearchSysCacheTupleCopy(RELOID,
F_OIDEQ, ObjectIdGetDatum(relid),
ObjectIdGetDatum(relid)); 0, 0, 0);
if (!HeapTupleIsValid(rtup))
elog(ERROR, "pg_class entry for relid %d vanished during vacuuming",
relid);
rd = heap_openr(RelationRelationName); rd = heap_openr(RelationRelationName);
rsdesc = heap_beginscan(rd, false, SnapshotNow, 1, &rskey);
if (!HeapTupleIsValid(rtup = heap_getnext(rsdesc, 0, &rbuf)))
elog(ERROR, "pg_class entry for relid %d vanished during vacuuming",
relid);
/* overwrite the existing statistics in the tuple */ /* overwrite the existing statistics in the tuple */
vc_setpagelock(rd, BufferGetBlockNumber(rbuf)); vc_setpagelock(rd, ItemPointerGetBlockNumber(&rtup->t_ctid));
pgcform = (Form_pg_class) GETSTRUCT(rtup); pgcform = (Form_pg_class) GETSTRUCT(rtup);
pgcform->reltuples = ntups; pgcform->reltuples = ntups;
pgcform->relpages = npages; pgcform->relpages = npages;
@ -1795,9 +1771,9 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
ScanKeyEntryInitialize(&askey, 0, Anum_pg_attribute_attrelid, ScanKeyEntryInitialize(&askey, 0, Anum_pg_attribute_attrelid,
F_INT4EQ, relid); F_INT4EQ, relid);
asdesc = heap_beginscan(ad, false, SnapshotNow, 1, &askey); scan = heap_beginscan(ad, false, SnapshotNow, 1, &askey);
while (HeapTupleIsValid(atup = heap_getnext(asdesc, 0, &abuf))) while (HeapTupleIsValid(atup = heap_getnext(scan, 0)))
{ {
int i; int i;
float32data selratio; /* average ratio of rows selected float32data selratio; /* average ratio of rows selected
@ -1824,7 +1800,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
if (VacAttrStatsEqValid(stats)) if (VacAttrStatsEqValid(stats))
{ {
vc_setpagelock(ad, BufferGetBlockNumber(abuf)); vc_setpagelock(ad, ItemPointerGetBlockNumber(&atup->t_ctid));
if (stats->nonnull_cnt + stats->null_cnt == 0 || if (stats->nonnull_cnt + stats->null_cnt == 0 ||
(stats->null_cnt <= 1 && stats->best_cnt == 1)) (stats->null_cnt <= 1 && stats->best_cnt == 1))
@ -1853,7 +1829,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
if (selratio > 1.0) if (selratio > 1.0)
selratio = 1.0; selratio = 1.0;
attp->attdisbursion = selratio; attp->attdisbursion = selratio;
WriteNoReleaseBuffer(abuf); WriteNoReleaseBuffer(ItemPointerGetBlockNumber(&atup->t_ctid));
/* DO PG_STATISTIC INSERTS */ /* DO PG_STATISTIC INSERTS */
@ -1888,9 +1864,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
values[i++] = (Datum) fmgr(F_TEXTIN, out_string); values[i++] = (Datum) fmgr(F_TEXTIN, out_string);
pfree(out_string); pfree(out_string);
sdesc = sd->rd_att; stup = heap_formtuple(sd->rd_att, values, nulls);
stup = heap_formtuple(sdesc, values, nulls);
/* ---------------- /* ----------------
* insert the tuple in the relation and get the tuple's oid. * insert the tuple in the relation and get the tuple's oid.
@ -1903,13 +1877,15 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
} }
} }
} }
heap_endscan(asdesc); heap_endscan(scan);
heap_close(ad); heap_close(ad);
heap_close(sd); heap_close(sd);
} }
/* XXX -- after write, should invalidate relcache in other backends */ /* XXX -- after write, should invalidate relcache in other backends */
WriteNoReleaseBuffer(rbuf); /* heap_endscan release scan' buffers ? */ #ifdef NOT_USED
WriteNoReleaseBuffer(&rtup->t_ctid); /* heap_endscan release scan' buffers ? */
#endif
/* /*
* invalidating system relations confuses the function cache of * invalidating system relations confuses the function cache of
@ -1918,8 +1894,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
if (!IsSystemRelationName(pgcform->relname.data)) if (!IsSystemRelationName(pgcform->relname.data))
RelationInvalidateHeapTuple(rd, rtup); RelationInvalidateHeapTuple(rd, rtup);
/* that's all, folks */ pfree(rtup);
heap_endscan(rsdesc);
heap_close(rd); heap_close(rd);
} }
@ -1947,7 +1922,7 @@ vc_delhilowstats(Oid relid, int attcnt, int *attnums)
else else
pgsscan = heap_beginscan(pgstatistic, false, SnapshotNow, 0, NULL); pgsscan = heap_beginscan(pgstatistic, false, SnapshotNow, 0, NULL);
while (HeapTupleIsValid(pgstup = heap_getnext(pgsscan, 0, NULL))) while (HeapTupleIsValid(pgstup = heap_getnext(pgsscan, 0)))
{ {
if (attcnt > 0) if (attcnt > 0)
{ {
@ -2156,7 +2131,7 @@ vc_getindices(Oid relid, int *nindices, Relation **Irel)
pgiscan = heap_beginscan(pgindex, false, SnapshotNow, 1, &pgikey); pgiscan = heap_beginscan(pgindex, false, SnapshotNow, 1, &pgikey);
while (HeapTupleIsValid(pgitup = heap_getnext(pgiscan, 0, NULL))) while (HeapTupleIsValid(pgitup = heap_getnext(pgiscan, 0)))
{ {
d = heap_getattr(pgitup, Anum_pg_index_indexrelid, d = heap_getattr(pgitup, Anum_pg_index_indexrelid,
pgidesc, &n); pgidesc, &n);
@ -2233,7 +2208,7 @@ vc_mkindesc(Relation onerel, int nindices, Relation *Irel, IndDesc **Idesc)
{ {
pgIndexTup = pgIndexTup =
SearchSysCacheTuple(INDEXRELID, SearchSysCacheTuple(INDEXRELID,
ObjectIdGetDatum(Irel[i]->rd_id), ObjectIdGetDatum(RelationGetRelid(Irel[i])),
0, 0, 0); 0, 0, 0);
Assert(pgIndexTup); Assert(pgIndexTup);
idcur->tform = (IndexTupleForm) GETSTRUCT(pgIndexTup); idcur->tform = (IndexTupleForm) GETSTRUCT(pgIndexTup);

View File

@ -26,7 +26,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.52 1998/08/06 05:12:33 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.53 1998/08/19 02:01:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -283,7 +283,7 @@ ExecCheckPerms(CmdType operation,
{ {
int i = 1; int i = 1;
Oid relid; Oid relid;
HeapTuple htp; HeapTuple htup;
List *lp; List *lp;
List *qvars, List *qvars,
*tvars; *tvars;
@ -314,14 +314,14 @@ ExecCheckPerms(CmdType operation,
} }
relid = rte->relid; relid = rte->relid;
htp = SearchSysCacheTuple(RELOID, htup = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(htup))
elog(ERROR, "ExecCheckPerms: bogus RT relid: %d", elog(ERROR, "ExecCheckPerms: bogus RT relid: %d",
relid); relid);
StrNCpy(rname.data, StrNCpy(rname.data,
((Form_pg_class) GETSTRUCT(htp))->relname.data, ((Form_pg_class) GETSTRUCT(htup))->relname.data,
NAMEDATALEN); NAMEDATALEN);
if (i == resultRelation) if (i == resultRelation)
{ /* this is the result relation */ { /* this is the result relation */
@ -1290,9 +1290,10 @@ ExecAttrDefault(Relation rel, HeapTuple tuple)
if (repl == NULL) if (repl == NULL)
return (tuple); return (tuple);
newtuple = heap_modifytuple(tuple, InvalidBuffer, rel, replValue, replNull, repl); newtuple = heap_modifytuple(tuple, rel, replValue, replNull, repl);
pfree(repl); pfree(repl);
pfree(tuple);
pfree(replNull); pfree(replNull);
pfree(replValue); pfree(replValue);
@ -1323,7 +1324,7 @@ ExecRelCheck(Relation rel, HeapTuple tuple)
slot->ttc_whichplan = -1; slot->ttc_whichplan = -1;
rte->relname = nameout(&(rel->rd_rel->relname)); rte->relname = nameout(&(rel->rd_rel->relname));
rte->refname = rte->relname; rte->refname = rte->relname;
rte->relid = rel->rd_id; rte->relid = RelationGetRelid(rel);
rte->inh = false; rte->inh = false;
rte->inFromCl = true; rte->inFromCl = true;
rtlist = lcons(rte, NIL); rtlist = lcons(rte, NIL);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.34 1998/07/27 19:37:56 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.35 1998/08/19 02:02:01 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -760,10 +760,7 @@ ExecOpenIndices(Oid resultRelationOid,
fiList = NIL; fiList = NIL;
predList = NIL; predList = NIL;
while (tuple = heap_getnext(indexSd, /* scan desc */ while (HeapTupleIsValid(tuple = heap_getnext(indexSd, 0)))
false, /* scan backward flag */
NULL), /* return: buffer */
HeapTupleIsValid(tuple))
{ {
/* ---------------- /* ----------------
@ -1020,8 +1017,6 @@ ExecFormIndexTuple(HeapTuple heapTuple,
keyAttributeNumbers, /* array of att nums to extract */ keyAttributeNumbers, /* array of att nums to extract */
heapTuple, /* tuple from base relation */ heapTuple, /* tuple from base relation */
heapDescriptor, /* heap tuple's descriptor */ heapDescriptor, /* heap tuple's descriptor */
InvalidBuffer, /* buffer associated with heap
* tuple */
datum, /* return: array of attributes */ datum, /* return: array of attributes */
nulls, /* return: array of char's */ nulls, /* return: array of char's */
fInfoP); /* functional index information */ fInfoP); /* functional index information */
@ -1136,8 +1131,6 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
* extract */ * extract */
heapTuple, /* tuple from base relation */ heapTuple, /* tuple from base relation */
heapDescriptor, /* heap tuple's descriptor */ heapDescriptor, /* heap tuple's descriptor */
InvalidBuffer, /* buffer associated with heap
* tuple */
datum, /* return: array of attributes */ datum, /* return: array of attributes */
nulls, /* return: array of char's */ nulls, /* return: array of char's */
fInfoP); /* functional index information */ fInfoP); /* functional index information */

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.23 1998/08/04 18:42:38 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.24 1998/08/19 02:02:02 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -123,7 +123,6 @@ IndexNext(IndexScan *node)
{ {
tuple = heap_fetch(heapRelation, snapshot, tuple = heap_fetch(heapRelation, snapshot,
&result->heap_iptr, &buffer); &result->heap_iptr, &buffer);
/* be tidy */
pfree(result); pfree(result);
if (tuple != NULL) if (tuple != NULL)
@ -224,7 +223,7 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
ScanDirection direction; ScanDirection direction;
IndexScanDescPtr scanDescs; IndexScanDescPtr scanDescs;
ScanKey *scanKeys; ScanKey *scanKeys;
IndexScanDesc sdesc; IndexScanDesc scan;
ScanKey skey; ScanKey skey;
int numIndices; int numIndices;
int i; int i;
@ -301,9 +300,9 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
} }
} }
} }
sdesc = scanDescs[i]; scan = scanDescs[i];
skey = scanKeys[i]; skey = scanKeys[i];
index_rescan(sdesc, direction, skey); index_rescan(scan, direction, skey);
} }
/* ---------------- /* ----------------
* perhaps return something meaningful * perhaps return something meaningful

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.14 1998/07/27 19:37:57 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeMaterial.c,v 1.15 1998/08/19 02:02:03 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -59,7 +59,6 @@ ExecMaterial(Material *node)
HeapScanDesc currentScanDesc; HeapScanDesc currentScanDesc;
HeapTuple heapTuple; HeapTuple heapTuple;
TupleTableSlot *slot; TupleTableSlot *slot;
Buffer buffer;
/* ---------------- /* ----------------
* get state info from node * get state info from node
@ -162,10 +161,7 @@ ExecMaterial(Material *node)
*/ */
currentScanDesc = matstate->csstate.css_currentScanDesc; currentScanDesc = matstate->csstate.css_currentScanDesc;
heapTuple = heap_getnext(currentScanDesc, /* scan desc */ heapTuple = heap_getnext(currentScanDesc, ScanDirectionIsBackward(dir));
ScanDirectionIsBackward(dir),
/* bkwd flag */
&buffer); /* return: buffer */
/* ---------------- /* ----------------
* put the tuple into the scan tuple slot and return the slot. * put the tuple into the scan tuple slot and return the slot.
@ -177,7 +173,7 @@ ExecMaterial(Material *node)
return ExecStoreTuple(heapTuple, /* tuple to store */ return ExecStoreTuple(heapTuple, /* tuple to store */
slot, /* slot to store in */ slot, /* slot to store in */
buffer, /* buffer for this tuple */ currentScanDesc->rs_cbuf, /* buffer for this tuple */
false); /* don't pfree this pointer */ false); /* don't pfree this pointer */
} }
@ -370,7 +366,7 @@ List /* nothing of interest */
ExecMaterialMarkPos(Material node) ExecMaterialMarkPos(Material node)
{ {
MaterialState matstate; MaterialState matstate;
HeapScanDesc sdesc; HeapScanDesc scan;
/* ---------------- /* ----------------
* if we haven't materialized yet, just return NIL. * if we haven't materialized yet, just return NIL.
@ -386,8 +382,8 @@ ExecMaterialMarkPos(Material node)
* they will never return positions for all I know -cim 10/16/89 * they will never return positions for all I know -cim 10/16/89
* ---------------- * ----------------
*/ */
sdesc = get_css_currentScanDesc((CommonScanState) matstate); scan = get_css_currentScanDesc((CommonScanState) matstate);
heap_markpos(sdesc); heap_markpos(scan);
return NIL; return NIL;
} }
@ -400,7 +396,7 @@ void
ExecMaterialRestrPos(Material node) ExecMaterialRestrPos(Material node)
{ {
MaterialState matstate; MaterialState matstate;
HeapScanDesc sdesc; HeapScanDesc scan;
/* ---------------- /* ----------------
* if we haven't materialized yet, just return. * if we haven't materialized yet, just return.
@ -414,8 +410,8 @@ ExecMaterialRestrPos(Material node)
* restore the scan to the previously marked position * restore the scan to the previously marked position
* ---------------- * ----------------
*/ */
sdesc = get_css_currentScanDesc((CommonScanState) matstate); scan = get_css_currentScanDesc((CommonScanState) matstate);
heap_restrpos(sdesc); heap_restrpos(scan);
} }
#endif #endif

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.11 1998/07/27 19:37:57 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.12 1998/08/19 02:02:05 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -55,7 +55,6 @@ SeqNext(SeqScan *node)
EState *estate; EState *estate;
ScanDirection direction; ScanDirection direction;
TupleTableSlot *slot; TupleTableSlot *slot;
Buffer buffer;
/* ---------------- /* ----------------
* get information from the estate and scan state * get information from the estate and scan state
@ -70,9 +69,7 @@ SeqNext(SeqScan *node)
* get the next tuple from the access methods * get the next tuple from the access methods
* ---------------- * ----------------
*/ */
tuple = heap_getnext(scandesc, /* scan desc */ tuple = heap_getnext(scandesc, ScanDirectionIsBackward(direction));
ScanDirectionIsBackward(direction), /* backward flag */
&buffer); /* return: buffer */
/* ---------------- /* ----------------
* save the tuple and the buffer returned to us by the access methods * save the tuple and the buffer returned to us by the access methods
@ -86,8 +83,7 @@ SeqNext(SeqScan *node)
slot = ExecStoreTuple(tuple,/* tuple to store */ slot = ExecStoreTuple(tuple,/* tuple to store */
slot, /* slot to store in */ slot, /* slot to store in */
buffer, /* buffer associated with this scandesc->rs_cbuf,/* buffer associated with this tuple */
* tuple */
false); /* don't pfree this pointer */ false); /* don't pfree this pointer */
/* ---------------- /* ----------------
@ -364,8 +360,8 @@ ExecSeqReScan(SeqScan *node, ExprContext *exprCtxt, Plan *parent)
CommonScanState *scanstate; CommonScanState *scanstate;
EState *estate; EState *estate;
Plan *outerPlan; Plan *outerPlan;
Relation rdesc; Relation rel;
HeapScanDesc sdesc; HeapScanDesc scan;
ScanDirection direction; ScanDirection direction;
scanstate = node->scanstate; scanstate = node->scanstate;
@ -380,11 +376,11 @@ ExecSeqReScan(SeqScan *node, ExprContext *exprCtxt, Plan *parent)
else else
{ {
/* otherwise, we are scanning a relation */ /* otherwise, we are scanning a relation */
rdesc = scanstate->css_currentRelation; rel = scanstate->css_currentRelation;
sdesc = scanstate->css_currentScanDesc; scan = scanstate->css_currentScanDesc;
direction = estate->es_direction; direction = estate->es_direction;
sdesc = ExecReScanR(rdesc, sdesc, direction, 0, NULL); scan = ExecReScanR(rel, scan, direction, 0, NULL);
scanstate->css_currentScanDesc = sdesc; scanstate->css_currentScanDesc = scan;
} }
} }
@ -399,7 +395,7 @@ ExecSeqMarkPos(SeqScan *node)
{ {
CommonScanState *scanstate; CommonScanState *scanstate;
Plan *outerPlan; Plan *outerPlan;
HeapScanDesc sdesc; HeapScanDesc scan;
scanstate = node->scanstate; scanstate = node->scanstate;
@ -421,8 +417,8 @@ ExecSeqMarkPos(SeqScan *node)
* *
* ---------------- * ----------------
*/ */
sdesc = scanstate->css_currentScanDesc; scan = scanstate->css_currentScanDesc;
heap_markpos(sdesc); heap_markpos(scan);
return; return;
} }
@ -438,7 +434,7 @@ ExecSeqRestrPos(SeqScan *node)
{ {
CommonScanState *scanstate; CommonScanState *scanstate;
Plan *outerPlan; Plan *outerPlan;
HeapScanDesc sdesc; HeapScanDesc scan;
scanstate = node->scanstate; scanstate = node->scanstate;
@ -459,6 +455,6 @@ ExecSeqRestrPos(SeqScan *node)
* position using the access methods.. * position using the access methods..
* ---------------- * ----------------
*/ */
sdesc = scanstate->css_currentScanDesc; scan = scanstate->css_currentScanDesc;
heap_restrpos(sdesc); heap_restrpos(scan);
} }

View File

@ -15,7 +15,7 @@
* ExecEndTee * ExecEndTee
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/Attic/nodeTee.c,v 1.20 1998/08/06 05:12:36 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/Attic/nodeTee.c,v 1.21 1998/08/19 02:02:06 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -303,7 +303,6 @@ ExecTee(Tee *node, Plan *parent)
HeapTuple heapTuple; HeapTuple heapTuple;
Relation bufferRel; Relation bufferRel;
HeapScanDesc scanDesc; HeapScanDesc scanDesc;
Buffer buffer;
estate = ((Plan *) node)->state; estate = ((Plan *) node)->state;
teeState = node->teestate; teeState = node->teestate;
@ -366,10 +365,7 @@ ExecTee(Tee *node, Plan *parent)
HeapTuple throwAway; HeapTuple throwAway;
/* Buffer buffer; */ /* Buffer buffer; */
throwAway = heap_getnext(scanDesc, throwAway = heap_getnext(scanDesc,ScanDirectionIsBackward(dir));
ScanDirectionIsBackward(dir),
/* &buffer */
(Buffer *) NULL);
} }
/* /*
@ -393,9 +389,7 @@ ExecTee(Tee *node, Plan *parent)
scanDesc = (parent == node->leftParent) ? scanDesc = (parent == node->leftParent) ?
teeState->tee_leftScanDesc : teeState->tee_rightScanDesc; teeState->tee_leftScanDesc : teeState->tee_rightScanDesc;
heapTuple = heap_getnext(scanDesc, heapTuple = heap_getnext(scanDesc, ScanDirectionIsBackward(dir));
ScanDirectionIsBackward(dir),
&buffer);
/* /*
* Increase the pin count on the buffer page, because the tuple * Increase the pin count on the buffer page, because the tuple
@ -404,15 +398,15 @@ ExecTee(Tee *node, Plan *parent)
* count on the next iteration. * count on the next iteration.
*/ */
if (buffer != InvalidBuffer) if (scanDesc->rs_cbuf != InvalidBuffer)
IncrBufferRefCount(buffer); IncrBufferRefCount(scanDesc->rs_cbuf);
slot = teeState->cstate.cs_ResultTupleSlot; slot = teeState->cstate.cs_ResultTupleSlot;
slot->ttc_tupleDescriptor = RelationGetTupleDescriptor(bufferRel); slot->ttc_tupleDescriptor = RelationGetTupleDescriptor(bufferRel);
result = ExecStoreTuple(heapTuple, /* tuple to store */ result = ExecStoreTuple(heapTuple, /* tuple to store */
slot, /* slot to store in */ slot, /* slot to store in */
buffer, /* this tuple's buffer */ scanDesc->rs_cbuf, /* this tuple's buffer */
false); /* don't free stuff from false); /* don't free stuff from
* heap_getnext */ * heap_getnext */

View File

@ -466,7 +466,7 @@ SPI_gettype(TupleDesc tupdesc, int fnumber)
} }
typeTuple = SearchSysCacheTuple(TYPOID, typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(tupdesc->attrs[fnumber - 1]->atttypid), ObjectIdGetDatum(tupdesc->attrs[fnumber - 1]->atttypid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTuple)) if (!HeapTupleIsValid(typeTuple))

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.23 1998/07/22 05:48:59 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.24 1998/08/19 02:02:09 momjian Exp $
* *
* NOTES * NOTES
* This should be moved to a more appropriate place. It is here * This should be moved to a more appropriate place. It is here
@ -182,7 +182,7 @@ lo_creat(int mode)
return InvalidOid; return InvalidOid;
} }
lobjId = lobjDesc->heap_r->rd_id; lobjId = RelationGetRelid(lobjDesc->heap_r);
inv_close(lobjDesc); inv_close(lobjDesc);
@ -288,7 +288,7 @@ lo_import(text *filename)
* the oid for the large object is just the oid of the relation * the oid for the large object is just the oid of the relation
* XInv??? which contains the data. * XInv??? which contains the data.
*/ */
lobjOid = lobj->heap_r->rd_id; lobjOid = RelationGetRelid(lobj->heap_r);
/* /*
* read in from the Unix file and write to the inversion file * read in from the Unix file and write to the inversion file

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.30 1998/08/16 05:37:04 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.31 1998/08/19 02:02:11 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1071,7 +1071,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
* --Nels, Jan '93 * --Nels, Jan '93
*/ */
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry); scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
tuple = heap_getnext(scan, false, (Buffer *) NULL); tuple = heap_getnext(scan, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
elog(DEBUG, "clause_pred_clause_test: unknown pred_op"); elog(DEBUG, "clause_pred_clause_test: unknown pred_op");
@ -1102,7 +1102,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
ObjectIdGetDatum(clause_op)); ObjectIdGetDatum(clause_op));
scan = heap_beginscan(relation, false, SnapshotNow, 3, entry); scan = heap_beginscan(relation, false, SnapshotNow, 3, entry);
tuple = heap_getnext(scan, false, (Buffer *) NULL); tuple = heap_getnext(scan, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
elog(DEBUG, "clause_pred_clause_test: unknown clause_op"); elog(DEBUG, "clause_pred_clause_test: unknown clause_op");
@ -1134,7 +1134,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
Int16GetDatum(test_strategy)); Int16GetDatum(test_strategy));
scan = heap_beginscan(relation, false, SnapshotNow, 3, entry); scan = heap_beginscan(relation, false, SnapshotNow, 3, entry);
tuple = heap_getnext(scan, false, (Buffer *) NULL); tuple = heap_getnext(scan, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
elog(DEBUG, "clause_pred_clause_test: unknown test_op"); elog(DEBUG, "clause_pred_clause_test: unknown test_op");

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.18 1998/08/10 02:26:25 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.19 1998/08/19 02:02:13 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -496,7 +496,9 @@ xfunc_func_expense(LispValue node, LispValue args)
funcid = get_funcid((Func) node); funcid = get_funcid((Func) node);
/* look up tuple in cache */ /* look up tuple in cache */
tupl = SearchSysCacheTuple(PROOID, ObjectIdGetDatum(funcid), 0, 0, 0); tupl = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(funcid),
0, 0, 0);
if (!HeapTupleIsValid(tupl)) if (!HeapTupleIsValid(tupl))
elog(ERROR, "Cache lookup failed for procedure %d", funcid); elog(ERROR, "Cache lookup failed for procedure %d", funcid);
proc = (Form_pg_proc) GETSTRUCT(tupl); proc = (Form_pg_proc) GETSTRUCT(tupl);
@ -610,7 +612,7 @@ xfunc_width(LispValue clause)
{ {
/* base case: width is width of this attribute */ /* base case: width is width of this attribute */
tupl = SearchSysCacheTuple(TYPOID, tupl = SearchSysCacheTuple(TYPOID,
PointerGetDatum(get_vartype((Var) clause)), ObjectIdGetDatum(get_vartype((Var) clause)),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tupl)) if (!HeapTupleIsValid(tupl))
elog(ERROR, "Cache lookup failed for type %d", elog(ERROR, "Cache lookup failed for type %d",
@ -1307,7 +1309,9 @@ xfunc_func_width(RegProcedure funcid, LispValue args)
/* lookup function and find its return type */ /* lookup function and find its return type */
Assert(RegProcedureIsValid(funcid)); Assert(RegProcedureIsValid(funcid));
tupl = SearchSysCacheTuple(PROOID, ObjectIdGetDatum(funcid), 0, 0, 0); tupl = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(funcid),
0, 0, 0);
if (!HeapTupleIsValid(tupl)) if (!HeapTupleIsValid(tupl))
elog(ERROR, "Cache lookup failed for procedure %d", funcid); elog(ERROR, "Cache lookup failed for procedure %d", funcid);
proc = (Form_pg_proc) GETSTRUCT(tupl); proc = (Form_pg_proc) GETSTRUCT(tupl);

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.18 1998/07/27 19:38:00 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.19 1998/08/19 02:02:16 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -65,7 +65,7 @@ relation_info(Query *root, Index relid,
relationObjectId = getrelid(relid, root->rtable); relationObjectId = getrelid(relid, root->rtable);
relationTuple = SearchSysCacheTuple(RELOID, relationTuple = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(relationObjectId), ObjectIdGetDatum(relationObjectId),
0, 0, 0); 0, 0, 0);
if (HeapTupleIsValid(relationTuple)) if (HeapTupleIsValid(relationTuple))
{ {
@ -153,7 +153,7 @@ index_info(Query *root, bool first, int relid, IdxInfoRetval *info)
} }
if (!HeapScanIsValid(scan)) if (!HeapScanIsValid(scan))
elog(ERROR, "index_info: scan not started"); elog(ERROR, "index_info: scan not started");
indexTuple = heap_getnext(scan, 0, (Buffer *) NULL); indexTuple = heap_getnext(scan, 0);
if (!HeapTupleIsValid(indexTuple)) if (!HeapTupleIsValid(indexTuple))
{ {
heap_endscan(scan); heap_endscan(scan);
@ -414,9 +414,7 @@ find_inheritance_children(Oid inhparent)
key[0].sk_argument = ObjectIdGetDatum((Oid) inhparent); key[0].sk_argument = ObjectIdGetDatum((Oid) inhparent);
relation = heap_openr(InheritsRelationName); relation = heap_openr(InheritsRelationName);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key); scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(inheritsTuple = while (HeapTupleIsValid(inheritsTuple = heap_getnext(scan, 0)))
heap_getnext(scan, 0,
(Buffer *) NULL)))
{ {
inhrelid = ((InheritsTupleForm) GETSTRUCT(inheritsTuple))->inhrel; inhrelid = ((InheritsTupleForm) GETSTRUCT(inheritsTuple))->inhrel;
list = lappendi(list, inhrelid); list = lappendi(list, inhrelid);
@ -450,12 +448,8 @@ VersionGetParents(Oid verrelid)
relation = heap_openr(VersionRelationName); relation = heap_openr(VersionRelationName);
key[0].sk_argument = ObjectIdGetDatum(verrelid); key[0].sk_argument = ObjectIdGetDatum(verrelid);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key); scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
for (;;) while (HeapTupleIsValid(versionTuple = heap_getnext(scan, 0)))
{ {
versionTuple = heap_getnext(scan, 0,
(Buffer *) NULL);
if (!HeapTupleIsValid(versionTuple))
break;
verbaseid = ((VersionTupleForm) verbaseid = ((VersionTupleForm)
GETSTRUCT(versionTuple))->verbaseid; GETSTRUCT(versionTuple))->verbaseid;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.11 1998/06/15 19:28:54 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.12 1998/08/19 02:02:18 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -230,7 +230,8 @@ ParseAgg(ParseState *pstate, char *aggname, Oid basetype,
HeapTuple theAggTuple; HeapTuple theAggTuple;
bool usenulls = false; bool usenulls = false;
theAggTuple = SearchSysCacheTuple(AGGNAME, PointerGetDatum(aggname), theAggTuple = SearchSysCacheTuple(AGGNAME,
PointerGetDatum(aggname),
ObjectIdGetDatum(basetype), ObjectIdGetDatum(basetype),
0, 0); 0, 0);
if (!HeapTupleIsValid(theAggTuple)) if (!HeapTupleIsValid(theAggTuple))

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.24 1998/07/27 19:38:02 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.25 1998/08/19 02:02:20 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -488,7 +488,8 @@ funcid_get_rettype(Oid funcid)
HeapTuple func_tuple = NULL; HeapTuple func_tuple = NULL;
Oid funcrettype = (Oid) 0; Oid funcrettype = (Oid) 0;
func_tuple = SearchSysCacheTuple(PROOID, ObjectIdGetDatum(funcid), func_tuple = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(funcid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(func_tuple)) if (!HeapTupleIsValid(func_tuple))
@ -514,9 +515,7 @@ func_get_candidates(char *funcname, int nargs)
HeapTuple tuple; HeapTuple tuple;
IndexScanDesc sd; IndexScanDesc sd;
RetrieveIndexResult indexRes; RetrieveIndexResult indexRes;
Buffer buffer;
Form_pg_proc pgProcP; Form_pg_proc pgProcP;
bool bufferUsed = FALSE;
CandidateList candidates = NULL; CandidateList candidates = NULL;
CandidateList current_candidate; CandidateList current_candidate;
int i; int i;
@ -535,24 +534,19 @@ func_get_candidates(char *funcname, int nargs)
do do
{ {
tuple = (HeapTuple) NULL; tuple = (HeapTuple) NULL;
if (bufferUsed)
{
ReleaseBuffer(buffer);
bufferUsed = FALSE;
}
indexRes = index_getnext(sd, ForwardScanDirection); indexRes = index_getnext(sd, ForwardScanDirection);
if (indexRes) if (indexRes)
{ {
ItemPointer iptr; ItemPointer iptr;
Buffer buffer;
iptr = &indexRes->heap_iptr; iptr = &indexRes->heap_iptr;
tuple = heap_fetch(heapRelation, SnapshotNow, iptr, &buffer); tuple = heap_fetch(heapRelation, SnapshotNow, iptr, &buffer);
pfree(indexRes); pfree(indexRes);
if (HeapTupleIsValid(tuple)) if (HeapTupleIsValid(tuple))
{ {
pgProcP = (Form_pg_proc) GETSTRUCT(tuple); pgProcP = (Form_pg_proc) GETSTRUCT(tuple);
bufferUsed = TRUE;
if (pgProcP->pronargs == nargs) if (pgProcP->pronargs == nargs)
{ {
current_candidate = (CandidateList) current_candidate = (CandidateList)
@ -567,6 +561,7 @@ func_get_candidates(char *funcname, int nargs)
current_candidate->next = candidates; current_candidate->next = candidates;
candidates = current_candidate; candidates = current_candidate;
} }
ReleaseBuffer(buffer);
} }
} }
} while (indexRes); } while (indexRes);
@ -1000,7 +995,6 @@ find_inheritors(Oid relid, Oid **supervec)
*elt; *elt;
Relation rd; Relation rd;
Buffer buf;
Datum d; Datum d;
bool newrelid; bool newrelid;
char isNull; char isNull;
@ -1026,7 +1020,7 @@ find_inheritors(Oid relid, Oid **supervec)
inhscan = heap_beginscan(inhrel, 0, SnapshotNow, 1, &skey); inhscan = heap_beginscan(inhrel, 0, SnapshotNow, 1, &skey);
while (HeapTupleIsValid(inhtup = heap_getnext(inhscan, 0, &buf))) while (HeapTupleIsValid(inhtup = heap_getnext(inhscan, 0)))
{ {
qentry = (SuperQE *) palloc(sizeof(SuperQE)); qentry = (SuperQE *) palloc(sizeof(SuperQE));
@ -1036,8 +1030,6 @@ find_inheritors(Oid relid, Oid **supervec)
/* put this one on the queue */ /* put this one on the queue */
DLAddTail(queue, DLNewElem(qentry)); DLAddTail(queue, DLNewElem(qentry));
ReleaseBuffer(buf);
} }
heap_endscan(inhscan); heap_endscan(inhscan);
@ -1311,7 +1303,7 @@ ParseComplexProjection(ParseState *pstate,
rd = heap_openr(typeidTypeName(argtype)); rd = heap_openr(typeidTypeName(argtype));
if (RelationIsValid(rd)) if (RelationIsValid(rd))
{ {
relid = RelationGetRelationId(rd); relid = RelationGetRelid(rd);
heap_close(rd); heap_close(rd);
} }
if (RelationIsValid(rd)) if (RelationIsValid(rd))
@ -1369,7 +1361,7 @@ ParseComplexProjection(ParseState *pstate,
rd = heap_openr(typeidTypeName(argtype)); rd = heap_openr(typeidTypeName(argtype));
if (RelationIsValid(rd)) if (RelationIsValid(rd))
{ {
relid = RelationGetRelationId(rd); relid = RelationGetRelid(rd);
heap_close(rd); heap_close(rd);
} }
if (RelationIsValid(rd)) if (RelationIsValid(rd))
@ -1406,7 +1398,7 @@ ParseComplexProjection(ParseState *pstate,
rd = heap_openr(typeidTypeName(param->paramtype)); rd = heap_openr(typeidTypeName(param->paramtype));
if (RelationIsValid(rd)) if (RelationIsValid(rd))
{ {
relid = RelationGetRelationId(rd); relid = RelationGetRelid(rd);
heap_close(rd); heap_close(rd);
if ((attnum = get_attnum(relid, funcname)) if ((attnum = get_attnum(relid, funcname))
!= InvalidAttrNumber) != InvalidAttrNumber)

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.18 1998/07/20 11:17:11 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.19 1998/08/19 02:02:23 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -284,7 +284,7 @@ make_array_ref(Node *expr,
/* get the type tuple for the element type */ /* get the type tuple for the element type */
type_tuple = SearchSysCacheTuple(TYPOID, type_tuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(type_struct_array->typelem), ObjectIdGetDatum(type_struct_array->typelem),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(type_tuple)) if (!HeapTupleIsValid(type_tuple))
elog(ERROR, "make_array_ref: Cache lookup failed for type %d\n", elog(ERROR, "make_array_ref: Cache lookup failed for type %d\n",
@ -365,7 +365,7 @@ make_array_set(Expr *target_expr,
type_struct_array->typname); type_struct_array->typname);
/* get the type tuple for the element type */ /* get the type tuple for the element type */
type_tuple = SearchSysCacheTuple(TYPOID, type_tuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(type_struct_array->typelem), ObjectIdGetDatum(type_struct_array->typelem),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(type_tuple)) if (!HeapTupleIsValid(type_tuple))

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.14 1998/07/27 19:38:04 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.15 1998/08/19 02:02:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -86,7 +86,6 @@ binary_oper_get_candidates(char *opname,
HeapScanDesc pg_operator_scan; HeapScanDesc pg_operator_scan;
HeapTuple tup; HeapTuple tup;
OperatorTupleForm oper; OperatorTupleForm oper;
Buffer buffer;
int nkeys; int nkeys;
int ncandidates = 0; int ncandidates = 0;
ScanKeyData opKey[3]; ScanKeyData opKey[3];
@ -112,23 +111,18 @@ binary_oper_get_candidates(char *opname,
nkeys, nkeys,
opKey); opKey);
do while (HeapTupleIsValid(tup = heap_getnext(pg_operator_scan, 0)))
{ {
tup = heap_getnext(pg_operator_scan, 0, &buffer); current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList));
if (HeapTupleIsValid(tup)) current_candidate->args = (Oid *) palloc(2 * sizeof(Oid));
{
current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList));
current_candidate->args = (Oid *) palloc(2 * sizeof(Oid));
oper = (OperatorTupleForm) GETSTRUCT(tup); oper = (OperatorTupleForm) GETSTRUCT(tup);
current_candidate->args[0] = oper->oprleft; current_candidate->args[0] = oper->oprleft;
current_candidate->args[1] = oper->oprright; current_candidate->args[1] = oper->oprright;
current_candidate->next = *candidates; current_candidate->next = *candidates;
*candidates = current_candidate; *candidates = current_candidate;
ncandidates++; ncandidates++;
ReleaseBuffer(buffer); }
}
} while (HeapTupleIsValid(tup));
heap_endscan(pg_operator_scan); heap_endscan(pg_operator_scan);
heap_close(pg_operator_desc); heap_close(pg_operator_desc);
@ -465,7 +459,7 @@ oper_exact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarn
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(arg1), ObjectIdGetDatum(arg1),
ObjectIdGetDatum(arg2), ObjectIdGetDatum(arg2),
Int8GetDatum('b')); CharGetDatum('b'));
/* Did not find anything? then try flipping arguments on a commutative operator... */ /* Did not find anything? then try flipping arguments on a commutative operator... */
if (!HeapTupleIsValid(tup) && (arg1 != arg2)) if (!HeapTupleIsValid(tup) && (arg1 != arg2))
@ -474,7 +468,7 @@ oper_exact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWarn
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(arg2), ObjectIdGetDatum(arg2),
ObjectIdGetDatum(arg1), ObjectIdGetDatum(arg1),
Int8GetDatum('b')); CharGetDatum('b'));
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
@ -545,7 +539,7 @@ oper_inexact(char *op, Oid arg1, Oid arg2, Node **ltree, Node **rtree, bool noWa
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(candidates->args[0]), ObjectIdGetDatum(candidates->args[0]),
ObjectIdGetDatum(candidates->args[1]), ObjectIdGetDatum(candidates->args[1]),
Int8GetDatum('b')); CharGetDatum('b'));
Assert(HeapTupleIsValid(tup)); Assert(HeapTupleIsValid(tup));
#if PARSEDEBUG #if PARSEDEBUG
@ -569,8 +563,7 @@ printf("oper_inexact: found candidate\n");
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(targetOids[0]), ObjectIdGetDatum(targetOids[0]),
ObjectIdGetDatum(targetOids[1]), ObjectIdGetDatum(targetOids[1]),
Int8GetDatum('b')); CharGetDatum('b'));
} }
else else
tup = NULL; tup = NULL;
@ -635,7 +628,6 @@ unary_oper_get_candidates(char *op,
HeapScanDesc pg_operator_scan; HeapScanDesc pg_operator_scan;
HeapTuple tup; HeapTuple tup;
OperatorTupleForm oper; OperatorTupleForm oper;
Buffer buffer;
int ncandidates = 0; int ncandidates = 0;
static ScanKeyData opKey[2] = { static ScanKeyData opKey[2] = {
@ -659,29 +651,24 @@ printf("unary_oper_get_candidates: start scan for '%s'\n", op);
2, 2,
opKey); opKey);
do while (HeapTupleIsValid(tup = heap_getnext(pg_operator_scan, 0)))
{ {
tup = heap_getnext(pg_operator_scan, 0, &buffer); current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList));
if (HeapTupleIsValid(tup)) current_candidate->args = (Oid *) palloc(sizeof(Oid));
{
current_candidate = (CandidateList) palloc(sizeof(struct _CandidateList));
current_candidate->args = (Oid *) palloc(sizeof(Oid));
oper = (OperatorTupleForm) GETSTRUCT(tup); oper = (OperatorTupleForm) GETSTRUCT(tup);
if (rightleft == 'r') if (rightleft == 'r')
current_candidate->args[0] = oper->oprleft; current_candidate->args[0] = oper->oprleft;
else else
current_candidate->args[0] = oper->oprright; current_candidate->args[0] = oper->oprright;
current_candidate->next = *candidates; current_candidate->next = *candidates;
*candidates = current_candidate; *candidates = current_candidate;
#ifdef PARSEDEBUG #ifdef PARSEDEBUG
printf("unary_oper_get_candidates: found candidate '%s' for type %s\n", printf("unary_oper_get_candidates: found candidate '%s' for type %s\n",
op, typeidTypeName(current_candidate->args[0])); op, typeidTypeName(current_candidate->args[0]));
#endif #endif
ncandidates++; ncandidates++;
ReleaseBuffer(buffer); }
}
} while (HeapTupleIsValid(tup));
heap_endscan(pg_operator_scan); heap_endscan(pg_operator_scan);
heap_close(pg_operator_desc); heap_close(pg_operator_desc);
@ -707,7 +694,7 @@ right_oper(char *op, Oid arg)
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(arg), ObjectIdGetDatum(arg),
ObjectIdGetDatum(InvalidOid), ObjectIdGetDatum(InvalidOid),
Int8GetDatum('r')); CharGetDatum('r'));
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {
@ -723,7 +710,7 @@ right_oper(char *op, Oid arg)
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(candidates->args[0]), ObjectIdGetDatum(candidates->args[0]),
ObjectIdGetDatum(InvalidOid), ObjectIdGetDatum(InvalidOid),
Int8GetDatum('r')); CharGetDatum('r'));
Assert(HeapTupleIsValid(tup)); Assert(HeapTupleIsValid(tup));
} }
else else
@ -736,7 +723,7 @@ right_oper(char *op, Oid arg)
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(InvalidOid), ObjectIdGetDatum(InvalidOid),
ObjectIdGetDatum(*targetOid), ObjectIdGetDatum(*targetOid),
Int8GetDatum('r')); CharGetDatum('r'));
} }
else else
tup = NULL; tup = NULL;
@ -767,7 +754,7 @@ left_oper(char *op, Oid arg)
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(InvalidOid), ObjectIdGetDatum(InvalidOid),
ObjectIdGetDatum(arg), ObjectIdGetDatum(arg),
Int8GetDatum('l')); CharGetDatum('l'));
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {
@ -783,7 +770,7 @@ left_oper(char *op, Oid arg)
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(InvalidOid), ObjectIdGetDatum(InvalidOid),
ObjectIdGetDatum(candidates->args[0]), ObjectIdGetDatum(candidates->args[0]),
Int8GetDatum('l')); CharGetDatum('l'));
Assert(HeapTupleIsValid(tup)); Assert(HeapTupleIsValid(tup));
#ifdef PARSEDEBUG #ifdef PARSEDEBUG
printf("left_oper: searched cache for single left oper candidate '%s %s'\n", printf("left_oper: searched cache for single left oper candidate '%s %s'\n",
@ -797,7 +784,7 @@ printf("left_oper: searched cache for single left oper candidate '%s %s'\n",
PointerGetDatum(op), PointerGetDatum(op),
ObjectIdGetDatum(InvalidOid), ObjectIdGetDatum(InvalidOid),
ObjectIdGetDatum(*targetOid), ObjectIdGetDatum(*targetOid),
Int8GetDatum('l')); CharGetDatum('l'));
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.13 1998/08/18 00:48:57 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.14 1998/08/19 02:02:25 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -208,7 +208,7 @@ addRangeTableEntry(ParseState *pstate,
elog(ERROR, "%s: %s", elog(ERROR, "%s: %s",
relname, aclcheck_error_strings[ACLCHECK_NO_CLASS]); relname, aclcheck_error_strings[ACLCHECK_NO_CLASS]);
rte->relid = RelationGetRelationId(relation); rte->relid = RelationGetRelid(relation);
heap_close(relation); heap_close(relation);
@ -237,7 +237,7 @@ addRangeTableEntry(ParseState *pstate,
List * List *
expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno) expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno)
{ {
Relation rdesc; Relation rel;
List *te_tail = NIL, List *te_tail = NIL,
*te_head = NIL; *te_head = NIL;
Var *varnode; Var *varnode;
@ -249,13 +249,13 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno)
if (rte == NULL) if (rte == NULL)
rte = addRangeTableEntry(pstate, relname, refname, FALSE, FALSE); rte = addRangeTableEntry(pstate, relname, refname, FALSE, FALSE);
rdesc = heap_open(rte->relid); rel = heap_open(rte->relid);
if (rdesc == NULL) if (rel == NULL)
elog(ERROR, "Unable to expand all -- heap_open failed on %s", elog(ERROR, "Unable to expand all -- heap_open failed on %s",
rte->refname); rte->refname);
maxattrs = RelationGetNumberOfAttributes(rdesc); maxattrs = RelationGetNumberOfAttributes(rel);
for (varattno = 0; varattno <= maxattrs - 1; varattno++) for (varattno = 0; varattno <= maxattrs - 1; varattno++)
{ {
@ -263,7 +263,7 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno)
char *resname = NULL; char *resname = NULL;
TargetEntry *te = makeNode(TargetEntry); TargetEntry *te = makeNode(TargetEntry);
attrname = pstrdup((rdesc->rd_att->attrs[varattno]->attname).data); attrname = pstrdup((rel->rd_att->attrs[varattno]->attname).data);
varnode = (Var *) make_var(pstate, rte->relid, refname, attrname); varnode = (Var *) make_var(pstate, rte->relid, refname, attrname);
handleTargetColname(pstate, &resname, refname, attrname); handleTargetColname(pstate, &resname, refname, attrname);
@ -289,7 +289,7 @@ expandAll(ParseState *pstate, char *relname, char *refname, int *this_resno)
te_tail = lappend(te_tail, te); te_tail = lappend(te_tail, te);
} }
heap_close(rdesc); heap_close(rel);
return (te_head); return (te_head);
} }
@ -343,7 +343,7 @@ attnameIsSet(Relation rd, char *name)
return (false); /* no sys attr is a set */ return (false); /* no sys attr is a set */
} }
} }
return (get_attisset(rd->rd_id, name)); return (get_attisset(RelationGetRelid(rd), name));
} }
/* /*

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.20 1998/08/05 04:49:11 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.21 1998/08/19 02:02:26 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -683,7 +683,7 @@ printf("MakeTargetlistExpr: attrtypmod is %d\n", (int4) attrtypmod);
lowerIndexpr, lowerIndexpr,
(Expr *) expr); (Expr *) expr);
attrtype = attnumTypeId(rd, resdomno); attrtype = attnumTypeId(rd, resdomno);
attrtypmod = get_atttypmod(rd->rd_id, resdomno); attrtypmod = get_atttypmod(RelationGetRelid(rd), resdomno);
} }
} }
else else

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.13 1998/07/20 11:17:11 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.14 1998/08/19 02:02:27 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -47,7 +47,8 @@ typeidTypeName(Oid id)
HeapTuple tup; HeapTuple tup;
TypeTupleForm typetuple; TypeTupleForm typetuple;
if (!(tup = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(id), if (!(tup = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(id),
0, 0, 0))) 0, 0, 0)))
{ {
elog(ERROR, "type id lookup of %u failed", id); elog(ERROR, "type id lookup of %u failed", id);
@ -63,7 +64,8 @@ typeidType(Oid id)
{ {
HeapTuple tup; HeapTuple tup;
if (!(tup = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(id), if (!(tup = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(id),
0, 0, 0))) 0, 0, 0)))
{ {
elog(ERROR, "type id lookup of %u failed", id); elog(ERROR, "type id lookup of %u failed", id);
@ -81,7 +83,9 @@ typenameType(char *s)
if (s == NULL) if (s == NULL)
elog(ERROR, "type(): Null type"); elog(ERROR, "type(): Null type");
if (!(tup = SearchSysCacheTuple(TYPNAME, PointerGetDatum(s), 0, 0, 0))) if (!(tup = SearchSysCacheTuple(TYPNAME,
PointerGetDatum(s),
0, 0, 0)))
elog(ERROR, "type name lookup of %s failed", s); elog(ERROR, "type name lookup of %s failed", s);
return ((Type) tup); return ((Type) tup);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.17 1998/08/18 00:48:58 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.18 1998/08/19 02:02:29 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -97,7 +97,7 @@ InsertRule(char *rulname,
eventrel = heap_openr(evobj); eventrel = heap_openr(evobj);
if (eventrel == NULL) if (eventrel == NULL)
elog(ERROR, "rules cannot be defined on relations not in schema"); elog(ERROR, "rules cannot be defined on relations not in schema");
eventrel_oid = RelationGetRelationId(eventrel); eventrel_oid = RelationGetRelid(eventrel);
/* /*
* if the slotname is null, we know that this is a multi-attr rule * if the slotname is null, we know that this is a multi-attr rule
@ -201,7 +201,7 @@ DefineQueryRewrite(RuleStmt *stmt)
event_relation = heap_openr(event_obj->relname); event_relation = heap_openr(event_obj->relname);
if (event_relation == NULL) if (event_relation == NULL)
elog(ERROR, "virtual relations not supported yet"); elog(ERROR, "virtual relations not supported yet");
ev_relid = RelationGetRelationId(event_relation); ev_relid = RelationGetRelid(event_relation);
if (eslot_string == NULL) if (eslot_string == NULL)
{ {

View File

@ -6,7 +6,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.18 1998/08/18 00:48:59 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.19 1998/08/19 02:02:30 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1038,7 +1038,9 @@ CheckViewPerms(Relation view, List *rtable)
/* /*
* get the usename of the view's owner * get the usename of the view's owner
*/ */
utup = SearchSysCacheTuple(USESYSID, view->rd_rel->relowner, 0, 0, 0); utup = SearchSysCacheTuple(USESYSID,
ObjectIdGetDatum(view->rd_rel->relowner),
0, 0, 0);
if (!HeapTupleIsValid(utup)) if (!HeapTupleIsValid(utup))
{ {
elog(ERROR, "cache lookup for userid %d failed", elog(ERROR, "cache lookup for userid %d failed",

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.15 1998/07/27 19:38:08 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.16 1998/08/19 02:02:32 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -32,21 +32,23 @@
char * char *
RewriteGetRuleEventRel(char *rulename) RewriteGetRuleEventRel(char *rulename)
{ {
HeapTuple htp; HeapTuple htup;
Oid eventrel; Oid eventrel;
htp = SearchSysCacheTuple(REWRITENAME, PointerGetDatum(rulename), htup = SearchSysCacheTuple(REWRITENAME,
0, 0, 0); PointerGetDatum(rulename),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "RewriteGetRuleEventRel: rule \"%s\" not found", elog(ERROR, "RewriteGetRuleEventRel: rule \"%s\" not found",
rulename); rulename);
eventrel = ((Form_pg_rewrite) GETSTRUCT(htp))->ev_class; eventrel = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
htp = SearchSysCacheTuple(RELOID, PointerGetDatum(eventrel), htup = SearchSysCacheTuple(RELOID,
PointerGetDatum(eventrel),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(htp)) if (!HeapTupleIsValid(htup))
elog(ERROR, "RewriteGetRuleEventRel: class %d not found", elog(ERROR, "RewriteGetRuleEventRel: class %d not found",
eventrel); eventrel);
return ((Form_pg_class) GETSTRUCT(htp))->relname.data; return ((Form_pg_class) GETSTRUCT(htup))->relname.data;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
@ -68,8 +70,6 @@ void
RemoveRewriteRule(char *ruleName) RemoveRewriteRule(char *ruleName)
{ {
Relation RewriteRelation = NULL; Relation RewriteRelation = NULL;
HeapScanDesc scanDesc = NULL;
ScanKeyData scanKeyData;
HeapTuple tuple = NULL; HeapTuple tuple = NULL;
Oid ruleId = (Oid) 0; Oid ruleId = (Oid) 0;
Oid eventRelationOid = (Oid) NULL; Oid eventRelationOid = (Oid) NULL;
@ -84,13 +84,9 @@ RemoveRewriteRule(char *ruleName)
/* /*
* Scan the RuleRelation ('pg_rewrite') until we find a tuple * Scan the RuleRelation ('pg_rewrite') until we find a tuple
*/ */
ScanKeyEntryInitialize(&scanKeyData, 0, Anum_pg_rewrite_rulename, tuple = SearchSysCacheTupleCopy(REWRITENAME,
F_NAMEEQ, NameGetDatum(ruleName)); PointerGetDatum(ruleName),
scanDesc = heap_beginscan(RewriteRelation, 0, 0, 0);
0, SnapshotNow, 1, &scanKeyData);
tuple = heap_getnext(scanDesc, 0, (Buffer *) NULL);
/* /*
* complain if no rule with such name existed * complain if no rule with such name existed
*/ */
@ -105,14 +101,14 @@ RemoveRewriteRule(char *ruleName)
* relation's OID * relation's OID
*/ */
ruleId = tuple->t_oid; ruleId = tuple->t_oid;
eventRelationOidDatum = eventRelationOidDatum = heap_getattr(tuple,
heap_getattr(tuple, Anum_pg_rewrite_ev_class,
Anum_pg_rewrite_ev_class, RelationGetTupleDescriptor(RewriteRelation),
RelationGetTupleDescriptor(RewriteRelation), &isNull);
&isNull);
if (isNull) if (isNull)
{ {
/* XXX strange!!! */ /* XXX strange!!! */
pfree(tuple);
elog(ERROR, "RemoveRewriteRule: null event target relation!"); elog(ERROR, "RemoveRewriteRule: null event target relation!");
} }
eventRelationOid = DatumGetObjectId(eventRelationOidDatum); eventRelationOid = DatumGetObjectId(eventRelationOidDatum);
@ -128,9 +124,10 @@ RemoveRewriteRule(char *ruleName)
/* /*
* Now delete the tuple... * Now delete the tuple...
*/ */
heap_delete(RewriteRelation, &(tuple->t_ctid)); heap_delete(RewriteRelation, &tuple->t_ctid);
pfree(tuple);
heap_close(RewriteRelation); heap_close(RewriteRelation);
heap_endscan(scanDesc);
} }
/* /*
@ -163,20 +160,8 @@ RelationRemoveRules(Oid relid)
scanDesc = heap_beginscan(RewriteRelation, scanDesc = heap_beginscan(RewriteRelation,
0, SnapshotNow, 1, &scanKeyData); 0, SnapshotNow, 1, &scanKeyData);
for (;;) while (HeapTupleIsValid(tuple = heap_getnext(scanDesc, 0)))
{ heap_delete(RewriteRelation, &tuple->t_ctid);
tuple = heap_getnext(scanDesc, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
{
break; /* we're done */
}
/*
* delete the tuple...
*/
heap_delete(RewriteRelation, &(tuple->t_ctid));
}
heap_endscan(scanDesc); heap_endscan(scanDesc);
heap_close(RewriteRelation); heap_close(RewriteRelation);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.24 1998/07/27 19:38:09 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.25 1998/08/19 02:02:33 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -22,6 +22,7 @@
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
#include "storage/buf.h" /* for InvalidBuffer */ #include "storage/buf.h" /* for InvalidBuffer */
#include "storage/bufmgr.h"
#include "utils/builtins.h" /* for textout */ #include "utils/builtins.h" /* for textout */
#include "utils/catcache.h" /* for CacheContext */ #include "utils/catcache.h" /* for CacheContext */
#include "utils/mcxt.h" /* MemoryContext stuff */ #include "utils/mcxt.h" /* MemoryContext stuff */
@ -89,9 +90,7 @@ int
IsDefinedRewriteRule(char *ruleName) IsDefinedRewriteRule(char *ruleName)
{ {
Relation RewriteRelation = NULL; Relation RewriteRelation = NULL;
HeapScanDesc scanDesc = NULL; HeapTuple tuple;
ScanKeyData scanKey;
HeapTuple tuple = NULL;
/* /*
@ -99,21 +98,13 @@ IsDefinedRewriteRule(char *ruleName)
*/ */
RewriteRelation = heap_openr(RewriteRelationName); RewriteRelation = heap_openr(RewriteRelationName);
/* tuple = SearchSysCacheTuple(REWRITENAME,
* Scan the RuleRelation ('pg_rewrite') until we find a tuple PointerGetDatum(ruleName),
*/ 0, 0, 0);
ScanKeyEntryInitialize(&scanKey, 0, Anum_pg_rewrite_rulename,
F_NAMEEQ, PointerGetDatum(ruleName));
scanDesc = heap_beginscan(RewriteRelation,
0, SnapshotNow, 1, &scanKey);
tuple = heap_getnext(scanDesc, 0, (Buffer *) NULL);
/* /*
* return whether or not the rewrite rule existed * return whether or not the rewrite rule existed
*/ */
heap_close(RewriteRelation); heap_close(RewriteRelation);
heap_endscan(scanDesc);
return (HeapTupleIsValid(tuple)); return (HeapTupleIsValid(tuple));
} }
@ -122,40 +113,28 @@ setRelhasrulesInRelation(Oid relationId, bool relhasrules)
{ {
Relation relationRelation; Relation relationRelation;
HeapTuple tuple; HeapTuple tuple;
HeapTuple newTuple;
Relation idescs[Num_pg_class_indices]; Relation idescs[Num_pg_class_indices];
Form_pg_class relp;
/* /*
* Lock a relation given its Oid. Go to the RelationRelation (i.e. * Lock a relation given its Oid. Go to the RelationRelation (i.e.
* pg_relation), find the appropriate tuple, and add the specified * pg_relation), find the appropriate tuple, and add the specified
* lock to it. * lock to it.
*/ */
tuple = SearchSysCacheTupleCopy(RELOID,
ObjectIdGetDatum(relationId),
0, 0, 0);
Assert(HeapTupleIsValid(tuple));
relationRelation = heap_openr(RelationRelationName); relationRelation = heap_openr(RelationRelationName);
tuple = ClassOidIndexScan(relationRelation, relationId); ((Form_pg_class)GETSTRUCT(tuple))->relhasrules = relhasrules;
heap_replace(relationRelation, &tuple->t_ctid, tuple);
/*
* Create a new tuple (i.e. a copy of the old tuple with its rule lock
* field changed and replace the old tuple in the RelationRelation
* NOTE: XXX ??? do we really need to make that copy ????
*/
newTuple = heap_copytuple(tuple);
relp = (Form_pg_class) GETSTRUCT(newTuple);
relp->relhasrules = relhasrules;
heap_replace(relationRelation, &(tuple->t_ctid), newTuple);
/* keep the catalog indices up to date */ /* keep the catalog indices up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
newTuple);
CatalogCloseIndices(Num_pg_class_indices, idescs); CatalogCloseIndices(Num_pg_class_indices, idescs);
/* be tidy */
pfree(tuple); pfree(tuple);
pfree(newTuple);
heap_close(relationRelation); heap_close(relationRelation);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.40 1998/08/01 15:26:12 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.41 1998/08/19 02:02:35 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -100,7 +100,7 @@ static void BufferSync(void);
static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld); static int BufferReplace(BufferDesc *bufHdr, bool bufferLockHeld);
/* not static but used by vacuum only ... */ /* not static but used by vacuum only ... */
int BlowawayRelationBuffers(Relation rdesc, BlockNumber block); int BlowawayRelationBuffers(Relation rel, BlockNumber block);
/* --------------------------------------------------- /* ---------------------------------------------------
* RelationGetBufferWithBuffer * RelationGetBufferWithBuffer
@ -135,7 +135,7 @@ RelationGetBufferWithBuffer(Relation relation,
else else
{ {
bufHdr = &LocalBufferDescriptors[-buffer - 1]; bufHdr = &LocalBufferDescriptors[-buffer - 1];
if (bufHdr->tag.relId.relId == relation->rd_id && if (bufHdr->tag.relId.relId == RelationGetRelid(relation) &&
bufHdr->tag.blockNum == blockNumber) bufHdr->tag.blockNum == blockNumber)
return (buffer); return (buffer);
} }
@ -416,7 +416,7 @@ BufferAlloc(Relation reln,
} }
} }
#ifdef BMTRACE #ifdef BMTRACE
_bm_trace((reln->rd_rel->relisshared ? 0 : MyDatabaseId), reln->rd_id, blockNum, BufferDescriptorGetBuffer(buf), BMT_ALLOCFND); _bm_trace((reln->rd_rel->relisshared ? 0 : MyDatabaseId), RelationGetRelid(reln), blockNum, BufferDescriptorGetBuffer(buf), BMT_ALLOCFND);
#endif /* BMTRACE */ #endif /* BMTRACE */
SpinRelease(BufMgrLock); SpinRelease(BufMgrLock);
@ -660,7 +660,7 @@ BufferAlloc(Relation reln,
} }
#ifdef BMTRACE #ifdef BMTRACE
_bm_trace((reln->rd_rel->relisshared ? 0 : MyDatabaseId), reln->rd_id, blockNum, BufferDescriptorGetBuffer(buf), BMT_ALLOCNOTFND); _bm_trace((reln->rd_rel->relisshared ? 0 : MyDatabaseId), RelationGetRelid(reln), blockNum, BufferDescriptorGetBuffer(buf), BMT_ALLOCNOTFND);
#endif /* BMTRACE */ #endif /* BMTRACE */
SpinRelease(BufMgrLock); SpinRelease(BufMgrLock);
@ -1389,19 +1389,19 @@ RelationGetNumberOfBlocks(Relation relation)
* -------------------------------------------------------------------- * --------------------------------------------------------------------
*/ */
void void
ReleaseRelationBuffers(Relation rdesc) ReleaseRelationBuffers(Relation rel)
{ {
int i; int i;
int holding = 0; int holding = 0;
BufferDesc *buf; BufferDesc *buf;
if (rdesc->rd_islocal) if (rel->rd_islocal)
{ {
for (i = 0; i < NLocBuffer; i++) for (i = 0; i < NLocBuffer; i++)
{ {
buf = &LocalBufferDescriptors[i]; buf = &LocalBufferDescriptors[i];
if ((buf->flags & BM_DIRTY) && if ((buf->flags & BM_DIRTY) &&
(buf->tag.relId.relId == rdesc->rd_id)) (buf->tag.relId.relId == RelationGetRelid(rel)))
buf->flags &= ~BM_DIRTY; buf->flags &= ~BM_DIRTY;
} }
return; return;
@ -1417,7 +1417,7 @@ ReleaseRelationBuffers(Relation rdesc)
} }
if ((buf->flags & BM_DIRTY) && if ((buf->flags & BM_DIRTY) &&
(buf->tag.relId.dbId == MyDatabaseId) && (buf->tag.relId.dbId == MyDatabaseId) &&
(buf->tag.relId.relId == rdesc->rd_id)) (buf->tag.relId.relId == RelationGetRelid(rel)))
{ {
buf->flags &= ~BM_DIRTY; buf->flags &= ~BM_DIRTY;
if (!(buf->flags & BM_FREE)) if (!(buf->flags & BM_FREE))
@ -1559,29 +1559,29 @@ BufferPoolBlowaway()
* -------------------------------------------------------------------- * --------------------------------------------------------------------
*/ */
int int
BlowawayRelationBuffers(Relation rdesc, BlockNumber block) BlowawayRelationBuffers(Relation rel, BlockNumber block)
{ {
int i; int i;
BufferDesc *buf; BufferDesc *buf;
if (rdesc->rd_islocal) if (rel->rd_islocal)
{ {
for (i = 0; i < NLocBuffer; i++) for (i = 0; i < NLocBuffer; i++)
{ {
buf = &LocalBufferDescriptors[i]; buf = &LocalBufferDescriptors[i];
if (buf->tag.relId.relId == rdesc->rd_id && if (buf->tag.relId.relId == RelationGetRelid(rel) &&
buf->tag.blockNum >= block) buf->tag.blockNum >= block)
{ {
if (buf->flags & BM_DIRTY) if (buf->flags & BM_DIRTY)
{ {
elog(NOTICE, "BlowawayRelationBuffers(%s (local), %u): block %u is dirty", elog(NOTICE, "BlowawayRelationBuffers(%s (local), %u): block %u is dirty",
rdesc->rd_rel->relname.data, block, buf->tag.blockNum); rel->rd_rel->relname.data, block, buf->tag.blockNum);
return (-1); return (-1);
} }
if (LocalRefCount[i] > 0) if (LocalRefCount[i] > 0)
{ {
elog(NOTICE, "BlowawayRelationBuffers(%s (local), %u): block %u is referenced (%d)", elog(NOTICE, "BlowawayRelationBuffers(%s (local), %u): block %u is referenced (%d)",
rdesc->rd_rel->relname.data, block, rel->rd_rel->relname.data, block,
buf->tag.blockNum, LocalRefCount[i]); buf->tag.blockNum, LocalRefCount[i]);
return (-2); return (-2);
} }
@ -1596,7 +1596,7 @@ BlowawayRelationBuffers(Relation rdesc, BlockNumber block)
{ {
buf = &BufferDescriptors[i]; buf = &BufferDescriptors[i];
if (buf->tag.relId.dbId == MyDatabaseId && if (buf->tag.relId.dbId == MyDatabaseId &&
buf->tag.relId.relId == rdesc->rd_id && buf->tag.relId.relId == RelationGetRelid(rel) &&
buf->tag.blockNum >= block) buf->tag.blockNum >= block)
{ {
if (buf->flags & BM_DIRTY) if (buf->flags & BM_DIRTY)

View File

@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.18 1998/02/26 04:35:26 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.19 1998/08/19 02:02:37 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -76,13 +76,13 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
/* a low tech search for now -- not optimized for scans */ /* a low tech search for now -- not optimized for scans */
for (i = 0; i < NLocBuffer; i++) for (i = 0; i < NLocBuffer; i++)
{ {
if (LocalBufferDescriptors[i].tag.relId.relId == reln->rd_id && if (LocalBufferDescriptors[i].tag.relId.relId == RelationGetRelid(reln) &&
LocalBufferDescriptors[i].tag.blockNum == blockNum) LocalBufferDescriptors[i].tag.blockNum == blockNum)
{ {
#ifdef LBDEBUG #ifdef LBDEBUG
fprintf(stderr, "LB ALLOC (%d,%d) %d\n", fprintf(stderr, "LB ALLOC (%d,%d) %d\n",
reln->rd_id, blockNum, -i - 1); RelationGetRelid(reln), blockNum, -i - 1);
#endif #endif
LocalRefCount[i]++; LocalRefCount[i]++;
*foundPtr = TRUE; *foundPtr = TRUE;
@ -92,7 +92,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
#ifdef LBDEBUG #ifdef LBDEBUG
fprintf(stderr, "LB ALLOC (%d,%d) %d\n", fprintf(stderr, "LB ALLOC (%d,%d) %d\n",
reln->rd_id, blockNum, -nextFreeLocalBuf - 1); RelationGetRelid(reln), blockNum, -nextFreeLocalBuf - 1);
#endif #endif
/* need to get a new buffer (round robin for now) */ /* need to get a new buffer (round robin for now) */
@ -132,7 +132,7 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
/* /*
* it's all ours now. * it's all ours now.
*/ */
bufHdr->tag.relId.relId = reln->rd_id; bufHdr->tag.relId.relId = RelationGetRelid(reln);
bufHdr->tag.blockNum = blockNum; bufHdr->tag.blockNum = blockNum;
bufHdr->flags &= ~BM_DIRTY; bufHdr->flags &= ~BM_DIRTY;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.33 1998/08/06 05:12:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.34 1998/08/19 02:02:38 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -81,12 +81,12 @@
static HeapTuple static HeapTuple
inv_newtuple(LargeObjectDesc *obj_desc, Buffer buffer, inv_newtuple(LargeObjectDesc *obj_desc, Buffer buffer,
Page page, char *dbuf, int nwrite); Page page, char *dbuf, int nwrite);
static HeapTuple inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP); static HeapTuple inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *buffer);
static int inv_wrnew(LargeObjectDesc *obj_desc, char *buf, int nbytes); static int inv_wrnew(LargeObjectDesc *obj_desc, char *buf, int nbytes);
static int static int
inv_wrold(LargeObjectDesc *obj_desc, char *dbuf, int nbytes, inv_wrold(LargeObjectDesc *obj_desc, char *dbuf, int nbytes,
HeapTuple htup, Buffer buffer); HeapTuple tuple, Buffer buffer);
static void inv_indextup(LargeObjectDesc *obj_desc, HeapTuple htup); static void inv_indextup(LargeObjectDesc *obj_desc, HeapTuple tuple);
static int _inv_getsize(Relation hreln, TupleDesc hdesc, Relation ireln); static int _inv_getsize(Relation hreln, TupleDesc hdesc, Relation ireln);
/* /*
@ -122,14 +122,16 @@ inv_create(int flags)
sprintf(objname, "xinv%d", file_oid); sprintf(objname, "xinv%d", file_oid);
sprintf(indname, "xinx%d", file_oid); sprintf(indname, "xinx%d", file_oid);
if (SearchSysCacheTuple(RELNAME, PointerGetDatum(objname), if (SearchSysCacheTuple(RELNAME,
PointerGetDatum(objname),
0, 0, 0) != NULL) 0, 0, 0) != NULL)
{ {
elog(ERROR, elog(ERROR,
"internal error: %s already exists -- cannot create large obj", "internal error: %s already exists -- cannot create large obj",
objname); objname);
} }
if (SearchSysCacheTuple(RELNAME, PointerGetDatum(indname), if (SearchSysCacheTuple(RELNAME,
PointerGetDatum(indname),
0, 0, 0) != NULL) 0, 0, 0) != NULL)
{ {
elog(ERROR, elog(ERROR,
@ -331,7 +333,7 @@ inv_stat(LargeObjectDesc *obj_desc, struct pgstat * stbuf)
obj_desc->flags |= IFS_RDLOCK; obj_desc->flags |= IFS_RDLOCK;
} }
stbuf->st_ino = obj_desc->heap_r->rd_id; stbuf->st_ino = RelationGetRelid(obj_desc->heap_r);
#if 1 #if 1
stbuf->st_mode = (S_IFREG | 0666); /* IFREG|rw-rw-rw- */ stbuf->st_mode = (S_IFREG | 0666); /* IFREG|rw-rw-rw- */
#else #else
@ -439,8 +441,7 @@ inv_tell(LargeObjectDesc *obj_desc)
int int
inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes) inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
{ {
HeapTuple htup; HeapTuple tuple;
Buffer b;
int nread; int nread;
int off; int off;
int ncopy; int ncopy;
@ -467,18 +468,21 @@ inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
/* fetch a block at a time */ /* fetch a block at a time */
while (nread < nbytes) while (nread < nbytes)
{ {
Buffer buffer;
/* fetch an inversion file system block */ /* fetch an inversion file system block */
htup = inv_fetchtup(obj_desc, &b); tuple = inv_fetchtup(obj_desc, &buffer);
if (!HeapTupleIsValid(htup)) if (!HeapTupleIsValid(tuple))
{ {
obj_desc->flags |= IFS_ATEOF; obj_desc->flags |= IFS_ATEOF;
break; break;
} }
/* copy the data from this block into the buffer */ /* copy the data from this block into the buffer */
d = heap_getattr(htup, 2, obj_desc->hdesc, &isNull); d = heap_getattr(tuple, 2, obj_desc->hdesc, &isNull);
ReleaseBuffer(buffer);
fsblock = (struct varlena *) DatumGetPointer(d); fsblock = (struct varlena *) DatumGetPointer(d);
off = obj_desc->offset - obj_desc->lowbyte; off = obj_desc->offset - obj_desc->lowbyte;
@ -487,9 +491,6 @@ inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
ncopy = (nbytes - nread); ncopy = (nbytes - nread);
memmove(buf, &(fsblock->vl_dat[off]), ncopy); memmove(buf, &(fsblock->vl_dat[off]), ncopy);
/* be a good citizen */
ReleaseBuffer(b);
/* move pointers past the amount we just read */ /* move pointers past the amount we just read */
buf += ncopy; buf += ncopy;
nread += ncopy; nread += ncopy;
@ -503,8 +504,7 @@ inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes)
int int
inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
{ {
HeapTuple htup; HeapTuple tuple;
Buffer b;
int nwritten; int nwritten;
int tuplen; int tuplen;
@ -527,7 +527,8 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
/* write a block at a time */ /* write a block at a time */
while (nwritten < nbytes) while (nwritten < nbytes)
{ {
Buffer buffer;
/* /*
* Fetch the current inversion file system block. If the class * Fetch the current inversion file system block. If the class
* storing the inversion file is empty, we don't want to do an * storing the inversion file is empty, we don't want to do an
@ -537,21 +538,22 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
if ((obj_desc->flags & IFS_ATEOF) if ((obj_desc->flags & IFS_ATEOF)
|| obj_desc->heap_r->rd_nblocks == 0) || obj_desc->heap_r->rd_nblocks == 0)
htup = (HeapTuple) NULL; tuple = (HeapTuple) NULL;
else else
htup = inv_fetchtup(obj_desc, &b); tuple = inv_fetchtup(obj_desc, &buffer);
/* either append or replace a block, as required */ /* either append or replace a block, as required */
if (!HeapTupleIsValid(htup)) if (!HeapTupleIsValid(tuple))
tuplen = inv_wrnew(obj_desc, buf, nbytes - nwritten); tuplen = inv_wrnew(obj_desc, buf, nbytes - nwritten);
else else
{ {
if (obj_desc->offset > obj_desc->highbyte) if (obj_desc->offset > obj_desc->highbyte)
tuplen = inv_wrnew(obj_desc, buf, nbytes - nwritten); tuplen = inv_wrnew(obj_desc, buf, nbytes - nwritten);
else else
tuplen = inv_wrold(obj_desc, buf, nbytes - nwritten, htup, b); tuplen = inv_wrold(obj_desc, buf, nbytes - nwritten, tuple, buffer);
} }
ReleaseBuffer(buffer);
/* move pointers past the amount we just wrote */ /* move pointers past the amount we just wrote */
buf += tuplen; buf += tuplen;
nwritten += tuplen; nwritten += tuplen;
@ -602,9 +604,9 @@ inv_cleanindex(LargeObjectDesc *obj_desc)
* such tuple exists. * such tuple exists.
*/ */
static HeapTuple static HeapTuple
inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP) inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *buffer)
{ {
HeapTuple htup; HeapTuple tuple;
RetrieveIndexResult res; RetrieveIndexResult res;
Datum d; Datum d;
int firstbyte, int firstbyte,
@ -642,8 +644,11 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
&skey); &skey);
} }
res = NULL;
do do
{ {
if (res)
pfree(res);
res = index_getnext(obj_desc->iscan, ForwardScanDirection); res = index_getnext(obj_desc->iscan, ForwardScanDirection);
if (res == (RetrieveIndexResult) NULL) if (res == (RetrieveIndexResult) NULL)
@ -662,10 +667,9 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
* *
*/ */
htup = heap_fetch(obj_desc->heap_r, SnapshotNow, tuple = heap_fetch(obj_desc->heap_r, SnapshotNow,
&(res->heap_iptr), bufP); &(res->heap_iptr), buffer);
} while (tuple == (HeapTuple) NULL);
} while (htup == (HeapTuple) NULL);
/* remember this tid -- we may need it for later reads/writes */ /* remember this tid -- we may need it for later reads/writes */
ItemPointerCopy(&(res->heap_iptr), &(obj_desc->htid)); ItemPointerCopy(&(res->heap_iptr), &(obj_desc->htid));
@ -673,8 +677,8 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
} }
else else
{ {
htup = heap_fetch(obj_desc->heap_r, SnapshotNow, tuple = heap_fetch(obj_desc->heap_r, SnapshotNow,
&(obj_desc->htid), bufP); &(obj_desc->htid), buffer);
} }
/* /*
@ -683,9 +687,9 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
* return the tuple. * return the tuple.
*/ */
d = heap_getattr(htup, 1, obj_desc->hdesc, &isNull); d = heap_getattr(tuple, 1, obj_desc->hdesc, &isNull);
lastbyte = (int32) DatumGetInt32(d); lastbyte = (int32) DatumGetInt32(d);
d = heap_getattr(htup, 2, obj_desc->hdesc, &isNull); d = heap_getattr(tuple, 2, obj_desc->hdesc, &isNull);
fsblock = (struct varlena *) DatumGetPointer(d); fsblock = (struct varlena *) DatumGetPointer(d);
/* /*
@ -697,8 +701,7 @@ inv_fetchtup(LargeObjectDesc *obj_desc, Buffer *bufP)
obj_desc->lowbyte = firstbyte; obj_desc->lowbyte = firstbyte;
obj_desc->highbyte = lastbyte; obj_desc->highbyte = lastbyte;
/* done */ return tuple;
return (htup);
} }
/* /*
@ -798,7 +801,7 @@ static int
inv_wrold(LargeObjectDesc *obj_desc, inv_wrold(LargeObjectDesc *obj_desc,
char *dbuf, char *dbuf,
int nbytes, int nbytes,
HeapTuple htup, HeapTuple tuple,
Buffer buffer) Buffer buffer)
{ {
Relation hr; Relation hr;
@ -814,6 +817,7 @@ inv_wrold(LargeObjectDesc *obj_desc,
freespc; freespc;
bool isNull; bool isNull;
int keep_offset; int keep_offset;
RetrieveIndexResult res;
/* /*
* Since we're using a no-overwrite storage manager, the way we * Since we're using a no-overwrite storage manager, the way we
@ -822,9 +826,9 @@ inv_wrold(LargeObjectDesc *obj_desc,
* abstraction. * abstraction.
*/ */
TransactionIdStore(GetCurrentTransactionId(), &(htup->t_xmax)); TransactionIdStore(GetCurrentTransactionId(), &(tuple->t_xmax));
htup->t_cmax = GetCurrentCommandId(); tuple->t_cmax = GetCurrentCommandId();
htup->t_infomask &= ~(HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID); tuple->t_infomask &= ~(HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID);
/* /*
* If we're overwriting the entire block, we're lucky. All we need to * If we're overwriting the entire block, we're lucky. All we need to
@ -851,7 +855,7 @@ inv_wrold(LargeObjectDesc *obj_desc,
newpage = BufferGetPage(newbuf); newpage = BufferGetPage(newbuf);
hr = obj_desc->heap_r; hr = obj_desc->heap_r;
freespc = IFREESPC(page); freespc = IFREESPC(page);
d = heap_getattr(htup, 2, obj_desc->hdesc, &isNull); d = heap_getattr(tuple, 2, obj_desc->hdesc, &isNull);
fsblock = (struct varlena *) DatumGetPointer(d); fsblock = (struct varlena *) DatumGetPointer(d);
tupbytes = fsblock->vl_len - sizeof(fsblock->vl_len); tupbytes = fsblock->vl_len - sizeof(fsblock->vl_len);
@ -956,8 +960,12 @@ inv_wrold(LargeObjectDesc *obj_desc,
* move the scandesc forward so we don't reread the newly inserted * move the scandesc forward so we don't reread the newly inserted
* tuple on the next index scan * tuple on the next index scan
*/ */
res = NULL;
if (obj_desc->iscan) if (obj_desc->iscan)
index_getnext(obj_desc->iscan, ForwardScanDirection); res = index_getnext(obj_desc->iscan, ForwardScanDirection);
if (res)
pfree(res);
/* /*
* Okay, by here, a tuple for the new block is correctly placed, * Okay, by here, a tuple for the new block is correctly placed,
@ -1038,7 +1046,7 @@ inv_newtuple(LargeObjectDesc *obj_desc,
*/ */
ntup->t_len = tupsize; ntup->t_len = tupsize;
ItemPointerSet(&(ntup->t_ctid), BufferGetBlockNumber(buffer), off); ItemPointerSet(&ntup->t_ctid, BufferGetBlockNumber(buffer), off);
LastOidProcessed = ntup->t_oid = newoid(); LastOidProcessed = ntup->t_oid = newoid();
TransactionIdStore(GetCurrentTransactionId(), &(ntup->t_xmin)); TransactionIdStore(GetCurrentTransactionId(), &(ntup->t_xmin));
ntup->t_cmin = GetCurrentCommandId(); ntup->t_cmin = GetCurrentCommandId();
@ -1091,7 +1099,7 @@ inv_newtuple(LargeObjectDesc *obj_desc,
} }
static void static void
inv_indextup(LargeObjectDesc *obj_desc, HeapTuple htup) inv_indextup(LargeObjectDesc *obj_desc, HeapTuple tuple)
{ {
InsertIndexResult res; InsertIndexResult res;
Datum v[1]; Datum v[1];
@ -1100,7 +1108,7 @@ inv_indextup(LargeObjectDesc *obj_desc, HeapTuple htup)
n[0] = ' '; n[0] = ' ';
v[0] = Int32GetDatum(obj_desc->highbyte); v[0] = Int32GetDatum(obj_desc->highbyte);
res = index_insert(obj_desc->index_r, &v[0], &n[0], res = index_insert(obj_desc->index_r, &v[0], &n[0],
&(htup->t_ctid), obj_desc->heap_r); &(tuple->t_ctid), obj_desc->heap_r);
if (res) if (res)
pfree(res); pfree(res);
@ -1203,17 +1211,15 @@ _inv_getsize(Relation hreln, TupleDesc hdesc, Relation ireln)
{ {
IndexScanDesc iscan; IndexScanDesc iscan;
RetrieveIndexResult res; RetrieveIndexResult res;
Buffer buf; HeapTuple tuple;
HeapTuple htup;
Datum d; Datum d;
long size; long size;
bool isNull; bool isNull;
Buffer buffer;
/* scan backwards from end */ /* scan backwards from end */
iscan = index_beginscan(ireln, (bool) 1, 0, (ScanKey) NULL); iscan = index_beginscan(ireln, (bool) 1, 0, (ScanKey) NULL);
buf = InvalidBuffer;
do do
{ {
res = index_getnext(iscan, BackwardScanDirection); res = index_getnext(iscan, BackwardScanDirection);
@ -1235,25 +1241,18 @@ _inv_getsize(Relation hreln, TupleDesc hdesc, Relation ireln)
* rather that NowTimeQual. We currently have no way to pass a * rather that NowTimeQual. We currently have no way to pass a
* time qual in. * time qual in.
*/ */
tuple = heap_fetch(hreln, SnapshotNow, &res->heap_iptr, &buffer);
if (buf != InvalidBuffer)
ReleaseBuffer(buf);
htup = heap_fetch(hreln, SnapshotNow, &(res->heap_iptr), &buf);
pfree(res); pfree(res);
} while (!HeapTupleIsValid(tuple));
} while (!HeapTupleIsValid(htup));
/* don't need the index scan anymore */ /* don't need the index scan anymore */
index_endscan(iscan); index_endscan(iscan);
pfree(iscan); pfree(iscan);
/* get olastbyte attribute */ /* get olastbyte attribute */
d = heap_getattr(htup, 1, hdesc, &isNull); d = heap_getattr(tuple, 1, hdesc, &isNull);
size = DatumGetInt32(d) + 1; size = DatumGetInt32(d) + 1;
ReleaseBuffer(buffer);
/* wei hates it if you forget to do this */
ReleaseBuffer(buf);
return (size); return (size);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.16 1998/08/01 15:26:24 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lmgr.c,v 1.17 1998/08/19 02:02:40 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -67,7 +67,7 @@ RelationInitLockInfo(Relation relation)
extern GlobalMemory CacheCxt; extern GlobalMemory CacheCxt;
Assert(RelationIsValid(relation)); Assert(RelationIsValid(relation));
Assert(OidIsValid(RelationGetRelationId(relation))); Assert(OidIsValid(RelationGetRelid(relation)));
info = (LockInfo) relation->lockInfo; info = (LockInfo) relation->lockInfo;
@ -80,7 +80,7 @@ RelationInitLockInfo(Relation relation)
info = (LockInfo) palloc(sizeof(LockInfoData)); info = (LockInfo) palloc(sizeof(LockInfoData));
MemoryContextSwitchTo(oldcxt); MemoryContextSwitchTo(oldcxt);
info->lockRelId.relId = RelationGetRelationId(relation); info->lockRelId.relId = RelationGetRelid(relation);
if (IsSharedSystemRelationName(relname)) if (IsSharedSystemRelationName(relname))
info->lockRelId.dbId = InvalidOid; info->lockRelId.dbId = InvalidOid;
else else

View File

@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.21 1998/08/01 15:26:26 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/Attic/multi.c,v 1.22 1998/08/19 02:02:44 momjian Exp $
* *
* NOTES: * NOTES:
* (1) The lock.c module assumes that the caller here is doing * (1) The lock.c module assumes that the caller here is doing
@ -248,7 +248,7 @@ MultiAcquire(LOCKMETHOD lockmethod,
LOCKMODE lockmode, LOCKMODE lockmode,
PG_LOCK_LEVEL level) PG_LOCK_LEVEL level)
{ {
LOCKMODE locks[N_LEVELS]; LOCKMODE locks[N_LEVELS];
int i, int i,
status; status;
LOCKTAG xxTag, LOCKTAG xxTag,

View File

@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.9 1998/06/23 15:35:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.10 1998/08/19 02:02:46 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -181,7 +181,7 @@ mmcreate(Relation reln)
(*MMCurRelno)++; (*MMCurRelno)++;
tag.mmrt_relid = reln->rd_id; tag.mmrt_relid = RelationGetRelid(reln);
if (reln->rd_rel->relisshared) if (reln->rd_rel->relisshared)
tag.mmrt_dbid = (Oid) 0; tag.mmrt_dbid = (Oid) 0;
else else
@ -233,7 +233,7 @@ mmunlink(Relation reln)
for (i = 0; i < MMNBUFFERS; i++) for (i = 0; i < MMNBUFFERS; i++)
{ {
if (MMBlockTags[i].mmct_dbid == reldbid if (MMBlockTags[i].mmct_dbid == reldbid
&& MMBlockTags[i].mmct_relid == reln->rd_id) && MMBlockTags[i].mmct_relid == RelationGetRelid(reln))
{ {
entry = (MMHashEntry *) hash_search(MMCacheHT, entry = (MMHashEntry *) hash_search(MMCacheHT,
(char *) &MMBlockTags[i], (char *) &MMBlockTags[i],
@ -249,7 +249,7 @@ mmunlink(Relation reln)
} }
} }
rtag.mmrt_dbid = reldbid; rtag.mmrt_dbid = reldbid;
rtag.mmrt_relid = reln->rd_id; rtag.mmrt_relid = RelationGetRelid(reln);
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT, (char *) &rtag, rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT, (char *) &rtag,
HASH_REMOVE, &found); HASH_REMOVE, &found);
@ -290,7 +290,7 @@ mmextend(Relation reln, char *buffer)
reldbid = MyDatabaseId; reldbid = MyDatabaseId;
tag.mmct_dbid = rtag.mmrt_dbid = reldbid; tag.mmct_dbid = rtag.mmrt_dbid = reldbid;
tag.mmct_relid = rtag.mmrt_relid = reln->rd_id; tag.mmct_relid = rtag.mmrt_relid = RelationGetRelid(reln);
SpinAcquire(MMCacheLock); SpinAcquire(MMCacheLock);
@ -334,7 +334,7 @@ mmextend(Relation reln, char *buffer)
entry->mmhe_bufno = i; entry->mmhe_bufno = i;
MMBlockTags[i].mmct_dbid = reldbid; MMBlockTags[i].mmct_dbid = reldbid;
MMBlockTags[i].mmct_relid = reln->rd_id; MMBlockTags[i].mmct_relid = RelationGetRelid(reln);
MMBlockTags[i].mmct_blkno = rentry->mmrhe_nblocks; MMBlockTags[i].mmct_blkno = rentry->mmrhe_nblocks;
/* page numbers are zero-based, so we increment this at the end */ /* page numbers are zero-based, so we increment this at the end */
@ -389,7 +389,7 @@ mmread(Relation reln, BlockNumber blocknum, char *buffer)
else else
tag.mmct_dbid = MyDatabaseId; tag.mmct_dbid = MyDatabaseId;
tag.mmct_relid = reln->rd_id; tag.mmct_relid = RelationGetRelid(reln);
tag.mmct_blkno = blocknum; tag.mmct_blkno = blocknum;
SpinAcquire(MMCacheLock); SpinAcquire(MMCacheLock);
@ -436,7 +436,7 @@ mmwrite(Relation reln, BlockNumber blocknum, char *buffer)
else else
tag.mmct_dbid = MyDatabaseId; tag.mmct_dbid = MyDatabaseId;
tag.mmct_relid = reln->rd_id; tag.mmct_relid = RelationGetRelid(reln);
tag.mmct_blkno = blocknum; tag.mmct_blkno = blocknum;
SpinAcquire(MMCacheLock); SpinAcquire(MMCacheLock);
@ -509,7 +509,7 @@ mmnblocks(Relation reln)
else else
rtag.mmrt_dbid = MyDatabaseId; rtag.mmrt_dbid = MyDatabaseId;
rtag.mmrt_relid = reln->rd_id; rtag.mmrt_relid = RelationGetRelid(reln);
SpinAcquire(MMCacheLock); SpinAcquire(MMCacheLock);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.18 1998/06/15 19:29:26 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/fastpath.c,v 1.19 1998/08/19 02:02:48 momjian Exp $
* *
* NOTES * NOTES
* This cruft is the server side of PQfn. * This cruft is the server side of PQfn.
@ -204,7 +204,8 @@ update_fp_info(Oid func_id, struct fp_info * fip)
MemSet((char *) fip, 0, (int) sizeof(struct fp_info)); MemSet((char *) fip, 0, (int) sizeof(struct fp_info));
fip->funcid = InvalidOid; fip->funcid = InvalidOid;
func_htp = SearchSysCacheTuple(PROOID, ObjectIdGetDatum(func_id), func_htp = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(func_id),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(func_htp)) if (!HeapTupleIsValid(func_htp))
{ {
@ -236,7 +237,8 @@ update_fp_info(Oid func_id, struct fp_info * fip)
if (OidIsValid(rettype)) if (OidIsValid(rettype))
{ {
type_htp = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(rettype), type_htp = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(rettype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(type_htp)) if (!HeapTupleIsValid(type_htp))
{ {

View File

@ -4,7 +4,7 @@
# Makefile for utils/adt # Makefile for utils/adt
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.15 1998/07/26 04:30:52 scrappy Exp $ # $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.16 1998/08/19 02:02:52 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -21,7 +21,7 @@ OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o chunk.o \
date.o datetime.o datum.o dt.o filename.o float.o \ date.o datetime.o datum.o dt.o filename.o float.o \
geo_ops.o geo_selfuncs.o int.o int8.o like.o \ geo_ops.o geo_selfuncs.o int.o int8.o like.o \
misc.o nabstime.o name.o not_in.o numutils.o \ misc.o nabstime.o name.o not_in.o numutils.o \
oid.o oidname.o oidint2.o oidint4.o oracle_compat.o \ oid.o oracle_compat.o \
regexp.o regproc.o selfuncs.o sets.o tid.o timestamp.o \ regexp.o regproc.o selfuncs.o sets.o tid.o timestamp.o \
varchar.o varlena.o version.o varchar.o varlena.o version.o

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.28 1998/06/15 19:29:31 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.29 1998/08/19 02:02:53 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -86,7 +86,7 @@ getid(char *s, char *n)
static char * static char *
aclparse(char *s, AclItem *aip, unsigned *modechg) aclparse(char *s, AclItem *aip, unsigned *modechg)
{ {
HeapTuple htp; HeapTuple htup;
char name[NAMEDATALEN]; char name[NAMEDATALEN];
Assert(s && aip && modechg); Assert(s && aip && modechg);
@ -150,11 +150,12 @@ aclparse(char *s, AclItem *aip, unsigned *modechg)
switch (aip->ai_idtype) switch (aip->ai_idtype)
{ {
case ACL_IDTYPE_UID: case ACL_IDTYPE_UID:
htp = SearchSysCacheTuple(USENAME, PointerGetDatum(name), htup = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(name),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "aclparse: non-existent user \"%s\"", name); elog(ERROR, "aclparse: non-existent user \"%s\"", name);
aip->ai_id = ((Form_pg_shadow) GETSTRUCT(htp))->usesysid; aip->ai_id = ((Form_pg_shadow) GETSTRUCT(htup))->usesysid;
break; break;
case ACL_IDTYPE_GID: case ACL_IDTYPE_GID:
aip->ai_id = get_grosysid(name); aip->ai_id = get_grosysid(name);
@ -241,7 +242,7 @@ aclitemout(AclItem *aip)
{ {
char *p; char *p;
char *out; char *out;
HeapTuple htp; HeapTuple htup;
unsigned i; unsigned i;
static AclItem default_aclitem = {ACL_ID_WORLD, static AclItem default_aclitem = {ACL_ID_WORLD,
ACL_IDTYPE_WORLD, ACL_IDTYPE_WORLD,
@ -260,9 +261,10 @@ aclitemout(AclItem *aip)
switch (aip->ai_idtype) switch (aip->ai_idtype)
{ {
case ACL_IDTYPE_UID: case ACL_IDTYPE_UID:
htp = SearchSysCacheTuple(USESYSID, ObjectIdGetDatum(aip->ai_id), htup = SearchSysCacheTuple(USESYSID,
0, 0, 0); ObjectIdGetDatum(aip->ai_id),
if (!HeapTupleIsValid(htp)) 0, 0, 0);
if (!HeapTupleIsValid(htup))
{ {
char *tmp = int2out(aip->ai_id); char *tmp = int2out(aip->ai_id);
@ -283,7 +285,7 @@ aclitemout(AclItem *aip)
} }
else else
strncat(p, (char *) &((Form_pg_shadow) strncat(p, (char *) &((Form_pg_shadow)
GETSTRUCT(htp))->usename, GETSTRUCT(htup))->usename,
sizeof(NameData)); sizeof(NameData));
break; break;
case ACL_IDTYPE_GID: case ACL_IDTYPE_GID:

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.31 1998/07/12 21:29:22 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.32 1998/08/19 02:02:55 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1302,7 +1302,8 @@ system_cache_lookup(Oid element_type,
HeapTuple typeTuple; HeapTuple typeTuple;
TypeTupleForm typeStruct; TypeTupleForm typeStruct;
typeTuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(element_type), typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(element_type),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTuple)) if (!HeapTupleIsValid(typeTuple))

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.23 1998/06/15 19:29:33 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.24 1998/08/19 02:02:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -614,7 +614,7 @@ datetime_datetime(DateADT date, TimeADT *time)
int32 /* RelativeTime */ int32 /* RelativeTime */
int42reltime(int32 timevalue) int4reltime(int32 timevalue)
{ {
return (timevalue); return (timevalue);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.10 1998/07/27 19:38:18 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.11 1998/08/19 02:02:57 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -78,9 +78,8 @@ int4notin(int16 not_in_arg, char *relation_and_attr)
retval = true; retval = true;
/* do a scan of the relation, and do the check */ /* do a scan of the relation, and do the check */
for (current_tuple = heap_getnext(scan_descriptor, 0, NULL); while (HeapTupleIsValid(current_tuple = heap_getnext(scan_descriptor, 0)) &&
current_tuple != NULL && retval; retval)
current_tuple = heap_getnext(scan_descriptor, 0, NULL))
{ {
value = heap_getattr(current_tuple, value = heap_getattr(current_tuple,
(AttrNumber) attrid, (AttrNumber) attrid,

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.15 1998/02/26 04:37:16 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.16 1998/08/19 02:02:59 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -125,6 +125,46 @@ oid8eq(Oid arg1[], Oid arg2[])
return (bool) (memcmp(arg1, arg2, 8 * sizeof(Oid)) == 0); return (bool) (memcmp(arg1, arg2, 8 * sizeof(Oid)) == 0);
} }
bool
oid8lt(Oid arg1[], Oid arg2[])
{
int i;
for (i=0; i < 8; i++)
if (!int4eq(arg1[i], arg2[i]))
return int4lt(arg1[i], arg2[i]);
return false;
}
bool
oid8le(Oid arg1[], Oid arg2[])
{
int i;
for (i=0; i < 8; i++)
if (!int4eq(arg1[i], arg2[i]))
return int4le(arg1[i], arg2[i]);
return true;
}
bool
oid8ge(Oid arg1[], Oid arg2[])
{
int i;
for (i=0; i < 8; i++)
if (!int4eq(arg1[i], arg2[i]))
return int4ge(arg1[i], arg2[i]);
return true;
}
bool
oid8gt(Oid arg1[], Oid arg2[])
{
int i;
for (i=0; i < 8; i++)
if (!int4eq(arg1[i], arg2[i]))
return int4gt(arg1[i], arg2[i]);
return false;
}
bool bool
oideqint4(Oid arg1, int32 arg2) oideqint4(Oid arg1, int32 arg2)
{ {

View File

@ -1,116 +0,0 @@
/*-------------------------------------------------------------------------
*
* oidint2.c--
* Functions for the built-in type "oidint2".
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/oidint2.c,v 1.6 1998/06/15 19:29:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include "postgres.h"
#include "utils/palloc.h"
#include "utils/builtins.h" /* for pg_atoi() */
#include "utils/oidcompos.h" /* where function declarations go */
OidInt2
oidint2in(char *o)
{
OidInt2 oi;
char *p;
oi = (OidInt2) palloc(sizeof(OidInt2Data));
for (p = o; *p != '\0' && *p != '/'; p++)
continue;
oi->oi_oid = (Oid) pg_atoi(o, sizeof(Oid), '/');
if (*p == '\0')
oi->oi_int2 = 0;
else
oi->oi_int2 = (int16) pg_atoi(++p, sizeof(int2), '\0');
return (oi);
}
char *
oidint2out(OidInt2 o)
{
char *r;
/*
* -2147483647/-32767 0 1 1234567890123456789
*/
r = (char *) palloc(19);
sprintf(r, "%d/%d", o->oi_oid, o->oi_int2);
return (r);
}
bool
oidint2lt(OidInt2 o1, OidInt2 o2)
{
return
((bool) (o1->oi_oid < o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int2 < o2->oi_int2)));
}
bool
oidint2le(OidInt2 o1, OidInt2 o2)
{
return ((bool) (o1->oi_oid < o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int2 <= o2->oi_int2)));
}
bool
oidint2eq(OidInt2 o1, OidInt2 o2)
{
return ((bool) (o1->oi_oid == o2->oi_oid && o1->oi_int2 == o2->oi_int2));
}
bool
oidint2ge(OidInt2 o1, OidInt2 o2)
{
return ((bool) (o1->oi_oid > o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int2 >= o2->oi_int2)));
}
bool
oidint2gt(OidInt2 o1, OidInt2 o2)
{
return ((bool) (o1->oi_oid > o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int2 > o2->oi_int2)));
}
bool
oidint2ne(OidInt2 o1, OidInt2 o2)
{
return ((bool) (o1->oi_oid != o2->oi_oid || o1->oi_int2 != o2->oi_int2));
}
int
oidint2cmp(OidInt2 o1, OidInt2 o2)
{
if (oidint2lt(o1, o2))
return (-1);
else if (oidint2eq(o1, o2))
return (0);
else
return (1);
}
OidInt2
mkoidint2(Oid v_oid, uint16 v_int2)
{
OidInt2 o;
o = (OidInt2) palloc(sizeof(OidInt2Data));
o->oi_oid = v_oid;
o->oi_int2 = v_int2;
return (o);
}

View File

@ -1,116 +0,0 @@
/*-------------------------------------------------------------------------
*
* oidint4.c--
* Functions for the built-in type "oidint4".
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/oidint4.c,v 1.6 1998/06/15 19:29:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h> /* for sprintf() */
#include "postgres.h"
#include "utils/palloc.h"
#include "utils/builtins.h"
#include "utils/oidcompos.h" /* where function declarations go */
OidInt4
oidint4in(char *o)
{
OidInt4 oi;
char *p;
oi = (OidInt4) palloc(sizeof(OidInt4Data));
for (p = o; *p != '\0' && *p != '/'; p++)
continue;
oi->oi_oid = (Oid) pg_atoi(o, sizeof(Oid), '/');
if (*p == '\0')
oi->oi_int4 = 0;
else
oi->oi_int4 = pg_atoi(++p, sizeof(int4), '\0');
return (oi);
}
char *
oidint4out(OidInt4 o)
{
char *r;
/*
* -2147483647/-2147483647 0 1 2
* 123456789012345678901234
*/
r = (char *) palloc(24);
sprintf(r, "%d/%d", o->oi_oid, o->oi_int4);
return (r);
}
bool
oidint4lt(OidInt4 o1, OidInt4 o2)
{
return
((bool) (o1->oi_oid < o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int4 < o2->oi_int4)));
}
bool
oidint4le(OidInt4 o1, OidInt4 o2)
{
return ((bool) (o1->oi_oid < o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int4 <= o2->oi_int4)));
}
bool
oidint4eq(OidInt4 o1, OidInt4 o2)
{
return ((bool) (o1->oi_oid == o2->oi_oid && o1->oi_int4 == o2->oi_int4));
}
bool
oidint4ge(OidInt4 o1, OidInt4 o2)
{
return ((bool) (o1->oi_oid > o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int4 >= o2->oi_int4)));
}
bool
oidint4gt(OidInt4 o1, OidInt4 o2)
{
return ((bool) (o1->oi_oid > o2->oi_oid ||
(o1->oi_oid == o2->oi_oid && o1->oi_int4 > o2->oi_int4)));
}
bool
oidint4ne(OidInt4 o1, OidInt4 o2)
{
return ((bool) (o1->oi_oid != o2->oi_oid || o1->oi_int4 != o2->oi_int4));
}
int
oidint4cmp(OidInt4 o1, OidInt4 o2)
{
if (oidint4lt(o1, o2))
return (-1);
else if (oidint4eq(o1, o2))
return (0);
else
return (1);
}
OidInt4
mkoidint4(Oid v_oid, uint32 v_int4)
{
OidInt4 o;
o = (OidInt4) palloc(sizeof(OidInt4Data));
o->oi_oid = v_oid;
o->oi_int4 = v_int4;
return (o);
}

View File

@ -1,125 +0,0 @@
/*-------------------------------------------------------------------------
*
* oidname.c--
* adt for multiple key indices involving oid and name. Used for cache
* index scans (could also be used in the general case with name).
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/oidname.c,v 1.12 1998/02/26 04:37:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "postgres.h"
#include "utils/oidcompos.h" /* where function declarations go */
#include "utils/builtins.h" /* for pg_atoi() */
#include "utils/palloc.h"
OidName
oidnamein(char *inStr)
{
OidName oc;
char *inptr;
oc = (OidName) palloc(sizeof(OidNameData));
MemSet(oc, 0, sizeof(OidNameData));
for (inptr = inStr; *inptr && *inptr != ','; inptr++)
;
if (*inptr)
{
oc->id = (Oid) pg_atoi(inStr, sizeof(Oid), ',');
/* copy one less to ensure null-padding */
++inptr;
StrNCpy(oc->name.data, inptr, NAMEDATALEN);
}
else
elog(ERROR, "Bad input data for type oidname");
return oc;
}
char *
oidnameout(OidName oidname)
{
char buf[30 + NAMEDATALEN]; /* oidname length + oid length +
* some safety */
char *res;
sprintf(buf, "%d,%s", oidname->id, oidname->name.data);
res = pstrdup(buf);
return (res);
}
bool
oidnamelt(OidName o1, OidName o2)
{
return (bool)
(o1->id < o2->id ||
(o1->id == o2->id && namecmp(&o1->name, &o2->name) < 0));
}
bool
oidnamele(OidName o1, OidName o2)
{
return (bool)
(o1->id < o2->id ||
(o1->id == o2->id && namecmp(&o1->name, &o2->name) <= 0));
}
bool
oidnameeq(OidName o1, OidName o2)
{
return (bool)
(o1->id == o2->id &&
(namecmp(&o1->name, &o2->name) == 0));
}
bool
oidnamene(OidName o1, OidName o2)
{
return (bool)
(o1->id != o2->id ||
(namecmp(&o1->name, &o2->name) != 0));
}
bool
oidnamege(OidName o1, OidName o2)
{
return (bool) (o1->id > o2->id || (o1->id == o2->id &&
namecmp(&o1->name, &o2->name) >= 0));
}
bool
oidnamegt(OidName o1, OidName o2)
{
return (bool) (o1->id > o2->id || (o1->id == o2->id &&
namecmp(&o1->name, &o2->name) > 0));
}
int
oidnamecmp(OidName o1, OidName o2)
{
if (o1->id == o2->id)
return (namecmp(&o1->name, &o2->name));
return (o1->id < o2->id) ? -1 : 1;
}
OidName
mkoidname(Oid id, char *name)
{
OidName oidname;
oidname = (OidName) palloc(sizeof(Oid) + NAMEDATALEN);
oidname->id = id;
namestrcpy(&oidname->name, name);
return oidname;
}

View File

@ -1,4 +1,4 @@
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* regproc.c-- * regproc.c--
* Functions for the built-in type "RegProcedure". * Functions for the built-in type "RegProcedure".
@ -7,143 +7,190 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.21 1998/07/27 19:38:19 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.22 1998/08/19 02:03:04 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <string.h> #include <string.h>
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h"
#include "access/heapam.h" #include "access/heapam.h"
#include "access/relscan.h" #include "access/relscan.h"
#include "fmgr.h" #include "fmgr.h"
#include "utils/palloc.h" #include "utils/palloc.h"
#include "utils/syscache.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "utils/builtins.h" /* where function declarations go */ #include "utils/builtins.h" /* where function declarations go */
/***************************************************************************** /*****************************************************************************
* USER I/O ROUTINES * * USER I/O ROUTINES *
*****************************************************************************/ *****************************************************************************/
/* /*
* regprocin - converts "proname" to proid * regprocin - converts "proname" to proid
* *
* proid of NULL signifies unknown * proid of NULL signifies unknown
*/ */
int32 int32
regprocin(char *proname) regprocin(char *pro_oid_name)
{ {
Relation proc;
HeapScanDesc procscan;
HeapTuple proctup; HeapTuple proctup;
ScanKeyData key;
RegProcedure result = (Oid) 0; RegProcedure result = (Oid) 0;
bool isnull;
if (proname == NULL) if (pro_oid_name == NULL)
return (0); return (0);
proc = heap_openr(ProcedureRelationName);
if (!RelationIsValid(proc))
if (!IsBootstrapProcessingMode())
{ {
elog(ERROR, "regprocin: could not open %s", /*
ProcedureRelationName); * we need to use the oid because there can be multiple entries
return (0); * with the same name, i.e. 1323(int4eq)
*/
proctup = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(atoi(pro_oid_name)),
0, 0, 0);
if (HeapTupleIsValid(proctup))
result = (RegProcedure) proctup->t_oid;
else result = (RegProcedure) 0;
} }
ScanKeyEntryInitialize(&key, else
(bits16) 0,
(AttrNumber) 1,
(RegProcedure) F_NAMEEQ,
(Datum) proname);
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{ {
Relation proc;
HeapScanDesc procscan;
ScanKeyData key;
bool isnull;
proc = heap_openr(ProcedureRelationName);
if (!RelationIsValid(proc))
{
elog(ERROR, "regprocin: could not open %s",
ProcedureRelationName);
return (0);
}
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) 1,
(RegProcedure) F_NAMEEQ,
(Datum) pro_oid_name);
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{
heap_close(proc);
elog(ERROR, "regprocin: could not being scan of %s",
ProcedureRelationName);
return (0);
}
proctup = heap_getnext(procscan, 0);
if (HeapTupleIsValid(proctup))
{
result = (RegProcedure) heap_getattr(proctup,
ObjectIdAttributeNumber,
RelationGetTupleDescriptor(proc),
&isnull);
if (isnull)
elog(FATAL, "regprocin: null procedure %s", pro_oid_name);
}
else
result = (RegProcedure) 0;
heap_endscan(procscan);
heap_close(proc); heap_close(proc);
elog(ERROR, "regprocin: could not being scan of %s", }
ProcedureRelationName);
return (0);
}
proctup = heap_getnext(procscan, 0, (Buffer *) NULL);
switch (HeapTupleIsValid(proctup))
{
case 1:
result = (RegProcedure) heap_getattr(proctup,
ObjectIdAttributeNumber,
RelationGetTupleDescriptor(proc),
&isnull);
if (isnull)
elog(FATAL, "regprocin: null procedure %s", proname);
break;
case 0:
result = (RegProcedure) 0;
#ifdef EBUG #ifdef EBUG
elog(DEBUG, "regprocin: no such procedure %s", proname); elog(DEBUG, "regprocin: no such procedure %s", pro_oid_name);
#endif /* defined(EBUG) */ #endif /* defined(EBUG) */
} return (int32) result;
heap_endscan(procscan);
heap_close(proc);
return ((int32) result);
} }
/* /*
* regprocout - converts proid to "proname" * regprocout - converts proid to "pro_oid_name"
*/ */
char * char *
regprocout(RegProcedure proid) regprocout(RegProcedure proid)
{ {
Relation proc;
HeapScanDesc procscan;
HeapTuple proctup; HeapTuple proctup;
char *result; char *result;
ScanKeyData key;
result = (char *) palloc(NAMEDATALEN); result = (char *) palloc(NAMEDATALEN);
proc = heap_openr(ProcedureRelationName);
if (!RelationIsValid(proc))
{
elog(ERROR, "regprocout: could not open %s",
ProcedureRelationName);
return (0);
}
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) ObjectIdAttributeNumber,
(RegProcedure) F_INT4EQ,
(Datum) proid);
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key); if (!IsBootstrapProcessingMode())
if (!HeapScanIsValid(procscan))
{ {
heap_close(proc); proctup = SearchSysCacheTuple(PROOID,
elog(ERROR, "regprocout: could not being scan of %s", ObjectIdGetDatum(proid),
ProcedureRelationName); 0, 0, 0);
return (0);
if (HeapTupleIsValid(proctup))
{
char *s;
s = ((Form_pg_proc) GETSTRUCT(proctup))->proname.data;
snprintf(result, NAMEDATALEN, "%d(%s)", proid, s);
}
else
{
result[0] = '-';
result[1] = '\0';
}
} }
proctup = heap_getnext(procscan, 0, (Buffer *) NULL); else
switch (HeapTupleIsValid(proctup))
{ {
Relation proc;
HeapScanDesc procscan;
ScanKeyData key;
proc = heap_openr(ProcedureRelationName);
if (!RelationIsValid(proc))
{
elog(ERROR, "regprocout: could not open %s",
ProcedureRelationName);
return (0);
}
ScanKeyEntryInitialize(&key,
(bits16) 0,
(AttrNumber) ObjectIdAttributeNumber,
(RegProcedure) F_INT4EQ,
(Datum) proid);
procscan = heap_beginscan(proc, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(procscan))
{
heap_close(proc);
elog(ERROR, "regprocout: could not being scan of %s",
ProcedureRelationName);
return (0);
}
proctup = heap_getnext(procscan, 0);
if (HeapTupleIsValid(proctup))
{
char *s; char *s;
bool isnull; bool isnull;
case 1:
s = (char *) heap_getattr(proctup, 1, s = (char *) heap_getattr(proctup, 1,
RelationGetTupleDescriptor(proc), &isnull); RelationGetTupleDescriptor(proc), &isnull);
if (!isnull) if (!isnull)
{
StrNCpy(result, s, NAMEDATALEN); StrNCpy(result, s, NAMEDATALEN);
break; else
} elog(FATAL, "regprocout: null procedure %d", proid);
elog(FATAL, "regprocout: null procedure %d", proid); }
/* FALLTHROUGH */ else
case 0: {
result[0] = '-'; result[0] = '-';
result[1] = '\0'; result[1] = '\0';
}
heap_endscan(procscan);
heap_close(proc);
return (result);
}
#ifdef EBUG #ifdef EBUG
elog(DEBUG, "regprocout: no such procedure %d", proid); elog(DEBUG, "regprocout: no such procedure %d", proid);
#endif /* defined(EBUG) */ #endif /* defined(EBUG) */
}
heap_endscan(procscan);
heap_close(proc);
return (result); return (result);
} }
@ -153,11 +200,8 @@ regprocout(RegProcedure proid)
text * text *
oid8types(Oid (*oidArray)[]) oid8types(Oid (*oidArray)[])
{ {
Relation type;
HeapScanDesc typescan;
HeapTuple typetup; HeapTuple typetup;
text *result; text *result;
ScanKeyData key;
int num; int num;
Oid *sp; Oid *sp;
@ -170,55 +214,26 @@ oid8types(Oid (*oidArray)[])
result = (text *) palloc(NAMEDATALEN * 8 + 8 + VARHDRSZ); result = (text *) palloc(NAMEDATALEN * 8 + 8 + VARHDRSZ);
*VARDATA(result) = '\0'; *VARDATA(result) = '\0';
type = heap_openr(TypeRelationName);
if (!RelationIsValid(type))
{
elog(ERROR, "int8typeout: could not open %s",
TypeRelationName);
return (0);
}
sp = *oidArray; sp = *oidArray;
for (num = 8; num != 0; num--, sp++) for (num = 8; num != 0; num--, sp++)
{ {
if (*sp != InvalidOid) if (*sp != InvalidOid)
{ {
ScanKeyEntryInitialize(&key, typetup = SearchSysCacheTuple(TYPOID,
(bits16) 0, ObjectIdGetDatum(*sp),
(AttrNumber) ObjectIdAttributeNumber, 0, 0, 0);
(RegProcedure) F_INT4EQ,
(Datum) *sp);
typescan = heap_beginscan(type, 0, SnapshotNow, 1, &key);
if (!HeapScanIsValid(typescan))
{
heap_close(type);
elog(ERROR, "int8typeout: could not being scan of %s",
TypeRelationName);
return (0);
}
typetup = heap_getnext(typescan, 0, (Buffer *) NULL);
if (HeapTupleIsValid(typetup)) if (HeapTupleIsValid(typetup))
{ {
char *s; char *s;
bool isnull;
s = (char *) heap_getattr(typetup, 1, s = ((TypeTupleForm) GETSTRUCT(typetup))->typname.data;
RelationGetTupleDescriptor(type), &isnull); StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s,
if (!isnull)
{
StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s,
NAMEDATALEN); NAMEDATALEN);
strcat(VARDATA(result), " "); strcat(VARDATA(result), " ");
}
else
elog(FATAL, "int8typeout: null procedure %d", *sp);
/* FALLTHROUGH */
} }
heap_endscan(typescan);
} }
} }
heap_close(type);
VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ; VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ;
return (result); return (result);
} }

View File

@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.20 1998/07/27 19:38:20 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.21 1998/08/19 02:03:05 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -295,7 +295,8 @@ getattdisbursion(Oid relid, AttrNumber attnum)
if (nvals > 0) if (nvals > 0)
return (nvals); return (nvals);
atp = SearchSysCacheTuple(RELOID, ObjectIdGetDatum(relid), atp = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(relid),
0, 0, 0); 0, 0, 0);
/* /*
@ -334,8 +335,8 @@ gethilokey(Oid relid,
char **high, char **high,
char **low) char **low)
{ {
Relation rdesc; Relation rel;
HeapScanDesc sdesc; HeapScanDesc scan;
static ScanKeyData key[3] = { static ScanKeyData key[3] = {
{0, Anum_pg_statistic_starelid, F_OIDEQ, {0, 0, F_OIDEQ}}, {0, Anum_pg_statistic_starelid, F_OIDEQ, {0, 0, F_OIDEQ}},
{0, Anum_pg_statistic_staattnum, F_INT2EQ, {0, 0, F_INT2EQ}}, {0, Anum_pg_statistic_staattnum, F_INT2EQ, {0, 0, F_INT2EQ}},
@ -344,13 +345,13 @@ gethilokey(Oid relid,
bool isnull; bool isnull;
HeapTuple tuple; HeapTuple tuple;
rdesc = heap_openr(StatisticRelationName); rel = heap_openr(StatisticRelationName);
key[0].sk_argument = ObjectIdGetDatum(relid); key[0].sk_argument = ObjectIdGetDatum(relid);
key[1].sk_argument = Int16GetDatum((int16) attnum); key[1].sk_argument = Int16GetDatum((int16) attnum);
key[2].sk_argument = ObjectIdGetDatum(opid); key[2].sk_argument = ObjectIdGetDatum(opid);
sdesc = heap_beginscan(rdesc, 0, SnapshotNow, 3, key); scan = heap_beginscan(rel, 0, SnapshotNow, 3, key);
tuple = heap_getnext(sdesc, 0, (Buffer *) NULL); tuple = heap_getnext(scan, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
*high = "n"; *high = "n";
@ -365,19 +366,19 @@ gethilokey(Oid relid,
*high = textout((struct varlena *) *high = textout((struct varlena *)
heap_getattr(tuple, heap_getattr(tuple,
Anum_pg_statistic_stahikey, Anum_pg_statistic_stahikey,
RelationGetTupleDescriptor(rdesc), RelationGetTupleDescriptor(rel),
&isnull)); &isnull));
if (isnull) if (isnull)
elog(DEBUG, "gethilokey: high key is null"); elog(DEBUG, "gethilokey: high key is null");
*low = textout((struct varlena *) *low = textout((struct varlena *)
heap_getattr(tuple, heap_getattr(tuple,
Anum_pg_statistic_stalokey, Anum_pg_statistic_stalokey,
RelationGetTupleDescriptor(rdesc), RelationGetTupleDescriptor(rel),
&isnull)); &isnull));
if (isnull) if (isnull)
elog(DEBUG, "gethilokey: low key is null"); elog(DEBUG, "gethilokey: low key is null");
heap_endscan(sdesc); heap_endscan(scan);
heap_close(rdesc); heap_close(rel);
} }
float64 float64
@ -497,7 +498,8 @@ hashsel(Oid operatorObjectId,
* have selectivity functions * have selectivity functions
*/ */
atp = SearchSysCacheTuple(RELOID, ObjectIdGetDatum(indexrelid), atp = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(indexrelid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(atp)) if (!HeapTupleIsValid(atp))
{ {
@ -549,7 +551,8 @@ hashnpage(Oid operatorObjectId,
int npage; int npage;
int ntuples; int ntuples;
atp = SearchSysCacheTuple(RELOID, ObjectIdGetDatum(indexrelid), atp = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(indexrelid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(atp)) if (!HeapTupleIsValid(atp))
{ {

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.15 1998/07/27 19:38:21 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.16 1998/08/19 02:03:06 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -56,13 +56,6 @@ SetDefine(char *querystr, char *typename)
Datum replValue[Natts_pg_proc]; Datum replValue[Natts_pg_proc];
char replNull[Natts_pg_proc]; char replNull[Natts_pg_proc];
char repl[Natts_pg_proc]; char repl[Natts_pg_proc];
HeapScanDesc pg_proc_scan;
Buffer buffer;
ItemPointerData ipdata;
static ScanKeyData oidKey[1] = {
{0, ObjectIdAttributeNumber, F_OIDEQ}};
setoid = ProcedureCreate(procname, /* changed below, after oid known */ setoid = ProcedureCreate(procname, /* changed below, after oid known */
true, /* returnsSet */ true, /* returnsSet */
@ -117,37 +110,26 @@ SetDefine(char *querystr, char *typename)
/* change the pg_proc tuple */ /* change the pg_proc tuple */
procrel = heap_openr(ProcedureRelationName); procrel = heap_openr(ProcedureRelationName);
RelationSetLockForWrite(procrel); RelationSetLockForWrite(procrel);
fmgr_info(F_OIDEQ,
&oidKey[0].sk_func); tup = SearchSysCacheTuple(PROOID,
oidKey[0].sk_nargs = oidKey[0].sk_func.fn_nargs; ObjectIdGetDatum(setoid),
oidKey[0].sk_argument = ObjectIdGetDatum(setoid); 0, 0, 0);
pg_proc_scan = heap_beginscan(procrel,
0,
SnapshotSelf,
1,
oidKey);
tup = heap_getnext(pg_proc_scan, 0, &buffer);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ {
newtup = heap_modifytuple(tup, newtup = heap_modifytuple(tup,
buffer,
procrel, procrel,
replValue, replValue,
replNull, replNull,
repl); repl);
/* XXX may not be necessary */
ItemPointerCopy(&tup->t_ctid, &ipdata);
setheapoverride(true); setheapoverride(true);
heap_replace(procrel, &ipdata, newtup); heap_replace(procrel, &tup->t_ctid, newtup);
setheapoverride(false); setheapoverride(false);
setoid = newtup->t_oid; setoid = newtup->t_oid;
} }
else else
elog(ERROR, "setin: could not find new set oid tuple"); elog(ERROR, "setin: could not find new set oid tuple");
heap_endscan(pg_proc_scan);
if (RelationGetRelationTupleForm(procrel)->relhasindex) if (RelationGetRelationTupleForm(procrel)->relhasindex)
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.31 1998/07/27 19:38:22 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.32 1998/08/19 02:03:08 momjian Exp $
* *
* Notes: * Notes:
* XXX This needs to use exception.h to handle recovery when * XXX This needs to use exception.h to handle recovery when
@ -36,11 +36,9 @@
static void CatCacheRemoveCTup(CatCache *cache, Dlelem *e); static void CatCacheRemoveCTup(CatCache *cache, Dlelem *e);
static Index CatalogCacheComputeHashIndex(struct catcache * cacheInP); static Index CatalogCacheComputeHashIndex(struct catcache * cacheInP);
static Index static Index CatalogCacheComputeTupleHashIndex(struct catcache * cacheInOutP,
CatalogCacheComputeTupleHashIndex(struct catcache * cacheInOutP,
Relation relation, HeapTuple tuple); Relation relation, HeapTuple tuple);
static void static void CatalogCacheInitializeCache(struct catcache * cache,
CatalogCacheInitializeCache(struct catcache * cache,
Relation relation); Relation relation);
static long comphash(long l, char *v); static long comphash(long l, char *v);
@ -182,7 +180,7 @@ CatalogCacheInitializeCache(struct catcache * cache,
* ---------------- * ----------------
*/ */
Assert(RelationIsValid(relation)); Assert(RelationIsValid(relation));
cache->relationId = RelationGetRelationId(relation); cache->relationId = RelationGetRelid(relation);
tupdesc = cache->cc_tupdesc = RelationGetTupleDescriptor(relation); tupdesc = cache->cc_tupdesc = RelationGetTupleDescriptor(relation);
CACHE3_elog(DEBUG, "CatalogCacheInitializeCache: relid %d, %d keys", CACHE3_elog(DEBUG, "CatalogCacheInitializeCache: relid %d, %d keys",
@ -250,7 +248,7 @@ CatalogCacheInitializeCache(struct catcache * cache,
*/ */
relation = index_openr(cache->cc_indname); relation = index_openr(cache->cc_indname);
Assert(relation); Assert(relation);
cache->indexId = RelationGetRelationId(relation); cache->indexId = RelationGetRelid(relation);
index_close(relation); index_close(relation);
} }
else else
@ -827,7 +825,6 @@ SearchSysCache(struct catcache * cache,
CatCTup *nct2; CatCTup *nct2;
Dlelem *elt; Dlelem *elt;
HeapTuple ntp = 0; HeapTuple ntp = 0;
Buffer buffer;
Relation relation; Relation relation;
MemoryContext oldcxt; MemoryContext oldcxt;
@ -997,8 +994,7 @@ SearchSysCache(struct catcache * cache,
sd = heap_beginscan(relation, 0, SnapshotNow, sd = heap_beginscan(relation, 0, SnapshotNow,
cache->cc_nkeys, cache->cc_skey); cache->cc_nkeys, cache->cc_skey);
/* should this buffer be ReleaseBuffer'd? --djm 8/20/96 */ ntp = heap_getnext(sd, 0);
ntp = heap_getnext(sd, 0, &buffer);
MemoryContextSwitchTo((MemoryContext) CacheCxt); MemoryContextSwitchTo((MemoryContext) CacheCxt);
@ -1129,7 +1125,7 @@ RelationInvalidateCatalogCacheTuple(Relation relation,
* in the proper hash bucket * in the proper hash bucket
* ---------------- * ----------------
*/ */
relationId = RelationGetRelationId(relation); relationId = RelationGetRelid(relation);
for (ccp = Caches; ccp; ccp = ccp->cc_next) for (ccp = Caches; ccp; ccp = ccp->cc_next)
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.14 1998/07/26 04:30:55 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.15 1998/08/19 02:03:09 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -72,7 +72,8 @@ GetDynamicFuncArgType(Var *arg, ExprContext *econtext)
relname = (char *) getrelname(rtid, econtext->ecxt_range_table); relname = (char *) getrelname(rtid, econtext->ecxt_range_table);
tup = SearchSysCacheTuple(TYPNAME, PointerGetDatum(relname), tup = SearchSysCacheTuple(TYPNAME,
PointerGetDatum(relname),
0, 0, 0); 0, 0, 0);
if (!tup) if (!tup)
elog(ERROR, "Lookup failed on type tuple for class %s", elog(ERROR, "Lookup failed on type tuple for class %s",
@ -129,7 +130,7 @@ init_fcache(Oid foid,
* ---------------- * ----------------
*/ */
typeTuple = SearchSysCacheTuple(TYPOID, typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(procedureStruct->prorettype), ObjectIdGetDatum(procedureStruct->prorettype),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(typeTuple)) if (!HeapTupleIsValid(typeTuple))

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.11 1998/06/15 19:29:39 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.12 1998/08/19 02:03:11 momjian Exp $
* *
* Note - this code is real crufty... * Note - this code is real crufty...
* *
@ -267,7 +267,7 @@ getmyrelids()
MyAMRelationId = tuple->t_oid; MyAMRelationId = tuple->t_oid;
tuple = SearchSysCacheTuple(RELNAME, tuple = SearchSysCacheTuple(RELNAME,
PointerGetDatum(AccessMethodOperatorRelationName), PointerGetDatum(AccessMethodOperatorRelationName),
0, 0, 0); 0, 0, 0);
Assert(HeapTupleIsValid(tuple)); Assert(HeapTupleIsValid(tuple));
MyAMOPRelationId = tuple->t_oid; MyAMOPRelationId = tuple->t_oid;
@ -476,7 +476,7 @@ RelationInvalidateRelationCache(Relation relation,
* ---------------- * ----------------
*/ */
ValidateHacks(); /* XXX */ ValidateHacks(); /* XXX */
relationId = RelationGetRelationId(relation); relationId = RelationGetRelid(relation);
/* ---------------- /* ----------------
* *

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.19 1998/08/16 05:38:41 thomas Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.20 1998/08/19 02:03:12 momjian Exp $
* *
* NOTES * NOTES
* Eventually, the index information should go through here, too. * Eventually, the index information should go through here, too.
@ -47,8 +47,7 @@ op_class(Oid oprno, int32 opclass, Oid amopid)
{ {
FormData_pg_amop amoptup; FormData_pg_amop amoptup;
if (SearchSysCacheStruct(AMOPOPID, if (SearchSysCacheStruct(AMOPOPID, (char *) &amoptup,
(char *) &amoptup,
ObjectIdGetDatum(opclass), ObjectIdGetDatum(opclass),
ObjectIdGetDatum(oprno), ObjectIdGetDatum(oprno),
ObjectIdGetDatum(amopid), ObjectIdGetDatum(amopid),
@ -72,8 +71,7 @@ get_attname(Oid relid, AttrNumber attnum)
{ {
FormData_pg_attribute att_tup; FormData_pg_attribute att_tup;
if (SearchSysCacheStruct(ATTNUM, if (SearchSysCacheStruct(ATTNUM, (char *) &att_tup,
(char *) &att_tup,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
UInt16GetDatum(attnum), UInt16GetDatum(attnum),
0, 0)) 0, 0))
@ -115,8 +113,7 @@ get_atttype(Oid relid, AttrNumber attnum)
{ {
AttributeTupleForm att_tup = (AttributeTupleForm) palloc(sizeof(*att_tup)); AttributeTupleForm att_tup = (AttributeTupleForm) palloc(sizeof(*att_tup));
if (SearchSysCacheStruct(ATTNUM, if (SearchSysCacheStruct(ATTNUM, (char *) att_tup,
(char *) att_tup,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
UInt16GetDatum(attnum), UInt16GetDatum(attnum),
0, 0)) 0, 0))
@ -132,24 +129,24 @@ get_atttype(Oid relid, AttrNumber attnum)
bool bool
get_attisset(Oid relid, char *attname) get_attisset(Oid relid, char *attname)
{ {
HeapTuple htup; HeapTuple tuple;
AttrNumber attno; AttrNumber attno;
AttributeTupleForm att_tup; AttributeTupleForm att_tup;
attno = get_attnum(relid, attname); attno = get_attnum(relid, attname);
htup = SearchSysCacheTuple(ATTNAME, tuple = SearchSysCacheTuple(ATTNAME,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
PointerGetDatum(attname), PointerGetDatum(attname),
0, 0); 0, 0);
if (!HeapTupleIsValid(htup)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "get_attisset: no attribute %s in relation %d", elog(ERROR, "get_attisset: no attribute %s in relation %d",
attname, relid); attname, relid);
if (heap_attisnull(htup, attno)) if (heap_attisnull(tuple, attno))
return false; return false;
else else
{ {
att_tup = (AttributeTupleForm) GETSTRUCT(htup); att_tup = (AttributeTupleForm) GETSTRUCT(tuple);
return att_tup->attisset; return att_tup->attisset;
} }
} }
@ -166,10 +163,9 @@ get_atttypmod(Oid relid, AttrNumber attnum)
{ {
FormData_pg_attribute att_tup; FormData_pg_attribute att_tup;
if (SearchSysCacheStruct(ATTNUM, if (SearchSysCacheStruct(ATTNUM, (char *) &att_tup,
(char *) &att_tup,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
Int32GetDatum(attnum), Int16GetDatum(attnum),
0, 0)) 0, 0))
return att_tup.atttypmod; return att_tup.atttypmod;
else else
@ -400,8 +396,7 @@ get_rel_name(Oid relid)
{ {
FormData_pg_class reltup; FormData_pg_class reltup;
if ((SearchSysCacheStruct(RELOID, if ((SearchSysCacheStruct(RELOID, (char *) &reltup,
(char *) &reltup,
ObjectIdGetDatum(relid), ObjectIdGetDatum(relid),
0, 0, 0))) 0, 0, 0)))
return pstrdup(reltup.relname.data); return pstrdup(reltup.relname.data);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.46 1998/08/11 18:28:22 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.47 1998/08/19 02:03:13 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -337,7 +337,6 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo)
Relation pg_class_desc; Relation pg_class_desc;
HeapScanDesc pg_class_scan; HeapScanDesc pg_class_scan;
ScanKeyData key; ScanKeyData key;
Buffer buf;
/* ---------------- /* ----------------
* form a scan key * form a scan key
@ -371,9 +370,8 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo)
pg_class_desc = heap_openr(RelationRelationName); pg_class_desc = heap_openr(RelationRelationName);
if (!IsInitProcessingMode()) if (!IsInitProcessingMode())
RelationSetLockForRead(pg_class_desc); RelationSetLockForRead(pg_class_desc);
pg_class_scan = pg_class_scan = heap_beginscan(pg_class_desc, 0, SnapshotNow, 1, &key);
heap_beginscan(pg_class_desc, 0, SnapshotNow, 1, &key); pg_class_tuple = heap_getnext(pg_class_scan, 0);
pg_class_tuple = heap_getnext(pg_class_scan, 0, &buf);
/* ---------------- /* ----------------
* get set to return tuple * get set to return tuple
@ -394,7 +392,6 @@ scan_pg_rel_seq(RelationBuildDescInfo buildinfo)
memmove((char *) return_tuple, memmove((char *) return_tuple,
(char *) pg_class_tuple, (char *) pg_class_tuple,
(int) pg_class_tuple->t_len); (int) pg_class_tuple->t_len);
ReleaseBuffer(buf);
} }
/* all done */ /* all done */
@ -534,15 +531,14 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
ScanKeyEntryInitialize(&key, 0, ScanKeyEntryInitialize(&key, 0,
Anum_pg_attribute_attrelid, Anum_pg_attribute_attrelid,
F_OIDEQ, F_OIDEQ,
ObjectIdGetDatum(relation->rd_id)); ObjectIdGetDatum(RelationGetRelid(relation)));
/* ---------------- /* ----------------
* open pg_attribute and begin a scan * open pg_attribute and begin a scan
* ---------------- * ----------------
*/ */
pg_attribute_desc = heap_openr(AttributeRelationName); pg_attribute_desc = heap_openr(AttributeRelationName);
pg_attribute_scan = pg_attribute_scan = heap_beginscan(pg_attribute_desc, 0, SnapshotNow, 1, &key);
heap_beginscan(pg_attribute_desc, 0, SnapshotNow, 1, &key);
/* ---------------- /* ----------------
* add attribute data to relation->rd_att * add attribute data to relation->rd_att
@ -550,7 +546,7 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
*/ */
need = natts; need = natts;
pg_attribute_tuple = heap_getnext(pg_attribute_scan, 0, (Buffer *) NULL); pg_attribute_tuple = heap_getnext(pg_attribute_scan, 0);
while (HeapTupleIsValid(pg_attribute_tuple) && need > 0) while (HeapTupleIsValid(pg_attribute_tuple) && need > 0)
{ {
attp = (AttributeTupleForm) GETSTRUCT(pg_attribute_tuple); attp = (AttributeTupleForm) GETSTRUCT(pg_attribute_tuple);
@ -565,13 +561,12 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
ATTRIBUTE_TUPLE_SIZE); ATTRIBUTE_TUPLE_SIZE);
need--; need--;
} }
pg_attribute_tuple = heap_getnext(pg_attribute_scan, pg_attribute_tuple = heap_getnext(pg_attribute_scan, 0);
0, (Buffer *) NULL);
} }
if (need > 0) if (need > 0)
elog(ERROR, "catalog is missing %d attribute%s for relid %d", elog(ERROR, "catalog is missing %d attribute%s for relid %d",
need, (need == 1 ? "" : "s"), relation->rd_id); need, (need == 1 ? "" : "s"), RelationGetRelid(relation));
/* ---------------- /* ----------------
* end the scan and close the attribute relation * end the scan and close the attribute relation
@ -600,8 +595,8 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
for (i = 1; i <= relation->rd_rel->relnatts; i++) for (i = 1; i <= relation->rd_rel->relnatts; i++)
{ {
atttup = (HeapTuple) AttributeNumIndexScan(attrel,
atttup = (HeapTuple) AttributeNumIndexScan(attrel, relation->rd_id, i); RelationGetRelid(relation), i);
if (!HeapTupleIsValid(atttup)) if (!HeapTupleIsValid(atttup))
elog(ERROR, "cannot find attribute %d of relation %s", i, elog(ERROR, "cannot find attribute %d of relation %s", i,
@ -705,24 +700,21 @@ RelationBuildRuleLock(Relation relation)
ScanKeyEntryInitialize(&key, 0, ScanKeyEntryInitialize(&key, 0,
Anum_pg_rewrite_ev_class, Anum_pg_rewrite_ev_class,
F_OIDEQ, F_OIDEQ,
ObjectIdGetDatum(relation->rd_id)); ObjectIdGetDatum(RelationGetRelid(relation)));
/* ---------------- /* ----------------
* open pg_attribute and begin a scan * open pg_attribute and begin a scan
* ---------------- * ----------------
*/ */
pg_rewrite_desc = heap_openr(RewriteRelationName); pg_rewrite_desc = heap_openr(RewriteRelationName);
pg_rewrite_scan = pg_rewrite_scan = heap_beginscan(pg_rewrite_desc, 0, SnapshotNow, 1, &key);
heap_beginscan(pg_rewrite_desc, 0, SnapshotNow, 1, &key); pg_rewrite_tupdesc = RelationGetTupleDescriptor(pg_rewrite_desc);
pg_rewrite_tupdesc =
RelationGetTupleDescriptor(pg_rewrite_desc);
/* ---------------- /* ----------------
* add attribute data to relation->rd_att * add attribute data to relation->rd_att
* ---------------- * ----------------
*/ */
while ((pg_rewrite_tuple = heap_getnext(pg_rewrite_scan, 0, while (HeapTupleIsValid(pg_rewrite_tuple=heap_getnext(pg_rewrite_scan, 0)))
(Buffer *) NULL)) != NULL)
{ {
bool isnull; bool isnull;
Datum ruleaction; Datum ruleaction;
@ -867,7 +859,7 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo)
* initialize the relation's relation id (relation->rd_id) * initialize the relation's relation id (relation->rd_id)
* ---------------- * ----------------
*/ */
relation->rd_id = relid; RelationGetRelid(relation) = relid;
/* ---------------- /* ----------------
* initialize relation->rd_refcnt * initialize relation->rd_refcnt
@ -1093,7 +1085,7 @@ formrdesc(char *relationName,
* initialize relation id * initialize relation id
* ---------------- * ----------------
*/ */
relation->rd_id = relation->rd_att->attrs[0]->attrelid; RelationGetRelid(relation) = relation->rd_att->attrs[0]->attrelid;
/* ---------------- /* ----------------
* add new reldesc to relcache * add new reldesc to relcache
@ -1109,7 +1101,7 @@ formrdesc(char *relationName,
* the check (and possible set) after cache insertion. * the check (and possible set) after cache insertion.
*/ */
relation->rd_rel->relhasindex = relation->rd_rel->relhasindex =
CatalogHasIndex(relationName, relation->rd_id); CatalogHasIndex(relationName, RelationGetRelid(relation));
} }
@ -1328,7 +1320,7 @@ RelationFlushRelation(Relation *relationPtr,
RelationCacheDelete(relation); RelationCacheDelete(relation);
FreeTupleDesc(relation->rd_att); FreeTupleDesc(relation->rd_att);
SystemCacheRelationFlushed(relation->rd_id); SystemCacheRelationFlushed(RelationGetRelid(relation));
FreeTriggerDesc(relation); FreeTriggerDesc(relation);
@ -1379,7 +1371,7 @@ RelationForgetRelation(Oid rid)
Relation reln = lfirst(curr); Relation reln = lfirst(curr);
Assert(reln != NULL && reln->rd_islocal); Assert(reln != NULL && reln->rd_islocal);
if (reln->rd_id == rid) if (RelationGetRelid(reln) == rid)
break; break;
prev = curr; prev = curr;
} }
@ -1678,7 +1670,6 @@ AttrDefaultFetch(Relation relation)
Form_pg_attrdef adform; Form_pg_attrdef adform;
IndexScanDesc sd; IndexScanDesc sd;
RetrieveIndexResult indexRes; RetrieveIndexResult indexRes;
Buffer buffer;
ItemPointer iptr; ItemPointer iptr;
struct varlena *val; struct varlena *val;
bool isnull; bool isnull;
@ -1689,7 +1680,7 @@ AttrDefaultFetch(Relation relation)
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDEQ, (RegProcedure) F_OIDEQ,
ObjectIdGetDatum(relation->rd_id)); ObjectIdGetDatum(RelationGetRelid(relation)));
adrel = heap_openr(AttrDefaultRelationName); adrel = heap_openr(AttrDefaultRelationName);
irel = index_openr(AttrDefaultIndex); irel = index_openr(AttrDefaultIndex);
@ -1698,6 +1689,8 @@ AttrDefaultFetch(Relation relation)
for (found = 0;;) for (found = 0;;)
{ {
Buffer buffer;
indexRes = index_getnext(sd, ForwardScanDirection); indexRes = index_getnext(sd, ForwardScanDirection);
if (!indexRes) if (!indexRes)
break; break;
@ -1736,12 +1729,12 @@ AttrDefaultFetch(Relation relation)
attrdef[i].adsrc = textout(val); attrdef[i].adsrc = textout(val);
break; break;
} }
ReleaseBuffer(buffer);
if (i >= ndef) if (i >= ndef)
elog(ERROR, "AttrDefaultFetch: unexpected record found for attr %d in rel %s", elog(ERROR, "AttrDefaultFetch: unexpected record found for attr %d in rel %s",
adform->adnum, adform->adnum,
relation->rd_rel->relname.data); relation->rd_rel->relname.data);
ReleaseBuffer(buffer);
} }
if (found < ndef) if (found < ndef)
@ -1752,7 +1745,6 @@ AttrDefaultFetch(Relation relation)
pfree(sd); pfree(sd);
index_close(irel); index_close(irel);
heap_close(adrel); heap_close(adrel);
} }
static void static void
@ -1766,7 +1758,6 @@ RelCheckFetch(Relation relation)
HeapTuple tuple; HeapTuple tuple;
IndexScanDesc sd; IndexScanDesc sd;
RetrieveIndexResult indexRes; RetrieveIndexResult indexRes;
Buffer buffer;
ItemPointer iptr; ItemPointer iptr;
Name rcname; Name rcname;
struct varlena *val; struct varlena *val;
@ -1777,7 +1768,7 @@ RelCheckFetch(Relation relation)
(bits16) 0x0, (bits16) 0x0,
(AttrNumber) 1, (AttrNumber) 1,
(RegProcedure) F_OIDEQ, (RegProcedure) F_OIDEQ,
ObjectIdGetDatum(relation->rd_id)); ObjectIdGetDatum(RelationGetRelid(relation)));
rcrel = heap_openr(RelCheckRelationName); rcrel = heap_openr(RelCheckRelationName);
irel = index_openr(RelCheckIndex); irel = index_openr(RelCheckIndex);
@ -1786,6 +1777,8 @@ RelCheckFetch(Relation relation)
for (found = 0;;) for (found = 0;;)
{ {
Buffer buffer;
indexRes = index_getnext(sd, ForwardScanDirection); indexRes = index_getnext(sd, ForwardScanDirection);
if (!indexRes) if (!indexRes)
break; break;
@ -1821,7 +1814,6 @@ RelCheckFetch(Relation relation)
relation->rd_rel->relname.data); relation->rd_rel->relname.data);
check[found].ccsrc = textout(val); check[found].ccsrc = textout(val);
found++; found++;
ReleaseBuffer(buffer); ReleaseBuffer(buffer);
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.19 1998/07/20 16:57:05 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.20 1998/08/19 02:03:15 momjian Exp $
* *
* NOTES * NOTES
* These routines allow the parser/planner/executor to perform * These routines allow the parser/planner/executor to perform
@ -67,262 +67,320 @@ typedef HeapTuple (*ScanFunc) ();
static struct cachedesc cacheinfo[] = { static struct cachedesc cacheinfo[] = {
{AccessMethodOperatorRelationName, /* AMOPOPID */ {AccessMethodOperatorRelationName, /* AMOPOPID */
3, 3,
{Anum_pg_amop_amopclaid, {
Anum_pg_amop_amopclaid,
Anum_pg_amop_amopopr, Anum_pg_amop_amopopr,
Anum_pg_amop_amopid, Anum_pg_amop_amopid,
0}, 0
},
sizeof(FormData_pg_amop), sizeof(FormData_pg_amop),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{AccessMethodOperatorRelationName, /* AMOPSTRATEGY */ {AccessMethodOperatorRelationName, /* AMOPSTRATEGY */
3, 3,
{Anum_pg_amop_amopid, {
Anum_pg_amop_amopid,
Anum_pg_amop_amopclaid, Anum_pg_amop_amopclaid,
Anum_pg_amop_amopstrategy, Anum_pg_amop_amopstrategy,
0}, 0
},
sizeof(FormData_pg_amop), sizeof(FormData_pg_amop),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{AttributeRelationName, /* ATTNAME */ {AttributeRelationName, /* ATTNAME */
2, 2,
{Anum_pg_attribute_attrelid, {
Anum_pg_attribute_attrelid,
Anum_pg_attribute_attname, Anum_pg_attribute_attname,
0, 0,
0}, 0
},
ATTRIBUTE_TUPLE_SIZE, ATTRIBUTE_TUPLE_SIZE,
AttributeNameIndex, AttributeNameIndex,
(ScanFunc) AttributeNameIndexScan}, (ScanFunc) AttributeNameIndexScan},
{AttributeRelationName, /* ATTNUM */ {AttributeRelationName, /* ATTNUM */
2, 2,
{Anum_pg_attribute_attrelid, {
Anum_pg_attribute_attrelid,
Anum_pg_attribute_attnum, Anum_pg_attribute_attnum,
0, 0,
0}, 0
},
ATTRIBUTE_TUPLE_SIZE, ATTRIBUTE_TUPLE_SIZE,
AttributeNumIndex, AttributeNumIndex,
(ScanFunc) AttributeNumIndexScan}, (ScanFunc) AttributeNumIndexScan},
{IndexRelationName, /* INDEXRELID */ {IndexRelationName, /* INDEXRELID */
1, 1,
{Anum_pg_index_indexrelid, {
Anum_pg_index_indexrelid,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_index, indpred), offsetof(FormData_pg_index, indpred),
NULL, NULL,
NULL}, NULL},
{LanguageRelationName, /* LANNAME */ {LanguageRelationName, /* LANNAME */
1, 1,
{Anum_pg_language_lanname, {
Anum_pg_language_lanname,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_language, lancompiler), offsetof(FormData_pg_language, lancompiler),
NULL, NULL,
NULL}, NULL},
{OperatorRelationName, /* OPRNAME */ {OperatorRelationName, /* OPRNAME */
4, 4,
{Anum_pg_operator_oprname, {
Anum_pg_operator_oprname,
Anum_pg_operator_oprleft, Anum_pg_operator_oprleft,
Anum_pg_operator_oprright, Anum_pg_operator_oprright,
Anum_pg_operator_oprkind}, Anum_pg_operator_oprkind
},
sizeof(FormData_pg_operator), sizeof(FormData_pg_operator),
NULL, NULL,
NULL}, NULL},
{OperatorRelationName, /* OPROID */ {OperatorRelationName, /* OPROID */
1, 1,
{ObjectIdAttributeNumber, {
ObjectIdAttributeNumber,
0, 0,
0, 0,
0}, 0
},
sizeof(FormData_pg_operator), sizeof(FormData_pg_operator),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{ProcedureRelationName, /* PRONAME */ {ProcedureRelationName, /* PRONAME */
3, 3,
{Anum_pg_proc_proname, {
Anum_pg_proc_proname,
Anum_pg_proc_pronargs, Anum_pg_proc_pronargs,
Anum_pg_proc_proargtypes, Anum_pg_proc_proargtypes,
0}, 0
},
offsetof(FormData_pg_proc, prosrc), offsetof(FormData_pg_proc, prosrc),
ProcedureNameIndex, ProcedureNameIndex,
(ScanFunc) ProcedureNameIndexScan}, (ScanFunc) ProcedureNameIndexScan},
{ProcedureRelationName, /* PROOID */ {ProcedureRelationName, /* PROOID */
1, 1,
{ObjectIdAttributeNumber, {
ObjectIdAttributeNumber,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_proc, prosrc), offsetof(FormData_pg_proc, prosrc),
ProcedureOidIndex, ProcedureOidIndex,
(ScanFunc) ProcedureOidIndexScan}, (ScanFunc) ProcedureOidIndexScan},
{RelationRelationName, /* RELNAME */ {RelationRelationName, /* RELNAME */
1, 1,
{Anum_pg_class_relname, {
Anum_pg_class_relname,
0, 0,
0, 0,
0}, 0
},
CLASS_TUPLE_SIZE, CLASS_TUPLE_SIZE,
ClassNameIndex, ClassNameIndex,
(ScanFunc) ClassNameIndexScan}, (ScanFunc) ClassNameIndexScan},
{RelationRelationName, /* RELOID */ {RelationRelationName, /* RELOID */
1, 1,
{ObjectIdAttributeNumber, {
ObjectIdAttributeNumber,
0, 0,
0, 0,
0}, 0
},
CLASS_TUPLE_SIZE, CLASS_TUPLE_SIZE,
ClassOidIndex, ClassOidIndex,
(ScanFunc) ClassOidIndexScan}, (ScanFunc) ClassOidIndexScan},
{TypeRelationName, /* TYPNAME */ {TypeRelationName, /* TYPNAME */
1, 1,
{Anum_pg_type_typname, {
Anum_pg_type_typname,
0, 0,
0, 0,
0}, 0
},
offsetof(TypeTupleFormData, typalign) +sizeof(char), offsetof(TypeTupleFormData, typalign) +sizeof(char),
TypeNameIndex, TypeNameIndex,
TypeNameIndexScan}, TypeNameIndexScan},
{TypeRelationName, /* TYPOID */ {TypeRelationName, /* TYPOID */
1, 1,
{ObjectIdAttributeNumber, {
ObjectIdAttributeNumber,
0, 0,
0, 0,
0}, 0
},
offsetof(TypeTupleFormData, typalign) +sizeof(char), offsetof(TypeTupleFormData, typalign) +sizeof(char),
TypeOidIndex, TypeOidIndex,
TypeOidIndexScan}, TypeOidIndexScan},
{AccessMethodRelationName, /* AMNAME */ {AccessMethodRelationName, /* AMNAME */
1, 1,
{Anum_pg_am_amname, {
Anum_pg_am_amname,
0, 0,
0, 0,
0}, 0
},
sizeof(FormData_pg_am), sizeof(FormData_pg_am),
NULL, NULL,
NULL}, NULL},
{OperatorClassRelationName, /* CLANAME */ {OperatorClassRelationName, /* CLANAME */
1, 1,
{Anum_pg_opclass_opcname, {
Anum_pg_opclass_opcname,
0, 0,
0, 0,
0}, 0
},
sizeof(FormData_pg_opclass), sizeof(FormData_pg_opclass),
NULL, NULL,
NULL}, NULL},
{IndexRelationName, /* INDRELIDKEY */ {IndexRelationName, /* INDRELIDKEY */ /* never used */
2, 2,
{Anum_pg_index_indrelid, {
Anum_pg_index_indrelid,
Anum_pg_index_indkey, Anum_pg_index_indkey,
0, 0,
0}, 0
},
offsetof(FormData_pg_index, indpred), offsetof(FormData_pg_index, indpred),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{InheritsRelationName, /* INHRELID */ {InheritsRelationName, /* INHRELID */
2, 2,
{Anum_pg_inherits_inhrel, {
Anum_pg_inherits_inhrel,
Anum_pg_inherits_inhseqno, Anum_pg_inherits_inhseqno,
0, 0,
0}, 0
},
sizeof(FormData_pg_inherits), sizeof(FormData_pg_inherits),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{RewriteRelationName, /* RULOID */ {RewriteRelationName, /* RULOID */
1, 1,
{ObjectIdAttributeNumber, {
ObjectIdAttributeNumber,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_rewrite, ev_qual), offsetof(FormData_pg_rewrite, ev_qual),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{AggregateRelationName, /* AGGNAME */ {AggregateRelationName, /* AGGNAME */
2, 2,
{Anum_pg_aggregate_aggname, {
Anum_pg_aggregate_aggname,
Anum_pg_aggregate_aggbasetype, Anum_pg_aggregate_aggbasetype,
0, 0,
0}, 0
},
offsetof(FormData_pg_aggregate, agginitval1), offsetof(FormData_pg_aggregate, agginitval1),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{ListenerRelationName, /* LISTENREL */ {ListenerRelationName, /* LISTENREL */
2, 2,
{Anum_pg_listener_relname, {
Anum_pg_listener_relname,
Anum_pg_listener_pid, Anum_pg_listener_pid,
0, 0,
0}, 0
},
sizeof(FormData_pg_listener), sizeof(FormData_pg_listener),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{ShadowRelationName, /* USENAME */ {ShadowRelationName, /* USENAME */
1, 1,
{Anum_pg_shadow_usename, {
Anum_pg_shadow_usename,
0, 0,
0, 0,
0}, 0
},
sizeof(FormData_pg_shadow), sizeof(FormData_pg_shadow),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{ShadowRelationName, /* USESYSID */ {ShadowRelationName, /* USESYSID */
1, 1,
{Anum_pg_shadow_usesysid, {
Anum_pg_shadow_usesysid,
0, 0,
0, 0,
0}, 0
},
sizeof(FormData_pg_shadow), sizeof(FormData_pg_shadow),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{GroupRelationName, /* GRONAME */ {GroupRelationName, /* GRONAME */
1, 1,
{Anum_pg_group_groname, {
Anum_pg_group_groname,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_group, grolist[0]), offsetof(FormData_pg_group, grolist[0]),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{GroupRelationName, /* GROSYSID */ {GroupRelationName, /* GROSYSID */
1, 1,
{Anum_pg_group_grosysid, {
Anum_pg_group_grosysid,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_group, grolist[0]), offsetof(FormData_pg_group, grolist[0]),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{RewriteRelationName, /* REWRITENAME */ {RewriteRelationName, /* REWRITENAME */
1, 1,
{Anum_pg_rewrite_rulename, {
Anum_pg_rewrite_rulename,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_rewrite, ev_qual), offsetof(FormData_pg_rewrite, ev_qual),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{ProcedureRelationName, /* PROSRC */ {ProcedureRelationName, /* PROSRC */
1, 1,
{Anum_pg_proc_prosrc, {
Anum_pg_proc_prosrc,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_proc, prosrc), offsetof(FormData_pg_proc, prosrc),
ProcedureSrcIndex, ProcedureSrcIndex,
(ScanFunc) ProcedureSrcIndexScan}, (ScanFunc) ProcedureSrcIndexScan},
{OperatorClassRelationName, /* CLADEFTYPE */ {OperatorClassRelationName, /* CLADEFTYPE */
1, 1,
{Anum_pg_opclass_opcdeftype, {
Anum_pg_opclass_opcdeftype,
0, 0,
0, 0,
0}, 0
},
sizeof(FormData_pg_opclass), sizeof(FormData_pg_opclass),
NULL, NULL,
(ScanFunc) NULL}, (ScanFunc) NULL},
{LanguageRelationName, /* LANOID */ {LanguageRelationName, /* LANOID */
1, 1,
{ObjectIdAttributeNumber, {
ObjectIdAttributeNumber,
0, 0,
0, 0,
0}, 0
},
offsetof(FormData_pg_language, lancompiler), offsetof(FormData_pg_language, lancompiler),
NULL, NULL,
NULL} NULL}
@ -380,16 +438,39 @@ InitCatalogCache()
} }
} }
} }
/*
* SearchSysCacheTupleCopy--
*
* THis is like SearchSysCacheTuple, except it returns a copy of the tuple
* that the user is required to pfree().
*/
HeapTuple
SearchSysCacheTupleCopy(int cacheId,/* cache selection code */
Datum key1,
Datum key2,
Datum key3,
Datum key4)
{
HeapTuple cachetup;
cachetup = SearchSysCacheTuple(cacheId, key1, key2, key3, key4);
if (PointerIsValid(cachetup))
return heap_copytuple(cachetup);
else
return cachetup; /* NULL */
}
/* /*
* SearchSysCacheTuple-- * SearchSysCacheTuple--
* *
* A layer on top of SearchSysCache that does the initialization and * A layer on top of SearchSysCache that does the initialization and
* key-setting for you. * key-setting for you.
* *
* Returns the tuple if one is found, NULL if not. * Returns the cache copy of the tuple if one is found, NULL if not.
* The tuple is the 'cache' copy.
* *
* XXX The tuple that is returned is NOT supposed to be pfree'd! * XXX The tuple that is returned is NOT supposed to be pfree'd!
*/ */
HeapTuple HeapTuple
SearchSysCacheTuple(int cacheId,/* cache selection code */ SearchSysCacheTuple(int cacheId,/* cache selection code */
@ -542,7 +623,6 @@ SearchSysCacheGetAttribute(int cacheId,
if (isNull) if (isNull)
{ {
/* /*
* Used to be an elog(DEBUG, ...) here and a claim that it should * Used to be an elog(DEBUG, ...) here and a claim that it should
* be a FATAL error, I don't think either is warranted -mer 6/9/92 * be a FATAL error, I don't think either is warranted -mer 6/9/92
@ -622,7 +702,6 @@ TypeDefaultRetrieve(Oid typId)
cacheinfo[TYPOID].name, TYPOID); cacheinfo[TYPOID].name, TYPOID);
#endif /* defined(CACHEDEBUG) */ #endif /* defined(CACHEDEBUG) */
return (NULL); return (NULL);
} }
dataSize = VARSIZE(typDefault) - VARHDRSZ; dataSize = VARSIZE(typDefault) - VARHDRSZ;

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.18 1998/06/15 19:29:42 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.19 1998/08/19 02:03:16 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -58,7 +58,7 @@ fmgr_dynamic(Oid procedureId, int *pronargs)
*probinstring; *probinstring;
Datum probinattr; Datum probinattr;
func_ptr user_fn; func_ptr user_fn;
Relation rdesc; Relation rel;
bool isnull; bool isnull;
if (procedureId == procedureId_save) if (procedureId == procedureId_save)
@ -71,7 +71,8 @@ fmgr_dynamic(Oid procedureId, int *pronargs)
* The procedure isn't a builtin, so we'll have to do a catalog lookup * The procedure isn't a builtin, so we'll have to do a catalog lookup
* to find its pg_proc entry. * to find its pg_proc entry.
*/ */
procedureTuple = SearchSysCacheTuple(PROOID, ObjectIdGetDatum(procedureId), procedureTuple = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(procedureId),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(procedureTuple)) if (!HeapTupleIsValid(procedureTuple))
{ {
@ -87,13 +88,13 @@ fmgr_dynamic(Oid procedureId, int *pronargs)
/* /*
* Extract the procedure info from the pg_proc tuple. Since probin is * Extract the procedure info from the pg_proc tuple. Since probin is
* varlena, do a amgetattr() on the procedure tuple. To do that, we * varlena, do a amgetattr() on the procedure tuple. To do that, we
* need the rdesc for the procedure relation, so... * need the rel for the procedure relation, so...
*/ */
/* open pg_procedure */ /* open pg_procedure */
rdesc = heap_openr(ProcedureRelationName); rel = heap_openr(ProcedureRelationName);
if (!RelationIsValid(rdesc)) if (!RelationIsValid(rel))
{ {
elog(ERROR, "fmgr: Could not open relation %s", elog(ERROR, "fmgr: Could not open relation %s",
ProcedureRelationName); ProcedureRelationName);
@ -101,10 +102,10 @@ fmgr_dynamic(Oid procedureId, int *pronargs)
} }
probinattr = heap_getattr(procedureTuple, probinattr = heap_getattr(procedureTuple,
Anum_pg_proc_probin, Anum_pg_proc_probin,
RelationGetTupleDescriptor(rdesc), &isnull); RelationGetTupleDescriptor(rel), &isnull);
if (!PointerIsValid(probinattr) /* || isnull */ ) if (!PointerIsValid(probinattr) /* || isnull */ )
{ {
heap_close(rdesc); heap_close(rel);
elog(ERROR, "fmgr: Could not extract probin for %d from %s", elog(ERROR, "fmgr: Could not extract probin for %d from %s",
procedureId, ProcedureRelationName); procedureId, ProcedureRelationName);
return ((func_ptr) NULL); return ((func_ptr) NULL);

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.17 1998/06/15 19:29:44 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.18 1998/08/19 02:03:18 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -172,7 +172,7 @@ fmgr_info(Oid procedureId, FmgrInfo *finfo)
if (!(fcp = fmgr_isbuiltin(procedureId))) if (!(fcp = fmgr_isbuiltin(procedureId)))
{ {
procedureTuple = SearchSysCacheTuple(PROOID, procedureTuple = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(procedureId), ObjectIdGetDatum(procedureId),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(procedureTuple)) if (!HeapTupleIsValid(procedureTuple))
{ {

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.19 1998/08/11 18:28:25 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.20 1998/08/19 02:03:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -468,8 +468,9 @@ SetUserId()
} }
userName = GetPgUserName(); userName = GetPgUserName();
userTup = SearchSysCacheTuple(USENAME, PointerGetDatum(userName), userTup = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(userName),
0, 0, 0);
if (!HeapTupleIsValid(userTup)) if (!HeapTupleIsValid(userTup))
elog(FATAL, "SetUserId: user \"%s\" is not in \"%s\"", elog(FATAL, "SetUserId: user \"%s\" is not in \"%s\"",
userName, userName,

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.15 1998/08/11 18:28:30 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.16 1998/08/19 02:03:24 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -45,7 +45,6 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
Relation dbrel; Relation dbrel;
HeapTuple dbtup; HeapTuple dbtup;
HeapTuple tup; HeapTuple tup;
Buffer buf;
HeapScanDesc scan; HeapScanDesc scan;
ScanKeyData scanKey; ScanKeyData scanKey;
@ -64,13 +63,10 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
/* /*
* Since we're going to close the relation, copy the tuple. * Since we're going to close the relation, copy the tuple.
*/ */
tup = heap_getnext(scan, 0, &buf); tup = heap_getnext(scan, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{
dbtup = heap_copytuple(tup); dbtup = heap_copytuple(tup);
ReleaseBuffer(buf);
}
else else
dbtup = tup; dbtup = tup;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.5 1998/02/25 13:08:23 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.6 1998/08/19 02:03:25 momjian Exp $
* *
* DESCRIPTION * DESCRIPTION
* See superuser(). * See superuser().
@ -30,8 +30,9 @@ superuser(void)
HeapTuple utup; HeapTuple utup;
utup = SearchSysCacheTuple(USENAME, PointerGetDatum(UserName), utup = SearchSysCacheTuple(USENAME,
0, 0, 0); PointerGetDatum(UserName),
0, 0, 0);
Assert(utup != NULL); Assert(utup != NULL);
return ((Form_pg_shadow) GETSTRUCT(utup))->usesuper; return ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
} }

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.16 1998/06/15 19:29:58 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.17 1998/08/19 02:03:28 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,7 +40,7 @@ setheapoverride(bool on)
if (on) if (on)
{ {
TransactionIdStore(GetCurrentTransactionId(), TransactionIdStore(GetCurrentTransactionId(),
&HeapSpecialTransactionId); &HeapSpecialTransactionId);
HeapSpecialCommandId = GetCurrentCommandId(); HeapSpecialCommandId = GetCurrentCommandId();
} }
else else

View File

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: genam.h,v 1.13 1998/02/26 12:14:54 vadim Exp $ * $Id: genam.h,v 1.14 1998/08/19 02:03:35 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -47,7 +47,7 @@ index_getprocid(Relation irel, AttrNumber attnum,
extern Datum extern Datum
GetIndexValue(HeapTuple tuple, TupleDesc hTupDesc, GetIndexValue(HeapTuple tuple, TupleDesc hTupDesc,
int attOff, AttrNumber attrNums[], FuncIndexInfo *fInfo, int attOff, AttrNumber attrNums[], FuncIndexInfo *fInfo,
bool *attNull, Buffer buffer); bool *attNull);
/* in genam.c */ /* in genam.c */
extern IndexScanDesc extern IndexScanDesc

View File

@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: hash.h,v 1.16 1998/04/26 04:08:41 momjian Exp $ * $Id: hash.h,v 1.17 1998/08/19 02:03:37 momjian Exp $
* *
* NOTES * NOTES
* modeled after Margo Seltzer's hash implementation for unix. * modeled after Margo Seltzer's hash implementation for unix.
@ -271,6 +271,7 @@ extern uint32 hashint4(uint32 key);
extern uint32 hashfloat4(float32 keyp); extern uint32 hashfloat4(float32 keyp);
extern uint32 hashfloat8(float64 keyp); extern uint32 hashfloat8(float64 keyp);
extern uint32 hashoid(Oid key); extern uint32 hashoid(Oid key);
extern uint32 hashoid8(Oid key[]);
extern uint32 hashchar(char key); extern uint32 hashchar(char key);
extern uint32 hashtext(struct varlena * key); extern uint32 hashtext(struct varlena * key);
extern uint32 hashname(NameData *n); extern uint32 hashname(NameData *n);

Some files were not shown because too many files have changed in this diff Show More