@@ -76,16 +76,16 @@ static struct StatsArgInfo attarginfo[] =
76
76
[NUM_ATTRIBUTE_STATS_ARGS ] = {0 }
77
77
};
78
78
79
- static bool attribute_statistics_update (FunctionCallInfo fcinfo , int elevel );
79
+ static bool attribute_statistics_update (FunctionCallInfo fcinfo );
80
80
static Node * get_attr_expr (Relation rel , int attnum );
81
- static void get_attr_stat_type (Oid reloid , AttrNumber attnum , int elevel ,
81
+ static void get_attr_stat_type (Oid reloid , AttrNumber attnum ,
82
82
Oid * atttypid , int32 * atttypmod ,
83
83
char * atttyptype , Oid * atttypcoll ,
84
84
Oid * eq_opr , Oid * lt_opr );
85
- static bool get_elem_stat_type (Oid atttypid , char atttyptype , int elevel ,
85
+ static bool get_elem_stat_type (Oid atttypid , char atttyptype ,
86
86
Oid * elemtypid , Oid * elem_eq_opr );
87
87
static Datum text_to_stavalues (const char * staname , FmgrInfo * array_in , Datum d ,
88
- Oid typid , int32 typmod , int elevel , bool * ok );
88
+ Oid typid , int32 typmod , bool * ok );
89
89
static void set_stats_slot (Datum * values , bool * nulls , bool * replaces ,
90
90
int16 stakind , Oid staop , Oid stacoll ,
91
91
Datum stanumbers , bool stanumbers_isnull ,
@@ -109,11 +109,11 @@ static void init_empty_stats_tuple(Oid reloid, int16 attnum, bool inherited,
109
109
*
110
110
* Major errors, such as the table not existing, the attribute not existing,
111
111
* or a permissions failure are always reported at ERROR. Other errors, such
112
- * as a conversion failure on one statistic kind, are reported at 'elevel',
112
+ * as a conversion failure on one statistic kind, are reported as a WARNING
113
113
* and other statistic kinds may still be updated.
114
114
*/
115
115
static bool
116
- attribute_statistics_update (FunctionCallInfo fcinfo , int elevel )
116
+ attribute_statistics_update (FunctionCallInfo fcinfo )
117
117
{
118
118
Oid reloid ;
119
119
Name attname ;
@@ -184,67 +184,63 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
184
184
inherited = PG_GETARG_BOOL (INHERITED_ARG );
185
185
186
186
/*
187
- * Check argument sanity. If some arguments are unusable, emit at elevel
187
+ * Check argument sanity. If some arguments are unusable, emit a WARNING
188
188
* and set the corresponding argument to NULL in fcinfo.
189
189
*/
190
190
191
- if (!stats_check_arg_array (fcinfo , attarginfo , MOST_COMMON_FREQS_ARG ,
192
- elevel ))
191
+ if (!stats_check_arg_array (fcinfo , attarginfo , MOST_COMMON_FREQS_ARG ))
193
192
{
194
193
do_mcv = false;
195
194
result = false;
196
195
}
197
196
198
- if (!stats_check_arg_array (fcinfo , attarginfo , MOST_COMMON_ELEM_FREQS_ARG ,
199
- elevel ))
197
+ if (!stats_check_arg_array (fcinfo , attarginfo , MOST_COMMON_ELEM_FREQS_ARG ))
200
198
{
201
199
do_mcelem = false;
202
200
result = false;
203
201
}
204
- if (!stats_check_arg_array (fcinfo , attarginfo , ELEM_COUNT_HISTOGRAM_ARG ,
205
- elevel ))
202
+ if (!stats_check_arg_array (fcinfo , attarginfo , ELEM_COUNT_HISTOGRAM_ARG ))
206
203
{
207
204
do_dechist = false;
208
205
result = false;
209
206
}
210
207
211
208
if (!stats_check_arg_pair (fcinfo , attarginfo ,
212
- MOST_COMMON_VALS_ARG , MOST_COMMON_FREQS_ARG ,
213
- elevel ))
209
+ MOST_COMMON_VALS_ARG , MOST_COMMON_FREQS_ARG ))
214
210
{
215
211
do_mcv = false;
216
212
result = false;
217
213
}
218
214
219
215
if (!stats_check_arg_pair (fcinfo , attarginfo ,
220
216
MOST_COMMON_ELEMS_ARG ,
221
- MOST_COMMON_ELEM_FREQS_ARG , elevel ))
217
+ MOST_COMMON_ELEM_FREQS_ARG ))
222
218
{
223
219
do_mcelem = false;
224
220
result = false;
225
221
}
226
222
227
223
if (!stats_check_arg_pair (fcinfo , attarginfo ,
228
224
RANGE_LENGTH_HISTOGRAM_ARG ,
229
- RANGE_EMPTY_FRAC_ARG , elevel ))
225
+ RANGE_EMPTY_FRAC_ARG ))
230
226
{
231
227
do_range_length_histogram = false;
232
228
result = false;
233
229
}
234
230
235
231
/* derive information from attribute */
236
- get_attr_stat_type (reloid , attnum , elevel ,
232
+ get_attr_stat_type (reloid , attnum ,
237
233
& atttypid , & atttypmod ,
238
234
& atttyptype , & atttypcoll ,
239
235
& eq_opr , & lt_opr );
240
236
241
237
/* if needed, derive element type */
242
238
if (do_mcelem || do_dechist )
243
239
{
244
- if (!get_elem_stat_type (atttypid , atttyptype , elevel ,
240
+ if (!get_elem_stat_type (atttypid , atttyptype ,
245
241
& elemtypid , & elem_eq_opr ))
246
242
{
247
- ereport (elevel ,
243
+ ereport (WARNING ,
248
244
(errmsg ("unable to determine element type of attribute \"%s\"" , NameStr (* attname )),
249
245
errdetail ("Cannot set STATISTIC_KIND_MCELEM or STATISTIC_KIND_DECHIST." )));
250
246
elemtypid = InvalidOid ;
@@ -259,7 +255,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
259
255
/* histogram and correlation require less-than operator */
260
256
if ((do_histogram || do_correlation ) && !OidIsValid (lt_opr ))
261
257
{
262
- ereport (elevel ,
258
+ ereport (WARNING ,
263
259
(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
264
260
errmsg ("could not determine less-than operator for attribute \"%s\"" , NameStr (* attname )),
265
261
errdetail ("Cannot set STATISTIC_KIND_HISTOGRAM or STATISTIC_KIND_CORRELATION." )));
@@ -273,7 +269,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
273
269
if ((do_range_length_histogram || do_bounds_histogram ) &&
274
270
!(atttyptype == TYPTYPE_RANGE || atttyptype == TYPTYPE_MULTIRANGE ))
275
271
{
276
- ereport (elevel ,
272
+ ereport (WARNING ,
277
273
(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
278
274
errmsg ("attribute \"%s\" is not a range type" , NameStr (* attname )),
279
275
errdetail ("Cannot set STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM or STATISTIC_KIND_BOUNDS_HISTOGRAM." )));
@@ -322,7 +318,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
322
318
& array_in_fn ,
323
319
PG_GETARG_DATUM (MOST_COMMON_VALS_ARG ),
324
320
atttypid , atttypmod ,
325
- elevel , & converted );
321
+ & converted );
326
322
327
323
if (converted )
328
324
{
@@ -344,7 +340,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
344
340
stavalues = text_to_stavalues ("histogram_bounds" ,
345
341
& array_in_fn ,
346
342
PG_GETARG_DATUM (HISTOGRAM_BOUNDS_ARG ),
347
- atttypid , atttypmod , elevel ,
343
+ atttypid , atttypmod ,
348
344
& converted );
349
345
350
346
if (converted )
@@ -382,7 +378,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
382
378
& array_in_fn ,
383
379
PG_GETARG_DATUM (MOST_COMMON_ELEMS_ARG ),
384
380
elemtypid , atttypmod ,
385
- elevel , & converted );
381
+ & converted );
386
382
387
383
if (converted )
388
384
{
@@ -422,7 +418,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
422
418
& array_in_fn ,
423
419
PG_GETARG_DATUM (RANGE_BOUNDS_HISTOGRAM_ARG ),
424
420
atttypid , atttypmod ,
425
- elevel , & converted );
421
+ & converted );
426
422
427
423
if (converted )
428
424
{
@@ -449,7 +445,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
449
445
stavalues = text_to_stavalues ("range_length_histogram" ,
450
446
& array_in_fn ,
451
447
PG_GETARG_DATUM (RANGE_LENGTH_HISTOGRAM_ARG ),
452
- FLOAT8OID , 0 , elevel , & converted );
448
+ FLOAT8OID , 0 , & converted );
453
449
454
450
if (converted )
455
451
{
@@ -517,7 +513,7 @@ get_attr_expr(Relation rel, int attnum)
517
513
* Derive type information from the attribute.
518
514
*/
519
515
static void
520
- get_attr_stat_type (Oid reloid , AttrNumber attnum , int elevel ,
516
+ get_attr_stat_type (Oid reloid , AttrNumber attnum ,
521
517
Oid * atttypid , int32 * atttypmod ,
522
518
char * atttyptype , Oid * atttypcoll ,
523
519
Oid * eq_opr , Oid * lt_opr )
@@ -599,7 +595,7 @@ get_attr_stat_type(Oid reloid, AttrNumber attnum, int elevel,
599
595
* Derive element type information from the attribute type.
600
596
*/
601
597
static bool
602
- get_elem_stat_type (Oid atttypid , char atttyptype , int elevel ,
598
+ get_elem_stat_type (Oid atttypid , char atttyptype ,
603
599
Oid * elemtypid , Oid * elem_eq_opr )
604
600
{
605
601
TypeCacheEntry * elemtypcache ;
@@ -634,13 +630,13 @@ get_elem_stat_type(Oid atttypid, char atttyptype, int elevel,
634
630
/*
635
631
* Cast a text datum into an array with element type elemtypid.
636
632
*
637
- * If an error is encountered, capture it and re-throw at elevel , and set ok
638
- * to false. If the resulting array contains NULLs, raise an error at elevel
639
- * and set ok to false. Otherwise, set ok to true.
633
+ * If an error is encountered, capture it and re-throw a WARNING , and set ok
634
+ * to false. If the resulting array contains NULLs, raise a WARNING and set ok
635
+ * to false. Otherwise, set ok to true.
640
636
*/
641
637
static Datum
642
638
text_to_stavalues (const char * staname , FmgrInfo * array_in , Datum d , Oid typid ,
643
- int32 typmod , int elevel , bool * ok )
639
+ int32 typmod , bool * ok )
644
640
{
645
641
LOCAL_FCINFO (fcinfo , 8 );
646
642
char * s ;
@@ -667,16 +663,15 @@ text_to_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid,
667
663
668
664
if (escontext .error_occurred )
669
665
{
670
- if (elevel != ERROR )
671
- escontext .error_data -> elevel = elevel ;
666
+ escontext .error_data -> elevel = WARNING ;
672
667
ThrowErrorData (escontext .error_data );
673
668
* ok = false;
674
669
return (Datum ) 0 ;
675
670
}
676
671
677
672
if (array_contains_nulls (DatumGetArrayTypeP (result )))
678
673
{
679
- ereport (elevel ,
674
+ ereport (WARNING ,
680
675
(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
681
676
errmsg ("\"%s\" array cannot contain NULL values" , staname )));
682
677
* ok = false;
@@ -851,33 +846,6 @@ init_empty_stats_tuple(Oid reloid, int16 attnum, bool inherited,
851
846
}
852
847
}
853
848
854
- /*
855
- * Import statistics for a given relation attribute.
856
- *
857
- * Inserts or replaces a row in pg_statistic for the given relation and
858
- * attribute name. It takes input parameters that correspond to columns in the
859
- * view pg_stats.
860
- *
861
- * Parameters null_frac, avg_width, and n_distinct all correspond to NOT NULL
862
- * columns in pg_statistic. The remaining parameters all belong to a specific
863
- * stakind. Some stakinds require multiple parameters, which must be specified
864
- * together (or neither specified).
865
- *
866
- * Parameters are only superficially validated. Omitting a parameter or
867
- * passing NULL leaves the statistic unchanged.
868
- *
869
- * Parameters corresponding to ANYARRAY columns are instead passed in as text
870
- * values, which is a valid input string for an array of the type or element
871
- * type of the attribute. Any error generated by the array_in() function will
872
- * in turn fail the function.
873
- */
874
- Datum
875
- pg_set_attribute_stats (PG_FUNCTION_ARGS )
876
- {
877
- attribute_statistics_update (fcinfo , ERROR );
878
- PG_RETURN_VOID ();
879
- }
880
-
881
849
/*
882
850
* Delete statistics for the given attribute.
883
851
*/
@@ -933,10 +901,10 @@ pg_restore_attribute_stats(PG_FUNCTION_ARGS)
933
901
InvalidOid , NULL , NULL );
934
902
935
903
if (!stats_fill_fcinfo_from_arg_pairs (fcinfo , positional_fcinfo ,
936
- attarginfo , WARNING ))
904
+ attarginfo ))
937
905
result = false;
938
906
939
- if (!attribute_statistics_update (positional_fcinfo , WARNING ))
907
+ if (!attribute_statistics_update (positional_fcinfo ))
940
908
result = false;
941
909
942
910
PG_RETURN_BOOL (result );
0 commit comments