mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
Disallow modifying statistics on system columns.
Reported-by: Heikki Linnakangas Discussion: https://postgr.es/m/df3e1c41-4e6c-40ad-9636-98deefe488cd@iki.fi
This commit is contained in:
parent
efdc7d7475
commit
869ee4f10e
@ -167,6 +167,13 @@ attribute_statistics_update(FunctionCallInfo fcinfo, int elevel)
|
|||||||
stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);
|
stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);
|
||||||
attname = PG_GETARG_NAME(ATTNAME_ARG);
|
attname = PG_GETARG_NAME(ATTNAME_ARG);
|
||||||
attnum = get_attnum(reloid, NameStr(*attname));
|
attnum = get_attnum(reloid, NameStr(*attname));
|
||||||
|
|
||||||
|
if (attnum < 0)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot modify statistics on system column \"%s\"",
|
||||||
|
NameStr(*attname))));
|
||||||
|
|
||||||
if (attnum == InvalidAttrNumber)
|
if (attnum == InvalidAttrNumber)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||||
@ -882,6 +889,13 @@ pg_clear_attribute_stats(PG_FUNCTION_ARGS)
|
|||||||
stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);
|
stats_check_required_arg(fcinfo, attarginfo, ATTNAME_ARG);
|
||||||
attname = PG_GETARG_NAME(ATTNAME_ARG);
|
attname = PG_GETARG_NAME(ATTNAME_ARG);
|
||||||
attnum = get_attnum(reloid, NameStr(*attname));
|
attnum = get_attnum(reloid, NameStr(*attname));
|
||||||
|
|
||||||
|
if (attnum < 0)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
|
errmsg("cannot clear statistics on system column \"%s\"",
|
||||||
|
NameStr(*attname))));
|
||||||
|
|
||||||
if (attnum == InvalidAttrNumber)
|
if (attnum == InvalidAttrNumber)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||||
|
@ -195,6 +195,15 @@ SELECT pg_catalog.pg_set_attribute_stats(
|
|||||||
avg_width => 2::integer,
|
avg_width => 2::integer,
|
||||||
n_distinct => 0.3::real);
|
n_distinct => 0.3::real);
|
||||||
ERROR: "relation" cannot be NULL
|
ERROR: "relation" cannot be NULL
|
||||||
|
-- error: attribute is system column
|
||||||
|
SELECT pg_catalog.pg_set_attribute_stats(
|
||||||
|
relation => 'stats_import.test'::regclass,
|
||||||
|
attname => 'xmin'::name,
|
||||||
|
inherited => false::boolean,
|
||||||
|
null_frac => 0.1::real,
|
||||||
|
avg_width => 2::integer,
|
||||||
|
n_distinct => 0.3::real);
|
||||||
|
ERROR: cannot modify statistics on system column "xmin"
|
||||||
-- error: attname doesn't exist
|
-- error: attname doesn't exist
|
||||||
SELECT pg_catalog.pg_set_attribute_stats(
|
SELECT pg_catalog.pg_set_attribute_stats(
|
||||||
relation => 'stats_import.test'::regclass,
|
relation => 'stats_import.test'::regclass,
|
||||||
@ -204,6 +213,12 @@ SELECT pg_catalog.pg_set_attribute_stats(
|
|||||||
avg_width => 2::integer,
|
avg_width => 2::integer,
|
||||||
n_distinct => 0.3::real);
|
n_distinct => 0.3::real);
|
||||||
ERROR: column "nope" of relation "test" does not exist
|
ERROR: column "nope" of relation "test" does not exist
|
||||||
|
-- error: attribute is system column
|
||||||
|
SELECT pg_catalog.pg_clear_attribute_stats(
|
||||||
|
relation => 'stats_import.test'::regclass,
|
||||||
|
attname => 'ctid'::name,
|
||||||
|
inherited => false::boolean);
|
||||||
|
ERROR: cannot clear statistics on system column "ctid"
|
||||||
-- error: attname doesn't exist
|
-- error: attname doesn't exist
|
||||||
SELECT pg_catalog.pg_clear_attribute_stats(
|
SELECT pg_catalog.pg_clear_attribute_stats(
|
||||||
relation => 'stats_import.test'::regclass,
|
relation => 'stats_import.test'::regclass,
|
||||||
|
@ -145,6 +145,15 @@ SELECT pg_catalog.pg_set_attribute_stats(
|
|||||||
avg_width => 2::integer,
|
avg_width => 2::integer,
|
||||||
n_distinct => 0.3::real);
|
n_distinct => 0.3::real);
|
||||||
|
|
||||||
|
-- error: attribute is system column
|
||||||
|
SELECT pg_catalog.pg_set_attribute_stats(
|
||||||
|
relation => 'stats_import.test'::regclass,
|
||||||
|
attname => 'xmin'::name,
|
||||||
|
inherited => false::boolean,
|
||||||
|
null_frac => 0.1::real,
|
||||||
|
avg_width => 2::integer,
|
||||||
|
n_distinct => 0.3::real);
|
||||||
|
|
||||||
-- error: attname doesn't exist
|
-- error: attname doesn't exist
|
||||||
SELECT pg_catalog.pg_set_attribute_stats(
|
SELECT pg_catalog.pg_set_attribute_stats(
|
||||||
relation => 'stats_import.test'::regclass,
|
relation => 'stats_import.test'::regclass,
|
||||||
@ -154,6 +163,12 @@ SELECT pg_catalog.pg_set_attribute_stats(
|
|||||||
avg_width => 2::integer,
|
avg_width => 2::integer,
|
||||||
n_distinct => 0.3::real);
|
n_distinct => 0.3::real);
|
||||||
|
|
||||||
|
-- error: attribute is system column
|
||||||
|
SELECT pg_catalog.pg_clear_attribute_stats(
|
||||||
|
relation => 'stats_import.test'::regclass,
|
||||||
|
attname => 'ctid'::name,
|
||||||
|
inherited => false::boolean);
|
||||||
|
|
||||||
-- error: attname doesn't exist
|
-- error: attname doesn't exist
|
||||||
SELECT pg_catalog.pg_clear_attribute_stats(
|
SELECT pg_catalog.pg_clear_attribute_stats(
|
||||||
relation => 'stats_import.test'::regclass,
|
relation => 'stats_import.test'::regclass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user