Skip to content

Commit 6c8b986

Browse files
committed
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
1 parent fa8ae19 commit 6c8b986

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,8 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
24752475
break;
24762476
case OBJECT_STATISTIC_EXT:
24772477
if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2478-
aclcheck_error_type(ACLCHECK_NOT_OWNER, address.objectId);
2478+
aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
2479+
NameListToString(castNode(List, object)));
24792480
break;
24802481
default:
24812482
elog(ERROR, "unrecognized object type: %d",

src/test/regress/expected/stats_ext.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ DROP TABLE ext_stats_test;
5252
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
5353
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
5454
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
55+
COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
56+
CREATE ROLE temp_role;
57+
SET SESSION AUTHORIZATION temp_role;
58+
COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
59+
ERROR: must be owner of statistics object ab1_a_b_stats
60+
DROP STATISTICS ab1_a_b_stats;
61+
ERROR: must be owner of statistics object ab1_a_b_stats
62+
ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
63+
ERROR: must be owner of statistics object ab1_a_b_stats
64+
RESET SESSION AUTHORIZATION;
65+
DROP ROLE temp_role;
5566
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
5667
NOTICE: statistics object "ab1_a_b_stats" already exists, skipping
5768
DROP STATISTICS ab1_a_b_stats;

src/test/regress/sql/stats_ext.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ DROP TABLE ext_stats_test;
4141
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
4242
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
4343
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
44+
COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
45+
CREATE ROLE temp_role;
46+
SET SESSION AUTHORIZATION temp_role;
47+
COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
48+
DROP STATISTICS ab1_a_b_stats;
49+
ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
50+
RESET SESSION AUTHORIZATION;
51+
DROP ROLE temp_role;
52+
4453
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
4554
DROP STATISTICS ab1_a_b_stats;
4655

0 commit comments

Comments
 (0)