summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/cache/syscache.c15
-rw-r--r--src/test/regress/input/tablespace.source6
-rw-r--r--src/test/regress/output/tablespace.source5
3 files changed, 21 insertions, 5 deletions
diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c
index 8ad87914d4d..8856ae1508f 100644
--- a/src/backend/utils/cache/syscache.c
+++ b/src/backend/utils/cache/syscache.c
@@ -1185,11 +1185,9 @@ HeapTuple
SearchSysCacheLocked1(int cacheId,
Datum key1)
{
+ CatCache *cache = SysCache[cacheId];
ItemPointerData tid;
LOCKTAG tag;
- Oid dboid =
- SysCache[cacheId]->cc_relisshared ? InvalidOid : MyDatabaseId;
- Oid reloid = cacheinfo[cacheId].reloid;
/*----------
* Since inplace updates may happen just before our LockTuple(), we must
@@ -1241,8 +1239,15 @@ SearchSysCacheLocked1(int cacheId,
tid = tuple->t_self;
ReleaseSysCache(tuple);
- /* like: LockTuple(rel, &tid, lockmode) */
- SET_LOCKTAG_TUPLE(tag, dboid, reloid,
+
+ /*
+ * Do like LockTuple(rel, &tid, lockmode). While cc_relisshared won't
+ * change from one iteration to another, it may have been a temporary
+ * "false" until our first SearchSysCache1().
+ */
+ SET_LOCKTAG_TUPLE(tag,
+ cache->cc_relisshared ? InvalidOid : MyDatabaseId,
+ cache->cc_reloid,
ItemPointerGetBlockNumber(&tid),
ItemPointerGetOffsetNumber(&tid));
(void) LockAcquire(&tag, lockmode, false, false);
diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/input/tablespace.source
index 1a181016d71..409caa42be3 100644
--- a/src/test/regress/input/tablespace.source
+++ b/src/test/regress/input/tablespace.source
@@ -255,6 +255,12 @@ ALTER INDEX testschema.part_a_idx SET TABLESPACE pg_default;
-- Fail, not empty
DROP TABLESPACE regress_tblspace;
+-- Adequate cache initialization before GRANT
+\c -
+BEGIN;
+GRANT ALL ON TABLESPACE regress_tblspace TO PUBLIC;
+ROLLBACK;
+
CREATE ROLE regress_tablespace_user1 login;
CREATE ROLE regress_tablespace_user2 login;
GRANT USAGE ON SCHEMA testschema TO regress_tablespace_user2;
diff --git a/src/test/regress/output/tablespace.source b/src/test/regress/output/tablespace.source
index 94c5f023c68..7e89657ab9d 100644
--- a/src/test/regress/output/tablespace.source
+++ b/src/test/regress/output/tablespace.source
@@ -720,6 +720,11 @@ ALTER INDEX testschema.part_a_idx SET TABLESPACE pg_default;
-- Fail, not empty
DROP TABLESPACE regress_tblspace;
ERROR: tablespace "regress_tblspace" is not empty
+-- Adequate cache initialization before GRANT
+\c -
+BEGIN;
+GRANT ALL ON TABLESPACE regress_tblspace TO PUBLIC;
+ROLLBACK;
CREATE ROLE regress_tablespace_user1 login;
CREATE ROLE regress_tablespace_user2 login;
GRANT USAGE ON SCHEMA testschema TO regress_tablespace_user2;