Skip to content

Commit f5dff44

Browse files
committed
I've attached a simple patch which should improve the performance of
hashname() and reduce the penalty incured when NAMEDATALEN is increased. I posted this to -hackers a couple days ago, and there haven't been any major complaints. It passes the regression tests. See -hackers for more discussion, as well as the suggestion from Tom Lane on which this patch is based. Unless anyone sees any problems, please apply for 7.3. Cheers, Neil Conway
1 parent 7464e7f commit f5dff44

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

src/backend/access/hash/hashfunc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.30 2001/03/22 03:59:13 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.31 2002/02/25 04:06:47 momjian Exp $
1212
*
1313
* NOTES
1414
* These functions are stored in pg_amproc. For each operator class
@@ -95,7 +95,7 @@ hashname(PG_FUNCTION_ARGS)
9595
{
9696
char *key = NameStr(*PG_GETARG_NAME(0));
9797

98-
return hash_any((char *) key, NAMEDATALEN);
98+
return hash_any(key, strlen(key));
9999
}
100100

101101
/*
@@ -125,7 +125,7 @@ hashvarlena(PG_FUNCTION_ARGS)
125125
*
126126
* (Comment from the original db3 hashing code: )
127127
*
128-
* "This is INCREDIBLY ugly, but fast. We break the string up into 8 byte
128+
* This is INCREDIBLY ugly, but fast. We break the string up into 8 byte
129129
* units. On the first time through the loop we get the 'leftover bytes'
130130
* (strlen % 8). On every later iteration, we perform 8 HASHC's so we handle
131131
* all 8 bytes. Essentially, this saves us 7 cmp & branch instructions. If
@@ -134,7 +134,7 @@ hashvarlena(PG_FUNCTION_ARGS)
134134
* "OZ's original sdbm hash"
135135
*/
136136
Datum
137-
hash_any(char *keydata, int keylen)
137+
hash_any(const char *keydata, int keylen)
138138
{
139139
uint32 n;
140140
int loop;

src/backend/utils/cache/catcache.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.87 2002/02/19 20:11:17 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.88 2002/02/25 04:06:50 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -97,7 +97,6 @@ static Index CatalogCacheComputeHashIndex(CatCache *cache,
9797
static Index CatalogCacheComputeTupleHashIndex(CatCache *cache,
9898
HeapTuple tuple);
9999
static void CatalogCacheInitializeCache(CatCache *cache);
100-
static Datum cc_hashname(PG_FUNCTION_ARGS);
101100
#ifdef CATCACHE_STATS
102101
static void CatCachePrintStats(void);
103102
#endif
@@ -116,7 +115,7 @@ GetCCHashFunc(Oid keytype)
116115
case CHAROID:
117116
return hashchar;
118117
case NAMEOID:
119-
return cc_hashname;
118+
return hashname;
120119
case INT2OID:
121120
return hashint2;
122121
case INT2VECTOROID:
@@ -137,23 +136,6 @@ GetCCHashFunc(Oid keytype)
137136
}
138137
}
139138

140-
static Datum
141-
cc_hashname(PG_FUNCTION_ARGS)
142-
{
143-
/*
144-
* We need our own variant of hashname because we want to accept
145-
* null-terminated C strings as search values for name fields. So, we
146-
* have to make sure the data is correctly padded before we compute
147-
* the hash value.
148-
*/
149-
NameData my_n;
150-
151-
namestrcpy(&my_n, NameStr(*PG_GETARG_NAME(0)));
152-
153-
return DirectFunctionCall1(hashname, NameGetDatum(&my_n));
154-
}
155-
156-
157139
#ifdef CATCACHE_STATS
158140

159141
static void

src/include/access/hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: hash.h,v 1.42 2001/11/05 17:46:31 momjian Exp $
10+
* $Id: hash.h,v 1.43 2002/02/25 04:06:52 momjian Exp $
1111
*
1212
* NOTES
1313
* modeled after Margo Seltzer's hash implementation for unix.
@@ -265,7 +265,7 @@ extern Datum hashoidvector(PG_FUNCTION_ARGS);
265265
extern Datum hashint2vector(PG_FUNCTION_ARGS);
266266
extern Datum hashname(PG_FUNCTION_ARGS);
267267
extern Datum hashvarlena(PG_FUNCTION_ARGS);
268-
extern Datum hash_any(char *keydata, int keylen);
268+
extern Datum hash_any(const char *keydata, int keylen);
269269

270270

271271
/* private routines */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy