Skip to content

Commit 1fe1a04

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 6197d7b commit 1fe1a04

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
@@ -2476,7 +2476,8 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
24762476
break;
24772477
case OBJECT_STATISTIC_EXT:
24782478
if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2479-
aclcheck_error_type(ACLCHECK_NOT_OWNER, address.objectId);
2479+
aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
2480+
NameListToString(castNode(List, object)));
24802481
break;
24812482
default:
24822483
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
@@ -54,6 +54,17 @@ DROP TABLE ext_stats_test;
5454
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
5555
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
5656
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
57+
COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
58+
CREATE ROLE temp_role;
59+
SET SESSION AUTHORIZATION temp_role;
60+
COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
61+
ERROR: must be owner of statistics object ab1_a_b_stats
62+
DROP STATISTICS ab1_a_b_stats;
63+
ERROR: must be owner of statistics object ab1_a_b_stats
64+
ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
65+
ERROR: must be owner of statistics object ab1_a_b_stats
66+
RESET SESSION AUTHORIZATION;
67+
DROP ROLE temp_role;
5768
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
5869
NOTICE: statistics object "ab1_a_b_stats" already exists, skipping
5970
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
@@ -43,6 +43,15 @@ DROP TABLE ext_stats_test;
4343
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
4444
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
4545
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
46+
COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
47+
CREATE ROLE temp_role;
48+
SET SESSION AUTHORIZATION temp_role;
49+
COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
50+
DROP STATISTICS ab1_a_b_stats;
51+
ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
52+
RESET SESSION AUTHORIZATION;
53+
DROP ROLE temp_role;
54+
4655
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
4756
DROP STATISTICS ab1_a_b_stats;
4857

0 commit comments

Comments
 (0)