summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/relfilenumbermap.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-08-08 08:27:26 +0200
committerPeter Eisentraut <peter@eisentraut.org>2024-09-12 10:48:39 +0200
commit811af9786b919d7acb22ea00ecb63f47de7942cd (patch)
tree1b075e1c0e8c49cf901a09cc02ff667dff0ef86f /src/backend/utils/cache/relfilenumbermap.c
parent00c76cf21c42c17e60e73a87dea0d1b4e234d9da (diff)
Don't overwrite scan key in systable_beginscan()
When systable_beginscan() and systable_beginscan_ordered() choose an index scan, they remap the attribute numbers in the passed-in scan keys to the attribute numbers of the index, and then write those remapped attribute numbers back into the scan key passed by the caller. This second part is surprising and gratuitous. It means that a scan key cannot safely be used more than once (but it might sometimes work, depending on circumstances). Also, there is no value in providing these remapped attribute numbers back to the caller, since they can't do anything with that. Fix that by making a copy of the scan keys passed by the caller and make the modifications there. Also, some code that had to work around the previous situation is simplified. Discussion: https://www.postgresql.org/message-id/flat/f8c739d9-f48d-4187-b214-df3391ba41ab@eisentraut.org
Diffstat (limited to 'src/backend/utils/cache/relfilenumbermap.c')
-rw-r--r--src/backend/utils/cache/relfilenumbermap.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/backend/utils/cache/relfilenumbermap.c b/src/backend/utils/cache/relfilenumbermap.c
index 9e76f745297..8dbccdb551e 100644
--- a/src/backend/utils/cache/relfilenumbermap.c
+++ b/src/backend/utils/cache/relfilenumbermap.c
@@ -141,7 +141,6 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
SysScanDesc scandesc;
Relation relation;
HeapTuple ntp;
- ScanKeyData skey[2];
Oid relid;
if (RelfilenumberMapHash == NULL)
@@ -181,6 +180,8 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
}
else
{
+ ScanKeyData skey[2];
+
/*
* Not a shared table, could either be a plain relation or a
* non-shared, nailed one, like e.g. pg_class.
@@ -189,10 +190,8 @@ RelidByRelfilenumber(Oid reltablespace, RelFileNumber relfilenumber)
/* check for plain relations by looking in pg_class */
relation = table_open(RelationRelationId, AccessShareLock);
- /* copy scankey to local copy, it will be modified during the scan */
+ /* copy scankey to local copy and set scan arguments */
memcpy(skey, relfilenumber_skey, sizeof(skey));
-
- /* set scan arguments */
skey[0].sk_argument = ObjectIdGetDatum(reltablespace);
skey[1].sk_argument = ObjectIdGetDatum(relfilenumber);