Re: [HACKERS] Cache Hash Index meta page. - Mailing list pgsql-hackers
From | Mithun Cy |
---|---|
Subject | Re: [HACKERS] Cache Hash Index meta page. |
Date | |
Msg-id | CAD__OuhWbWt=t-nXGMGdvdqqm7X8aNfoh=AA13huVtx80S8+9g@mail.gmail.com Whole thread Raw |
In response to | Re: Cache Hash Index meta page. (Robert Haas <robertmhaas@gmail.com>) |
Responses |
Re: [HACKERS] Cache Hash Index meta page.
|
List | pgsql-hackers |
+ bucket = _hash_hashkey2bucket(hashkey, metap->hashm_maxbucket,
metap->hashm_highmask,
metap->hashm_lowmask);This hunk appears useless.
+ metap = (HashMetaPage)rel->rd_amcache;Whitespace.
+ /* Cache the metapage data for next time*/Whitespace.
+ /* Check if this bucket is split after we have cached the metapage.Whitespace.
Shouldn't _hash_doinsert() be using the cache, too?
Clients | After Meta page cache | Base Code | %imp |
1 | 2276.151633 | 2304.253611 | -1.2195696631 |
32 | 36816.596513 | 36439.552652 | 1.0347104549 |
64 | 50943.763133 | 51005.236973 | -0.120524565 |
128 | 49156.980457 | 48458.275106 | 1.4418700407 |
I think it's probably not a good idea to cache the entire metapage. The only things that you are "really" trying to cache, I think, are hashm_maxbucket, hashm_lowmask, and hashm_highmask. The entire HashPageMetaData structure is 696 bytes on my machine, and it doesn't really make sense to copy the whole thing into memory if you only need 16 bytes of it. It could even be dangerous -- if somebody tries to rely on the cache for some other bit of data and we're not really guaranteeing that it's fresh enough for that.I'd suggest defining a new structure HashMetaDataCache with members hmc_maxbucket, hmc_lowmask, and hmc_highmask. The structure can have a comment explaining that we only care about having the data be fresh enough to test whether the bucket mapping we computed for a tuple is still correct, and that for that to be the case we only need to know whether a bucket has suffered a new split since we last refreshed the cache.
uint32 hashm_spares[HASH_MAX_SPLITPOINTS], for bucket number to block mapping in "BUCKET_TO_BLKNO(metap, bucket)".
Note : #define HASH_MAX_SPLITPOINTS 32, so it is (3*uint32 + 32*uint32) = 35*4 = 140 bytes.
The comments in this patch need some work, e.g.:
-
+ oopaque->hasho_prevblkno = maxbucket;No comment?
+ */
+ if (itemsz > HashMaxItemSize((Page) metap))
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("index row size %zu exceeds hash maximum %zu",
+ itemsz, HashMaxItemSize((Page) metap)),
+ errhint("Values larger than a buffer page cannot be indexed.")));
"metap" (HashMetaPage) and Page are different data structure their member types are not in sync, so should not typecast blindly as above. I think we should remove this part of the code as we only store hash keys. So I have removed same but kept the assert below as it is.
Attachment
pgsql-hackers by date: