Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5be8ce8

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 589be6f commit 5be8ce8

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/backend/catalog/objectaddress.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,8 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
25712571
break;
25722572
case OBJECT_STATISTIC_EXT:
25732573
if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2574-
aclcheck_error_type(ACLCHECK_NOT_OWNER, address.objectId);
2574+
aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
2575+
NameListToString(castNode(List, object)));
25752576
break;
25762577
default:
25772578
elog(ERROR, "unrecognized object type: %d",

src/test/regress/expected/stats_ext.out

+11
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ DROP TABLE ext_stats_test;
6767
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
6868
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
6969
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
70+
COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
71+
CREATE ROLE temp_role;
72+
SET SESSION AUTHORIZATION temp_role;
73+
COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
74+
ERROR: must be owner of statistics object ab1_a_b_stats
75+
DROP STATISTICS ab1_a_b_stats;
76+
ERROR: must be owner of statistics object ab1_a_b_stats
77+
ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
78+
ERROR: must be owner of statistics object ab1_a_b_stats
79+
RESET SESSION AUTHORIZATION;
80+
DROP ROLE temp_role;
7081
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
7182
NOTICE: statistics object "ab1_a_b_stats" already exists, skipping
7283
DROP STATISTICS ab1_a_b_stats;

src/test/regress/sql/stats_ext.sql

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ DROP TABLE ext_stats_test;
4848
-- Ensure stats are dropped sanely, and test IF NOT EXISTS while at it
4949
CREATE TABLE ab1 (a INTEGER, b INTEGER, c INTEGER);
5050
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
51+
COMMENT ON STATISTICS ab1_a_b_stats IS 'new comment';
52+
CREATE ROLE temp_role;
53+
SET SESSION AUTHORIZATION temp_role;
54+
COMMENT ON STATISTICS ab1_a_b_stats IS 'changed comment';
55+
DROP STATISTICS ab1_a_b_stats;
56+
ALTER STATISTICS ab1_a_b_stats RENAME TO ab1_a_b_stats_new;
57+
RESET SESSION AUTHORIZATION;
58+
DROP ROLE temp_role;
59+
5160
CREATE STATISTICS IF NOT EXISTS ab1_a_b_stats ON a, b FROM ab1;
5261
DROP STATISTICS ab1_a_b_stats;
5362

0 commit comments

Comments
 (0)