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

Restructure indexscan API (index_beginscan, index_getnext) per

yesterday's proposal to pghackers.  Also remove unnecessary parameters
to heap_beginscan, heap_rescan.  I modified pg_proc.h to reflect the
new numbers of parameters for the AM interface routines, but did not
force an initdb because nothing actually looks at those fields.
This commit is contained in:
Tom Lane
2002-05-20 23:51:44 +00:00
parent c961474c96
commit 44fbe20d62
59 changed files with 834 additions and 1283 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.56 2002/03/09 17:35:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.57 2002/05/20 23:51:41 tgl Exp $
*
* NOTES
* This file contains only the public interface routines.
@@ -210,7 +210,7 @@ hashgettuple(PG_FUNCTION_ARGS)
{
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
RetrieveIndexResult res;
bool res;
/*
* If we've already initialized this scan, we can just advance it in
@@ -223,7 +223,7 @@ hashgettuple(PG_FUNCTION_ARGS)
else
res = _hash_first(scan, dir);
PG_RETURN_POINTER(res);
PG_RETURN_BOOL(res);
}
@@ -234,17 +234,15 @@ Datum
hashbeginscan(PG_FUNCTION_ARGS)
{
Relation rel = (Relation) PG_GETARG_POINTER(0);
bool fromEnd = PG_GETARG_BOOL(1);
uint16 keysz = PG_GETARG_UINT16(2);
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(3);
int keysz = PG_GETARG_INT32(1);
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(2);
IndexScanDesc scan;
HashScanOpaque so;
scan = RelationGetIndexScan(rel, fromEnd, keysz, scankey);
scan = RelationGetIndexScan(rel, keysz, scankey);
so = (HashScanOpaque) palloc(sizeof(HashScanOpaqueData));
so->hashso_curbuf = so->hashso_mrkbuf = InvalidBuffer;
scan->opaque = so;
scan->flags = 0x0;
/* register scan in case we change pages it's using */
_hash_regscan(scan);
@@ -259,11 +257,7 @@ Datum
hashrescan(PG_FUNCTION_ARGS)
{
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
#ifdef NOT_USED /* XXX surely it's wrong to ignore this? */
bool fromEnd = PG_GETARG_BOOL(1);
#endif
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(2);
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(1);
ItemPointer iptr;
HashScanOpaque so;
@@ -272,13 +266,13 @@ hashrescan(PG_FUNCTION_ARGS)
/* we hold a read lock on the current page in the scan */
if (ItemPointerIsValid(iptr = &(scan->currentItemData)))
{
_hash_relbuf(scan->relation, so->hashso_curbuf, HASH_READ);
_hash_relbuf(scan->indexRelation, so->hashso_curbuf, HASH_READ);
so->hashso_curbuf = InvalidBuffer;
ItemPointerSetInvalid(iptr);
}
if (ItemPointerIsValid(iptr = &(scan->currentMarkData)))
{
_hash_relbuf(scan->relation, so->hashso_mrkbuf, HASH_READ);
_hash_relbuf(scan->indexRelation, so->hashso_mrkbuf, HASH_READ);
so->hashso_mrkbuf = InvalidBuffer;
ItemPointerSetInvalid(iptr);
}
@@ -309,7 +303,7 @@ hashendscan(PG_FUNCTION_ARGS)
/* release any locks we still hold */
if (ItemPointerIsValid(iptr = &(scan->currentItemData)))
{
_hash_relbuf(scan->relation, so->hashso_curbuf, HASH_READ);
_hash_relbuf(scan->indexRelation, so->hashso_curbuf, HASH_READ);
so->hashso_curbuf = InvalidBuffer;
ItemPointerSetInvalid(iptr);
}
@@ -317,7 +311,7 @@ hashendscan(PG_FUNCTION_ARGS)
if (ItemPointerIsValid(iptr = &(scan->currentMarkData)))
{
if (BufferIsValid(so->hashso_mrkbuf))
_hash_relbuf(scan->relation, so->hashso_mrkbuf, HASH_READ);
_hash_relbuf(scan->indexRelation, so->hashso_mrkbuf, HASH_READ);
so->hashso_mrkbuf = InvalidBuffer;
ItemPointerSetInvalid(iptr);
}
@@ -346,7 +340,7 @@ hashmarkpos(PG_FUNCTION_ARGS)
/* release lock on old marked data, if any */
if (ItemPointerIsValid(iptr = &(scan->currentMarkData)))
{
_hash_relbuf(scan->relation, so->hashso_mrkbuf, HASH_READ);
_hash_relbuf(scan->indexRelation, so->hashso_mrkbuf, HASH_READ);
so->hashso_mrkbuf = InvalidBuffer;
ItemPointerSetInvalid(iptr);
}
@@ -354,7 +348,7 @@ hashmarkpos(PG_FUNCTION_ARGS)
/* bump lock on currentItemData and copy to currentMarkData */
if (ItemPointerIsValid(&(scan->currentItemData)))
{
so->hashso_mrkbuf = _hash_getbuf(scan->relation,
so->hashso_mrkbuf = _hash_getbuf(scan->indexRelation,
BufferGetBlockNumber(so->hashso_curbuf),
HASH_READ);
scan->currentMarkData = scan->currentItemData;
@@ -378,7 +372,7 @@ hashrestrpos(PG_FUNCTION_ARGS)
/* release lock on current data, if any */
if (ItemPointerIsValid(iptr = &(scan->currentItemData)))
{
_hash_relbuf(scan->relation, so->hashso_curbuf, HASH_READ);
_hash_relbuf(scan->indexRelation, so->hashso_curbuf, HASH_READ);
so->hashso_curbuf = InvalidBuffer;
ItemPointerSetInvalid(iptr);
}
@@ -386,7 +380,7 @@ hashrestrpos(PG_FUNCTION_ARGS)
/* bump lock on currentMarkData and copy to currentItemData */
if (ItemPointerIsValid(&(scan->currentMarkData)))
{
so->hashso_curbuf = _hash_getbuf(scan->relation,
so->hashso_curbuf = _hash_getbuf(scan->indexRelation,
BufferGetBlockNumber(so->hashso_mrkbuf),
HASH_READ);
@@ -413,7 +407,6 @@ hashbulkdelete(PG_FUNCTION_ARGS)
BlockNumber num_pages;
double tuples_removed;
double num_index_tuples;
RetrieveIndexResult res;
IndexScanDesc iscan;
tuples_removed = 0;
@@ -424,30 +417,25 @@ hashbulkdelete(PG_FUNCTION_ARGS)
*/
/* walk through the entire index */
iscan = index_beginscan(rel, false, 0, (ScanKey) NULL);
iscan = index_beginscan(NULL, rel, SnapshotAny, 0, (ScanKey) NULL);
while ((res = index_getnext(iscan, ForwardScanDirection))
!= (RetrieveIndexResult) NULL)
while (index_getnext_indexitem(iscan, ForwardScanDirection))
{
ItemPointer heapptr = &res->heap_iptr;
if (callback(heapptr, callback_state))
if (callback(&iscan->xs_ctup.t_self, callback_state))
{
ItemPointer indexptr = &res->index_iptr;
ItemPointerData indextup = iscan->currentItemData;
/* adjust any active scans that will be affected by deletion */
/* (namely, my own scan) */
_hash_adjscans(rel, indexptr);
_hash_adjscans(rel, &indextup);
/* delete the data from the page */
_hash_pagedel(rel, indexptr);
_hash_pagedel(rel, &indextup);
tuples_removed += 1;
}
else
num_index_tuples += 1;
pfree(res);
}
index_endscan(iscan);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashscan.c,v 1.25 2001/07/15 22:48:15 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashscan.c,v 1.26 2002/05/20 23:51:41 tgl Exp $
*
* NOTES
* Because we can be doing an index scan on a relation while we
@@ -119,7 +119,7 @@ _hash_adjscans(Relation rel, ItemPointer tid)
relid = RelationGetRelid(rel);
for (l = HashScans; l != (HashScanList) NULL; l = l->hashsl_next)
{
if (relid == l->hashsl_scan->relation->rd_id)
if (relid == l->hashsl_scan->indexRelation->rd_id)
_hash_scandel(l->hashsl_scan, ItemPointerGetBlockNumber(tid),
ItemPointerGetOffsetNumber(tid));
}
@@ -136,7 +136,7 @@ _hash_scandel(IndexScanDesc scan, BlockNumber blkno, OffsetNumber offno)
if (!_hash_scantouched(scan, blkno, offno))
return;
metabuf = _hash_getbuf(scan->relation, HASH_METAPAGE, HASH_READ);
metabuf = _hash_getbuf(scan->indexRelation, HASH_METAPAGE, HASH_READ);
so = (HashScanOpaque) scan->opaque;
buf = so->hashso_curbuf;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashsearch.c,v 1.27 2001/10/25 05:49:21 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashsearch.c,v 1.28 2002/05/20 23:51:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -59,7 +59,7 @@ _hash_search(Relation rel,
* exit, we have the page containing the next item locked but not
* pinned.
*/
RetrieveIndexResult
bool
_hash_next(IndexScanDesc scan, ScanDirection dir)
{
Relation rel;
@@ -67,13 +67,12 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
Buffer metabuf;
Page page;
OffsetNumber offnum;
RetrieveIndexResult res;
ItemPointer current;
HashItem hitem;
IndexTuple itup;
HashScanOpaque so;
rel = scan->relation;
rel = scan->indexRelation;
so = (HashScanOpaque) scan->opaque;
current = &(scan->currentItemData);
@@ -101,7 +100,7 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
* next tuple, we come back with a lock on that buffer.
*/
if (!_hash_step(scan, &buf, dir, metabuf))
return (RetrieveIndexResult) NULL;
return false;
/* if we're here, _hash_step found a valid tuple */
current = &(scan->currentItemData);
@@ -110,9 +109,9 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
_hash_checkpage(page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
hitem = (HashItem) PageGetItem(page, PageGetItemId(page, offnum));
itup = &hitem->hash_itup;
res = FormRetrieveIndexResult(current, &(itup->t_tid));
scan->xs_ctup.t_self = itup->t_tid;
return res;
return true;
}
static void
@@ -161,13 +160,13 @@ _hash_readprev(Relation rel,
/*
* _hash_first() -- Find the first item in a scan.
*
* Return the RetrieveIndexResult of the first item in the tree that
* satisfies the qualificatin associated with the scan descriptor. On
* Find the first item in the tree that
* satisfies the qualification associated with the scan descriptor. On
* exit, the page containing the current index tuple is read locked
* and pinned, and the scan's opaque data entry is updated to
* include the buffer.
*/
RetrieveIndexResult
bool
_hash_first(IndexScanDesc scan, ScanDirection dir)
{
Relation rel;
@@ -180,10 +179,9 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
IndexTuple itup;
ItemPointer current;
OffsetNumber offnum;
RetrieveIndexResult res;
HashScanOpaque so;
rel = scan->relation;
rel = scan->indexRelation;
so = (HashScanOpaque) scan->opaque;
current = &(scan->currentItemData);
@@ -230,7 +228,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
{
_hash_relbuf(rel, buf, HASH_READ);
_hash_relbuf(rel, metabuf, HASH_READ);
return (RetrieveIndexResult) NULL;
return false;
}
}
}
@@ -241,7 +239,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
}
if (!_hash_step(scan, &buf, dir, metabuf))
return (RetrieveIndexResult) NULL;
return false;
/* if we're here, _hash_step found a valid tuple */
current = &(scan->currentItemData);
@@ -250,9 +248,9 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
_hash_checkpage(page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
hitem = (HashItem) PageGetItem(page, PageGetItemId(page, offnum));
itup = &hitem->hash_itup;
res = FormRetrieveIndexResult(current, &(itup->t_tid));
scan->xs_ctup.t_self = itup->t_tid;
return res;
return true;
}
/*
@@ -285,7 +283,7 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir, Buffer metabuf)
HashItem hitem;
IndexTuple itup;
rel = scan->relation;
rel = scan->indexRelation;
current = &(scan->currentItemData);
so = (HashScanOpaque) scan->opaque;
allbuckets = (scan->numberOfKeys < 1);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashutil.c,v 1.28 2002/03/06 20:49:43 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashutil.c,v 1.29 2002/05/20 23:51:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -63,7 +63,7 @@ _hash_checkqual(IndexScanDesc scan, IndexTuple itup)
{
if (scan->numberOfKeys > 0)
return (index_keytest(itup,
RelationGetDescr(scan->relation),
RelationGetDescr(scan->indexRelation),
scan->numberOfKeys, scan->keyData));
else
return true;