aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/common/heaptuple.c46
-rw-r--r--src/backend/access/common/printtup.c8
-rw-r--r--src/backend/access/common/tupdesc.c5
-rw-r--r--src/backend/access/gist/gist.c27
-rw-r--r--src/backend/access/gist/gistscan.c4
-rw-r--r--src/backend/access/hash/hash.c20
-rw-r--r--src/backend/access/hash/hashfunc.c14
-rw-r--r--src/backend/access/hash/hashscan.c4
-rw-r--r--src/backend/access/heap/heapam.c476
-rw-r--r--src/backend/access/index/genam.c12
-rw-r--r--src/backend/access/index/indexam.c8
-rw-r--r--src/backend/access/index/istrat.c99
-rw-r--r--src/backend/access/nbtree/nbtcompare.c59
-rw-r--r--src/backend/access/nbtree/nbtinsert.c8
-rw-r--r--src/backend/access/nbtree/nbtree.c22
-rw-r--r--src/backend/access/nbtree/nbtscan.c6
-rw-r--r--src/backend/access/nbtree/nbtutils.c5
-rw-r--r--src/backend/access/rtree/rtree.c18
-rw-r--r--src/backend/access/rtree/rtscan.c6
19 files changed, 429 insertions, 418 deletions
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index ec5b756e748..cade50db3ca 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -8,7 +8,7 @@
*
*
* 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
* The old interface functions have been converted to macros
@@ -736,13 +736,6 @@ heap_copytuple(HeapTuple tuple)
if (!HeapTupleIsValid(tuple))
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);
memmove((char *) newTuple, (char *) tuple, (int) tuple->t_len);
return (newTuple);
@@ -863,11 +856,11 @@ heap_formtuple(TupleDesc tupleDescriptor,
* heap_modifytuple
*
* forms a new tuple from an old tuple and a set of replacement values.
+ * returns a new palloc'ed tuple.
* ----------------
*/
HeapTuple
heap_modifytuple(HeapTuple tuple,
- Buffer buffer,
Relation relation,
Datum replValue[],
char replNull[],
@@ -879,7 +872,6 @@ heap_modifytuple(HeapTuple tuple,
char *nulls;
bool isNull;
HeapTuple newTuple;
- int madecopy;
uint8 infomask;
/* ----------------
@@ -887,26 +879,11 @@ heap_modifytuple(HeapTuple tuple,
* ----------------
*/
Assert(HeapTupleIsValid(tuple));
- Assert(BufferIsValid(buffer) || RelationIsValid(relation));
- Assert(HeapTupleIsValid(tuple));
+ Assert(RelationIsValid(relation));
Assert(PointerIsValid(replValue));
Assert(PointerIsValid(replNull));
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;
/* ----------------
@@ -933,10 +910,7 @@ heap_modifytuple(HeapTuple tuple,
}
else if (repl[attoff] != 'r')
- {
elog(ERROR, "heap_modifytuple: repl is \\%3d", repl[attoff]);
-
- }
else
{ /* == 'r' */
value[attoff] = replValue[attoff];
@@ -961,18 +935,8 @@ heap_modifytuple(HeapTuple tuple,
(char *) &tuple->t_oid,
((char *) &tuple->t_hoff - (char *) &tuple->t_oid)); /* XXX */
newTuple->t_infomask = infomask;
- newTuple->t_natts = numberOfAttributes; /* fix t_natts just in
- * case */
-
- /* ----------------
- * if we made a copy of the tuple, then free it.
- * ----------------
- */
- if (madecopy)
- pfree(tuple);
-
- return
- newTuple;
+ newTuple->t_natts = numberOfAttributes; /* fix t_natts just in case */
+ return newTuple;
}
/* ----------------------------------------------------------------
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c
index c07a2f9c978..936725a2ce5 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -8,7 +8,7 @@
*
*
* 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);
if (HeapTupleIsValid(typeTuple))
- return ((Oid)
- ((TypeTupleForm) GETSTRUCT(typeTuple))->typoutput);
+ return ((Oid) ((TypeTupleForm) GETSTRUCT(typeTuple))->typoutput);
elog(ERROR, "typtoout: Cache lookup of type %d failed", type);
return (InvalidOid);
@@ -63,8 +62,7 @@ gettypelem(Oid type)
0, 0, 0);
if (HeapTupleIsValid(typeTuple))
- return ((Oid)
- ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
+ return ((Oid) ((TypeTupleForm) GETSTRUCT(typeTuple))->typelem);
elog(ERROR, "typtoout: Cache lookup of type %d failed", type);
return (InvalidOid);
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index f096c1b8870..569fac67101 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -7,7 +7,7 @@
*
*
* 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
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -327,7 +327,8 @@ TupleDescInitEntry(TupleDesc desc,
* -cim 6/14/90
* ----------------
*/
- tuple = SearchSysCacheTuple(TYPOID, ObjectIdGetDatum(typeid),
+ tuple = SearchSysCacheTuple(TYPOID,
+ ObjectIdGetDatum(typeid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
{
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 1445ff7f2eb..e61c3ce5dd2 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -87,7 +87,6 @@ gistbuild(Relation heap,
PredInfo *predInfo)
{
HeapScanDesc scan;
- Buffer buffer;
AttrNumber i;
HeapTuple htup;
IndexTuple itup;
@@ -112,14 +111,15 @@ gistbuild(Relation heap,
*oldPred;
GISTSTATE giststate;
GISTENTRY tmpcentry;
+ Buffer buffer = InvalidBuffer;
bool *compvec;
/* GiSTs only know how to do stupid locking now */
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);
- setheapoverride(FALSE);
+ setheapoverride(false);
pred = predInfo->pred;
oldPred = predInfo->oldPred;
@@ -170,15 +170,13 @@ gistbuild(Relation heap,
econtext = NULL;
}
#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 */
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++;
/*
@@ -240,8 +238,7 @@ gistbuild(Relation heap,
attoff,
attnum,
finfo,
- &attnull,
- buffer);
+ &attnull);
nulls[attoff] = (attnull ? 'n' : ' ');
}
@@ -302,8 +299,8 @@ gistbuild(Relation heap,
* flushed. We close them to guarantee that they will be.
*/
- hrelid = heap->rd_id;
- irelid = index->rd_id;
+ hrelid = RelationGetRelid(heap);
+ irelid = RelationGetRelid(index);
heap_close(heap);
index_close(index);
@@ -1165,11 +1162,13 @@ initGISTstate(GISTSTATE *giststate, Relation index)
fmgr_info(equal_proc, &giststate->equalFn);
/* 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);
itupform = (IndexTupleForm) GETSTRUCT(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;
if (giststate->haskeytype)
{
diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c
index 7b9d49726ba..ee016c1a934 100644
--- a/src/backend/access/gist/gistscan.c
+++ b/src/backend/access/gist/gistscan.c
@@ -284,12 +284,12 @@ gistdropscan(IndexScanDesc s)
}
void
-gistadjscans(Relation r, int op, BlockNumber blkno, OffsetNumber offnum)
+gistadjscans(Relation rel, int op, BlockNumber blkno, OffsetNumber offnum)
{
GISTScanList l;
Oid relid;
- relid = r->rd_id;
+ relid = RelationGetRelid(rel);
for (l = GISTScans; l != (GISTScanList) NULL; l = l->gsl_next)
{
if (l->gsl_scan->relation->rd_id == relid)
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 6e913e7da49..4bcc7eab524 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -7,7 +7,7 @@
*
*
* 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
* This file contains only the public interface routines.
@@ -53,7 +53,6 @@ hashbuild(Relation heap,
PredInfo *predInfo)
{
HeapScanDesc hscan;
- Buffer buffer;
HeapTuple htup;
IndexTuple itup;
TupleDesc htupdesc,
@@ -65,6 +64,7 @@ hashbuild(Relation heap,
nitups;
int i;
HashItem hitem;
+ Buffer buffer = InvalidBuffer;
#ifndef OMIT_PARTIAL_INDEX
ExprContext *econtext;
@@ -120,14 +120,13 @@ hashbuild(Relation heap,
}
#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 */
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++;
@@ -193,8 +192,7 @@ hashbuild(Relation heap,
attoff,
attnum,
finfo,
- &attnull,
- buffer);
+ &attnull);
nulls[attoff] = (attnull ? 'n' : ' ');
}
@@ -248,8 +246,8 @@ hashbuild(Relation heap,
*/
if (IsNormalProcessingMode())
{
- hrelid = heap->rd_id;
- irelid = index->rd_id;
+ hrelid = RelationGetRelid(heap);
+ irelid = RelationGetRelid(index);
heap_close(heap);
index_close(index);
UpdateStats(hrelid, nhtups, true);
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index f5af00fe2b1..d57c65e4e07 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -7,7 +7,7 @@
*
*
* 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
* These functions are stored in pg_amproc. For each operator class
@@ -133,6 +133,18 @@ hashoid(Oid 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 PRIME2 1048583
diff --git a/src/backend/access/hash/hashscan.c b/src/backend/access/hash/hashscan.c
index 708dc18943e..ebc41220352 100644
--- a/src/backend/access/hash/hashscan.c
+++ b/src/backend/access/hash/hashscan.c
@@ -7,7 +7,7 @@
*
*
* 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
* 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;
Oid relid;
- relid = rel->rd_id;
+ relid = RelationGetRelid(rel);
for (l = HashScans; l != (HashScanList) NULL; l = l->hashsl_next)
{
if (relid == l->hashsl_scan->relation->rd_id)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 75127b027d1..139db3b5e36 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -7,7 +7,7 @@
*
*
* 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
@@ -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
-initsdesc(HeapScanDesc sdesc,
+initscan(HeapScanDesc scan,
Relation relation,
int atend,
unsigned nkeys,
@@ -120,8 +120,8 @@ initsdesc(HeapScanDesc sdesc,
* relation is empty
* ----------------
*/
- sdesc->rs_ntup = sdesc->rs_ctup = sdesc->rs_ptup = NULL;
- sdesc->rs_nbuf = sdesc->rs_cbuf = sdesc->rs_pbuf = InvalidBuffer;
+ scan->rs_ntup = scan->rs_ctup = scan->rs_ptup = NULL;
+ scan->rs_nbuf = scan->rs_cbuf = scan->rs_pbuf = InvalidBuffer;
}
else if (atend)
{
@@ -129,10 +129,10 @@ initsdesc(HeapScanDesc sdesc,
* reverse scan
* ----------------
*/
- sdesc->rs_ntup = sdesc->rs_ctup = NULL;
- sdesc->rs_nbuf = sdesc->rs_cbuf = InvalidBuffer;
- sdesc->rs_ptup = NULL;
- sdesc->rs_pbuf = UnknownBuffer;
+ scan->rs_ntup = scan->rs_ctup = NULL;
+ scan->rs_nbuf = scan->rs_cbuf = InvalidBuffer;
+ scan->rs_ptup = NULL;
+ scan->rs_pbuf = UnknownBuffer;
}
else
{
@@ -140,35 +140,35 @@ initsdesc(HeapScanDesc sdesc,
* forward scan
* ----------------
*/
- sdesc->rs_ctup = sdesc->rs_ptup = NULL;
- sdesc->rs_cbuf = sdesc->rs_pbuf = InvalidBuffer;
- sdesc->rs_ntup = NULL;
- sdesc->rs_nbuf = UnknownBuffer;
+ scan->rs_ctup = scan->rs_ptup = NULL;
+ scan->rs_cbuf = scan->rs_pbuf = InvalidBuffer;
+ scan->rs_ntup = NULL;
+ scan->rs_nbuf = UnknownBuffer;
} /* invalid too */
/* we don't have a marked position... */
- ItemPointerSetInvalid(&(sdesc->rs_mptid));
- ItemPointerSetInvalid(&(sdesc->rs_mctid));
- ItemPointerSetInvalid(&(sdesc->rs_mntid));
- ItemPointerSetInvalid(&(sdesc->rs_mcd));
+ ItemPointerSetInvalid(&(scan->rs_mptid));
+ ItemPointerSetInvalid(&(scan->rs_mctid));
+ ItemPointerSetInvalid(&(scan->rs_mntid));
+ ItemPointerSetInvalid(&(scan->rs_mcd));
/* ----------------
* copy the scan key, if appropriate
* ----------------
*/
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
-unpinsdesc(HeapScanDesc sdesc)
+unpinscan(HeapScanDesc scan)
{
- if (BufferIsValid(sdesc->rs_pbuf))
- ReleaseBuffer(sdesc->rs_pbuf);
+ if (BufferIsValid(scan->rs_pbuf))
+ ReleaseBuffer(scan->rs_pbuf);
/* ------------------------------------
* Scan will pin buffer one for each non-NULL tuple pointer
@@ -176,11 +176,11 @@ unpinsdesc(HeapScanDesc sdesc)
* times.
* ------------------------------------
*/
- if (BufferIsValid(sdesc->rs_cbuf))
- ReleaseBuffer(sdesc->rs_cbuf);
+ if (BufferIsValid(scan->rs_cbuf))
+ ReleaseBuffer(scan->rs_cbuf);
- if (BufferIsValid(sdesc->rs_nbuf))
- ReleaseBuffer(sdesc->rs_nbuf);
+ if (BufferIsValid(scan->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
* 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
heapgettup(Relation relation,
ItemPointer tid,
int dir,
- Buffer *b,
+ Buffer *buf,
Snapshot snapshot,
int nkeys,
ScanKey key)
@@ -248,7 +253,7 @@ heapgettup(Relation relation,
elog(DEBUG, "heapgettup(%s, tid=0x%x, dir=%d, ...)",
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",
relation->rd_rel->relkind, &relation->rd_rel->relname,
@@ -278,19 +283,19 @@ heapgettup(Relation relation,
/* assume it is a valid TID XXX */
if (ItemPointerIsValid(tid) == false)
{
- *b = InvalidBuffer;
+ *buf= InvalidBuffer;
return (NULL);
}
- *b = RelationGetBufferWithBuffer(relation,
+ *buf = RelationGetBufferWithBuffer(relation,
ItemPointerGetBlockNumber(tid),
- *b);
+ *buf);
#ifndef NO_BUFFERISVALID
- if (!BufferIsValid(*b))
+ if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer");
#endif
- dp = (Page) BufferGetPage(*b);
+ dp = (Page) BufferGetPage(*buf);
lineoff = ItemPointerGetOffsetNumber(tid);
lpp = PageGetItemId(dp, lineoff);
@@ -316,17 +321,17 @@ heapgettup(Relation relation,
}
if (page < 0)
{
- *b = InvalidBuffer;
+ *buf = InvalidBuffer;
return (NULL);
}
- *b = RelationGetBufferWithBuffer(relation, page, *b);
+ *buf = RelationGetBufferWithBuffer(relation, page, *buf);
#ifndef NO_BUFFERISVALID
- if (!BufferIsValid(*b))
+ if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer");
#endif
- dp = (Page) BufferGetPage(*b);
+ dp = (Page) BufferGetPage(*buf);
lines = PageGetMaxOffsetNumber(dp);
if (tid == NULL)
{
@@ -360,18 +365,18 @@ heapgettup(Relation relation,
if (page >= pages)
{
- *b = InvalidBuffer;
+ *buf = InvalidBuffer;
return (NULL);
}
/* page and lineoff now reference the physically next tid */
- *b = RelationGetBufferWithBuffer(relation, page, *b);
+ *buf = RelationGetBufferWithBuffer(relation, page, *buf);
#ifndef NO_BUFFERISVALID
- if (!BufferIsValid(*b))
+ if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer");
#endif
- dp = (Page) BufferGetPage(*b);
+ dp = (Page) BufferGetPage(*buf);
lines = PageGetMaxOffsetNumber(dp);
}
@@ -401,7 +406,7 @@ heapgettup(Relation relation,
* if current tuple qualifies, return it.
* ----------------
*/
- HeapTupleSatisfies(lpp, relation, *b, (PageHeader) dp,
+ HeapTupleSatisfies(lpp, relation, *buf, (PageHeader) dp,
snapshot, nkeys, key, rtup);
if (rtup != NULL)
{
@@ -409,7 +414,6 @@ heapgettup(Relation relation,
if (ItemPointerGetBlockNumber(iptr) != page)
{
-
/*
* set block id to the correct page number --- this is
* a hack to support the virtual fragment concept
@@ -448,19 +452,19 @@ heapgettup(Relation relation,
*/
if (page < 0 || page >= pages)
{
- if (BufferIsValid(*b))
- ReleaseBuffer(*b);
- *b = InvalidBuffer;
+ if (BufferIsValid(*buf))
+ ReleaseBuffer(*buf);
+ *buf = InvalidBuffer;
return (NULL);
}
- *b = ReleaseAndReadBuffer(*b, relation, page);
+ *buf = ReleaseAndReadBuffer(*buf, relation, page);
#ifndef NO_BUFFERISVALID
- if (!BufferIsValid(*b))
+ if (!BufferIsValid(*buf))
elog(ERROR, "heapgettup: failed ReadBuffer");
#endif
- dp = (Page) BufferGetPage(*b);
+ dp = (Page) BufferGetPage(*buf);
lines = lineoff = PageGetMaxOffsetNumber((Page) dp);
linesleft = lines - 1;
if (dir < 0)
@@ -584,7 +588,7 @@ heap_beginscan(Relation relation,
unsigned nkeys,
ScanKey key)
{
- HeapScanDesc sdesc;
+ HeapScanDesc scan;
/* ----------------
* increment access statistics
@@ -620,29 +624,29 @@ heap_beginscan(Relation relation,
* allocate and initialize scan descriptor
* ----------------
*/
- sdesc = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
+ scan = (HeapScanDesc) palloc(sizeof(HeapScanDescData));
relation->rd_nblocks = smgrnblocks(DEFAULT_SMGR, relation);
- sdesc->rs_rd = relation;
+ scan->rs_rd = relation;
if (nkeys)
/*
- * we do this here instead of in initsdesc() because heap_rescan
- * also calls initsdesc() and we don't want to allocate memory
+ * we do this here instead of in initscan() because heap_rescan
+ * also calls initscan() and we don't want to allocate memory
* again
*/
- sdesc->rs_key = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys);
+ scan->rs_key = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys);
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;
- sdesc->rs_snapshot = snapshot;
- sdesc->rs_nkeys = (short) nkeys;
+ scan->rs_atend = atend;
+ scan->rs_snapshot = snapshot;
+ scan->rs_nkeys = (short) nkeys;
- return (sdesc);
+ return (scan);
}
/* ----------------
@@ -650,7 +654,7 @@ heap_beginscan(Relation relation,
* ----------------
*/
void
-heap_rescan(HeapScanDesc sdesc,
+heap_rescan(HeapScanDesc scan,
bool scanFromEnd,
ScanKey key)
{
@@ -667,14 +671,14 @@ heap_rescan(HeapScanDesc sdesc,
* unpin scan buffers
* ----------------
*/
- unpinsdesc(sdesc);
+ unpinscan(scan);
/* ----------------
* reinitialize scan descriptor
* ----------------
*/
- initsdesc(sdesc, sdesc->rs_rd, scanFromEnd, sdesc->rs_nkeys, key);
- sdesc->rs_atend = (bool) scanFromEnd;
+ initscan(scan, scan->rs_rd, scanFromEnd, scan->rs_nkeys, key);
+ scan->rs_atend = (bool) scanFromEnd;
}
/* ----------------
@@ -685,7 +689,7 @@ heap_rescan(HeapScanDesc sdesc,
* ----------------
*/
void
-heap_endscan(HeapScanDesc sdesc)
+heap_endscan(HeapScanDesc scan)
{
/* ----------------
* increment access statistics
@@ -700,36 +704,38 @@ heap_endscan(HeapScanDesc sdesc)
* unpin scan buffers
* ----------------
*/
- unpinsdesc(sdesc);
+ unpinscan(scan);
/* ----------------
* 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
* ----------------
*/
- 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
*
* Fix to work with index relations.
+ * We don't return the buffer anymore, but you can get it from the
+ * returned HeapTuple.
* ----------------
*/
#ifdef HEAPDEBUGALL
#define HEAPDEBUG_1 \
-elog(DEBUG, "heap_getnext([%s,nkeys=%d],backw=%d,0x%x) called", \
- sdesc->rs_rd->rd_rel->relname.data, sdesc->rs_nkeys, backw, b)
+elog(DEBUG, "heap_getnext([%s,nkeys=%d],backw=%d) called", \
+ scan->rs_rd->rd_rel->relname.data, scan->rs_nkeys, backw)
#define HEAPDEBUG_2 \
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
-heap_getnext(HeapScanDesc scandesc,
- int backw,
- Buffer *b)
+heap_getnext(HeapScanDesc scandesc, int backw)
{
- HeapScanDesc sdesc = scandesc;
- Buffer localb;
+ HeapScanDesc scan = scandesc;
/* ----------------
* increment access statistics
@@ -780,16 +783,13 @@ heap_getnext(HeapScanDesc scandesc,
* argument checks
* ----------------
*/
- if (sdesc == NULL)
+ if (scan == NULL)
elog(ERROR, "heap_getnext: NULL relscan");
/* ----------------
* initialize return buffer to InvalidBuffer
* ----------------
*/
- if (!PointerIsValid(b))
- b = &localb;
- (*b) = InvalidBuffer;
HEAPDEBUG_1; /* heap_getnext( info ) */
@@ -801,11 +801,11 @@ heap_getnext(HeapScanDesc scandesc,
*/
HEAPDEBUG_2; /* heap_getnext called with backw */
- if (sdesc->rs_ptup == sdesc->rs_ctup &&
- BufferIsInvalid(sdesc->rs_pbuf))
+ if (scan->rs_ptup == scan->rs_ctup &&
+ BufferIsInvalid(scan->rs_pbuf))
{
- if (BufferIsValid(sdesc->rs_nbuf))
- ReleaseBuffer(sdesc->rs_nbuf);
+ if (BufferIsValid(scan->rs_nbuf))
+ ReleaseBuffer(scan->rs_nbuf);
return (NULL);
}
@@ -813,37 +813,37 @@ heap_getnext(HeapScanDesc scandesc,
* Copy the "current" tuple/buffer to "next". Pin/unpin the
* buffers accordingly
*/
- if (sdesc->rs_nbuf != sdesc->rs_cbuf)
+ if (scan->rs_nbuf != scan->rs_cbuf)
{
- if (BufferIsValid(sdesc->rs_nbuf))
- ReleaseBuffer(sdesc->rs_nbuf);
- if (BufferIsValid(sdesc->rs_cbuf))
- IncrBufferRefCount(sdesc->rs_cbuf);
+ if (BufferIsValid(scan->rs_nbuf))
+ ReleaseBuffer(scan->rs_nbuf);
+ if (BufferIsValid(scan->rs_cbuf))
+ IncrBufferRefCount(scan->rs_cbuf);
}
- sdesc->rs_ntup = sdesc->rs_ctup;
- sdesc->rs_nbuf = sdesc->rs_cbuf;
+ scan->rs_ntup = scan->rs_ctup;
+ 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))
- ReleaseBuffer(sdesc->rs_cbuf);
- if (BufferIsValid(sdesc->rs_pbuf))
- IncrBufferRefCount(sdesc->rs_pbuf);
+ if (BufferIsValid(scan->rs_cbuf))
+ ReleaseBuffer(scan->rs_cbuf);
+ if (BufferIsValid(scan->rs_pbuf))
+ IncrBufferRefCount(scan->rs_pbuf);
}
- sdesc->rs_ctup = sdesc->rs_ptup;
- sdesc->rs_cbuf = sdesc->rs_pbuf;
+ scan->rs_ctup = scan->rs_ptup;
+ scan->rs_cbuf = scan->rs_pbuf;
}
else
{ /* NONTUP */
ItemPointer iptr;
- iptr = (sdesc->rs_ctup != NULL) ?
- &(sdesc->rs_ctup->t_ctid) : (ItemPointer) NULL;
+ iptr = (scan->rs_ctup != 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
* already set. On a backward scan, both rs_ctup and rs_ntup
* 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
*/
- sdesc->rs_ctup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
+ scan->rs_ctup = (HeapTuple)
+ heapgettup(scan->rs_rd,
iptr,
-1,
- &(sdesc->rs_cbuf),
- sdesc->rs_snapshot,
- sdesc->rs_nkeys,
- sdesc->rs_key);
+ &(scan->rs_cbuf),
+ scan->rs_snapshot,
+ scan->rs_nkeys,
+ 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))
- ReleaseBuffer(sdesc->rs_pbuf);
- sdesc->rs_ptup = NULL;
- sdesc->rs_pbuf = InvalidBuffer;
- if (BufferIsValid(sdesc->rs_nbuf))
- ReleaseBuffer(sdesc->rs_nbuf);
- sdesc->rs_ntup = NULL;
- sdesc->rs_nbuf = InvalidBuffer;
+ if (BufferIsValid(scan->rs_pbuf))
+ ReleaseBuffer(scan->rs_pbuf);
+ scan->rs_ptup = NULL;
+ scan->rs_pbuf = InvalidBuffer;
+ if (BufferIsValid(scan->rs_nbuf))
+ ReleaseBuffer(scan->rs_nbuf);
+ scan->rs_ntup = NULL;
+ scan->rs_nbuf = InvalidBuffer;
return (NULL);
}
- if (BufferIsValid(sdesc->rs_pbuf))
- ReleaseBuffer(sdesc->rs_pbuf);
- sdesc->rs_ptup = NULL;
- sdesc->rs_pbuf = UnknownBuffer;
+ if (BufferIsValid(scan->rs_pbuf))
+ ReleaseBuffer(scan->rs_pbuf);
+ scan->rs_ptup = NULL;
+ scan->rs_pbuf = UnknownBuffer;
}
else
@@ -886,11 +886,11 @@ heap_getnext(HeapScanDesc scandesc,
* handle forward scan
* ----------------
*/
- if (sdesc->rs_ctup == sdesc->rs_ntup &&
- BufferIsInvalid(sdesc->rs_nbuf))
+ if (scan->rs_ctup == scan->rs_ntup &&
+ BufferIsInvalid(scan->rs_nbuf))
{
- if (BufferIsValid(sdesc->rs_pbuf))
- ReleaseBuffer(sdesc->rs_pbuf);
+ if (BufferIsValid(scan->rs_pbuf))
+ ReleaseBuffer(scan->rs_pbuf);
HEAPDEBUG_3; /* heap_getnext returns NULL at end */
return (NULL);
}
@@ -899,38 +899,38 @@ heap_getnext(HeapScanDesc scandesc,
* Copy the "current" tuple/buffer to "previous". Pin/unpin the
* buffers accordingly
*/
- if (sdesc->rs_pbuf != sdesc->rs_cbuf)
+ if (scan->rs_pbuf != scan->rs_cbuf)
{
- if (BufferIsValid(sdesc->rs_pbuf))
- ReleaseBuffer(sdesc->rs_pbuf);
- if (BufferIsValid(sdesc->rs_cbuf))
- IncrBufferRefCount(sdesc->rs_cbuf);
+ if (BufferIsValid(scan->rs_pbuf))
+ ReleaseBuffer(scan->rs_pbuf);
+ if (BufferIsValid(scan->rs_cbuf))
+ IncrBufferRefCount(scan->rs_cbuf);
}
- sdesc->rs_ptup = sdesc->rs_ctup;
- sdesc->rs_pbuf = sdesc->rs_cbuf;
+ scan->rs_ptup = scan->rs_ctup;
+ 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))
- ReleaseBuffer(sdesc->rs_cbuf);
- if (BufferIsValid(sdesc->rs_nbuf))
- IncrBufferRefCount(sdesc->rs_nbuf);
+ if (BufferIsValid(scan->rs_cbuf))
+ ReleaseBuffer(scan->rs_cbuf);
+ if (BufferIsValid(scan->rs_nbuf))
+ IncrBufferRefCount(scan->rs_nbuf);
}
- sdesc->rs_ctup = sdesc->rs_ntup;
- sdesc->rs_cbuf = sdesc->rs_nbuf;
+ scan->rs_ctup = scan->rs_ntup;
+ scan->rs_cbuf = scan->rs_nbuf;
HEAPDEBUG_5; /* heap_getnext next tuple was cached */
}
else
{ /* NONTUP */
ItemPointer iptr;
- iptr = (sdesc->rs_ctup != NULL) ?
- &sdesc->rs_ctup->t_ctid : (ItemPointer) NULL;
+ iptr = (scan->rs_ctup != 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
* already set. On a forward scan, both rs_ctup and rs_ptup
* 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
*/
- sdesc->rs_ctup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
+ scan->rs_ctup = (HeapTuple)
+ heapgettup(scan->rs_rd,
iptr,
1,
- &sdesc->rs_cbuf,
- sdesc->rs_snapshot,
- sdesc->rs_nkeys,
- sdesc->rs_key);
+ &scan->rs_cbuf,
+ scan->rs_snapshot,
+ scan->rs_nkeys,
+ 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))
- ReleaseBuffer(sdesc->rs_nbuf);
- sdesc->rs_ntup = NULL;
- sdesc->rs_nbuf = InvalidBuffer;
- if (BufferIsValid(sdesc->rs_pbuf))
- ReleaseBuffer(sdesc->rs_pbuf);
- sdesc->rs_ptup = NULL;
- sdesc->rs_pbuf = InvalidBuffer;
+ if (BufferIsValid(scan->rs_nbuf))
+ ReleaseBuffer(scan->rs_nbuf);
+ scan->rs_ntup = NULL;
+ scan->rs_nbuf = InvalidBuffer;
+ if (BufferIsValid(scan->rs_pbuf))
+ ReleaseBuffer(scan->rs_pbuf);
+ scan->rs_ptup = NULL;
+ scan->rs_pbuf = InvalidBuffer;
HEAPDEBUG_6; /* heap_getnext returning EOS */
return (NULL);
}
- if (BufferIsValid(sdesc->rs_nbuf))
- ReleaseBuffer(sdesc->rs_nbuf);
- sdesc->rs_ntup = NULL;
- sdesc->rs_nbuf = UnknownBuffer;
+ if (BufferIsValid(scan->rs_nbuf))
+ ReleaseBuffer(scan->rs_nbuf);
+ scan->rs_ntup = NULL;
+ scan->rs_nbuf = UnknownBuffer;
}
/* ----------------
@@ -973,24 +973,31 @@ heap_getnext(HeapScanDesc scandesc,
* point to the proper return buffer and return the tuple.
* ----------------
*/
- (*b) = sdesc->rs_cbuf;
HEAPDEBUG_7; /* heap_getnext returning tuple */
- return (sdesc->rs_ctup);
+ return scan->rs_ctup;
}
/* ----------------
* heap_fetch - retrive tuple with tid
*
* 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
heap_fetch(Relation relation,
Snapshot snapshot,
ItemPointer tid,
- Buffer *b)
+ Buffer *userbuf)
{
ItemId lp;
Buffer buffer;
@@ -998,6 +1005,8 @@ heap_fetch(Relation relation,
HeapTuple tuple;
OffsetNumber offnum;
+ AssertMacro(PointerIsValid(userbuf)); /* see comments above */
+
/* ----------------
* increment access statistics
* ----------------
@@ -1061,17 +1070,12 @@ heap_fetch(Relation relation,
/* ----------------
* all checks passed, now either return a copy of the tuple
* 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))
- *b = buffer;
- else
- {
- tuple = heap_copytuple(tuple);
- ReleaseBuffer(buffer);
- }
+ *userbuf = buffer; /* user is required to ReleaseBuffer() this */
+
return (tuple);
}
@@ -1161,7 +1165,7 @@ heap_delete(Relation relation, ItemPointer tid)
ItemId lp;
HeapTuple tp;
PageHeader dp;
- Buffer b;
+ Buffer buf;
/* ----------------
* increment access statistics
@@ -1182,16 +1186,16 @@ heap_delete(Relation relation, ItemPointer tid)
*/
RelationSetLockForWrite(relation);
- b = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
+ buf = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
#ifndef NO_BUFFERISVALID
- if (!BufferIsValid(b))
+ if (!BufferIsValid(buf))
{ /* XXX L_SH better ??? */
elog(ERROR, "heap_delete: failed ReadBuffer");
}
#endif /* NO_BUFFERISVALID */
- dp = (PageHeader) BufferGetPage(b);
+ dp = (PageHeader) BufferGetPage(buf);
lp = PageGetItemId(dp, ItemPointerGetOffsetNumber(tid));
/*
@@ -1208,20 +1212,20 @@ heap_delete(Relation relation, ItemPointer tid)
*/
if (IsSystemRelationName(RelationGetRelationName(relation)->data))
RelationUnsetLockForWrite(relation);
- ReleaseBuffer(b);
+ ReleaseBuffer(buf);
return (1);
}
/* ----------------
* check that we're deleteing a valid item
* ----------------
*/
- HeapTupleSatisfies(lp, relation, b, dp,
+ HeapTupleSatisfies(lp, relation, buf, dp,
false, 0, (ScanKey) NULL, tp);
if (!tp)
{
/* XXX call something else */
- ReleaseBuffer(b);
+ ReleaseBuffer(buf);
elog(ERROR, "heap_delete: (am)invalid tid");
}
@@ -1248,7 +1252,7 @@ heap_delete(Relation relation, ItemPointer tid)
RelationInvalidateHeapTuple(relation, tp);
SetRefreshWhenInvalidate((bool) !ImmediateInvalidation);
- WriteBuffer(b);
+ WriteBuffer(buf);
if (IsSystemRelationName(RelationGetRelationName(relation)->data))
RelationUnsetLockForWrite(relation);
@@ -1426,7 +1430,7 @@ heap_replace(Relation relation, ItemPointer otid, HeapTuple tup)
* ----------------
*/
void
-heap_markpos(HeapScanDesc sdesc)
+heap_markpos(HeapScanDesc scan)
{
/* ----------------
@@ -1438,50 +1442,50 @@ heap_markpos(HeapScanDesc sdesc)
/* Note: no locking manipulations needed */
- if (sdesc->rs_ptup == NULL &&
- BufferIsUnknown(sdesc->rs_pbuf))
+ if (scan->rs_ptup == NULL &&
+ BufferIsUnknown(scan->rs_pbuf))
{ /* == NONTUP */
- sdesc->rs_ptup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
- (sdesc->rs_ctup == NULL) ?
- (ItemPointer) NULL : &sdesc->rs_ctup->t_ctid,
+ scan->rs_ptup = (HeapTuple)
+ heapgettup(scan->rs_rd,
+ (scan->rs_ctup == NULL) ?
+ (ItemPointer) NULL : &scan->rs_ctup->t_ctid,
-1,
- &sdesc->rs_pbuf,
- sdesc->rs_snapshot,
- sdesc->rs_nkeys,
- sdesc->rs_key);
+ &scan->rs_pbuf,
+ scan->rs_snapshot,
+ scan->rs_nkeys,
+ scan->rs_key);
}
- else if (sdesc->rs_ntup == NULL &&
- BufferIsUnknown(sdesc->rs_nbuf))
+ else if (scan->rs_ntup == NULL &&
+ BufferIsUnknown(scan->rs_nbuf))
{ /* == NONTUP */
- sdesc->rs_ntup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
- (sdesc->rs_ctup == NULL) ?
- (ItemPointer) NULL : &sdesc->rs_ctup->t_ctid,
+ scan->rs_ntup = (HeapTuple)
+ heapgettup(scan->rs_rd,
+ (scan->rs_ctup == NULL) ?
+ (ItemPointer) NULL : &scan->rs_ctup->t_ctid,
1,
- &sdesc->rs_nbuf,
- sdesc->rs_snapshot,
- sdesc->rs_nkeys,
- sdesc->rs_key);
+ &scan->rs_nbuf,
+ scan->rs_snapshot,
+ scan->rs_nkeys,
+ scan->rs_key);
}
/* ----------------
* Should not unpin the buffer pages. They may still be in use.
* ----------------
*/
- if (sdesc->rs_ptup != NULL)
- sdesc->rs_mptid = sdesc->rs_ptup->t_ctid;
+ if (scan->rs_ptup != NULL)
+ scan->rs_mptid = scan->rs_ptup->t_ctid;
else
- ItemPointerSetInvalid(&sdesc->rs_mptid);
- if (sdesc->rs_ctup != NULL)
- sdesc->rs_mctid = sdesc->rs_ctup->t_ctid;
+ ItemPointerSetInvalid(&scan->rs_mptid);
+ if (scan->rs_ctup != NULL)
+ scan->rs_mctid = scan->rs_ctup->t_ctid;
else
- ItemPointerSetInvalid(&sdesc->rs_mctid);
- if (sdesc->rs_ntup != NULL)
- sdesc->rs_mntid = sdesc->rs_ntup->t_ctid;
+ ItemPointerSetInvalid(&scan->rs_mctid);
+ if (scan->rs_ntup != NULL)
+ scan->rs_mntid = scan->rs_ntup->t_ctid;
else
- ItemPointerSetInvalid(&sdesc->rs_mntid);
+ ItemPointerSetInvalid(&scan->rs_mntid);
}
/* ----------------
@@ -1506,7 +1510,7 @@ heap_markpos(HeapScanDesc sdesc)
* ----------------
*/
void
-heap_restrpos(HeapScanDesc sdesc)
+heap_restrpos(HeapScanDesc scan)
{
/* ----------------
* increment access statistics
@@ -1519,50 +1523,50 @@ heap_restrpos(HeapScanDesc sdesc)
/* Note: no locking manipulations needed */
- unpinsdesc(sdesc);
+ unpinscan(scan);
/* force heapgettup to pin buffer for each loaded tuple */
- sdesc->rs_pbuf = InvalidBuffer;
- sdesc->rs_cbuf = InvalidBuffer;
- sdesc->rs_nbuf = InvalidBuffer;
+ scan->rs_pbuf = InvalidBuffer;
+ scan->rs_cbuf = InvalidBuffer;
+ scan->rs_nbuf = InvalidBuffer;
- if (!ItemPointerIsValid(&sdesc->rs_mptid))
- sdesc->rs_ptup = NULL;
+ if (!ItemPointerIsValid(&scan->rs_mptid))
+ scan->rs_ptup = NULL;
else
{
- sdesc->rs_ptup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
- &sdesc->rs_mptid,
+ scan->rs_ptup = (HeapTuple)
+ heapgettup(scan->rs_rd,
+ &scan->rs_mptid,
0,
- &sdesc->rs_pbuf,
+ &scan->rs_pbuf,
false,
0,
(ScanKey) NULL);
}
- if (!ItemPointerIsValid(&sdesc->rs_mctid))
- sdesc->rs_ctup = NULL;
+ if (!ItemPointerIsValid(&scan->rs_mctid))
+ scan->rs_ctup = NULL;
else
{
- sdesc->rs_ctup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
- &sdesc->rs_mctid,
+ scan->rs_ctup = (HeapTuple)
+ heapgettup(scan->rs_rd,
+ &scan->rs_mctid,
0,
- &sdesc->rs_cbuf,
+ &scan->rs_cbuf,
false,
0,
(ScanKey) NULL);
}
- if (!ItemPointerIsValid(&sdesc->rs_mntid))
- sdesc->rs_ntup = NULL;
+ if (!ItemPointerIsValid(&scan->rs_mntid))
+ scan->rs_ntup = NULL;
else
{
- sdesc->rs_ntup = (HeapTuple)
- heapgettup(sdesc->rs_rd,
- &sdesc->rs_mntid,
+ scan->rs_ntup = (HeapTuple)
+ heapgettup(scan->rs_rd,
+ &scan->rs_mntid,
0,
- &sdesc->rs_nbuf,
+ &scan->rs_nbuf,
false,
0,
(ScanKey) NULL);
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 229ca5d1a27..59e2cb1b546 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -7,7 +7,7 @@
*
*
* 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
* many of the old access method routines have been turned into
@@ -216,14 +216,15 @@ IndexScanMarkPosition(IndexScanDesc scan)
if (scan->flags & ScanUncheckedPrevious)
{
- result =
- index_getnext(scan, BackwardScanDirection);
+ result = index_getnext(scan, BackwardScanDirection);
if (result != NULL)
+ {
scan->previousItemData = result->index_iptr;
+ pfree(result);
+ }
else
ItemPointerSetInvalid(&scan->previousItemData);
-
}
else if (scan->flags & ScanUncheckedNext)
{
@@ -231,7 +232,10 @@ IndexScanMarkPosition(IndexScanDesc scan)
index_getnext(scan, ForwardScanDirection);
if (result != NULL)
+ {
scan->nextItemData = result->index_iptr;
+ pfree(result);
+ }
else
ItemPointerSetInvalid(&scan->nextItemData);
}
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index e6af2ff9e6a..3f3721341ac 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -7,7 +7,7 @@
*
*
* 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
* 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.
* ----------------
*/
- result = (RetrieveIndexResult)
- fmgr(procedure, scan, direction);
+ result = (RetrieveIndexResult)fmgr(procedure, scan, direction);
return result;
}
@@ -376,8 +375,7 @@ GetIndexValue(HeapTuple tuple,
int attOff,
AttrNumber attrNums[],
FuncIndexInfo *fInfo,
- bool *attNull,
- Buffer buffer)
+ bool *attNull)
{
Datum returnVal;
bool isNull;
diff --git a/src/backend/access/index/istrat.c b/src/backend/access/index/istrat.c
index 480644857ce..b4c6117069a 100644
--- a/src/backend/access/index/istrat.c
+++ b/src/backend/access/index/istrat.c
@@ -8,13 +8,14 @@
*
*
* 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 "miscadmin.h"
#include "access/heapam.h"
#include "access/istrat.h"
#include "catalog/catname.h"
@@ -22,6 +23,7 @@
#include "catalog/pg_amproc.h"
#include "catalog/pg_index.h"
#include "catalog/pg_operator.h"
+#include "utils/syscache.h"
#include "fmgr.h"
#include "utils/memutils.h" /* could have been access/itup.h */
@@ -30,8 +32,7 @@ static bool StrategyEvaluationIsValid(StrategyEvaluation evaluation);
static bool
StrategyExpressionIsValid(StrategyExpression expression,
StrategyNumber maxStrategy);
-static ScanKey
-StrategyMapGetScanKeyEntry(StrategyMap map,
+static ScanKey StrategyMapGetScanKeyEntry(StrategyMap map,
StrategyNumber strategyNumber);
static bool
StrategyOperatorIsValid(StrategyOperator operator,
@@ -95,8 +96,7 @@ IndexStrategyGetStrategyMap(IndexStrategy indexStrategy,
Assert(AttributeNumberIsValid(attrNum));
maxStrategyNum = AMStrategies(maxStrategyNum); /* XXX */
- return
- &indexStrategy->strategyMapData[maxStrategyNum * (attrNum - 1)];
+ return &indexStrategy->strategyMapData[maxStrategyNum * (attrNum - 1)];
}
/*
@@ -108,8 +108,7 @@ AttributeNumberGetIndexStrategySize(AttrNumber maxAttributeNumber,
StrategyNumber maxStrategyNumber)
{
maxStrategyNumber = AMStrategies(maxStrategyNumber); /* XXX */
- return
- maxAttributeNumber * maxStrategyNumber * sizeof(ScanKeyData);
+ return maxAttributeNumber * maxStrategyNumber * sizeof(ScanKeyData);
}
#ifdef USE_ASSERT_CHECKING
@@ -483,39 +482,52 @@ OperatorRelationFillScanKeyEntry(Relation operatorRelation,
Oid operatorObjectId,
ScanKey entry)
{
- HeapScanDesc scan;
- ScanKeyData scanKeyData;
HeapTuple tuple;
+ HeapScanDesc scan = NULL;
- ScanKeyEntryInitialize(&scanKeyData, 0,
- ObjectIdAttributeNumber,
- F_OIDEQ,
- ObjectIdGetDatum(operatorObjectId));
+ if (!IsBootstrapProcessingMode())
+ {
+ tuple = SearchSysCacheTuple(OPROID,
+ ObjectIdGetDatum(operatorObjectId),
+ 0, 0, 0);
+ }
+ else
+ {
+ ScanKeyData scanKeyData;
+
+ ScanKeyEntryInitialize(&scanKeyData, 0,
+ ObjectIdAttributeNumber,
+ F_OIDEQ,
+ ObjectIdGetDatum(operatorObjectId));
- scan = heap_beginscan(operatorRelation, false, SnapshotNow,
- 1, &scanKeyData);
+ scan = heap_beginscan(operatorRelation, false, SnapshotNow,
+ 1, &scanKeyData);
+
+ tuple = heap_getnext(scan, 0);
+ }
- tuple = heap_getnext(scan, false, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
{
+ if (IsBootstrapProcessingMode())
+ heap_endscan(scan);
elog(ERROR, "OperatorObjectIdFillScanKeyEntry: unknown operator %lu",
(uint32) operatorObjectId);
}
entry->sk_flags = 0;
- entry->sk_procedure =
- ((OperatorTupleForm) GETSTRUCT(tuple))->oprcode;
+ entry->sk_procedure = ((OperatorTupleForm) GETSTRUCT(tuple))->oprcode;
fmgr_info(entry->sk_procedure, &entry->sk_func);
entry->sk_nargs = entry->sk_func.fn_nargs;
+ if (IsBootstrapProcessingMode())
+ heap_endscan(scan);
+
if (!RegProcedureIsValid(entry->sk_procedure))
{
elog(ERROR,
"OperatorObjectIdFillScanKeyEntry: no procedure for operator %lu",
(uint32) operatorObjectId);
}
-
- heap_endscan(scan);
}
@@ -532,28 +544,38 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
StrategyNumber maxSupportNumber,
AttrNumber maxAttributeNumber)
{
- Relation relation;
+ Relation relation = NULL;
+ HeapScanDesc scan = NULL;
+ ScanKeyData entry[2];
Relation operatorRelation;
- HeapScanDesc scan;
HeapTuple tuple;
- ScanKeyData entry[2];
StrategyMap map;
AttrNumber attributeNumber;
int attributeIndex;
Oid operatorClassObjectId[MaxIndexAttributeNumber];
- maxStrategyNumber = AMStrategies(maxStrategyNumber);
-
- ScanKeyEntryInitialize(&entry[0], 0, Anum_pg_index_indexrelid,
- F_OIDEQ,
- ObjectIdGetDatum(indexObjectId));
+ 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);
+ }
- relation = heap_openr(IndexRelationName);
- scan = heap_beginscan(relation, false, SnapshotNow, 1, entry);
- tuple = heap_getnext(scan, 0, (Buffer *) NULL);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "IndexSupportInitialize: corrupted catalogs");
+ maxStrategyNumber = AMStrategies(maxStrategyNumber);
+
/*
* XXX note that the following assumes the INDEX tuple is well formed
* and that the key[] and class[] are 0 terminated.
@@ -574,9 +596,12 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
operatorClassObjectId[attributeIndex] = iform->indclass[attributeIndex];
}
- heap_endscan(scan);
- heap_close(relation);
-
+ if (IsBootstrapProcessingMode())
+ {
+ heap_endscan(scan);
+ heap_close(relation);
+ }
+
/* if support routines exist for this access method, load them */
if (maxSupportNumber > 0)
{
@@ -606,8 +631,7 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
- while (tuple = heap_getnext(scan, 0, (Buffer *) NULL),
- HeapTupleIsValid(tuple))
+ while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{
form = (Form_pg_amproc) GETSTRUCT(tuple);
loc[(form->amprocnum - 1)] = form->amproc;
@@ -647,8 +671,7 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
scan = heap_beginscan(relation, false, SnapshotNow, 2, entry);
- while (tuple = heap_getnext(scan, 0, (Buffer *) NULL),
- HeapTupleIsValid(tuple))
+ while (HeapTupleIsValid(tuple = heap_getnext(scan, 0)))
{
Form_pg_amop form;
diff --git a/src/backend/access/nbtree/nbtcompare.c b/src/backend/access/nbtree/nbtcompare.c
index 43a09be03ef..45ec7b241de 100644
--- a/src/backend/access/nbtree/nbtcompare.c
+++ b/src/backend/access/nbtree/nbtcompare.c
@@ -7,7 +7,7 @@
*
*
* 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
* These functions are stored in pg_amproc. For each operator class
@@ -30,81 +30,96 @@
int32
btint2cmp(int16 a, int16 b)
{
- return ((int32) (a - b));
+ return (int32) (a - b);
}
int32
btint4cmp(int32 a, int32 b)
{
- return (a - b);
+ return a - b;
}
int32
btint24cmp(int16 a, int32 b)
{
- return (((int32) a) - b);
+ return ((int32) a) - b;
}
int32
btint42cmp(int32 a, int16 b)
{
- return (a - ((int32) b));
+ return a - ((int32) b);
}
int32
btfloat4cmp(float32 a, float32 b)
{
if (*a > *b)
- return (1);
+ return 1;
else if (*a == *b)
- return (0);
+ return 0;
else
- return (-1);
+ return -1;
}
int32
btfloat8cmp(float64 a, float64 b)
{
if (*a > *b)
- return (1);
+ return 1;
else if (*a == *b)
- return (0);
+ return 0;
else
- return (-1);
+ return -1;
}
int32
btoidcmp(Oid a, Oid b)
{
if (a > b)
- return (1);
+ return 1;
else if (a == b)
- return (0);
+ return 0;
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
btabstimecmp(AbsoluteTime a, AbsoluteTime b)
{
if (AbsoluteTimeIsBefore(a, b))
- return (-1);
+ return -1;
else if (AbsoluteTimeIsBefore(b, a))
- return (1);
+ return 1;
else
- return (0);
+ return 0;
}
int32
btcharcmp(char a, char b)
{
- return ((int32) ((uint8) a - (uint8) b));
+ return (int32) ((uint8) a - (uint8) b);
}
int32
btnamecmp(NameData *a, NameData *b)
{
- return (strncmp(a->data, b->data, NAMEDATALEN));
+ return strncmp(a->data, b->data, NAMEDATALEN);
}
int32
@@ -162,7 +177,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
#endif
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
@@ -170,7 +185,7 @@ bttextcmp(struct varlena * a, struct varlena * b)
*/
if (VARSIZE(a) < VARSIZE(b))
- return (-1);
+ return -1;
else
- return (1);
+ return 1;
}
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index 046cce37a0c..b575476ba8a 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -7,7 +7,7 @@
*
*
* 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;
int natts = rel->rd_rel->relnatts;
InsertIndexResult res;
-
+ Buffer buffer;
+
itup = &(btitem->bti_itup);
/* 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 */
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offset));
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)
{ /* it is a duplicate */
elog(ERROR, "Cannot insert a duplicate key into a unique index");
}
+ /* htup null so no buffer to release */
/* get next offnum */
if (offset < maxoff)
offset = OffsetNumberNext(offset);
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index c30d7d56aca..406cd467735 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -8,7 +8,7 @@
*
*
* 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
* This file contains only the public interface routines.
@@ -66,7 +66,6 @@ btbuild(Relation heap,
PredInfo *predInfo)
{
HeapScanDesc hscan;
- Buffer buffer;
HeapTuple htup;
IndexTuple itup;
TupleDesc htupdesc,
@@ -113,7 +112,7 @@ btbuild(Relation heap,
#endif
/* 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) */
if (oldPred == NULL)
@@ -155,9 +154,6 @@ btbuild(Relation heap,
#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 */
nhtups = nitups = 0;
@@ -167,9 +163,10 @@ btbuild(Relation heap,
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++;
/*
@@ -228,8 +225,7 @@ btbuild(Relation heap,
attoff,
attnum,
finfo,
- &attnull,
- buffer);
+ &attnull);
nulls[attoff] = (attnull ? 'n' : ' ');
}
@@ -323,8 +319,8 @@ btbuild(Relation heap,
*/
if (IsNormalProcessingMode())
{
- hrelid = heap->rd_id;
- irelid = index->rd_id;
+ hrelid = RelationGetRelid(heap);
+ irelid = RelationGetRelid(index);
heap_close(heap);
index_close(index);
UpdateStats(hrelid, nhtups, true);
@@ -371,7 +367,7 @@ btinsert(Relation rel, Datum *datum, char *nulls, ItemPointer ht_ctid, Relation
btitem = _bt_formitem(itup);
res = _bt_doinsert(rel, btitem,
- IndexIsUnique(RelationGetRelationId(rel)), heapRel);
+ IndexIsUnique(RelationGetRelid(rel)), heapRel);
pfree(btitem);
pfree(itup);
diff --git a/src/backend/access/nbtree/nbtscan.c b/src/backend/access/nbtree/nbtscan.c
index 7aa9d2ac571..b6566e936a9 100644
--- a/src/backend/access/nbtree/nbtscan.c
+++ b/src/backend/access/nbtree/nbtscan.c
@@ -7,7 +7,7 @@
*
*
* 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
@@ -96,10 +96,10 @@ _bt_adjscans(Relation rel, ItemPointer tid, int op)
BTScanList l;
Oid relid;
- relid = rel->rd_id;
+ relid = RelationGetRelid(rel);
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,
ItemPointerGetBlockNumber(tid),
ItemPointerGetOffsetNumber(tid));
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index f4fd602898c..f8a8e860dc3 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -7,7 +7,7 @@
*
*
* 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);
flag = 0x0;
}
- ScanKeyEntryInitialize(&skey[i],
- flag, (AttrNumber) (i + 1), proc, arg);
+ ScanKeyEntryInitialize(&skey[i], flag, (AttrNumber) (i + 1), proc, arg);
}
return (skey);
diff --git a/src/backend/access/rtree/rtree.c b/src/backend/access/rtree/rtree.c
index f8ea84a6d0c..c86fec6c3a8 100644
--- a/src/backend/access/rtree/rtree.c
+++ b/src/backend/access/rtree/rtree.c
@@ -7,7 +7,7 @@
*
*
* 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)
{
HeapScanDesc scan;
- Buffer buffer;
AttrNumber i;
HeapTuple htup;
IndexTuple itup;
@@ -95,6 +94,7 @@ rtbuild(Relation heap,
InsertIndexResult res;
Datum *d;
bool *nulls;
+ Buffer buffer = InvalidBuffer;
int nb,
nh,
ni;
@@ -164,15 +164,14 @@ rtbuild(Relation heap,
slot = NULL;
}
#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 */
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++;
/*
@@ -234,8 +233,7 @@ rtbuild(Relation heap,
attoff,
attnum,
finfo,
- &attnull,
- buffer);
+ &attnull);
nulls[attoff] = (attnull ? 'n' : ' ');
}
@@ -278,8 +276,8 @@ rtbuild(Relation heap,
* flushed. We close them to guarantee that they will be.
*/
- hrelid = heap->rd_id;
- irelid = index->rd_id;
+ hrelid = RelationGetRelid(heap);
+ irelid = RelationGetRelid(index);
heap_close(heap);
index_close(index);
diff --git a/src/backend/access/rtree/rtscan.c b/src/backend/access/rtree/rtscan.c
index 672d0e2005f..2c14968d4ef 100644
--- a/src/backend/access/rtree/rtscan.c
+++ b/src/backend/access/rtree/rtscan.c
@@ -7,7 +7,7 @@
*
*
* 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;
Oid relid;
- relid = r->rd_id;
+ relid = RelationGetRelid(r);
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);
}
}