@@ -76,16 +76,16 @@ static struct StatsArgInfo attarginfo[] =
7676[NUM_ATTRIBUTE_STATS_ARGS ]= {0 }
7777};
7878
79- static bool attribute_statistics_update (FunctionCallInfo fcinfo , int elevel );
79+ static bool attribute_statistics_update (FunctionCallInfo fcinfo );
8080static 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 ,
8282Oid * atttypid ,int32 * atttypmod ,
8383char * atttyptype ,Oid * atttypcoll ,
8484Oid * 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 ,
8686Oid * elemtypid ,Oid * elem_eq_opr );
8787static 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 );
8989static void set_stats_slot (Datum * values ,bool * nulls ,bool * replaces ,
9090int16 stakind ,Oid staop ,Oid stacoll ,
9191Datum stanumbers ,bool stanumbers_isnull ,
@@ -109,11 +109,11 @@ static void init_empty_stats_tuple(Oid reloid, int16 attnum, bool inherited,
109109 *
110110 * Major errors, such as the table not existing, the attribute not existing,
111111 * or a permissions failure are always reported at ERROR. Other errors, such
112- * as a conversion failure on one statistic kind, are reportedat 'elevel',
112+ * as a conversion failure on one statistic kind, are reportedas a WARNING
113113 * and other statistic kinds may still be updated.
114114 */
115115static bool
116- attribute_statistics_update (FunctionCallInfo fcinfo , int elevel )
116+ attribute_statistics_update (FunctionCallInfo fcinfo )
117117{
118118Oid reloid ;
119119Name attname ;
@@ -184,67 +184,63 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
184184inherited = PG_GETARG_BOOL (INHERITED_ARG );
185185
186186/*
187- * Check argument sanity. If some arguments are unusable, emitat elevel
187+ * Check argument sanity. If some arguments are unusable, emita WARNING
188188 * and set the corresponding argument to NULL in fcinfo.
189189 */
190190
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 ))
193192{
194193do_mcv = false;
195194result = false;
196195}
197196
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 ))
200198{
201199do_mcelem = false;
202200result = false;
203201}
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 ))
206203{
207204do_dechist = false;
208205result = false;
209206}
210207
211208if (!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 ))
214210{
215211do_mcv = false;
216212result = false;
217213}
218214
219215if (!stats_check_arg_pair (fcinfo ,attarginfo ,
220216MOST_COMMON_ELEMS_ARG ,
221- MOST_COMMON_ELEM_FREQS_ARG , elevel ))
217+ MOST_COMMON_ELEM_FREQS_ARG ))
222218{
223219do_mcelem = false;
224220result = false;
225221}
226222
227223if (!stats_check_arg_pair (fcinfo ,attarginfo ,
228224RANGE_LENGTH_HISTOGRAM_ARG ,
229- RANGE_EMPTY_FRAC_ARG , elevel ))
225+ RANGE_EMPTY_FRAC_ARG ))
230226{
231227do_range_length_histogram = false;
232228result = false;
233229}
234230
235231/* derive information from attribute */
236- get_attr_stat_type (reloid ,attnum ,elevel ,
232+ get_attr_stat_type (reloid ,attnum ,
237233& atttypid ,& atttypmod ,
238234& atttyptype ,& atttypcoll ,
239235& eq_opr ,& lt_opr );
240236
241237/* if needed, derive element type */
242238if (do_mcelem || do_dechist )
243239{
244- if (!get_elem_stat_type (atttypid ,atttyptype ,elevel ,
240+ if (!get_elem_stat_type (atttypid ,atttyptype ,
245241& elemtypid ,& elem_eq_opr ))
246242{
247- ereport (elevel ,
243+ ereport (WARNING ,
248244(errmsg ("unable to determine element type of attribute \"%s\"" ,NameStr (* attname )),
249245errdetail ("Cannot set STATISTIC_KIND_MCELEM or STATISTIC_KIND_DECHIST." )));
250246elemtypid = InvalidOid ;
@@ -259,7 +255,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
259255/* histogram and correlation require less-than operator */
260256if ((do_histogram || do_correlation )&& !OidIsValid (lt_opr ))
261257{
262- ereport (elevel ,
258+ ereport (WARNING ,
263259(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
264260errmsg ("could not determine less-than operator for attribute \"%s\"" ,NameStr (* attname )),
265261errdetail ("Cannot set STATISTIC_KIND_HISTOGRAM or STATISTIC_KIND_CORRELATION." )));
@@ -273,7 +269,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
273269if ((do_range_length_histogram || do_bounds_histogram )&&
274270!(atttyptype == TYPTYPE_RANGE || atttyptype == TYPTYPE_MULTIRANGE ))
275271{
276- ereport (elevel ,
272+ ereport (WARNING ,
277273(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
278274errmsg ("attribute \"%s\" is not a range type" ,NameStr (* attname )),
279275errdetail ("Cannot set STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM or STATISTIC_KIND_BOUNDS_HISTOGRAM." )));
@@ -322,7 +318,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
322318& array_in_fn ,
323319PG_GETARG_DATUM (MOST_COMMON_VALS_ARG ),
324320atttypid ,atttypmod ,
325- elevel , & converted );
321+ & converted );
326322
327323if (converted )
328324{
@@ -344,7 +340,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
344340stavalues = text_to_stavalues ("histogram_bounds" ,
345341& array_in_fn ,
346342PG_GETARG_DATUM (HISTOGRAM_BOUNDS_ARG ),
347- atttypid ,atttypmod ,elevel ,
343+ atttypid ,atttypmod ,
348344& converted );
349345
350346if (converted )
@@ -382,7 +378,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
382378& array_in_fn ,
383379PG_GETARG_DATUM (MOST_COMMON_ELEMS_ARG ),
384380elemtypid ,atttypmod ,
385- elevel , & converted );
381+ & converted );
386382
387383if (converted )
388384{
@@ -422,7 +418,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
422418& array_in_fn ,
423419PG_GETARG_DATUM (RANGE_BOUNDS_HISTOGRAM_ARG ),
424420atttypid ,atttypmod ,
425- elevel , & converted );
421+ & converted );
426422
427423if (converted )
428424{
@@ -449,7 +445,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
449445stavalues = text_to_stavalues ("range_length_histogram" ,
450446& array_in_fn ,
451447PG_GETARG_DATUM (RANGE_LENGTH_HISTOGRAM_ARG ),
452- FLOAT8OID ,0 ,elevel , & converted );
448+ FLOAT8OID ,0 ,& converted );
453449
454450if (converted )
455451{
@@ -517,7 +513,7 @@ get_attr_expr(Relation rel, int attnum)
517513 * Derive type information from the attribute.
518514 */
519515static void
520- get_attr_stat_type (Oid reloid ,AttrNumber attnum ,int elevel ,
516+ get_attr_stat_type (Oid reloid ,AttrNumber attnum ,
521517Oid * atttypid ,int32 * atttypmod ,
522518char * atttyptype ,Oid * atttypcoll ,
523519Oid * eq_opr ,Oid * lt_opr )
@@ -599,7 +595,7 @@ get_attr_stat_type(Oid reloid, AttrNumber attnum, int elevel,
599595 * Derive element type information from the attribute type.
600596 */
601597static bool
602- get_elem_stat_type (Oid atttypid ,char atttyptype ,int elevel ,
598+ get_elem_stat_type (Oid atttypid ,char atttyptype ,
603599Oid * elemtypid ,Oid * elem_eq_opr )
604600{
605601TypeCacheEntry * elemtypcache ;
@@ -634,13 +630,13 @@ get_elem_stat_type(Oid atttypid, char atttyptype, int elevel,
634630/*
635631 * Cast a text datum into an array with element type elemtypid.
636632 *
637- * If an error is encountered, capture it and re-throwat elevel , and set ok
638- * to false. If the resulting array contains NULLs, raisean error at elevel
639- *and set ok to false. Otherwise, set ok to true.
633+ * If an error is encountered, capture it and re-throwa WARNING , and set ok
634+ * to false. If the resulting array contains NULLs, raisea WARNING and set ok
635+ * to false. Otherwise, set ok to true.
640636 */
641637static Datum
642638text_to_stavalues (const char * staname ,FmgrInfo * array_in ,Datum d ,Oid typid ,
643- int32 typmod ,int elevel , bool * ok )
639+ int32 typmod ,bool * ok )
644640{
645641LOCAL_FCINFO (fcinfo ,8 );
646642char * s ;
@@ -667,16 +663,15 @@ text_to_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid,
667663
668664if (escontext .error_occurred )
669665{
670- if (elevel != ERROR )
671- escontext .error_data -> elevel = elevel ;
666+ escontext .error_data -> elevel = WARNING ;
672667ThrowErrorData (escontext .error_data );
673668* ok = false;
674669return (Datum )0 ;
675670}
676671
677672if (array_contains_nulls (DatumGetArrayTypeP (result )))
678673{
679- ereport (elevel ,
674+ ereport (WARNING ,
680675(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
681676errmsg ("\"%s\" array cannot contain NULL values" ,staname )));
682677* ok = false;
@@ -851,33 +846,6 @@ init_empty_stats_tuple(Oid reloid, int16 attnum, bool inherited,
851846}
852847}
853848
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-
881849/*
882850 * Delete statistics for the given attribute.
883851 */
@@ -933,10 +901,10 @@ pg_restore_attribute_stats(PG_FUNCTION_ARGS)
933901InvalidOid ,NULL ,NULL );
934902
935903if (!stats_fill_fcinfo_from_arg_pairs (fcinfo ,positional_fcinfo ,
936- attarginfo , WARNING ))
904+ attarginfo ))
937905result = false;
938906
939- if (!attribute_statistics_update (positional_fcinfo , WARNING ))
907+ if (!attribute_statistics_update (positional_fcinfo ))
940908result = false;
941909
942910PG_RETURN_BOOL (result );