Same motivation as for BTItem.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.82 2005/11/06 19:29:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.83 2006/01/25 23:26:11 tgl Exp $
*
* NOTES
* This file contains only the public interface routines.
{
HashBuildState *buildstate = (HashBuildState *) state;
IndexTuple itup;
- HashItem hitem;
/* form an index tuple and point it at the heap tuple */
itup = index_form_tuple(RelationGetDescr(index), values, isnull);
return;
}
- hitem = _hash_formitem(itup);
-
- _hash_doinsert(index, hitem);
+ _hash_doinsert(index, itup);
buildstate->indtuples += 1;
- pfree(hitem);
pfree(itup);
}
Relation heapRel = (Relation) PG_GETARG_POINTER(4);
bool checkUnique = PG_GETARG_BOOL(5);
#endif
- HashItem hitem;
IndexTuple itup;
/* generate an index tuple */
PG_RETURN_BOOL(false);
}
- hitem = _hash_formitem(itup);
-
- _hash_doinsert(rel, hitem);
+ _hash_doinsert(rel, itup);
- pfree(hitem);
pfree(itup);
PG_RETURN_BOOL(true);
maxoffno = PageGetMaxOffsetNumber(page);
while (offno <= maxoffno)
{
- HashItem hitem;
+ IndexTuple itup;
ItemPointer htup;
- hitem = (HashItem) PageGetItem(page,
- PageGetItemId(page, offno));
- htup = &(hitem->hash_itup.t_tid);
+ itup = (IndexTuple) PageGetItem(page,
+ PageGetItemId(page, offno));
+ htup = &(itup->t_tid);
if (callback(htup, callback_state))
{
/* delete the item from the page */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hashinsert.c,v 1.40 2005/11/06 19:29:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hashinsert.c,v 1.41 2006/01/25 23:26:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static OffsetNumber _hash_pgaddtup(Relation rel, Buffer buf,
- Size itemsize, HashItem hitem);
+ Size itemsize, IndexTuple itup);
/*
- * _hash_doinsert() -- Handle insertion of a single HashItem in the table.
+ * _hash_doinsert() -- Handle insertion of a single index tuple.
*
* This routine is called by the public interface routines, hashbuild
- * and hashinsert. By here, hashitem is completely filled in.
- * The datum to be used as a "key" is in the hashitem.
+ * and hashinsert. By here, itup is completely filled in.
*/
void
-_hash_doinsert(Relation rel, HashItem hitem)
+_hash_doinsert(Relation rel, IndexTuple itup)
{
Buffer buf;
Buffer metabuf;
HashMetaPage metap;
- IndexTuple itup;
BlockNumber blkno;
Page page;
HashPageOpaque pageopaque;
* Compute the hash key for the item. We do this first so as not to need
* to hold any locks while running the hash function.
*/
- itup = &(hitem->hash_itup);
if (rel->rd_rel->relnatts != 1)
elog(ERROR, "hash indexes support only one index key");
datum = index_getattr(itup, 1, RelationGetDescr(rel), &isnull);
hashkey = _hash_datum2hashkey(rel, datum);
/* compute item size too */
- itemsz = IndexTupleDSize(hitem->hash_itup)
- + (sizeof(HashItemData) - sizeof(IndexTupleData));
-
+ itemsz = IndexTupleDSize(*itup);
itemsz = MAXALIGN(itemsz); /* be safe, PageAddItem will do this but we
* need to be consistent */
}
/* found page with enough space, so add the item here */
- (void) _hash_pgaddtup(rel, buf, itemsz, hitem);
+ (void) _hash_pgaddtup(rel, buf, itemsz, itup);
/* write and release the modified page */
_hash_wrtbuf(rel, buf);
_hash_pgaddtup(Relation rel,
Buffer buf,
Size itemsize,
- HashItem hitem)
+ IndexTuple itup)
{
OffsetNumber itup_off;
Page page;
page = BufferGetPage(buf);
itup_off = OffsetNumberNext(PageGetMaxOffsetNumber(page));
- if (PageAddItem(page, (Item) hitem, itemsize, itup_off, LP_USED)
+ if (PageAddItem(page, (Item) itup, itemsize, itup_off, LP_USED)
== InvalidOffsetNumber)
elog(ERROR, "failed to add index item to \"%s\"",
RelationGetRelationName(rel));
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.49 2005/11/22 18:17:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hashovfl.c,v 1.50 2006/01/25 23:26:11 tgl Exp $
*
* NOTES
* Overflow pages look like ordinary relation pages.
HashPageOpaque ropaque;
OffsetNumber woffnum;
OffsetNumber roffnum;
- HashItem hitem;
+ IndexTuple itup;
Size itemsz;
/*
/* this test is needed in case page is empty on entry */
if (roffnum <= PageGetMaxOffsetNumber(rpage))
{
- hitem = (HashItem) PageGetItem(rpage,
- PageGetItemId(rpage, roffnum));
- itemsz = IndexTupleDSize(hitem->hash_itup)
- + (sizeof(HashItemData) - sizeof(IndexTupleData));
+ itup = (IndexTuple) PageGetItem(rpage,
+ PageGetItemId(rpage, roffnum));
+ itemsz = IndexTupleDSize(*itup);
itemsz = MAXALIGN(itemsz);
/*
* we have found room so insert on the "write" page.
*/
woffnum = OffsetNumberNext(PageGetMaxOffsetNumber(wpage));
- if (PageAddItem(wpage, (Item) hitem, itemsz, woffnum, LP_USED)
+ if (PageAddItem(wpage, (Item) itup, itemsz, woffnum, LP_USED)
== InvalidOffsetNumber)
elog(ERROR, "failed to add index item to \"%s\"",
RelationGetRelationName(rel));
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.54 2005/11/22 18:17:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hashpage.c,v 1.55 2006/01/25 23:26:11 tgl Exp $
*
* NOTES
* Postgres hash pages look like ordinary relation pages. The opaque
*/
data_width = get_typavgwidth(RelationGetDescr(rel)->attrs[0]->atttypid,
RelationGetDescr(rel)->attrs[0]->atttypmod);
- item_width = MAXALIGN(sizeof(HashItemData)) + MAXALIGN(data_width) +
+ item_width = MAXALIGN(sizeof(IndexTupleData)) + MAXALIGN(data_width) +
sizeof(ItemIdData); /* include the line pointer */
ffactor = (BLCKSZ * 3 / 4) / item_width;
/* keep to a sane range */
BlockNumber nblkno;
bool null;
Datum datum;
- HashItem hitem;
HashPageOpaque oopaque;
HashPageOpaque nopaque;
IndexTuple itup;
* It is annoying to call the hash function while holding locks, but
* releasing and relocking the page for each tuple is unappealing too.
*/
- hitem = (HashItem) PageGetItem(opage, PageGetItemId(opage, ooffnum));
- itup = &(hitem->hash_itup);
+ itup = (IndexTuple) PageGetItem(opage, PageGetItemId(opage, ooffnum));
datum = index_getattr(itup, 1, itupdesc, &null);
Assert(!null);
* current page in the new bucket, we must allocate a new overflow
* page and place the tuple on that page instead.
*/
- itemsz = IndexTupleDSize(hitem->hash_itup)
- + (sizeof(HashItemData) - sizeof(IndexTupleData));
-
+ itemsz = IndexTupleDSize(*itup);
itemsz = MAXALIGN(itemsz);
if (PageGetFreeSpace(npage) < itemsz)
}
noffnum = OffsetNumberNext(PageGetMaxOffsetNumber(npage));
- if (PageAddItem(npage, (Item) hitem, itemsz, noffnum, LP_USED)
+ if (PageAddItem(npage, (Item) itup, itemsz, noffnum, LP_USED)
== InvalidOffsetNumber)
elog(ERROR, "failed to add index item to \"%s\"",
RelationGetRelationName(rel));
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.42 2005/11/06 19:29:00 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hashsearch.c,v 1.43 2006/01/25 23:26:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Page page;
OffsetNumber offnum;
ItemPointer current;
- HashItem hitem;
IndexTuple itup;
/* we still have the buffer pinned and read-locked */
offnum = ItemPointerGetOffsetNumber(current);
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
- hitem = (HashItem) PageGetItem(page, PageGetItemId(page, offnum));
- itup = &hitem->hash_itup;
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
scan->xs_ctup.t_self = itup->t_tid;
return true;
Page page;
HashPageOpaque opaque;
HashMetaPage metap;
- HashItem hitem;
IndexTuple itup;
ItemPointer current;
OffsetNumber offnum;
offnum = ItemPointerGetOffsetNumber(current);
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
page = BufferGetPage(buf);
- hitem = (HashItem) PageGetItem(page, PageGetItemId(page, offnum));
- itup = &hitem->hash_itup;
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
scan->xs_ctup.t_self = itup->t_tid;
return true;
OffsetNumber maxoff;
OffsetNumber offnum;
BlockNumber blkno;
- HashItem hitem;
IndexTuple itup;
current = &(scan->currentItemData);
}
/* get ready to check this tuple */
- hitem = (HashItem) PageGetItem(page, PageGetItemId(page, offnum));
- itup = &hitem->hash_itup;
+ itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));
} while (!_hash_checkqual(scan, itup));
/* if we made it to here, we've found a valid tuple */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/hash/hashutil.c,v 1.45 2006/01/14 22:03:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/hash/hashutil.c,v 1.46 2006/01/25 23:26:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return true;
}
-/*
- * _hash_formitem -- construct a hash index entry
- */
-HashItem
-_hash_formitem(IndexTuple itup)
-{
- int nbytes_hitem;
- HashItem hitem;
- Size tuplen;
-
- /* disallow nulls in hash keys */
- if (IndexTupleHasNulls(itup))
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("hash indexes cannot contain null keys")));
-
- /*
- * make a copy of the index tuple (XXX do we still need to copy?)
- *
- * HashItemData used to have more fields than IndexTupleData, but no
- * longer...
- */
- tuplen = IndexTupleSize(itup);
- nbytes_hitem = tuplen +
- (sizeof(HashItemData) - sizeof(IndexTupleData));
-
- hitem = (HashItem) palloc(nbytes_hitem);
- memcpy(&(hitem->hash_itup), itup, tuplen);
-
- return hitem;
-}
-
/*
* _hash_datum2hashkey -- given a Datum, call the index's hash procedure
*/
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/hash.h,v 1.64 2005/11/06 19:29:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/hash.h,v 1.65 2006/01/25 23:26:11 tgl Exp $
*
* NOTES
* modeled after Margo Seltzer's hash implementation for unix.
typedef HashMetaPageData *HashMetaPage;
-typedef struct HashItemData
-{
- IndexTupleData hash_itup;
-} HashItemData;
-
-typedef HashItemData *HashItem;
-
/*
* Maximum size of a hash index item (it's okay to have only one per page)
*/
/* private routines */
/* hashinsert.c */
-extern void _hash_doinsert(Relation rel, HashItem hitem);
+extern void _hash_doinsert(Relation rel, IndexTuple itup);
/* hashovfl.c */
extern Buffer _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf);
/* hashutil.c */
extern bool _hash_checkqual(IndexScanDesc scan, IndexTuple itup);
-extern HashItem _hash_formitem(IndexTuple itup);
extern uint32 _hash_datum2hashkey(Relation rel, Datum key);
extern Bucket _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket,
uint32 highmask, uint32 lowmask);