diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/sort/tuplesort.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index e1e692d5f0f..65cda52714b 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -127,6 +127,7 @@ #include "access/htup_details.h" #include "access/nbtree.h" +#include "access/hash.h" #include "catalog/index.h" #include "catalog/pg_am.h" #include "commands/tablespace.h" @@ -473,7 +474,9 @@ struct Tuplesortstate bool enforceUnique; /* complain if we find duplicate tuples */ /* These are specific to the index_hash subcase: */ - uint32 hash_mask; /* mask for sortable part of hash code */ + uint32 high_mask; /* masks for sortable part of hash code */ + uint32 low_mask; + uint32 max_buckets; /* * These variables are specific to the Datum case; they are set by @@ -991,7 +994,9 @@ tuplesort_begin_index_btree(Relation heapRel, Tuplesortstate * tuplesort_begin_index_hash(Relation heapRel, Relation indexRel, - uint32 hash_mask, + uint32 high_mask, + uint32 low_mask, + uint32 max_buckets, int workMem, bool randomAccess) { Tuplesortstate *state = tuplesort_begin_common(workMem, randomAccess); @@ -1002,8 +1007,11 @@ tuplesort_begin_index_hash(Relation heapRel, #ifdef TRACE_SORT if (trace_sort) elog(LOG, - "begin index sort: hash_mask = 0x%x, workMem = %d, randomAccess = %c", - hash_mask, + "begin index sort: high_mask = 0x%x, low_mask = 0x%x, " + "max_buckets = 0x%x, workMem = %d, randomAccess = %c", + high_mask, + low_mask, + max_buckets, workMem, randomAccess ? 't' : 'f'); #endif @@ -1017,7 +1025,9 @@ tuplesort_begin_index_hash(Relation heapRel, state->heapRel = heapRel; state->indexRel = indexRel; - state->hash_mask = hash_mask; + state->high_mask = high_mask; + state->low_mask = low_mask; + state->max_buckets = max_buckets; MemoryContextSwitchTo(oldcontext); @@ -4157,8 +4167,8 @@ static int comparetup_index_hash(const SortTuple *a, const SortTuple *b, Tuplesortstate *state) { - uint32 hash1; - uint32 hash2; + Bucket bucket1; + Bucket bucket2; IndexTuple tuple1; IndexTuple tuple2; @@ -4167,13 +4177,16 @@ comparetup_index_hash(const SortTuple *a, const SortTuple *b, * that the first column of the index tuple is the hash key. */ Assert(!a->isnull1); - hash1 = DatumGetUInt32(a->datum1) & state->hash_mask; + bucket1 = _hash_hashkey2bucket(DatumGetUInt32(a->datum1), + state->max_buckets, state->high_mask, + state->low_mask); Assert(!b->isnull1); - hash2 = DatumGetUInt32(b->datum1) & state->hash_mask; - - if (hash1 > hash2) + bucket2 = _hash_hashkey2bucket(DatumGetUInt32(b->datum1), + state->max_buckets, state->high_mask, + state->low_mask); + if (bucket1 > bucket2) return 1; - else if (hash1 < hash2) + else if (bucket1 < bucket2) return -1; /* |