* Enlarge a catcache, doubling the number of buckets. */
| 858 | * Enlarge a catcache, doubling the number of buckets. |
| 859 | */ |
| 860 | static void |
| 861 | RehashCatCache(CatCache *cp) |
| 862 | { |
| 863 | dlist_head *newbucket; |
| 864 | int newnbuckets; |
| 865 | int i; |
| 866 | |
| 867 | elog(DEBUG1, "rehashing catalog cache id %d for %s; %d tups, %d buckets", |
| 868 | cp->id, cp->cc_relname, cp->cc_ntup, cp->cc_nbuckets); |
| 869 | |
| 870 | /* Allocate a new, larger, hash table. */ |
| 871 | newnbuckets = cp->cc_nbuckets * 2; |
| 872 | newbucket = (dlist_head *) MemoryContextAllocZero(CacheMemoryContext, newnbuckets * sizeof(dlist_head)); |
| 873 | |
| 874 | /* Move all entries from old hash table to new. */ |
| 875 | for (i = 0; i < cp->cc_nbuckets; i++) |
| 876 | { |
| 877 | dlist_mutable_iter iter; |
| 878 | |
| 879 | dlist_foreach_modify(iter, &cp->cc_bucket[i]) |
| 880 | { |
| 881 | CatCTup *ct = dlist_container(CatCTup, cache_elem, iter.cur); |
| 882 | int hashIndex = HASH_INDEX(ct->hash_value, newnbuckets); |
| 883 | |
| 884 | dlist_delete(iter.cur); |
| 885 | dlist_push_head(&newbucket[hashIndex], &ct->cache_elem); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | /* Switch to the new array. */ |
| 890 | pfree(cp->cc_bucket); |
| 891 | cp->cc_nbuckets = newnbuckets; |
| 892 | cp->cc_bucket = newbucket; |
| 893 | } |
| 894 | |
| 895 | /* |
| 896 | * CatalogCacheInitializeCache |
no test coverage detected