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

Commit 5f5454c

Browse files
author
Nikita Glukhov
committed
Fix access to root analyze counters
1 parent e561156 commit 5f5454c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/backend/utils/adt/jsonb_typanalyze.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,9 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
13891389
JsonPathEntry **paths;
13901390
Jsonb **pstats;
13911391
int npaths;
1392+
int root_analyzed_cnt;
1393+
int root_null_cnt;
1394+
double root_total_width;
13921395

13931396
jsonAnalyzeInit(&ctx, stats, fetchfunc, samplerows, totalrows,
13941397
false /* FIXME make GUC or simply remove */);
@@ -1403,6 +1406,10 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
14031406
/* Collect all values of all paths */
14041407
jsonAnalyzePass(&ctx, jsonAnalyzeCollectPaths, (void *)(intptr_t) true, NULL);
14051408

1409+
root_analyzed_cnt = ctx.analyzed_cnt;
1410+
root_null_cnt = ctx.null_cnt;
1411+
root_total_width = ctx.total_width;
1412+
14061413
/*
14071414
* Now that we're done with processing the documents, we sort the paths
14081415
* we extracted and calculate stats for each of them.
@@ -1454,6 +1461,10 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
14541461
pstats = MemoryContextAlloc(oldcxt, sizeof(*pstats) * npaths);
14551462
stack = MemoryContextAlloc(oldcxt, sizeof(*stack) * (ctx.maxdepth + 1));
14561463

1464+
root_analyzed_cnt = ctx.analyzed_cnt;
1465+
root_null_cnt = ctx.null_cnt;
1466+
root_total_width = ctx.total_width;
1467+
14571468
/*
14581469
* Next, process each path independently to save memory (we don't want
14591470
* to accumulate all values for all paths, with a lot of duplicities).
@@ -1499,23 +1510,23 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
14991510
}
15001511

15011512
/* We can only compute real stats if we found some non-null values. */
1502-
if (ctx.null_cnt >= samplerows)
1513+
if (root_null_cnt >= samplerows)
15031514
{
15041515
/* We found only nulls; assume the column is entirely null */
15051516
stats->stats_valid = true;
15061517
stats->stanullfrac = 1.0;
15071518
stats->stawidth = 0; /* "unknown" */
15081519
stats->stadistinct = 0.0; /* "unknown" */
15091520
}
1510-
else if (!ctx.analyzed_cnt)
1521+
else if (!root_analyzed_cnt)
15111522
{
1512-
int nonnull_cnt = samplerows - ctx.null_cnt;
1523+
int nonnull_cnt = samplerows - root_null_cnt;
15131524

15141525
/* We found some non-null values, but they were all too wide */
15151526
stats->stats_valid = true;
15161527
/* Do the simple null-frac and width stats */
1517-
stats->stanullfrac = (double) ctx.null_cnt / (double) samplerows;
1518-
stats->stawidth = ctx.total_width / (double) nonnull_cnt;
1528+
stats->stanullfrac = (double) root_null_cnt / (double) samplerows;
1529+
stats->stawidth = root_total_width / (double) nonnull_cnt;
15191530
/* Assume all too-wide values are distinct, so it's a unique column */
15201531
stats->stadistinct = -1.0 * (1.0 - stats->stanullfrac);
15211532
}

0 commit comments

Comments
 (0)