@@ -7954,3 +7954,58 @@ brincostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
7954
7954
7955
7955
* indexPages = index -> pages ;
7956
7956
}
7957
+
7958
+ /*
7959
+ * stats_form_tuple - Form pg_statistic tuple from StatsData.
7960
+ *
7961
+ * If 'data' parameter is NULL, form all-NULL tuple (nullfrac = 1.0).
7962
+ */
7963
+ HeapTuple
7964
+ stats_form_tuple (StatsData * data )
7965
+ {
7966
+ Relation rel ;
7967
+ HeapTuple tuple ;
7968
+ Datum values [Natts_pg_statistic ];
7969
+ bool nulls [Natts_pg_statistic ];
7970
+ int i ;
7971
+
7972
+ for (i = 0 ; i < Natts_pg_statistic ; ++ i )
7973
+ nulls [i ] = false;
7974
+
7975
+ values [Anum_pg_statistic_starelid - 1 ] = ObjectIdGetDatum (InvalidOid );
7976
+ values [Anum_pg_statistic_staattnum - 1 ] = Int16GetDatum (0 );
7977
+ values [Anum_pg_statistic_stainherit - 1 ] = BoolGetDatum (false);
7978
+ values [Anum_pg_statistic_stanullfrac - 1 ] =
7979
+ Float4GetDatum (data ? data -> nullfrac : 1.0 );
7980
+ values [Anum_pg_statistic_stawidth - 1 ] =
7981
+ Int32GetDatum (data ? data -> width : 0 );
7982
+ values [Anum_pg_statistic_stadistinct - 1 ] =
7983
+ Float4GetDatum (data ? data -> distinct : 0 );
7984
+
7985
+ for (i = 0 ; i < STATISTIC_NUM_SLOTS ; i ++ )
7986
+ {
7987
+ StatsSlot * slot = data ? & data -> slots [i ] : NULL ;
7988
+
7989
+ values [Anum_pg_statistic_stakind1 + i - 1 ] =
7990
+ Int16GetDatum (slot ? slot -> kind : 0 );
7991
+
7992
+ values [Anum_pg_statistic_staop1 + i - 1 ] =
7993
+ ObjectIdGetDatum (slot ? slot -> opid : InvalidOid );
7994
+
7995
+ if (slot && DatumGetPointer (slot -> numbers ))
7996
+ values [Anum_pg_statistic_stanumbers1 + i - 1 ] = slot -> numbers ;
7997
+ else
7998
+ nulls [Anum_pg_statistic_stanumbers1 + i - 1 ] = true;
7999
+
8000
+ if (slot && DatumGetPointer (slot -> values ))
8001
+ values [Anum_pg_statistic_stavalues1 + i - 1 ] = slot -> values ;
8002
+ else
8003
+ nulls [Anum_pg_statistic_stavalues1 + i - 1 ] = true;
8004
+ }
8005
+
8006
+ rel = table_open (StatisticRelationId , AccessShareLock );
8007
+ tuple = heap_form_tuple (RelationGetDescr (rel ), values , nulls );
8008
+ table_close (rel , NoLock );
8009
+
8010
+ return tuple ;
8011
+ }
0 commit comments