1
- /*
2
- * contrib/hstore/hstore_gin.c
1
+ /*-------------------------------------------------------------------------
2
+ *
3
+ * hstore_ops.c
4
+ * Definitions of gin_hstore_hash_ops operator class for hstore.
5
+ *
6
+ * Copyright (c) 2014, PostgreSQL Global Development Group
7
+ * Author: Alexander Korotkov <aekorotkov@gmail.com>
8
+ *
9
+ * IDENTIFICATION
10
+ * contrib/hstore_ops/hstore_ops.c
11
+ *
12
+ * GIN keys in this opclass are 64-bit integers where higher 32-bits are hash
13
+ * of hstore key and lower 32-bits are hash of hstore value.
14
+ *
15
+ *-------------------------------------------------------------------------
3
16
*/
4
17
#include "postgres.h"
5
18
@@ -15,6 +28,10 @@ PG_MODULE_MAGIC;
15
28
PG_FUNCTION_INFO_V1 (gin_compare_hstore_hash );
16
29
Datum gin_compare_hstore_hash (PG_FUNCTION_ARGS );
17
30
31
+ /*
32
+ * GIN comparison function: compare keys as _unsigned_ 64-bit integers. So, keys
33
+ * with same higher 32-bits will be together.
34
+ */
18
35
Datum
19
36
gin_compare_hstore_hash (PG_FUNCTION_ARGS )
20
37
{
@@ -35,6 +52,9 @@ gin_compare_hstore_hash(PG_FUNCTION_ARGS)
35
52
PG_FUNCTION_INFO_V1 (gin_compare_partial_hstore_hash );
36
53
Datum gin_compare_partial_hstore_hash (PG_FUNCTION_ARGS );
37
54
55
+ /*
56
+ * GIN comparison function: select GIN keys with same hash of hstore key.
57
+ */
38
58
Datum
39
59
gin_compare_partial_hstore_hash (PG_FUNCTION_ARGS )
40
60
{
@@ -57,6 +77,9 @@ gin_compare_partial_hstore_hash(PG_FUNCTION_ARGS)
57
77
PG_RETURN_INT32 (result );
58
78
}
59
79
80
+ /*
81
+ * Get hashed representation of key-value pair.
82
+ */
60
83
static uint64
61
84
get_entry_hash (HEntry * hsent , char * ptr , int i )
62
85
{
@@ -70,6 +93,9 @@ get_entry_hash(HEntry *hsent, char *ptr, int i)
70
93
return result ;
71
94
}
72
95
96
+ /*
97
+ * Get hstore key hash in same format as hash of key-value pair.
98
+ */
73
99
static uint64
74
100
get_key_hash (text * key )
75
101
{
@@ -83,6 +109,9 @@ get_key_hash(text *key)
83
109
PG_FUNCTION_INFO_V1 (gin_extract_hstore_hash );
84
110
Datum gin_extract_hstore_hash (PG_FUNCTION_ARGS );
85
111
112
+ /*
113
+ * Split hstore into hashes of key-value pairs.
114
+ */
86
115
Datum
87
116
gin_extract_hstore_hash (PG_FUNCTION_ARGS )
88
117
{
@@ -107,6 +136,9 @@ gin_extract_hstore_hash(PG_FUNCTION_ARGS)
107
136
PG_FUNCTION_INFO_V1 (gin_extract_hstore_query_hash );
108
137
Datum gin_extract_hstore_query_hash (PG_FUNCTION_ARGS );
109
138
139
+ /*
140
+ * Provide relevant hashes for either hstore, key or array of keys.
141
+ */
110
142
Datum
111
143
gin_extract_hstore_query_hash (PG_FUNCTION_ARGS )
112
144
{
@@ -118,7 +150,7 @@ gin_extract_hstore_query_hash(PG_FUNCTION_ARGS)
118
150
119
151
if (strategy == HStoreContainsStrategyNumber )
120
152
{
121
- /* Query is an hstore, so just apply gin_extract_hstore ... */
153
+ /* Query is an hstore, so just apply gin_extract_hstore_hash ... */
122
154
entries = (Datum * )
123
155
DatumGetPointer (DirectFunctionCall2 (gin_extract_hstore_hash ,
124
156
PG_GETARG_DATUM (0 ),
@@ -180,6 +212,9 @@ gin_extract_hstore_query_hash(PG_FUNCTION_ARGS)
180
212
PG_FUNCTION_INFO_V1 (gin_consistent_hstore_hash );
181
213
Datum gin_consistent_hstore_hash (PG_FUNCTION_ARGS );
182
214
215
+ /*
216
+ * Consistent
217
+ */
183
218
Datum
184
219
gin_consistent_hstore_hash (PG_FUNCTION_ARGS )
185
220
{
0 commit comments