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

Commit 27a64b7

Browse files
author
Nikita Glukhov
committed
Add comments for jsonPathStatsExtractData()
1 parent 06fac18 commit 27a64b7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/utils/adt/jsonb_selfuncs.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,9 @@ jsonStatsConvertArray(Datum jsonbValueArray, JsonStatType type, Oid typid,
694694
* jsonPathStatsExtractData
695695
* Extract pg_statistics values from statistics for a single path.
696696
*
697-
*
697+
* Extract ordinary MCV, Histogram, Correlation slots for a requested stats
698+
* type. If requested stats for JSONB, include also transformed JSON slot for
699+
* a path and possibly for its subpaths.
698700
*/
699701
static bool
700702
jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
@@ -715,6 +717,12 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
715717

716718
nullfrac = 1.0 - (1.0 - pstats->data->nullfrac) * (1.0 - nullfrac);
717719

720+
/*
721+
* Depending on requested statistics type, select:
722+
* - stavalues data type
723+
* - corresponding eq/lt operators
724+
* - JSONB field, containing stats slots for this statistics type
725+
*/
718726
switch (stattype)
719727
{
720728
case JsonStatJsonb:
@@ -750,6 +758,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
750758
break;
751759
}
752760

761+
/* Extract object containing slots */
753762
data = jsonGetField(*pstats->datum, key);
754763

755764
if (!DatumGetPointer(data))
@@ -768,6 +777,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
768777

769778
statdata->nullfrac += (1.0 - statdata->nullfrac) * nullfrac;
770779

780+
/* Include MCV slot if exists */
771781
if (DatumGetPointer(mcv))
772782
{
773783
slot->kind = STATISTIC_KIND_MCV;
@@ -780,6 +790,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
780790
slot++;
781791
}
782792

793+
/* Include Histogram slot if exists */
783794
if (DatumGetPointer(hst))
784795
{
785796
slot->kind = STATISTIC_KIND_HISTOGRAM;
@@ -791,6 +802,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
791802
slot++;
792803
}
793804

805+
/* Include Correlation slot if exists */
794806
if (DatumGetPointer(corr))
795807
{
796808
Datum correlation = Float4GetDatum(jsonGetFloat4(corr, 0));
@@ -803,6 +815,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
803815
slot++;
804816
}
805817

818+
/* Include JSON statistics for a given path and possibly for its subpaths */
806819
if ((stattype == JsonStatJsonb ||
807820
stattype == JsonStatJsonbWithoutSubpaths) &&
808821
jsonAnalyzeBuildSubPathsData(pstats->data->pathdatums,

0 commit comments

Comments
 (0)