@@ -81,19 +81,13 @@ typedef struct JsonPathEntry JsonPathEntry;
81
81
* XXX We need entry+lenth because JSON path elements may contain null
82
82
* bytes, I guess?
83
83
*/
84
- struct JsonPathEntry
84
+ typedef struct JsonPathEntry
85
85
{
86
86
JsonPathEntry * parent ;
87
87
const char * entry ; /* element of the path as a string */
88
88
int len ; /* length of entry string (may be 0) */
89
89
uint32 hash ; /* hash of the whole path (with parent) */
90
- };
91
-
92
- /*
93
- * A path is simply a pointer to the last element (we can traverse to
94
- * the top easily).
95
- */
96
- typedef JsonPathEntry * JsonPath ;
90
+ } JsonPathEntry ;
97
91
98
92
/* An array containing a dynamic number of JSON values. */
99
93
typedef struct JsonValues
@@ -191,12 +185,9 @@ typedef struct JsonAnalyzeContext
191
185
*
192
186
* Returned int instead of bool, because it is an implementation of
193
187
* HashCompareFunc.
194
- *
195
- * XXX Sould be JsonPathEntryMatch as it deals with JsonPathEntry nodes
196
- * not whole paths, no?
197
188
*/
198
189
static int
199
- JsonPathMatch (const void * key1 , const void * key2 , Size keysize )
190
+ JsonPathEntryMatch (const void * key1 , const void * key2 , Size keysize )
200
191
{
201
192
const JsonPathEntry * path1 = key1 ;
202
193
const JsonPathEntry * path2 = key2 ;
@@ -211,23 +202,17 @@ JsonPathMatch(const void *key1, const void *key2, Size keysize)
211
202
* JsonPathHash
212
203
* Calculate hash of the path entry.
213
204
*
214
- * XXX Again, maybe JsonPathEntryHash would be a better name?
215
- *
216
- * XXX Maybe should call JsonPathHash on the parent, instead of looking
217
- * at the field directly. Could easily happen we have not calculated it
218
- * yet, I guess.
205
+ * Parent hash should be already calculated.
219
206
*/
220
207
static uint32
221
- JsonPathHash (const void * key , Size keysize )
208
+ JsonPathEntryHash (const void * key , Size keysize )
222
209
{
223
210
const JsonPathEntry * path = key ;
224
-
225
- /* XXX Call JsonPathHash instead of direct access? */
226
211
uint32 hash = path -> parent ? path -> parent -> hash : 0 ;
227
212
228
213
hash = (hash << 1 ) | (hash >> 31 );
229
- hash ^= path -> len < 0 ? 0 : DatumGetUInt32 (
230
- hash_any ((const unsigned char * ) path -> entry , path -> len ));
214
+ hash ^= path -> len < 0 ? 0 :
215
+ DatumGetUInt32 ( hash_any ((const unsigned char * ) path -> entry , path -> len ));
231
216
232
217
return hash ;
233
218
}
@@ -241,7 +226,7 @@ JsonPathHash(const void *key, Size keysize)
241
226
* updated.
242
227
*/
243
228
static inline JsonPathAnlStats *
244
- jsonAnalyzeAddPath (JsonAnalyzeContext * ctx , JsonPath parent ,
229
+ jsonAnalyzeAddPath (JsonAnalyzeContext * ctx , JsonPathEntry * parent ,
245
230
const char * entry , int len )
246
231
{
247
232
JsonPathEntry path ;
@@ -252,7 +237,7 @@ jsonAnalyzeAddPath(JsonAnalyzeContext *ctx, JsonPath parent,
252
237
path .parent = parent ;
253
238
path .entry = entry ;
254
239
path .len = len ;
255
- path .hash = JsonPathHash (& path , 0 );
240
+ path .hash = JsonPathEntryHash (& path , 0 );
256
241
257
242
/* XXX See if we already saw this path earlier. */
258
243
stats = hash_search_with_hash_value (ctx -> pathshash , & path , path .hash ,
@@ -265,7 +250,7 @@ jsonAnalyzeAddPath(JsonAnalyzeContext *ctx, JsonPath parent,
265
250
if (!found )
266
251
{
267
252
JsonPathAnlStats * parent = (JsonPathAnlStats * ) stats -> path .parent ;
268
- JsonPath path = & stats -> path ;
253
+ JsonPathEntry * path = & stats -> path ;
269
254
const char * ppath = parent -> pathstr ;
270
255
StringInfoData si ;
271
256
MemoryContext oldcxt = MemoryContextSwitchTo (ctx -> mcxt );
@@ -586,7 +571,7 @@ jsonAnalyzeCollectPath(JsonAnalyzeContext *ctx, Jsonb *jb, void *param)
586
571
JsonPathAnlStats * pstats = (JsonPathAnlStats * ) param ;
587
572
JsonbValue jbvtmp ;
588
573
JsonbValue * jbv = JsonValueInitBinary (& jbvtmp , jb );
589
- JsonPath path ;
574
+ JsonPathEntry * path ;
590
575
591
576
if (!pstats -> entries )
592
577
{
@@ -1100,8 +1085,8 @@ jsonAnalyzeInit(JsonAnalyzeContext *ctx, VacAttrStats *stats,
1100
1085
MemSet (& hash_ctl , 0 , sizeof (hash_ctl ));
1101
1086
hash_ctl .keysize = sizeof (JsonPathEntry );
1102
1087
hash_ctl .entrysize = sizeof (JsonPathAnlStats );
1103
- hash_ctl .hash = JsonPathHash ;
1104
- hash_ctl .match = JsonPathMatch ;
1088
+ hash_ctl .hash = JsonPathEntryHash ;
1089
+ hash_ctl .match = JsonPathEntryMatch ;
1105
1090
hash_ctl .hcxt = ctx -> mcxt ;
1106
1091
1107
1092
ctx -> pathshash = hash_create ("JSON analyze path table" , 100 , & hash_ctl ,
0 commit comments