@@ -425,21 +425,18 @@ jsonAnalyzeJsonValue(JsonAnalyzeContext *ctx, JsonValueStats *vstats,
425
425
* Parse the JSON document and build/update stats.
426
426
*
427
427
* XXX The name seems a bit weird, with the two json bits.
428
- *
429
- * XXX The param is either NULL, (char *) -1, or a pointer
430
428
*/
431
429
static void
432
430
jsonAnalyzeJson (JsonAnalyzeContext * ctx , Jsonb * jb , void * param )
433
431
{
434
432
JsonbValue jv ;
435
433
JsonbIterator * it ;
436
434
JsonbIteratorToken tok ;
437
- JsonPathAnlStats * target = (JsonPathAnlStats * ) param ;
438
435
JsonPathAnlStats * stats = ctx -> root ;
436
+ bool collect_values = (bool )(intptr_t ) param ;
439
437
bool scalar = false;
440
438
441
- if ((!target || target == stats ) &&
442
- !JB_ROOT_IS_SCALAR (jb ))
439
+ if (collect_values && !JB_ROOT_IS_SCALAR (jb ))
443
440
jsonAnalyzeJsonValue (ctx , & stats -> vstats , JsonValueInitBinary (& jv , jb ));
444
441
445
442
it = JsonbIteratorInit (& jb -> root );
@@ -496,7 +493,7 @@ jsonAnalyzeJson(JsonAnalyzeContext *ctx, Jsonb *jb, void *param)
496
493
497
494
case WJB_VALUE :
498
495
case WJB_ELEM :
499
- if (! target || target == stats )
496
+ if (collect_values )
500
497
jsonAnalyzeJsonValue (ctx , & stats -> vstats , & jv );
501
498
502
499
/* XXX not sure why we're doing this? */
@@ -1222,7 +1219,8 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
1222
1219
/* XXX Not sure what the first branch is doing (or supposed to)? */
1223
1220
if (false)
1224
1221
{
1225
- jsonAnalyzePass (& ctx , jsonAnalyzeJson , NULL );
1222
+ /* Collect all values of all paths */
1223
+ jsonAnalyzePass (& ctx , jsonAnalyzeJson , (void * )(intptr_t ) true);
1226
1224
jsonAnalyzePaths (& ctx );
1227
1225
}
1228
1226
else
@@ -1244,19 +1242,15 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
1244
1242
oldcxt = MemoryContextSwitchTo (tmpcxt );
1245
1243
1246
1244
/*
1247
- * XXX It's not immediately clear why this is (-1) and not simply
1248
- * NULL. It crashes, so presumably it's used to tweak the behavior,
1249
- * but it's not clear why/how, and it affects place that is pretty
1250
- * far away, and so not obvious. We should use some sort of flag
1251
- * with a descriptive name instead.
1252
- *
1253
1245
* XXX If I understand correctly, we simply collect all paths first,
1254
1246
* without accumulating any Values. And then in the next step we
1255
1247
* process each path independently, probably to save memory (we
1256
1248
* don't want to accumulate all values for all paths, with a lot
1257
1249
* of duplicities).
1258
1250
*/
1259
- jsonAnalyzePass (& ctx , jsonAnalyzeJson , (void * ) -1 );
1251
+
1252
+ /* Collect all paths first and sort them */
1253
+ jsonAnalyzePass (& ctx , jsonAnalyzeJson , (void * )(intptr_t ) false);
1260
1254
jsonAnalyzeSortPaths (& ctx );
1261
1255
1262
1256
MemoryContextReset (tmpcxt );
0 commit comments