diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2021-08-31 18:03:05 +0200 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2021-08-31 18:40:09 +0200 |
commit | 6c8b98669d1479148f02375c68ff17772ce7f95b (patch) | |
tree | b8b2b9685c831a524071401e4ad368d7059e11b9 | |
parent | fa8ae19bea7f03a304705aba72b312cc2cea0d75 (diff) | |
download | postgresql-6c8b98669d1479148f02375c68ff17772ce7f95b.tar.gz postgresql-6c8b98669d1479148f02375c68ff17772ce7f95b.zip |
Fix lookup error in extended stats ownership check
When an ownership check on extended statistics object failed, the code
was calling aclcheck_error_type to report the failure, which is clearly
wrong, resulting in cache lookup errors. Fix by calling aclcheck_error.
This issue exists since the introduction of extended statistics, so
backpatch all the way back to PostgreSQL 10. It went unnoticed because
there were no tests triggering the error, so add one.
Reported-by: Mark Dilger
Backpatch-through: 10, where extended stats were introduced
Discussion: https://postgr.es/m/1F238937-7CC2-4703-A1B1-6DC225B8978A%40enterprisedb.com
-rw-r--r-- | src/backend/catalog/objectaddress.c | 3 | ||||
-rw-r--r-- | src/test/regress/expected/stats_ext.out | 11 | ||||
-rw-r--r-- | src/test/regress/sql/stats_ext.sql | 9 |
3 files changed, 22 insertions, 1 deletions
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c index e3f811b019f..f87f5b7d3e1 100644 --- a/src/backend/catalog/objectaddress.c +++ b/src/backend/catalog/objectaddress.c @@ -2475,7 +2475,8 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, break; case OBJECT_STATISTIC_EXT: if (!pg_statistics_object_ownercheck(address.objectId, roleid)) - aclcheck_error_type(ACLCHECK_NOT_OWNER, address.objectId); + aclcheck_error(ACLCHECK_NOT_OWNER, objtype, + NameListToString(castNode(List, object))); break; default: elog(ERROR, "unrecognized object type: %d", diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out index f7b351ec8e2..4edb56b99e9 100644 --- a/src/test/regress/expected/stats_ext.out +++ b/src/test/regress/expected/stats_ext.out @@ -52,6 +52,17 @@ DROP TABLE ext_stats_test; -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER); CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1; +COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment'; +CREATE ROLE temp_role; +SET SESSION AUTHORIZATION temp_role; +COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment'; +ERROR: must be owner of statistics object ab1_a_b_stats +DROP STATISTICS ab1_a_b_stats; +ERROR: must be owner of statistics object ab1_a_b_stats +ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new; +ERROR: must be owner of statistics object ab1_a_b_stats +RESET SESSION AUTHORIZATION; +DROP ROLE temp_role; CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1; NOTICE: statistics object "ab1_a_b_stats" already exists, skipping DROP STATISTICS ab1_a_b_stats; diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql index 85dcf8be099..24171d1e642 100644 --- a/src/test/regress/sql/stats_ext.sql +++ b/src/test/regress/sql/stats_ext.sql @@ -41,6 +41,15 @@ DROP TABLE ext_stats_test; -- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER); CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1; +COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment'; +CREATE ROLE temp_role; +SET SESSION AUTHORIZATION temp_role; +COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment'; +DROP STATISTICS ab1_a_b_stats; +ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new; +RESET SESSION AUTHORIZATION; +DROP ROLE temp_role; + CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1; DROP STATISTICS ab1_a_b_stats; |