2424#include "utils/fmgrprotos.h"
2525#include "utils/syscache.h"
2626
27- #define DEFAULT_RELPAGES Int32GetDatum(0)
28- #define DEFAULT_RELTUPLES Float4GetDatum(-1.0)
29- #define DEFAULT_RELALLVISIBLE Int32GetDatum(0)
3027
3128/*
3229 * Positional argument numbers, names, and types for
@@ -60,40 +57,25 @@ static bool relation_statistics_update(FunctionCallInfo fcinfo, int elevel,
6057static bool
6158relation_statistics_update (FunctionCallInfo fcinfo , int elevel , bool inplace )
6259{
60+ bool result = true;
6361 Oid reloid ;
6462 Relation crel ;
65- int32 relpages = DEFAULT_RELPAGES ;
63+ BlockNumber relpages = 0 ;
6664 bool update_relpages = false;
67- float reltuples = DEFAULT_RELTUPLES ;
65+ float reltuples = 0 ;
6866 bool update_reltuples = false;
69- int32 relallvisible = DEFAULT_RELALLVISIBLE ;
67+ BlockNumber relallvisible = 0 ;
7068 bool update_relallvisible = false;
71- bool result = true;
7269
7370 if (!PG_ARGISNULL (RELPAGES_ARG ))
7471 {
75- relpages = PG_GETARG_INT32 (RELPAGES_ARG );
76-
77- /*
78- * Partitioned tables may have relpages=-1. Note: for relations with
79- * no storage, relpages=-1 is not used consistently, but must be
80- * supported here.
81- */
82- if (relpages < -1 )
83- {
84- ereport (elevel ,
85- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
86- errmsg ("relpages cannot be < -1" )));
87- result = false;
88- }
89- else
90- update_relpages = true;
72+ relpages = PG_GETARG_UINT32 (RELPAGES_ARG );
73+ update_relpages = true;
9174 }
9275
9376 if (!PG_ARGISNULL (RELTUPLES_ARG ))
9477 {
9578 reltuples = PG_GETARG_FLOAT4 (RELTUPLES_ARG );
96-
9779 if (reltuples < -1.0 )
9880 {
9981 ereport (elevel ,
@@ -107,17 +89,8 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
10789
10890 if (!PG_ARGISNULL (RELALLVISIBLE_ARG ))
10991 {
110- relallvisible = PG_GETARG_INT32 (RELALLVISIBLE_ARG );
111-
112- if (relallvisible < 0 )
113- {
114- ereport (elevel ,
115- (errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
116- errmsg ("relallvisible cannot be < 0" )));
117- result = false;
118- }
119- else
120- update_relallvisible = true;
92+ relallvisible = PG_GETARG_UINT32 (RELALLVISIBLE_ARG );
93+ update_relallvisible = true;
12194 }
12295
12396 stats_check_required_arg (fcinfo , relarginfo , RELATION_ARG );
@@ -201,7 +174,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
201174 if (update_relpages && relpages != pgcform -> relpages )
202175 {
203176 replaces [nreplaces ] = Anum_pg_class_relpages ;
204- values [nreplaces ] = Int32GetDatum (relpages );
177+ values [nreplaces ] = UInt32GetDatum (relpages );
205178 nreplaces ++ ;
206179 }
207180
@@ -215,7 +188,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
215188 if (update_relallvisible && relallvisible != pgcform -> relallvisible )
216189 {
217190 replaces [nreplaces ] = Anum_pg_class_relallvisible ;
218- values [nreplaces ] = Int32GetDatum (relallvisible );
191+ values [nreplaces ] = UInt32GetDatum (relallvisible );
219192 nreplaces ++ ;
220193 }
221194
@@ -263,11 +236,11 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
263236
264237 newfcinfo -> args [0 ].value = PG_GETARG_OID (0 );
265238 newfcinfo -> args [0 ].isnull = PG_ARGISNULL (0 );
266- newfcinfo -> args [1 ].value = DEFAULT_RELPAGES ;
239+ newfcinfo -> args [1 ].value = UInt32GetDatum ( 0 ) ;
267240 newfcinfo -> args [1 ].isnull = false;
268- newfcinfo -> args [2 ].value = DEFAULT_RELTUPLES ;
241+ newfcinfo -> args [2 ].value = Float4GetDatum ( -1.0 ) ;
269242 newfcinfo -> args [2 ].isnull = false;
270- newfcinfo -> args [3 ].value = DEFAULT_RELALLVISIBLE ;
243+ newfcinfo -> args [3 ].value = UInt32GetDatum ( 0 ) ;
271244 newfcinfo -> args [3 ].isnull = false;
272245
273246 relation_statistics_update (newfcinfo , ERROR , false);
0 commit comments