@@ -1389,6 +1389,9 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
1389
1389
JsonPathEntry * * paths ;
1390
1390
Jsonb * * pstats ;
1391
1391
int npaths ;
1392
+ int root_analyzed_cnt ;
1393
+ int root_null_cnt ;
1394
+ double root_total_width ;
1392
1395
1393
1396
jsonAnalyzeInit (& ctx , stats , fetchfunc , samplerows , totalrows ,
1394
1397
false /* FIXME make GUC or simply remove */ );
@@ -1403,6 +1406,10 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
1403
1406
/* Collect all values of all paths */
1404
1407
jsonAnalyzePass (& ctx , jsonAnalyzeCollectPaths , (void * )(intptr_t ) true, NULL );
1405
1408
1409
+ root_analyzed_cnt = ctx .analyzed_cnt ;
1410
+ root_null_cnt = ctx .null_cnt ;
1411
+ root_total_width = ctx .total_width ;
1412
+
1406
1413
/*
1407
1414
* Now that we're done with processing the documents, we sort the paths
1408
1415
* we extracted and calculate stats for each of them.
@@ -1454,6 +1461,10 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
1454
1461
pstats = MemoryContextAlloc (oldcxt , sizeof (* pstats ) * npaths );
1455
1462
stack = MemoryContextAlloc (oldcxt , sizeof (* stack ) * (ctx .maxdepth + 1 ));
1456
1463
1464
+ root_analyzed_cnt = ctx .analyzed_cnt ;
1465
+ root_null_cnt = ctx .null_cnt ;
1466
+ root_total_width = ctx .total_width ;
1467
+
1457
1468
/*
1458
1469
* Next, process each path independently to save memory (we don't want
1459
1470
* to accumulate all values for all paths, with a lot of duplicities).
@@ -1499,23 +1510,23 @@ compute_json_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
1499
1510
}
1500
1511
1501
1512
/* 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 )
1503
1514
{
1504
1515
/* We found only nulls; assume the column is entirely null */
1505
1516
stats -> stats_valid = true;
1506
1517
stats -> stanullfrac = 1.0 ;
1507
1518
stats -> stawidth = 0 ; /* "unknown" */
1508
1519
stats -> stadistinct = 0.0 ; /* "unknown" */
1509
1520
}
1510
- else if (!ctx . analyzed_cnt )
1521
+ else if (!root_analyzed_cnt )
1511
1522
{
1512
- int nonnull_cnt = samplerows - ctx . null_cnt ;
1523
+ int nonnull_cnt = samplerows - root_null_cnt ;
1513
1524
1514
1525
/* We found some non-null values, but they were all too wide */
1515
1526
stats -> stats_valid = true;
1516
1527
/* 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 ;
1519
1530
/* Assume all too-wide values are distinct, so it's a unique column */
1520
1531
stats -> stadistinct = -1.0 * (1.0 - stats -> stanullfrac );
1521
1532
}
0 commit comments