mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
hash: Refactor bucket squeeze code.
In preparation for adding write-ahead logging to hash indexes, refactor _hash_freeovflpage and _hash_squeezebucket so that all related page modifications happen in a single section of code. The previous coding assumed that it would be fine to move tuples one at a time, and also that the various operations involved in freeing an overflow page didn't necessarily all need to be done together, all of which is true if you don't care about write-ahead logging. Amit Kapila, with slight changes by me.
This commit is contained in:
@@ -228,3 +228,44 @@ _hash_pgaddtup(Relation rel, Buffer buf, Size itemsize, IndexTuple itup)
|
||||
|
||||
return itup_off;
|
||||
}
|
||||
|
||||
/*
|
||||
* _hash_pgaddmultitup() -- add a tuple vector to a particular page in the
|
||||
* index.
|
||||
*
|
||||
* This routine has same requirements for locking and tuple ordering as
|
||||
* _hash_pgaddtup().
|
||||
*
|
||||
* Returns the offset number array at which the tuples were inserted.
|
||||
*/
|
||||
void
|
||||
_hash_pgaddmultitup(Relation rel, Buffer buf, IndexTuple *itups,
|
||||
OffsetNumber *itup_offsets, uint16 nitups)
|
||||
{
|
||||
OffsetNumber itup_off;
|
||||
Page page;
|
||||
uint32 hashkey;
|
||||
int i;
|
||||
|
||||
_hash_checkpage(rel, buf, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
|
||||
page = BufferGetPage(buf);
|
||||
|
||||
for (i = 0; i < nitups; i++)
|
||||
{
|
||||
Size itemsize;
|
||||
|
||||
itemsize = IndexTupleDSize(*itups[i]);
|
||||
itemsize = MAXALIGN(itemsize);
|
||||
|
||||
/* Find where to insert the tuple (preserving page's hashkey ordering) */
|
||||
hashkey = _hash_get_indextuple_hashkey(itups[i]);
|
||||
itup_off = _hash_binsearch(page, hashkey);
|
||||
|
||||
itup_offsets[i] = itup_off;
|
||||
|
||||
if (PageAddItem(page, (Item) itups[i], itemsize, itup_off, false, false)
|
||||
== InvalidOffsetNumber)
|
||||
elog(ERROR, "failed to add index item to \"%s\"",
|
||||
RelationGetRelationName(rel));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user