aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2023-08-07 15:13:24 -0700
committerJeff Davis <jdavis@postgresql.org>2023-08-09 13:09:25 -0700
commitfa2e874946c5b9f23394358c131e987df7cc8ffb (patch)
tree418135ed5b9a83ec551d0772b02c5d5f9e791f1c
parentc27f8621eedf744a7bc80e37dd2d3f0f559edf1b (diff)
downloadpostgresql-fa2e874946c5b9f23394358c131e987df7cc8ffb.tar.gz
postgresql-fa2e874946c5b9f23394358c131e987df7cc8ffb.zip
Recalculate search_path after ALTER ROLE.
Renaming a role can affect the meaning of the special string $user, so must cause search_path to be recalculated. Discussion: https://postgr.es/m/186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com Reviewed-by: Nathan Bossart, Michael Paquier Backpatch-through: 11
-rw-r--r--src/backend/catalog/namespace.c6
-rw-r--r--src/test/isolation/expected/search-path-inval.out97
-rw-r--r--src/test/isolation/isolation_schedule1
-rw-r--r--src/test/isolation/specs/search-path-inval.spec59
4 files changed, 162 insertions, 1 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 1f76b5d7f7b..0c679fbf944 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -4175,11 +4175,15 @@ InitializeSearchPath(void)
{
/*
* In normal mode, arrange for a callback on any syscache invalidation
- * of pg_namespace rows.
+ * of pg_namespace or pg_authid rows. (Changing a role name may affect
+ * the meaning of the special string $user.)
*/
CacheRegisterSyscacheCallback(NAMESPACEOID,
NamespaceCallback,
(Datum) 0);
+ CacheRegisterSyscacheCallback(AUTHOID,
+ NamespaceCallback,
+ (Datum) 0);
/* Force search path to be recomputed on next use */
baseSearchPathValid = false;
}
diff --git a/src/test/isolation/expected/search-path-inval.out b/src/test/isolation/expected/search-path-inval.out
new file mode 100644
index 00000000000..e0173afdb2d
--- /dev/null
+++ b/src/test/isolation/expected/search-path-inval.out
@@ -0,0 +1,97 @@
+Parsed test spec with 3 sessions
+
+starting permutation: s1a s2a s1a s2b
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user1
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+--------------------------
+data in regress_sp_user1.x
+(1 row)
+
+step s2a:
+ ALTER ROLE regress_sp_user1 RENAME TO regress_sp_user2;
+
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user2
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+---------------------------
+data in regress_sp_public.x
+(1 row)
+
+step s2b:
+ ALTER ROLE regress_sp_user2 RENAME TO regress_sp_user1;
+
+
+starting permutation: s1a s3a s1a s3b
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user1
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+--------------------------
+data in regress_sp_user1.x
+(1 row)
+
+step s3a:
+ ALTER SCHEMA regress_sp_user1 RENAME TO regress_sp_user2;
+
+step s1a:
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+
+current_user
+----------------
+regress_sp_user1
+(1 row)
+
+search_path
+--------------------------
+"$user", regress_sp_public
+(1 row)
+
+t
+---------------------------
+data in regress_sp_public.x
+(1 row)
+
+step s3b:
+ ALTER SCHEMA regress_sp_user2 RENAME TO regress_sp_user1;
+
diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule
index 4fc56ae99c9..eab9f2243ec 100644
--- a/src/test/isolation/isolation_schedule
+++ b/src/test/isolation/isolation_schedule
@@ -110,3 +110,4 @@ test: serializable-parallel
test: serializable-parallel-2
test: serializable-parallel-3
test: matview-write-skew
+test: search-path-inval \ No newline at end of file
diff --git a/src/test/isolation/specs/search-path-inval.spec b/src/test/isolation/specs/search-path-inval.spec
new file mode 100644
index 00000000000..08b1bba2fc9
--- /dev/null
+++ b/src/test/isolation/specs/search-path-inval.spec
@@ -0,0 +1,59 @@
+# Test search_path invalidation.
+
+setup
+{
+ CREATE USER regress_sp_user1;
+ CREATE SCHEMA regress_sp_user1 AUTHORIZATION regress_sp_user1;
+ CREATE SCHEMA regress_sp_public;
+ GRANT ALL PRIVILEGES ON SCHEMA regress_sp_public TO regress_sp_user1;
+}
+
+teardown
+{
+ DROP SCHEMA regress_sp_public CASCADE;
+ DROP SCHEMA regress_sp_user1 CASCADE;
+ DROP USER regress_sp_user1;
+}
+
+session s1
+setup
+{
+ SET search_path = "$user", regress_sp_public;
+ SET SESSION AUTHORIZATION regress_sp_user1;
+ CREATE TABLE regress_sp_user1.x(t) AS SELECT 'data in regress_sp_user1.x';
+ CREATE TABLE regress_sp_public.x(t) AS SELECT 'data in regress_sp_public.x';
+}
+step s1a
+{
+ SELECT CURRENT_USER;
+ SHOW search_path;
+ SELECT t FROM x;
+}
+
+session s2
+step s2a
+{
+ ALTER ROLE regress_sp_user1 RENAME TO regress_sp_user2;
+}
+step s2b
+{
+ ALTER ROLE regress_sp_user2 RENAME TO regress_sp_user1;
+}
+
+session s3
+step s3a
+{
+ ALTER SCHEMA regress_sp_user1 RENAME TO regress_sp_user2;
+}
+step s3b
+{
+ ALTER SCHEMA regress_sp_user2 RENAME TO regress_sp_user1;
+}
+
+# s1's search_path is invalidated by role name change in s2a, and
+# falls back to regress_sp_public.x
+permutation s1a s2a s1a s2b
+
+# s1's search_path is invalidated by schema name change in s2b, and
+# falls back to regress_sp_public.x
+permutation s1a s3a s1a s3b