PostgreSQL Source Code  git master
hashfunc.c File Reference
#include "postgres.h"
#include "access/hash.h"
#include "catalog/pg_collation.h"
#include "utils/builtins.h"
#include "utils/hashutils.h"
#include "utils/pg_locale.h"
Include dependency graph for hashfunc.c:

Go to the source code of this file.

Functions

Datum hashchar (PG_FUNCTION_ARGS)
 
Datum hashcharextended (PG_FUNCTION_ARGS)
 
Datum hashint2 (PG_FUNCTION_ARGS)
 
Datum hashint2extended (PG_FUNCTION_ARGS)
 
Datum hashint4 (PG_FUNCTION_ARGS)
 
Datum hashint4extended (PG_FUNCTION_ARGS)
 
Datum hashint8 (PG_FUNCTION_ARGS)
 
Datum hashint8extended (PG_FUNCTION_ARGS)
 
Datum hashoid (PG_FUNCTION_ARGS)
 
Datum hashoidextended (PG_FUNCTION_ARGS)
 
Datum hashenum (PG_FUNCTION_ARGS)
 
Datum hashenumextended (PG_FUNCTION_ARGS)
 
Datum hashfloat4 (PG_FUNCTION_ARGS)
 
Datum hashfloat4extended (PG_FUNCTION_ARGS)
 
Datum hashfloat8 (PG_FUNCTION_ARGS)
 
Datum hashfloat8extended (PG_FUNCTION_ARGS)
 
Datum hashoidvector (PG_FUNCTION_ARGS)
 
Datum hashoidvectorextended (PG_FUNCTION_ARGS)
 
Datum hashname (PG_FUNCTION_ARGS)
 
Datum hashnameextended (PG_FUNCTION_ARGS)
 
Datum hashtext (PG_FUNCTION_ARGS)
 
Datum hashtextextended (PG_FUNCTION_ARGS)
 
Datum hashvarlena (PG_FUNCTION_ARGS)
 
Datum hashvarlenaextended (PG_FUNCTION_ARGS)
 

Function Documentation

◆ hashchar()

Datum hashchar ( PG_FUNCTION_ARGS  )

Definition at line 47 of file hashfunc.c.

References hash_uint32(), and PG_GETARG_CHAR.

48 {
49  return hash_uint32((int32) PG_GETARG_CHAR(0));
50 }
signed int int32
Definition: c.h:346
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:268

◆ hashcharextended()

Datum hashcharextended ( PG_FUNCTION_ARGS  )

Definition at line 53 of file hashfunc.c.

References hash_uint32_extended(), PG_GETARG_CHAR, and PG_GETARG_INT64.

Referenced by JsonbHashScalarValueExtended().

54 {
56 }
signed int int32
Definition: c.h:346
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:268

◆ hashenum()

Datum hashenum ( PG_FUNCTION_ARGS  )

Definition at line 128 of file hashfunc.c.

References hash_uint32(), and PG_GETARG_OID.

129 {
130  return hash_uint32((uint32) PG_GETARG_OID(0));
131 }
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
unsigned int uint32
Definition: c.h:358

◆ hashenumextended()

Datum hashenumextended ( PG_FUNCTION_ARGS  )

Definition at line 134 of file hashfunc.c.

References hash_uint32_extended(), PG_GETARG_INT64, and PG_GETARG_OID.

135 {
137 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
unsigned int uint32
Definition: c.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634

◆ hashfloat4()

Datum hashfloat4 ( PG_FUNCTION_ARGS  )

Definition at line 140 of file hashfunc.c.

References hash_any(), sort-test::key, PG_GETARG_FLOAT4, and PG_RETURN_UINT32.

141 {
143  float8 key8;
144 
145  /*
146  * On IEEE-float machines, minus zero and zero have different bit patterns
147  * but should compare as equal. We must ensure that they have the same
148  * hash value, which is most reliably done this way:
149  */
150  if (key == (float4) 0)
151  PG_RETURN_UINT32(0);
152 
153  /*
154  * To support cross-type hashing of float8 and float4, we want to return
155  * the same hash value hashfloat8 would produce for an equal float8 value.
156  * So, widen the value to float8 and hash that. (We must do this rather
157  * than have hashfloat8 try to narrow its value to float4; that could fail
158  * on overflow.)
159  */
160  key8 = key;
161 
162  return hash_any((unsigned char *) &key8, sizeof(key8));
163 }
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:345
double float8
Definition: c.h:491
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:275
float float4
Definition: c.h:490
Datum hash_any(register const unsigned char *k, register int keylen)
Definition: hashfn.c:148

◆ hashfloat4extended()

Datum hashfloat4extended ( PG_FUNCTION_ARGS  )

Definition at line 166 of file hashfunc.c.

References hash_any_extended(), sort-test::key, PG_GETARG_FLOAT4, PG_GETARG_INT64, and PG_RETURN_UINT64.

167 {
169  uint64 seed = PG_GETARG_INT64(1);
170  float8 key8;
171 
172  /* Same approach as hashfloat4 */
173  if (key == (float4) 0)
174  PG_RETURN_UINT64(seed);
175  key8 = key;
176 
177  return hash_any_extended((unsigned char *) &key8, sizeof(key8), seed);
178 }
Datum hash_any_extended(register const unsigned char *k, register int keylen, uint64 seed)
Definition: hashfn.c:374
#define PG_RETURN_UINT64(x)
Definition: fmgr.h:358
double float8
Definition: c.h:491
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:275
float float4
Definition: c.h:490
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ hashfloat8()

Datum hashfloat8 ( PG_FUNCTION_ARGS  )

Definition at line 181 of file hashfunc.c.

References hash_any(), sort-test::key, PG_GETARG_FLOAT8, and PG_RETURN_UINT32.

Referenced by tablesample_init().

182 {
184 
185  /*
186  * On IEEE-float machines, minus zero and zero have different bit patterns
187  * but should compare as equal. We must ensure that they have the same
188  * hash value, which is most reliably done this way:
189  */
190  if (key == (float8) 0)
191  PG_RETURN_UINT32(0);
192 
193  return hash_any((unsigned char *) &key, sizeof(key));
194 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:345
double float8
Definition: c.h:491
Datum hash_any(register const unsigned char *k, register int keylen)
Definition: hashfn.c:148

◆ hashfloat8extended()

Datum hashfloat8extended ( PG_FUNCTION_ARGS  )

Definition at line 197 of file hashfunc.c.

References hash_any_extended(), sort-test::key, PG_GETARG_FLOAT8, PG_GETARG_INT64, and PG_RETURN_UINT64.

198 {
200  uint64 seed = PG_GETARG_INT64(1);
201 
202  /* Same approach as hashfloat8 */
203  if (key == (float8) 0)
204  PG_RETURN_UINT64(seed);
205 
206  return hash_any_extended((unsigned char *) &key, sizeof(key), seed);
207 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
Datum hash_any_extended(register const unsigned char *k, register int keylen, uint64 seed)
Definition: hashfn.c:374
#define PG_RETURN_UINT64(x)
Definition: fmgr.h:358
double float8
Definition: c.h:491
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ hashint2()

Datum hashint2 ( PG_FUNCTION_ARGS  )

Definition at line 59 of file hashfunc.c.

References hash_uint32(), and PG_GETARG_INT16.

60 {
61  return hash_uint32((int32) PG_GETARG_INT16(0));
62 }
signed int int32
Definition: c.h:346
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266

◆ hashint2extended()

Datum hashint2extended ( PG_FUNCTION_ARGS  )

Definition at line 65 of file hashfunc.c.

References hash_uint32_extended(), PG_GETARG_INT16, and PG_GETARG_INT64.

66 {
68 }
signed int int32
Definition: c.h:346
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634

◆ hashint4()

Datum hashint4 ( PG_FUNCTION_ARGS  )

Definition at line 71 of file hashfunc.c.

References hash_uint32(), and PG_GETARG_INT32.

72 {
73  return hash_uint32(PG_GETARG_INT32(0));
74 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613

◆ hashint4extended()

Datum hashint4extended ( PG_FUNCTION_ARGS  )

Definition at line 77 of file hashfunc.c.

References hash_uint32_extended(), PG_GETARG_INT32, and PG_GETARG_INT64.

78 {
80 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634

◆ hashint8()

Datum hashint8 ( PG_FUNCTION_ARGS  )

Definition at line 83 of file hashfunc.c.

References hash_uint32(), PG_GETARG_INT64, and val.

Referenced by interval_hash(), pg_lsn_hash(), time_hash(), timestamp_hash(), and timetz_hash().

84 {
85  /*
86  * The idea here is to produce a hash value compatible with the values
87  * produced by hashint4 and hashint2 for logically equal inputs; this is
88  * necessary to support cross-type hash joins across these input types.
89  * Since all three types are signed, we can xor the high half of the int8
90  * value if the sign is positive, or the complement of the high half when
91  * the sign is negative.
92  */
93  int64 val = PG_GETARG_INT64(0);
94  uint32 lohalf = (uint32) val;
95  uint32 hihalf = (uint32) (val >> 32);
96 
97  lohalf ^= (val >= 0) ? hihalf : ~hihalf;
98 
99  return hash_uint32(lohalf);
100 }
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613
unsigned int uint32
Definition: c.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
long val
Definition: informix.c:689

◆ hashint8extended()

Datum hashint8extended ( PG_FUNCTION_ARGS  )

Definition at line 103 of file hashfunc.c.

References hash_uint32_extended(), PG_GETARG_INT64, and val.

Referenced by interval_hash_extended(), pg_lsn_hash_extended(), time_hash_extended(), timestamp_hash_extended(), and timetz_hash_extended().

104 {
105  /* Same approach as hashint8 */
106  int64 val = PG_GETARG_INT64(0);
107  uint32 lohalf = (uint32) val;
108  uint32 hihalf = (uint32) (val >> 32);
109 
110  lohalf ^= (val >= 0) ? hihalf : ~hihalf;
111 
112  return hash_uint32_extended(lohalf, PG_GETARG_INT64(1));
113 }
unsigned int uint32
Definition: c.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634
long val
Definition: informix.c:689

◆ hashname()

Datum hashname ( PG_FUNCTION_ARGS  )

Definition at line 228 of file hashfunc.c.

References hash_any(), sort-test::key, NameStr, and PG_GETARG_NAME.

229 {
230  char *key = NameStr(*PG_GETARG_NAME(0));
231 
232  return hash_any((unsigned char *) key, strlen(key));
233 }
Datum hash_any(register const unsigned char *k, register int keylen)
Definition: hashfn.c:148
#define NameStr(name)
Definition: c.h:609
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ hashnameextended()

Datum hashnameextended ( PG_FUNCTION_ARGS  )

Definition at line 236 of file hashfunc.c.

References hash_any_extended(), sort-test::key, NameStr, PG_GETARG_INT64, and PG_GETARG_NAME.

237 {
238  char *key = NameStr(*PG_GETARG_NAME(0));
239 
240  return hash_any_extended((unsigned char *) key, strlen(key),
241  PG_GETARG_INT64(1));
242 }
Datum hash_any_extended(register const unsigned char *k, register int keylen, uint64 seed)
Definition: hashfn.c:374
#define NameStr(name)
Definition: c.h:609
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
#define PG_GETARG_NAME(n)
Definition: fmgr.h:273

◆ hashoid()

Datum hashoid ( PG_FUNCTION_ARGS  )

Definition at line 116 of file hashfunc.c.

References hash_uint32(), and PG_GETARG_OID.

117 {
118  return hash_uint32((uint32) PG_GETARG_OID(0));
119 }
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
unsigned int uint32
Definition: c.h:358

◆ hashoidextended()

Datum hashoidextended ( PG_FUNCTION_ARGS  )

Definition at line 122 of file hashfunc.c.

References hash_uint32_extended(), PG_GETARG_INT64, and PG_GETARG_OID.

123 {
125 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
unsigned int uint32
Definition: c.h:358
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634

◆ hashoidvector()

Datum hashoidvector ( PG_FUNCTION_ARGS  )

Definition at line 210 of file hashfunc.c.

References oidvector::dim1, hash_any(), sort-test::key, PG_GETARG_POINTER, and oidvector::values.

Referenced by oidvectorhashfast().

211 {
213 
214  return hash_any((unsigned char *) key->values, key->dim1 * sizeof(Oid));
215 }
Definition: c.h:588
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
unsigned int Oid
Definition: postgres_ext.h:31
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:596
int dim1
Definition: c.h:594
Datum hash_any(register const unsigned char *k, register int keylen)
Definition: hashfn.c:148

◆ hashoidvectorextended()

Datum hashoidvectorextended ( PG_FUNCTION_ARGS  )

Definition at line 218 of file hashfunc.c.

References oidvector::dim1, hash_any_extended(), sort-test::key, PG_GETARG_INT64, PG_GETARG_POINTER, and oidvector::values.

219 {
221 
222  return hash_any_extended((unsigned char *) key->values,
223  key->dim1 * sizeof(Oid),
224  PG_GETARG_INT64(1));
225 }
Datum hash_any_extended(register const unsigned char *k, register int keylen, uint64 seed)
Definition: hashfn.c:374
Definition: c.h:588
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
unsigned int Oid
Definition: postgres_ext.h:31
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:596
int dim1
Definition: c.h:594
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ hashtext()

Datum hashtext ( PG_FUNCTION_ARGS  )

Definition at line 245 of file hashfunc.c.

References buf, pg_locale_struct::deterministic, elog, ereport, errcode(), errhint(), errmsg(), ERROR, hash_any(), pg_locale_struct::info, sort-test::key, lc_collate_is_c(), palloc(), pfree(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_TEXT_PP, pg_newlocale_from_collation(), pg_locale_struct::provider, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by texthashfast().

246 {
247  text *key = PG_GETARG_TEXT_PP(0);
248  Oid collid = PG_GET_COLLATION();
249  pg_locale_t mylocale = 0;
250  Datum result;
251 
252  if (!collid)
253  ereport(ERROR,
254  (errcode(ERRCODE_INDETERMINATE_COLLATION),
255  errmsg("could not determine which collation to use for string hashing"),
256  errhint("Use the COLLATE clause to set the collation explicitly.")));
257 
258  if (!lc_collate_is_c(collid) && collid != DEFAULT_COLLATION_OID)
259  mylocale = pg_newlocale_from_collation(collid);
260 
261  if (!mylocale || mylocale->deterministic)
262  {
263  result = hash_any((unsigned char *) VARDATA_ANY(key),
264  VARSIZE_ANY_EXHDR(key));
265  }
266  else
267  {
268 #ifdef USE_ICU
269  if (mylocale->provider == COLLPROVIDER_ICU)
270  {
271  int32_t ulen = -1;
272  UChar *uchar = NULL;
273  Size bsize;
274  uint8_t *buf;
275 
276  ulen = icu_to_uchar(&uchar, VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
277 
278  bsize = ucol_getSortKey(mylocale->info.icu.ucol,
279  uchar, ulen, NULL, 0);
280  buf = palloc(bsize);
281  ucol_getSortKey(mylocale->info.icu.ucol,
282  uchar, ulen, buf, bsize);
283 
284  result = hash_any(buf, bsize);
285 
286  pfree(buf);
287  }
288  else
289 #endif
290  /* shouldn't happen */
291  elog(ERROR, "unsupported collprovider: %c", mylocale->provider);
292  }
293 
294  /* Avoid leaking memory for toasted inputs */
295  PG_FREE_IF_COPY(key, 0);
296 
297  return result;
298 }
union pg_locale_struct::@144 info
int errhint(const char *fmt,...)
Definition: elog.c:974
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1132
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:141
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1279
uintptr_t Datum
Definition: postgres.h:367
bool deterministic
Definition: pg_locale.h:85
Datum hash_any(register const unsigned char *k, register int keylen)
Definition: hashfn.c:148
size_t Size
Definition: c.h:466
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
int int32_t
Definition: crypt.c:108
Definition: c.h:549

◆ hashtextextended()

Datum hashtextextended ( PG_FUNCTION_ARGS  )

Definition at line 301 of file hashfunc.c.

References buf, pg_locale_struct::deterministic, elog, ereport, errcode(), errhint(), errmsg(), ERROR, hash_any_extended(), pg_locale_struct::info, sort-test::key, lc_collate_is_c(), palloc(), pfree(), PG_FREE_IF_COPY, PG_GET_COLLATION, PG_GETARG_INT64, PG_GETARG_TEXT_PP, pg_newlocale_from_collation(), pg_locale_struct::provider, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

302 {
303  text *key = PG_GETARG_TEXT_PP(0);
304  Oid collid = PG_GET_COLLATION();
305  pg_locale_t mylocale = 0;
306  Datum result;
307 
308  if (!collid)
309  ereport(ERROR,
310  (errcode(ERRCODE_INDETERMINATE_COLLATION),
311  errmsg("could not determine which collation to use for string hashing"),
312  errhint("Use the COLLATE clause to set the collation explicitly.")));
313 
314  if (!lc_collate_is_c(collid) && collid != DEFAULT_COLLATION_OID)
315  mylocale = pg_newlocale_from_collation(collid);
316 
317  if (!mylocale || mylocale->deterministic)
318  {
319  result = hash_any_extended((unsigned char *) VARDATA_ANY(key),
320  VARSIZE_ANY_EXHDR(key),
321  PG_GETARG_INT64(1));
322  }
323  else
324  {
325 #ifdef USE_ICU
326  if (mylocale->provider == COLLPROVIDER_ICU)
327  {
328  int32_t ulen = -1;
329  UChar *uchar = NULL;
330  Size bsize;
331  uint8_t *buf;
332 
333  ulen = icu_to_uchar(&uchar, VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
334 
335  bsize = ucol_getSortKey(mylocale->info.icu.ucol,
336  uchar, ulen, NULL, 0);
337  buf = palloc(bsize);
338  ucol_getSortKey(mylocale->info.icu.ucol,
339  uchar, ulen, buf, bsize);
340 
341  result = hash_any_extended(buf, bsize, PG_GETARG_INT64(1));
342 
343  pfree(buf);
344  }
345  else
346 #endif
347  /* shouldn't happen */
348  elog(ERROR, "unsupported collprovider: %c", mylocale->provider);
349  }
350 
351  PG_FREE_IF_COPY(key, 0);
352 
353  return result;
354 }
union pg_locale_struct::@144 info
Datum hash_any_extended(register const unsigned char *k, register int keylen, uint64 seed)
Definition: hashfn.c:374
int errhint(const char *fmt,...)
Definition: elog.c:974
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GET_COLLATION()
Definition: fmgr.h:193
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
void pfree(void *pointer)
Definition: mcxt.c:1031
#define ERROR
Definition: elog.h:43
bool lc_collate_is_c(Oid collation)
Definition: pg_locale.c:1132
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:141
pg_locale_t pg_newlocale_from_collation(Oid collid)
Definition: pg_locale.c:1279
uintptr_t Datum
Definition: postgres.h:367
bool deterministic
Definition: pg_locale.h:85
size_t Size
Definition: c.h:466
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
void * palloc(Size size)
Definition: mcxt.c:924
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
int int32_t
Definition: crypt.c:108
Definition: c.h:549
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277

◆ hashvarlena()

Datum hashvarlena ( PG_FUNCTION_ARGS  )

Definition at line 361 of file hashfunc.c.

References hash_any(), sort-test::key, PG_FREE_IF_COPY, PG_GETARG_VARLENA_PP, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

362 {
363  struct varlena *key = PG_GETARG_VARLENA_PP(0);
364  Datum result;
365 
366  result = hash_any((unsigned char *) VARDATA_ANY(key),
367  VARSIZE_ANY_EXHDR(key));
368 
369  /* Avoid leaking memory for toasted inputs */
370  PG_FREE_IF_COPY(key, 0);
371 
372  return result;
373 }
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define PG_GETARG_VARLENA_PP(n)
Definition: fmgr.h:283
uintptr_t Datum
Definition: postgres.h:367
Datum hash_any(register const unsigned char *k, register int keylen)
Definition: hashfn.c:148
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549

◆ hashvarlenaextended()

Datum hashvarlenaextended ( PG_FUNCTION_ARGS  )

Definition at line 376 of file hashfunc.c.

References hash_any_extended(), sort-test::key, PG_FREE_IF_COPY, PG_GETARG_INT64, PG_GETARG_VARLENA_PP, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

377 {
378  struct varlena *key = PG_GETARG_VARLENA_PP(0);
379  Datum result;
380 
381  result = hash_any_extended((unsigned char *) VARDATA_ANY(key),
382  VARSIZE_ANY_EXHDR(key),
383  PG_GETARG_INT64(1));
384 
385  PG_FREE_IF_COPY(key, 0);
386 
387  return result;
388 }
Datum hash_any_extended(register const unsigned char *k, register int keylen, uint64 seed)
Definition: hashfn.c:374
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define PG_GETARG_VARLENA_PP(n)
Definition: fmgr.h:283
uintptr_t Datum
Definition: postgres.h:367
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
Definition: c.h:549
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277