]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use relation_close() more consistently in contrib/
authorMichael Paquier <michael@paquier.xyz>
Tue, 6 Jan 2026 07:17:59 +0000 (16:17 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 6 Jan 2026 07:17:59 +0000 (16:17 +0900)
All the code paths updated here have been using index_close() to
close a relation that was opened with relation_open(), in pgstattuple
and pageinspect.  index_close() does the same thing as relation_close(),
so there is no harm, but being inconsistent could lead to issues if the
internals of these close() functions begin to introduce some specific
logic in the future.

In passing, this commit adds some comments explaining why we are using
relation_open() instead of index_open() in a few places, which is due to
the fact that partitioned indexes are not allowed in these functions.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Japin Li <japinli@hotmail.com>
Discussion: https://postgr.es/m/aUKamYGiDKO6byp5@ip-10-97-1-34.eu-west-3.compute.internal

contrib/pageinspect/hashfuncs.c
contrib/pgstattuple/pgstatindex.c

index 04089b560ec2ac424fe76487b880578ef6c33f8d..7fc97d043ce138dedbdb667ed9652d89a9a78034 100644 (file)
@@ -415,6 +415,10 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
                                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                                 errmsg("must be superuser to use raw page functions")));
 
+       /*
+        * This uses relation_open() and not index_open().  The latter allows
+        * partitioned indexes, and these are forbidden here.
+        */
        indexRel = relation_open(indexRelid, AccessShareLock);
 
        if (!IS_INDEX(indexRel) || !IS_HASH(indexRel))
@@ -486,7 +490,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
        bit = ISSET(freep, bitmapbit) != 0;
 
        _hash_relbuf(indexRel, mapbuf);
-       index_close(indexRel, AccessShareLock);
+       relation_close(indexRel, AccessShareLock);
 
        /* Build a tuple descriptor for our result type */
        if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)
index 40823d54fcac08c6333b1dc5cfd035378b023efb..ef723af1f19aac5de074ad68d742ce847fd30e88 100644 (file)
@@ -514,6 +514,10 @@ pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
        bool            nulls[3] = {false, false, false};
        Datum           result;
 
+       /*
+        * This uses relation_open() and not index_open().  The latter allows
+        * partitioned indexes, and these are forbidden here.
+        */
        rel = relation_open(relid, AccessShareLock);
 
        if (!IS_INDEX(rel) || !IS_GIN(rel))
@@ -597,6 +601,10 @@ pgstathashindex(PG_FUNCTION_ARGS)
        float8          free_percent;
        uint64          total_space;
 
+       /*
+        * This uses relation_open() and not index_open().  The latter allows
+        * partitioned indexes, and these are forbidden here.
+        */
        rel = relation_open(relid, AccessShareLock);
 
        if (!IS_INDEX(rel) || !IS_HASH(rel))
@@ -691,7 +699,7 @@ pgstathashindex(PG_FUNCTION_ARGS)
        }
 
        /* Done accessing the index */
-       index_close(rel, AccessShareLock);
+       relation_close(rel, AccessShareLock);
 
        /* Count unused pages as free space. */
        stats.free_space += (uint64) stats.unused_pages * stats.space_per_page;