Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c0f6906

Browse files
author
Nikita Glukhov
committed
Pass simple bool flag collect_values to jsonAnalyzeJson()
1 parent d99fd8d commit c0f6906

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/backend/utils/adt/jsonb_typanalyze.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,21 +425,18 @@ jsonAnalyzeJsonValue(JsonAnalyzeContext *ctx, JsonValueStats *vstats,
425425
* Parse the JSON document and build/update stats.
426426
*
427427
* 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
430428
*/
431429
static void
432430
jsonAnalyzeJson(JsonAnalyzeContext *ctx, Jsonb *jb, void *param)
433431
{
434432
JsonbValue jv;
435433
JsonbIterator *it;
436434
JsonbIteratorToken tok;
437-
JsonPathAnlStats *target = (JsonPathAnlStats *) param;
438435
JsonPathAnlStats *stats = ctx->root;
436+
bool collect_values = (bool)(intptr_t) param;
439437
bool scalar = false;
440438

441-
if ((!target || target == stats) &&
442-
!JB_ROOT_IS_SCALAR(jb))
439+
if (collect_values && !JB_ROOT_IS_SCALAR(jb))
443440
jsonAnalyzeJsonValue(ctx, &stats->vstats, JsonValueInitBinary(&jv, jb));
444441

445442
it = JsonbIteratorInit(&jb->root);
@@ -496,7 +493,7 @@ jsonAnalyzeJson(JsonAnalyzeContext *ctx, Jsonb *jb, void *param)
496493

497494
case WJB_VALUE:
498495
case WJB_ELEM:
499-
if (!target || target == stats)
496+
if (collect_values)
500497
jsonAnalyzeJsonValue(ctx, &stats->vstats, &jv);
501498

502499
/* XXX not sure why we're doing this? */
@@ -1222,7 +1219,8 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
12221219
/* XXX Not sure what the first branch is doing (or supposed to)? */
12231220
if (false)
12241221
{
1225-
jsonAnalyzePass(&ctx, jsonAnalyzeJson, NULL);
1222+
/* Collect all values of all paths */
1223+
jsonAnalyzePass(&ctx, jsonAnalyzeJson, (void *)(intptr_t) true);
12261224
jsonAnalyzePaths(&ctx);
12271225
}
12281226
else
@@ -1244,19 +1242,15 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
12441242
oldcxt = MemoryContextSwitchTo(tmpcxt);
12451243

12461244
/*
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-
*
12531245
* XXX If I understand correctly, we simply collect all paths first,
12541246
* without accumulating any Values. And then in the next step we
12551247
* process each path independently, probably to save memory (we
12561248
* don't want to accumulate all values for all paths, with a lot
12571249
* of duplicities).
12581250
*/
1259-
jsonAnalyzePass(&ctx, jsonAnalyzeJson, (void *) -1);
1251+
1252+
/* Collect all paths first and sort them */
1253+
jsonAnalyzePass(&ctx, jsonAnalyzeJson, (void *)(intptr_t) false);
12601254
jsonAnalyzeSortPaths(&ctx);
12611255

12621256
MemoryContextReset(tmpcxt);

0 commit comments

Comments
 (0)