24
24
#include "utils/fmgrprotos.h"
25
25
#include "utils/syscache.h"
26
26
27
- #define DEFAULT_RELPAGES Int32GetDatum(0)
28
- #define DEFAULT_RELTUPLES Float4GetDatum(-1.0)
29
- #define DEFAULT_RELALLVISIBLE Int32GetDatum(0)
30
27
31
28
/*
32
29
* Positional argument numbers, names, and types for
@@ -60,40 +57,25 @@ static bool relation_statistics_update(FunctionCallInfo fcinfo, int elevel,
60
57
static bool
61
58
relation_statistics_update (FunctionCallInfo fcinfo , int elevel , bool inplace )
62
59
{
60
+ bool result = true;
63
61
Oid reloid ;
64
62
Relation crel ;
65
- int32 relpages = DEFAULT_RELPAGES ;
63
+ BlockNumber relpages = 0 ;
66
64
bool update_relpages = false;
67
- float reltuples = DEFAULT_RELTUPLES ;
65
+ float reltuples = 0 ;
68
66
bool update_reltuples = false;
69
- int32 relallvisible = DEFAULT_RELALLVISIBLE ;
67
+ BlockNumber relallvisible = 0 ;
70
68
bool update_relallvisible = false;
71
- bool result = true;
72
69
73
70
if (!PG_ARGISNULL (RELPAGES_ARG ))
74
71
{
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;
91
74
}
92
75
93
76
if (!PG_ARGISNULL (RELTUPLES_ARG ))
94
77
{
95
78
reltuples = PG_GETARG_FLOAT4 (RELTUPLES_ARG );
96
-
97
79
if (reltuples < -1.0 )
98
80
{
99
81
ereport (elevel ,
@@ -107,17 +89,8 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
107
89
108
90
if (!PG_ARGISNULL (RELALLVISIBLE_ARG ))
109
91
{
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;
121
94
}
122
95
123
96
stats_check_required_arg (fcinfo , relarginfo , RELATION_ARG );
@@ -201,7 +174,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
201
174
if (update_relpages && relpages != pgcform -> relpages )
202
175
{
203
176
replaces [nreplaces ] = Anum_pg_class_relpages ;
204
- values [nreplaces ] = Int32GetDatum (relpages );
177
+ values [nreplaces ] = UInt32GetDatum (relpages );
205
178
nreplaces ++ ;
206
179
}
207
180
@@ -215,7 +188,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
215
188
if (update_relallvisible && relallvisible != pgcform -> relallvisible )
216
189
{
217
190
replaces [nreplaces ] = Anum_pg_class_relallvisible ;
218
- values [nreplaces ] = Int32GetDatum (relallvisible );
191
+ values [nreplaces ] = UInt32GetDatum (relallvisible );
219
192
nreplaces ++ ;
220
193
}
221
194
@@ -263,11 +236,11 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
263
236
264
237
newfcinfo -> args [0 ].value = PG_GETARG_OID (0 );
265
238
newfcinfo -> args [0 ].isnull = PG_ARGISNULL (0 );
266
- newfcinfo -> args [1 ].value = DEFAULT_RELPAGES ;
239
+ newfcinfo -> args [1 ].value = UInt32GetDatum ( 0 ) ;
267
240
newfcinfo -> args [1 ].isnull = false;
268
- newfcinfo -> args [2 ].value = DEFAULT_RELTUPLES ;
241
+ newfcinfo -> args [2 ].value = Float4GetDatum ( -1.0 ) ;
269
242
newfcinfo -> args [2 ].isnull = false;
270
- newfcinfo -> args [3 ].value = DEFAULT_RELALLVISIBLE ;
243
+ newfcinfo -> args [3 ].value = UInt32GetDatum ( 0 ) ;
271
244
newfcinfo -> args [3 ].isnull = false;
272
245
273
246
relation_statistics_update (newfcinfo , ERROR , false);
0 commit comments