Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d70610c

Browse files
committed
Several fixes for hash indexes that involve changing the on-disk index
layout; therefore, this change forces REINDEX of hash indexes (though not a full initdb). Widen hashm_ntuples to double so that hash space management doesn't get confused by more than 4G entries; enlarge the allowed number of free-space-bitmap pages; replace the useless bshift field with a useful bmshift field; eliminate 4 bytes of wasted space in the per-page special area.
1 parent 8b2450c commit d70610c

File tree

7 files changed

+130
-151
lines changed

7 files changed

+130
-151
lines changed

src/backend/access/hash/hash.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.66 2003/09/02 02:18:38 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.67 2003/09/02 18:13:29 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -449,25 +449,16 @@ hashbulkdelete(PG_FUNCTION_ARGS)
449449
BlockNumber num_pages;
450450
double tuples_removed;
451451
double num_index_tuples;
452-
uint32 deleted_tuples;
453-
uint32 tuples_remaining;
454-
uint32 orig_ntuples;
452+
double orig_ntuples;
455453
Bucket orig_maxbucket;
456454
Bucket cur_maxbucket;
457455
Bucket cur_bucket;
458456
Buffer metabuf;
459457
HashMetaPage metap;
460458
HashMetaPageData local_metapage;
461459

462-
/*
463-
* keep track of counts in both float form (to return) and integer form
464-
* (to update hashm_ntuples). It'd be better to make hashm_ntuples a
465-
* double, but that will have to wait for an initdb.
466-
*/
467460
tuples_removed = 0;
468461
num_index_tuples = 0;
469-
deleted_tuples = 0;
470-
tuples_remaining = 0;
471462

472463
/*
473464
* Read the metapage to fetch original bucket and tuple counts. Also,
@@ -479,7 +470,7 @@ hashbulkdelete(PG_FUNCTION_ARGS)
479470
*/
480471
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ);
481472
metap = (HashMetaPage) BufferGetPage(metabuf);
482-
_hash_checkpage((Page) metap, LH_META_PAGE);
473+
_hash_checkpage(rel, (Page) metap, LH_META_PAGE);
483474
orig_maxbucket = metap->hashm_maxbucket;
484475
orig_ntuples = metap->hashm_ntuples;
485476
memcpy(&local_metapage, metap, sizeof(local_metapage));
@@ -514,7 +505,7 @@ hashbulkdelete(PG_FUNCTION_ARGS)
514505

515506
buf = _hash_getbuf(rel, blkno, HASH_WRITE);
516507
page = BufferGetPage(buf);
517-
_hash_checkpage(page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
508+
_hash_checkpage(rel, page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
518509
opaque = (HashPageOpaque) PageGetSpecialPointer(page);
519510
Assert(opaque->hasho_bucket == cur_bucket);
520511

@@ -546,14 +537,12 @@ hashbulkdelete(PG_FUNCTION_ARGS)
546537
maxoffno = OffsetNumberPrev(maxoffno);
547538

548539
tuples_removed += 1;
549-
deleted_tuples += 1;
550540
}
551541
else
552542
{
553543
offno = OffsetNumberNext(offno);
554544

555545
num_index_tuples += 1;
556-
tuples_remaining += 1;
557546
}
558547
}
559548

@@ -584,7 +573,7 @@ hashbulkdelete(PG_FUNCTION_ARGS)
584573
/* Write-lock metapage and check for split since we started */
585574
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_WRITE);
586575
metap = (HashMetaPage) BufferGetPage(metabuf);
587-
_hash_checkpage((Page) metap, LH_META_PAGE);
576+
_hash_checkpage(rel, (Page) metap, LH_META_PAGE);
588577

589578
if (cur_maxbucket != metap->hashm_maxbucket)
590579
{
@@ -604,7 +593,7 @@ hashbulkdelete(PG_FUNCTION_ARGS)
604593
* No one has split or inserted anything since start of scan,
605594
* so believe our count as gospel.
606595
*/
607-
metap->hashm_ntuples = tuples_remaining;
596+
metap->hashm_ntuples = num_index_tuples;
608597
}
609598
else
610599
{
@@ -613,8 +602,8 @@ hashbulkdelete(PG_FUNCTION_ARGS)
613602
* double-scanned tuples in split buckets. Proceed by
614603
* dead-reckoning.
615604
*/
616-
if (metap->hashm_ntuples > deleted_tuples)
617-
metap->hashm_ntuples -= deleted_tuples;
605+
if (metap->hashm_ntuples > tuples_removed)
606+
metap->hashm_ntuples -= tuples_removed;
618607
else
619608
metap->hashm_ntuples = 0;
620609
num_index_tuples = metap->hashm_ntuples;

src/backend/access/hash/hashinsert.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashinsert.c,v 1.28 2003/09/01 20:26:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashinsert.c,v 1.29 2003/09/02 18:13:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -43,7 +43,7 @@ _hash_doinsert(Relation rel, HashItem hitem)
4343

4444
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ);
4545
metap = (HashMetaPage) BufferGetPage(metabuf);
46-
_hash_checkpage((Page) metap, LH_META_PAGE);
46+
_hash_checkpage(rel, (Page) metap, LH_META_PAGE);
4747

4848
/* we need a scan key to do our search, so build one */
4949
itup = &(hitem->hash_itup);
@@ -57,7 +57,7 @@ _hash_doinsert(Relation rel, HashItem hitem)
5757
*/
5858
_hash_search(rel, natts, itup_scankey, &buf, metap);
5959
page = BufferGetPage(buf);
60-
_hash_checkpage(page, LH_BUCKET_PAGE);
60+
_hash_checkpage(rel, page, LH_BUCKET_PAGE);
6161

6262
/*
6363
* trade in our read lock for a write lock so that we can do the
@@ -120,10 +120,10 @@ _hash_insertonpg(Relation rel,
120120
Bucket bucket;
121121

122122
metap = (HashMetaPage) BufferGetPage(metabuf);
123-
_hash_checkpage((Page) metap, LH_META_PAGE);
123+
_hash_checkpage(rel, (Page) metap, LH_META_PAGE);
124124

125125
page = BufferGetPage(buf);
126-
_hash_checkpage(page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
126+
_hash_checkpage(rel, page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
127127
pageopaque = (HashPageOpaque) PageGetSpecialPointer(page);
128128
bucket = pageopaque->hasho_bucket;
129129

@@ -166,7 +166,7 @@ _hash_insertonpg(Relation rel,
166166
elog(ERROR, "hash item too large");
167167
}
168168
}
169-
_hash_checkpage(page, LH_OVERFLOW_PAGE);
169+
_hash_checkpage(rel, page, LH_OVERFLOW_PAGE);
170170
pageopaque = (HashPageOpaque) PageGetSpecialPointer(page);
171171
Assert(pageopaque->hasho_bucket == bucket);
172172
}
@@ -195,7 +195,7 @@ _hash_insertonpg(Relation rel,
195195

196196
if (do_expand ||
197197
(metap->hashm_ntuples / (metap->hashm_maxbucket + 1))
198-
> metap->hashm_ffactor)
198+
> (double) metap->hashm_ffactor)
199199
_hash_expandtable(rel, metabuf);
200200
_hash_relbuf(rel, metabuf, HASH_READ);
201201
return res;
@@ -220,7 +220,7 @@ _hash_pgaddtup(Relation rel,
220220
Page page;
221221

222222
page = BufferGetPage(buf);
223-
_hash_checkpage(page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
223+
_hash_checkpage(rel, page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
224224

225225
itup_off = OffsetNumberNext(PageGetMaxOffsetNumber(page));
226226
if (PageAddItem(page, (Item) hitem, itemsize, itup_off, LP_USED)

src/backend/access/hash/hashovfl.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashovfl.c,v 1.39 2003/09/02 02:18:38 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashovfl.c,v 1.40 2003/09/02 18:13:30 tgl Exp $
1212
*
1313
* NOTES
1414
* Overflow pages look like ordinary relation pages.
@@ -97,12 +97,12 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf)
9797

9898
/* this had better be the last page in a bucket chain */
9999
page = BufferGetPage(buf);
100-
_hash_checkpage(page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
100+
_hash_checkpage(rel, page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
101101
pageopaque = (HashPageOpaque) PageGetSpecialPointer(page);
102102
Assert(!BlockNumberIsValid(pageopaque->hasho_nextblkno));
103103

104104
metap = (HashMetaPage) BufferGetPage(metabuf);
105-
_hash_checkpage((Page) metap, LH_META_PAGE);
105+
_hash_checkpage(rel, (Page) metap, LH_META_PAGE);
106106

107107
/* allocate an empty overflow page */
108108
ovflblkno = _hash_getovflpage(rel, metabuf);
@@ -114,9 +114,9 @@ _hash_addovflpage(Relation rel, Buffer metabuf, Buffer buf)
114114
ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage);
115115
ovflopaque->hasho_prevblkno = BufferGetBlockNumber(buf);
116116
ovflopaque->hasho_nextblkno = InvalidBlockNumber;
117-
ovflopaque->hasho_flag = LH_OVERFLOW_PAGE;
118-
ovflopaque->hasho_oaddr = 0;
119117
ovflopaque->hasho_bucket = pageopaque->hasho_bucket;
118+
ovflopaque->hasho_flag = LH_OVERFLOW_PAGE;
119+
ovflopaque->hasho_filler = HASHO_FILL;
120120
_hash_wrtnorelbuf(ovflbuf);
121121

122122
/* logically chain overflow page to previous page */
@@ -174,7 +174,7 @@ _hash_getovflpage(Relation rel, Buffer metabuf)
174174
mapblkno = metap->hashm_mapp[i];
175175
mapbuf = _hash_getbuf(rel, mapblkno, HASH_WRITE);
176176
mappage = BufferGetPage(mapbuf);
177-
_hash_checkpage(mappage, LH_BITMAP_PAGE);
177+
_hash_checkpage(rel, mappage, LH_BITMAP_PAGE);
178178
freep = HashPageGetBitmap(mappage);
179179

180180
if (i != first_page)
@@ -310,11 +310,11 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf)
310310

311311
metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_WRITE);
312312
metap = (HashMetaPage) BufferGetPage(metabuf);
313-
_hash_checkpage((Page) metap, LH_META_PAGE);
313+
_hash_checkpage(rel, (Page) metap, LH_META_PAGE);
314314

315315
ovflblkno = BufferGetBlockNumber(ovflbuf);
316316
ovflpage = BufferGetPage(ovflbuf);
317-
_hash_checkpage(ovflpage, LH_OVERFLOW_PAGE);
317+
_hash_checkpage(rel, ovflpage, LH_OVERFLOW_PAGE);
318318
ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage);
319319
nextblkno = ovflopaque->hasho_nextblkno;
320320
prevblkno = ovflopaque->hasho_prevblkno;
@@ -337,7 +337,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf)
337337
Page prevpage = BufferGetPage(prevbuf);
338338
HashPageOpaque prevopaque = (HashPageOpaque) PageGetSpecialPointer(prevpage);
339339

340-
_hash_checkpage(prevpage, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
340+
_hash_checkpage(rel, prevpage, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
341341
Assert(prevopaque->hasho_bucket == bucket);
342342
prevopaque->hasho_nextblkno = nextblkno;
343343
_hash_wrtbuf(rel, prevbuf);
@@ -348,7 +348,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf)
348348
Page nextpage = BufferGetPage(nextbuf);
349349
HashPageOpaque nextopaque = (HashPageOpaque) PageGetSpecialPointer(nextpage);
350350

351-
_hash_checkpage(nextpage, LH_OVERFLOW_PAGE);
351+
_hash_checkpage(rel, nextpage, LH_OVERFLOW_PAGE);
352352
Assert(nextopaque->hasho_bucket == bucket);
353353
nextopaque->hasho_prevblkno = prevblkno;
354354
_hash_wrtbuf(rel, nextbuf);
@@ -368,7 +368,7 @@ _hash_freeovflpage(Relation rel, Buffer ovflbuf)
368368

369369
mapbuf = _hash_getbuf(rel, blkno, HASH_WRITE);
370370
mappage = BufferGetPage(mapbuf);
371-
_hash_checkpage(mappage, LH_BITMAP_PAGE);
371+
_hash_checkpage(rel, mappage, LH_BITMAP_PAGE);
372372
freep = HashPageGetBitmap(mappage);
373373
CLRBIT(freep, bitmapbit);
374374
_hash_wrtbuf(rel, mapbuf);
@@ -406,11 +406,11 @@ _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno)
406406
pg = BufferGetPage(buf);
407407
_hash_pageinit(pg, BufferGetPageSize(buf));
408408
op = (HashPageOpaque) PageGetSpecialPointer(pg);
409-
op->hasho_oaddr = 0;
410409
op->hasho_prevblkno = InvalidBlockNumber;
411410
op->hasho_nextblkno = InvalidBlockNumber;
412-
op->hasho_flag = LH_BITMAP_PAGE;
413411
op->hasho_bucket = -1;
412+
op->hasho_flag = LH_BITMAP_PAGE;
413+
op->hasho_filler = HASHO_FILL;
414414

415415
/* set all of the bits to 1 */
416416
freep = HashPageGetBitmap(pg);
@@ -471,7 +471,7 @@ _hash_squeezebucket(Relation rel,
471471
wblkno = bucket_blkno;
472472
wbuf = _hash_getbuf(rel, wblkno, HASH_WRITE);
473473
wpage = BufferGetPage(wbuf);
474-
_hash_checkpage(wpage, LH_BUCKET_PAGE);
474+
_hash_checkpage(rel, wpage, LH_BUCKET_PAGE);
475475
wopaque = (HashPageOpaque) PageGetSpecialPointer(wpage);
476476

477477
/*
@@ -495,7 +495,7 @@ _hash_squeezebucket(Relation rel,
495495
_hash_relbuf(rel, rbuf, HASH_WRITE);
496496
rbuf = _hash_getbuf(rel, rblkno, HASH_WRITE);
497497
rpage = BufferGetPage(rbuf);
498-
_hash_checkpage(rpage, LH_OVERFLOW_PAGE);
498+
_hash_checkpage(rel, rpage, LH_OVERFLOW_PAGE);
499499
Assert(!PageIsEmpty(rpage));
500500
ropaque = (HashPageOpaque) PageGetSpecialPointer(rpage);
501501
Assert(ropaque->hasho_bucket == bucket);
@@ -531,7 +531,7 @@ _hash_squeezebucket(Relation rel,
531531

532532
wbuf = _hash_getbuf(rel, wblkno, HASH_WRITE);
533533
wpage = BufferGetPage(wbuf);
534-
_hash_checkpage(wpage, LH_OVERFLOW_PAGE);
534+
_hash_checkpage(rel, wpage, LH_OVERFLOW_PAGE);
535535
Assert(!PageIsEmpty(wpage));
536536
wopaque = (HashPageOpaque) PageGetSpecialPointer(wpage);
537537
Assert(wopaque->hasho_bucket == bucket);
@@ -576,7 +576,7 @@ _hash_squeezebucket(Relation rel,
576576

577577
rbuf = _hash_getbuf(rel, rblkno, HASH_WRITE);
578578
rpage = BufferGetPage(rbuf);
579-
_hash_checkpage(rpage, LH_OVERFLOW_PAGE);
579+
_hash_checkpage(rel, rpage, LH_OVERFLOW_PAGE);
580580
Assert(!PageIsEmpty(rpage));
581581
ropaque = (HashPageOpaque) PageGetSpecialPointer(rpage);
582582
Assert(ropaque->hasho_bucket == bucket);

0 commit comments

Comments
 (0)