@@ -694,7 +694,9 @@ jsonStatsConvertArray(Datum jsonbValueArray, JsonStatType type, Oid typid,
694
694
* jsonPathStatsExtractData
695
695
* Extract pg_statistics values from statistics for a single path.
696
696
*
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.
698
700
*/
699
701
static bool
700
702
jsonPathStatsExtractData (JsonPathStats pstats , JsonStatType stattype ,
@@ -715,6 +717,12 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
715
717
716
718
nullfrac = 1.0 - (1.0 - pstats -> data -> nullfrac ) * (1.0 - nullfrac );
717
719
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
+ */
718
726
switch (stattype )
719
727
{
720
728
case JsonStatJsonb :
@@ -750,6 +758,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
750
758
break ;
751
759
}
752
760
761
+ /* Extract object containing slots */
753
762
data = jsonGetField (* pstats -> datum , key );
754
763
755
764
if (!DatumGetPointer (data ))
@@ -768,6 +777,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
768
777
769
778
statdata -> nullfrac += (1.0 - statdata -> nullfrac ) * nullfrac ;
770
779
780
+ /* Include MCV slot if exists */
771
781
if (DatumGetPointer (mcv ))
772
782
{
773
783
slot -> kind = STATISTIC_KIND_MCV ;
@@ -780,6 +790,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
780
790
slot ++ ;
781
791
}
782
792
793
+ /* Include Histogram slot if exists */
783
794
if (DatumGetPointer (hst ))
784
795
{
785
796
slot -> kind = STATISTIC_KIND_HISTOGRAM ;
@@ -791,6 +802,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
791
802
slot ++ ;
792
803
}
793
804
805
+ /* Include Correlation slot if exists */
794
806
if (DatumGetPointer (corr ))
795
807
{
796
808
Datum correlation = Float4GetDatum (jsonGetFloat4 (corr , 0 ));
@@ -803,6 +815,7 @@ jsonPathStatsExtractData(JsonPathStats pstats, JsonStatType stattype,
803
815
slot ++ ;
804
816
}
805
817
818
+ /* Include JSON statistics for a given path and possibly for its subpaths */
806
819
if ((stattype == JsonStatJsonb ||
807
820
stattype == JsonStatJsonbWithoutSubpaths ) &&
808
821
jsonAnalyzeBuildSubPathsData (pstats -> data -> pathdatums ,
0 commit comments