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

Commit 0c5962c

Browse files
committed
Grab some low-hanging fruit in the new hash index build code.
oprofile shows that a nontrivial amount of time is being spent in repeated calls to index_getprocinfo, which really only needs to be called once. So do that, and inline _hash_datum2hashkey to make it work.
1 parent 32846f8 commit 0c5962c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/backend/utils/sort/tuplesort.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
* Portions Copyright (c) 1994, Regents of the University of California
9292
*
9393
* IDENTIFICATION
94-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.82 2008/03/16 23:15:08 tgl Exp $
94+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplesort.c,v 1.83 2008/03/17 03:45:36 tgl Exp $
9595
*
9696
*-------------------------------------------------------------------------
9797
*/
@@ -100,6 +100,7 @@
100100

101101
#include <limits.h>
102102

103+
#include "access/genam.h"
103104
#include "access/hash.h"
104105
#include "access/heapam.h"
105106
#include "access/nbtree.h"
@@ -346,6 +347,7 @@ struct Tuplesortstate
346347
bool enforceUnique; /* complain if we find duplicate tuples */
347348

348349
/* These are specific to the index_hash subcase: */
350+
FmgrInfo *hash_proc; /* call info for the hash function */
349351
uint32 hash_mask; /* mask for sortable part of hash code */
350352

351353
/*
@@ -676,6 +678,14 @@ tuplesort_begin_index_hash(Relation indexRel,
676678
state->reversedirection = reversedirection_index_hash;
677679

678680
state->indexRel = indexRel;
681+
682+
/*
683+
* We look up the index column's hash function just once, to avoid
684+
* chewing lots of cycles in repeated index_getprocinfo calls. This
685+
* assumes that our caller holds the index relation open throughout the
686+
* sort, else the pointer obtained here might cease to be valid.
687+
*/
688+
state->hash_proc = index_getprocinfo(indexRel, 1, HASHPROC);
679689
state->hash_mask = hash_mask;
680690

681691
MemoryContextSwitchTo(oldcontext);
@@ -2809,10 +2819,11 @@ comparetup_index_hash(const SortTuple *a, const SortTuple *b,
28092819

28102820
/* Compute hash codes and mask off bits we don't want to sort by */
28112821
Assert(!a->isnull1);
2822+
hash1 = DatumGetUInt32(FunctionCall1(state->hash_proc, a->datum1))
2823+
& state->hash_mask;
28122824
Assert(!b->isnull1);
2813-
2814-
hash1 = _hash_datum2hashkey(state->indexRel, a->datum1) & state->hash_mask;
2815-
hash2 = _hash_datum2hashkey(state->indexRel, b->datum1) & state->hash_mask;
2825+
hash2 = DatumGetUInt32(FunctionCall1(state->hash_proc, b->datum1))
2826+
& state->hash_mask;
28162827

28172828
if (hash1 > hash2)
28182829
return 1;

0 commit comments

Comments
 (0)