@@ -48,14 +48,13 @@ static struct StatsArgInfo relarginfo[] =
48
48
[NUM_RELATION_STATS_ARGS ] = {0 }
49
49
};
50
50
51
- static bool relation_statistics_update (FunctionCallInfo fcinfo , int elevel ,
52
- bool inplace );
51
+ static bool relation_statistics_update (FunctionCallInfo fcinfo , int elevel );
53
52
54
53
/*
55
54
* Internal function for modifying statistics for a relation.
56
55
*/
57
56
static bool
58
- relation_statistics_update (FunctionCallInfo fcinfo , int elevel , bool inplace )
57
+ relation_statistics_update (FunctionCallInfo fcinfo , int elevel )
59
58
{
60
59
bool result = true;
61
60
Oid reloid ;
@@ -66,6 +65,12 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
66
65
bool update_reltuples = false;
67
66
BlockNumber relallvisible = 0 ;
68
67
bool update_relallvisible = false;
68
+ HeapTuple ctup ;
69
+ Form_pg_class pgcform ;
70
+ int replaces [3 ] = {0 };
71
+ Datum values [3 ] = {0 };
72
+ bool nulls [3 ] = {0 };
73
+ int nreplaces = 0 ;
69
74
70
75
if (!PG_ARGISNULL (RELPAGES_ARG ))
71
76
{
@@ -110,101 +115,52 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
110
115
*/
111
116
crel = table_open (RelationRelationId , RowExclusiveLock );
112
117
113
- if (inplace )
118
+ ctup = SearchSysCache1 (RELOID , ObjectIdGetDatum (reloid ));
119
+ if (!HeapTupleIsValid (ctup ))
114
120
{
115
- HeapTuple ctup = NULL ;
116
- ScanKeyData key [1 ];
117
- Form_pg_class pgcform ;
118
- void * inplace_state = NULL ;
119
- bool dirty = false;
120
-
121
- ScanKeyInit (& key [0 ], Anum_pg_class_oid , BTEqualStrategyNumber , F_OIDEQ ,
122
- ObjectIdGetDatum (reloid ));
123
- systable_inplace_update_begin (crel , ClassOidIndexId , true, NULL , 1 , key ,
124
- & ctup , & inplace_state );
125
- if (!HeapTupleIsValid (ctup ))
126
- elog (ERROR , "pg_class entry for relid %u vanished while updating statistics" ,
127
- reloid );
128
- pgcform = (Form_pg_class ) GETSTRUCT (ctup );
129
-
130
- if (update_relpages && pgcform -> relpages != relpages )
131
- {
132
- pgcform -> relpages = relpages ;
133
- dirty = true;
134
- }
135
- if (update_reltuples && pgcform -> reltuples != reltuples )
136
- {
137
- pgcform -> reltuples = reltuples ;
138
- dirty = true;
139
- }
140
- if (update_relallvisible && pgcform -> relallvisible != relallvisible )
141
- {
142
- pgcform -> relallvisible = relallvisible ;
143
- dirty = true;
144
- }
145
-
146
- if (dirty )
147
- systable_inplace_update_finish (inplace_state , ctup );
148
- else
149
- systable_inplace_update_cancel (inplace_state );
150
-
151
- heap_freetuple (ctup );
121
+ ereport (elevel ,
122
+ (errcode (ERRCODE_OBJECT_IN_USE ),
123
+ errmsg ("pg_class entry for relid %u not found" , reloid )));
124
+ table_close (crel , RowExclusiveLock );
125
+ return false;
152
126
}
153
- else
154
- {
155
- TupleDesc tupdesc = RelationGetDescr (crel );
156
- HeapTuple ctup ;
157
- Form_pg_class pgcform ;
158
- int replaces [3 ] = {0 };
159
- Datum values [3 ] = {0 };
160
- bool nulls [3 ] = {0 };
161
- int nreplaces = 0 ;
162
-
163
- ctup = SearchSysCache1 (RELOID , ObjectIdGetDatum (reloid ));
164
- if (!HeapTupleIsValid (ctup ))
165
- {
166
- ereport (elevel ,
167
- (errcode (ERRCODE_OBJECT_IN_USE ),
168
- errmsg ("pg_class entry for relid %u not found" , reloid )));
169
- table_close (crel , RowExclusiveLock );
170
- return false;
171
- }
172
- pgcform = (Form_pg_class ) GETSTRUCT (ctup );
173
127
174
- if (update_relpages && relpages != pgcform -> relpages )
175
- {
176
- replaces [nreplaces ] = Anum_pg_class_relpages ;
177
- values [nreplaces ] = UInt32GetDatum (relpages );
178
- nreplaces ++ ;
179
- }
128
+ pgcform = (Form_pg_class ) GETSTRUCT (ctup );
180
129
181
- if (update_reltuples && reltuples != pgcform -> reltuples )
182
- {
183
- replaces [nreplaces ] = Anum_pg_class_reltuples ;
184
- values [nreplaces ] = Float4GetDatum ( reltuples );
185
- nreplaces ++ ;
186
- }
130
+ if (update_relpages && relpages != pgcform -> relpages )
131
+ {
132
+ replaces [nreplaces ] = Anum_pg_class_relpages ;
133
+ values [nreplaces ] = UInt32GetDatum ( relpages );
134
+ nreplaces ++ ;
135
+ }
187
136
188
- if (update_relallvisible && relallvisible != pgcform -> relallvisible )
189
- {
190
- replaces [nreplaces ] = Anum_pg_class_relallvisible ;
191
- values [nreplaces ] = UInt32GetDatum ( relallvisible );
192
- nreplaces ++ ;
193
- }
137
+ if (update_reltuples && reltuples != pgcform -> reltuples )
138
+ {
139
+ replaces [nreplaces ] = Anum_pg_class_reltuples ;
140
+ values [nreplaces ] = Float4GetDatum ( reltuples );
141
+ nreplaces ++ ;
142
+ }
194
143
195
- if (nreplaces > 0 )
196
- {
197
- HeapTuple newtup ;
144
+ if (update_relallvisible && relallvisible != pgcform -> relallvisible )
145
+ {
146
+ replaces [nreplaces ] = Anum_pg_class_relallvisible ;
147
+ values [nreplaces ] = UInt32GetDatum (relallvisible );
148
+ nreplaces ++ ;
149
+ }
198
150
199
- newtup = heap_modify_tuple_by_cols (ctup , tupdesc , nreplaces ,
200
- replaces , values , nulls );
201
- CatalogTupleUpdate (crel , & newtup -> t_self , newtup );
202
- heap_freetuple (newtup );
203
- }
151
+ if (nreplaces > 0 )
152
+ {
153
+ TupleDesc tupdesc = RelationGetDescr (crel );
154
+ HeapTuple newtup ;
204
155
205
- ReleaseSysCache (ctup );
156
+ newtup = heap_modify_tuple_by_cols (ctup , tupdesc , nreplaces ,
157
+ replaces , values , nulls );
158
+ CatalogTupleUpdate (crel , & newtup -> t_self , newtup );
159
+ heap_freetuple (newtup );
206
160
}
207
161
162
+ ReleaseSysCache (ctup );
163
+
208
164
/* release the lock, consistent with vac_update_relstats() */
209
165
table_close (crel , RowExclusiveLock );
210
166
@@ -219,7 +175,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
219
175
Datum
220
176
pg_set_relation_stats (PG_FUNCTION_ARGS )
221
177
{
222
- relation_statistics_update (fcinfo , ERROR , false );
178
+ relation_statistics_update (fcinfo , ERROR );
223
179
PG_RETURN_VOID ();
224
180
}
225
181
@@ -243,7 +199,7 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
243
199
newfcinfo -> args [3 ].value = UInt32GetDatum (0 );
244
200
newfcinfo -> args [3 ].isnull = false;
245
201
246
- relation_statistics_update (newfcinfo , ERROR , false );
202
+ relation_statistics_update (newfcinfo , ERROR );
247
203
PG_RETURN_VOID ();
248
204
}
249
205
@@ -261,7 +217,7 @@ pg_restore_relation_stats(PG_FUNCTION_ARGS)
261
217
relarginfo , WARNING ))
262
218
result = false;
263
219
264
- if (!relation_statistics_update (positional_fcinfo , WARNING , true ))
220
+ if (!relation_statistics_update (positional_fcinfo , WARNING ))
265
221
result = false;
266
222
267
223
PG_RETURN_BOOL (result );
0 commit comments