OSDN Git Service

Remove the no-longer-useful HashItem/HashItemData level of structure.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Jan 2006 23:26:11 +0000 (23:26 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 25 Jan 2006 23:26:11 +0000 (23:26 +0000)
Same motivation as for BTItem.

src/backend/access/hash/hash.c
src/backend/access/hash/hashinsert.c
src/backend/access/hash/hashovfl.c
src/backend/access/hash/hashpage.c
src/backend/access/hash/hashsearch.c
src/backend/access/hash/hashutil.c
src/include/access/hash.h

index de96523..3a01109 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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.
@@ -91,7 +91,6 @@ hashbuildCallback(Relation index,
 {
        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);
@@ -104,13 +103,10 @@ hashbuildCallback(Relation index,
                return;
        }
 
-       hitem = _hash_formitem(itup);
-
-       _hash_doinsert(index, hitem);
+       _hash_doinsert(index, itup);
 
        buildstate->indtuples += 1;
 
-       pfree(hitem);
        pfree(itup);
 }
 
@@ -132,7 +128,6 @@ hashinsert(PG_FUNCTION_ARGS)
        Relation        heapRel = (Relation) PG_GETARG_POINTER(4);
        bool            checkUnique = PG_GETARG_BOOL(5);
 #endif
-       HashItem        hitem;
        IndexTuple      itup;
 
        /* generate an index tuple */
@@ -154,11 +149,8 @@ hashinsert(PG_FUNCTION_ARGS)
                PG_RETURN_BOOL(false);
        }
 
-       hitem = _hash_formitem(itup);
-
-       _hash_doinsert(rel, hitem);
+       _hash_doinsert(rel, itup);
 
-       pfree(hitem);
        pfree(itup);
 
        PG_RETURN_BOOL(true);
@@ -565,12 +557,12 @@ loop_top:
                        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 */
index 065cbe3..e929dc6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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;
@@ -51,7 +49,6 @@ _hash_doinsert(Relation rel, HashItem hitem)
         * 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);
@@ -59,9 +56,7 @@ _hash_doinsert(Relation rel, HashItem hitem)
        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 */
 
@@ -157,7 +152,7 @@ _hash_doinsert(Relation rel, HashItem hitem)
        }
 
        /* 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);
@@ -199,7 +194,7 @@ static OffsetNumber
 _hash_pgaddtup(Relation rel,
                           Buffer buf,
                           Size itemsize,
-                          HashItem hitem)
+                          IndexTuple itup)
 {
        OffsetNumber itup_off;
        Page            page;
@@ -208,7 +203,7 @@ _hash_pgaddtup(Relation rel,
        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));
index c40973c..c9042ec 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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.
@@ -561,7 +561,7 @@ _hash_squeezebucket(Relation rel,
        HashPageOpaque ropaque;
        OffsetNumber woffnum;
        OffsetNumber roffnum;
-       HashItem        hitem;
+       IndexTuple      itup;
        Size            itemsz;
 
        /*
@@ -608,10 +608,9 @@ _hash_squeezebucket(Relation rel,
                /* 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);
 
                        /*
@@ -645,7 +644,7 @@ _hash_squeezebucket(Relation rel,
                         * 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));
index 2739bc2..adac1a3 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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
@@ -249,7 +249,7 @@ _hash_metapinit(Relation rel)
         */
        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 */
@@ -539,7 +539,6 @@ _hash_splitbucket(Relation rel,
        BlockNumber nblkno;
        bool            null;
        Datum           datum;
-       HashItem        hitem;
        HashPageOpaque oopaque;
        HashPageOpaque nopaque;
        IndexTuple      itup;
@@ -618,8 +617,7 @@ _hash_splitbucket(Relation rel,
                 * 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);
 
@@ -633,9 +631,7 @@ _hash_splitbucket(Relation rel,
                         * 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)
@@ -650,7 +646,7 @@ _hash_splitbucket(Relation rel,
                        }
 
                        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));
index dff2268..05fa683 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -37,7 +37,6 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
        Page            page;
        OffsetNumber offnum;
        ItemPointer current;
-       HashItem        hitem;
        IndexTuple      itup;
 
        /* we still have the buffer pinned and read-locked */
@@ -55,8 +54,7 @@ _hash_next(IndexScanDesc scan, ScanDirection dir)
        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;
@@ -126,7 +124,6 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
        Page            page;
        HashPageOpaque opaque;
        HashMetaPage metap;
-       HashItem        hitem;
        IndexTuple      itup;
        ItemPointer current;
        OffsetNumber offnum;
@@ -218,8 +215,7 @@ _hash_first(IndexScanDesc scan, ScanDirection dir)
        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;
@@ -248,7 +244,6 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
        OffsetNumber maxoff;
        OffsetNumber offnum;
        BlockNumber blkno;
-       HashItem        hitem;
        IndexTuple      itup;
 
        current = &(scan->currentItemData);
@@ -345,8 +340,7 @@ _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
                }
 
                /* 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 */
index 25defa9..cadbf8e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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 $
  *
  *-------------------------------------------------------------------------
  */
@@ -61,38 +61,6 @@ _hash_checkqual(IndexScanDesc scan, IndexTuple itup)
 }
 
 /*
- * _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
  */
 uint32
index f56b609..636dc9c 100644 (file)
@@ -7,7 +7,7 @@
  * 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.
@@ -158,13 +158,6 @@ typedef struct HashMetaPageData
 
 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)
  */
@@ -267,7 +260,7 @@ extern Datum hash_any(register const unsigned char *k, register int keylen);
 /* 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);
@@ -305,7 +298,6 @@ extern bool _hash_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir);
 
 /* 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);