Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita5cbdeb

Browse files
committed
Remove redundant pg_set_*_stats() variants.
After commitf3dae2a, the primary purpose of separating thepg_set_*_stats() from the pg_restore_*_stats() variants waseliminated.Leave pg_restore_relation_stats() and pg_restore_attribute_stats(),which satisfy both purposes, and remove pg_set_relation_stats() andpg_set_attribute_stats().Reviewed-by: Corey Huinker <corey.huinker@gmail.com>Discussion:https://postgr.es/m/1457469.1740419458@sss.pgh.pa.us
1 parentecbff43 commita5cbdeb

File tree

10 files changed

+872
-2022
lines changed

10 files changed

+872
-2022
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 104 additions & 150 deletions
Large diffs are not rendered by default.

‎src/backend/catalog/system_functions.sql

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -636,38 +636,6 @@ LANGUAGE INTERNAL
636636
CALLEDONNULL INPUT VOLATILE PARALLEL SAFE
637637
AS'pg_stat_reset_slru';
638638

639-
CREATEOR REPLACE FUNCTION
640-
pg_set_relation_stats(relation regclass,
641-
relpagesinteger DEFAULTNULL,
642-
reltuplesreal DEFAULTNULL,
643-
relallvisibleinteger DEFAULTNULL)
644-
RETURNS void
645-
LANGUAGE INTERNAL
646-
CALLEDONNULL INPUT VOLATILE
647-
AS'pg_set_relation_stats';
648-
649-
CREATEOR REPLACE FUNCTION
650-
pg_set_attribute_stats(relation regclass,
651-
attname name,
652-
inherited bool,
653-
null_fracreal DEFAULTNULL,
654-
avg_widthinteger DEFAULTNULL,
655-
n_distinctreal DEFAULTNULL,
656-
most_common_valstext DEFAULTNULL,
657-
most_common_freqsreal[] DEFAULTNULL,
658-
histogram_boundstext DEFAULTNULL,
659-
correlationreal DEFAULTNULL,
660-
most_common_elemstext DEFAULTNULL,
661-
most_common_elem_freqsreal[] DEFAULTNULL,
662-
elem_count_histogramreal[] DEFAULTNULL,
663-
range_length_histogramtext DEFAULTNULL,
664-
range_empty_fracreal DEFAULTNULL,
665-
range_bounds_histogramtext DEFAULTNULL)
666-
RETURNS void
667-
LANGUAGE INTERNAL
668-
CALLEDONNULL INPUT VOLATILE
669-
AS'pg_set_attribute_stats';
670-
671639
--
672640
-- The default permissions for functions mean that anyone can execute them.
673641
-- A number of functions shouldn't be executable by just anyone, but rather

‎src/backend/statistics/attribute_stats.c

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ static struct StatsArgInfo attarginfo[] =
7676
[NUM_ATTRIBUTE_STATS_ARGS]= {0}
7777
};
7878

79-
staticboolattribute_statistics_update(FunctionCallInfofcinfo,intelevel);
79+
staticboolattribute_statistics_update(FunctionCallInfofcinfo);
8080
staticNode*get_attr_expr(Relationrel,intattnum);
81-
staticvoidget_attr_stat_type(Oidreloid,AttrNumberattnum,intelevel,
81+
staticvoidget_attr_stat_type(Oidreloid,AttrNumberattnum,
8282
Oid*atttypid,int32*atttypmod,
8383
char*atttyptype,Oid*atttypcoll,
8484
Oid*eq_opr,Oid*lt_opr);
85-
staticboolget_elem_stat_type(Oidatttypid,charatttyptype,intelevel,
85+
staticboolget_elem_stat_type(Oidatttypid,charatttyptype,
8686
Oid*elemtypid,Oid*elem_eq_opr);
8787
staticDatumtext_to_stavalues(constchar*staname,FmgrInfo*array_in,Datumd,
88-
Oidtypid,int32typmod,intelevel,bool*ok);
88+
Oidtypid,int32typmod,bool*ok);
8989
staticvoidset_stats_slot(Datum*values,bool*nulls,bool*replaces,
9090
int16stakind,Oidstaop,Oidstacoll,
9191
Datumstanumbers,boolstanumbers_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
*/
115115
staticbool
116-
attribute_statistics_update(FunctionCallInfofcinfo,intelevel)
116+
attribute_statistics_update(FunctionCallInfofcinfo)
117117
{
118118
Oidreloid;
119119
Nameattname;
@@ -184,67 +184,63 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
184184
inherited=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
{
194193
do_mcv= false;
195194
result= 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
{
201199
do_mcelem= false;
202200
result= 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
{
207204
do_dechist= false;
208205
result= false;
209206
}
210207

211208
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))
214210
{
215211
do_mcv= false;
216212
result= false;
217213
}
218214

219215
if (!stats_check_arg_pair(fcinfo,attarginfo,
220216
MOST_COMMON_ELEMS_ARG,
221-
MOST_COMMON_ELEM_FREQS_ARG,elevel))
217+
MOST_COMMON_ELEM_FREQS_ARG))
222218
{
223219
do_mcelem= false;
224220
result= false;
225221
}
226222

227223
if (!stats_check_arg_pair(fcinfo,attarginfo,
228224
RANGE_LENGTH_HISTOGRAM_ARG,
229-
RANGE_EMPTY_FRAC_ARG,elevel))
225+
RANGE_EMPTY_FRAC_ARG))
230226
{
231227
do_range_length_histogram= false;
232228
result= 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 */
242238
if (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)),
249245
errdetail("Cannot set STATISTIC_KIND_MCELEM or STATISTIC_KIND_DECHIST.")));
250246
elemtypid=InvalidOid;
@@ -259,7 +255,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
259255
/* histogram and correlation require less-than operator */
260256
if ((do_histogram||do_correlation)&& !OidIsValid(lt_opr))
261257
{
262-
ereport(elevel,
258+
ereport(WARNING,
263259
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
264260
errmsg("could not determine less-than operator for attribute \"%s\"",NameStr(*attname)),
265261
errdetail("Cannot set STATISTIC_KIND_HISTOGRAM or STATISTIC_KIND_CORRELATION.")));
@@ -273,7 +269,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
273269
if ((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),
278274
errmsg("attribute \"%s\" is not a range type",NameStr(*attname)),
279275
errdetail("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,
323319
PG_GETARG_DATUM(MOST_COMMON_VALS_ARG),
324320
atttypid,atttypmod,
325-
elevel,&converted);
321+
&converted);
326322

327323
if (converted)
328324
{
@@ -344,7 +340,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
344340
stavalues=text_to_stavalues("histogram_bounds",
345341
&array_in_fn,
346342
PG_GETARG_DATUM(HISTOGRAM_BOUNDS_ARG),
347-
atttypid,atttypmod,elevel,
343+
atttypid,atttypmod,
348344
&converted);
349345

350346
if (converted)
@@ -382,7 +378,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
382378
&array_in_fn,
383379
PG_GETARG_DATUM(MOST_COMMON_ELEMS_ARG),
384380
elemtypid,atttypmod,
385-
elevel,&converted);
381+
&converted);
386382

387383
if (converted)
388384
{
@@ -422,7 +418,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
422418
&array_in_fn,
423419
PG_GETARG_DATUM(RANGE_BOUNDS_HISTOGRAM_ARG),
424420
atttypid,atttypmod,
425-
elevel,&converted);
421+
&converted);
426422

427423
if (converted)
428424
{
@@ -449,7 +445,7 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
449445
stavalues=text_to_stavalues("range_length_histogram",
450446
&array_in_fn,
451447
PG_GETARG_DATUM(RANGE_LENGTH_HISTOGRAM_ARG),
452-
FLOAT8OID,0,elevel,&converted);
448+
FLOAT8OID,0,&converted);
453449

454450
if (converted)
455451
{
@@ -517,7 +513,7 @@ get_attr_expr(Relation rel, int attnum)
517513
* Derive type information from the attribute.
518514
*/
519515
staticvoid
520-
get_attr_stat_type(Oidreloid,AttrNumberattnum,intelevel,
516+
get_attr_stat_type(Oidreloid,AttrNumberattnum,
521517
Oid*atttypid,int32*atttypmod,
522518
char*atttyptype,Oid*atttypcoll,
523519
Oid*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
*/
601597
staticbool
602-
get_elem_stat_type(Oidatttypid,charatttyptype,intelevel,
598+
get_elem_stat_type(Oidatttypid,charatttyptype,
603599
Oid*elemtypid,Oid*elem_eq_opr)
604600
{
605601
TypeCacheEntry*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 okto 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
*/
641637
staticDatum
642638
text_to_stavalues(constchar*staname,FmgrInfo*array_in,Datumd,Oidtypid,
643-
int32typmod,intelevel,bool*ok)
639+
int32typmod,bool*ok)
644640
{
645641
LOCAL_FCINFO(fcinfo,8);
646642
char*s;
@@ -667,16 +663,15 @@ text_to_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid,
667663

668664
if (escontext.error_occurred)
669665
{
670-
if (elevel!=ERROR)
671-
escontext.error_data->elevel=elevel;
666+
escontext.error_data->elevel=WARNING;
672667
ThrowErrorData(escontext.error_data);
673668
*ok= false;
674669
return (Datum)0;
675670
}
676671

677672
if (array_contains_nulls(DatumGetArrayTypeP(result)))
678673
{
679-
ereport(elevel,
674+
ereport(WARNING,
680675
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
681676
errmsg("\"%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)
933901
InvalidOid,NULL,NULL);
934902

935903
if (!stats_fill_fcinfo_from_arg_pairs(fcinfo,positional_fcinfo,
936-
attarginfo,WARNING))
904+
attarginfo))
937905
result= false;
938906

939-
if (!attribute_statistics_update(positional_fcinfo,WARNING))
907+
if (!attribute_statistics_update(positional_fcinfo))
940908
result= false;
941909

942910
PG_RETURN_BOOL(result);

‎src/backend/statistics/relation_stats.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ static struct StatsArgInfo relarginfo[] =
4848
[NUM_RELATION_STATS_ARGS]= {0}
4949
};
5050

51-
staticboolrelation_statistics_update(FunctionCallInfofcinfo,intelevel);
51+
staticboolrelation_statistics_update(FunctionCallInfofcinfo);
5252

5353
/*
5454
* Internal function for modifying statistics for a relation.
5555
*/
5656
staticbool
57-
relation_statistics_update(FunctionCallInfofcinfo,intelevel)
57+
relation_statistics_update(FunctionCallInfofcinfo)
5858
{
5959
boolresult= true;
6060
Oidreloid;
@@ -83,7 +83,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
8383
reltuples=PG_GETARG_FLOAT4(RELTUPLES_ARG);
8484
if (reltuples<-1.0)
8585
{
86-
ereport(elevel,
86+
ereport(WARNING,
8787
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
8888
errmsg("reltuples cannot be < -1.0")));
8989
result= false;
@@ -118,7 +118,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
118118
ctup=SearchSysCache1(RELOID,ObjectIdGetDatum(reloid));
119119
if (!HeapTupleIsValid(ctup))
120120
{
121-
ereport(elevel,
121+
ereport(WARNING,
122122
(errcode(ERRCODE_OBJECT_IN_USE),
123123
errmsg("pg_class entry for relid %u not found",reloid)));
124124
table_close(crel,RowExclusiveLock);
@@ -169,16 +169,6 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
169169
returnresult;
170170
}
171171

172-
/*
173-
* Set statistics for a given pg_class entry.
174-
*/
175-
Datum
176-
pg_set_relation_stats(PG_FUNCTION_ARGS)
177-
{
178-
relation_statistics_update(fcinfo,ERROR);
179-
PG_RETURN_VOID();
180-
}
181-
182172
/*
183173
* Clear statistics for a given pg_class entry; that is, set back to initial
184174
* stats for a newly-created table.
@@ -199,7 +189,7 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
199189
newfcinfo->args[3].value=UInt32GetDatum(0);
200190
newfcinfo->args[3].isnull= false;
201191

202-
relation_statistics_update(newfcinfo,ERROR);
192+
relation_statistics_update(newfcinfo);
203193
PG_RETURN_VOID();
204194
}
205195

@@ -214,10 +204,10 @@ pg_restore_relation_stats(PG_FUNCTION_ARGS)
214204
InvalidOid,NULL,NULL);
215205

216206
if (!stats_fill_fcinfo_from_arg_pairs(fcinfo,positional_fcinfo,
217-
relarginfo,WARNING))
207+
relarginfo))
218208
result= false;
219209

220-
if (!relation_statistics_update(positional_fcinfo,WARNING))
210+
if (!relation_statistics_update(positional_fcinfo))
221211
result= false;
222212

223213
PG_RETURN_BOOL(result);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp