summaryrefslogtreecommitdiff
path: root/src/include/access
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2024-03-21 23:00:34 +0200
committerAlexander Korotkov <akorotkov@postgresql.org>2024-03-21 23:00:34 +0200
commit02eb07ea89d27f1d05a5055bf779042d2953b4e7 (patch)
tree94e20546d3ec27d7b32b09488dda03cfaa58ac2d /src/include/access
parent57184c3b5d89763c882a15adfcdb00990a09d382 (diff)
Allow table AM to store complex data structures in rd_amcache
The new table AM method free_rd_amcache is responsible for freeing all the memory related to rd_amcache and setting free_rd_amcache to NULL. If the new method is not specified, we still assume rd_amcache to be a single chunk of memory, which could be just pfree'd. Discussion: https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com Reviewed-by: Matthias van de Meent, Mark Dilger, Pavel Borisov Reviewed-by: Nikita Malakhov, Japin Li
Diffstat (limited to 'src/include/access')
-rw-r--r--src/include/access/tableam.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 8249b37bbf1..fd474b74883 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -709,6 +709,14 @@ typedef struct TableAmRoutine
*/
/*
+ * This callback frees relation private cache data stored in rd_amcache.
+ * After the call all memory related to rd_amcache must be freed,
+ * rd_amcache must be set to NULL. If this callback is not provided,
+ * rd_amcache is assumed to point to a single memory chunk.
+ */
+ void (*free_rd_amcache) (Relation rel);
+
+ /*
* See table_relation_size().
*
* Note that currently a few callers use the MAIN_FORKNUM size to figure
@@ -1848,6 +1856,32 @@ table_index_validate_scan(Relation table_rel,
*/
/*
+ * Frees relation private cache data stored in rd_amcache. Uses
+ * free_rd_amcache method if provided. Assumes rd_amcache to point to single
+ * memory chunk otherwise.
+ */
+static inline void
+table_free_rd_amcache(Relation rel)
+{
+ if (rel->rd_tableam && rel->rd_tableam->free_rd_amcache)
+ {
+ rel->rd_tableam->free_rd_amcache(rel);
+
+ /*
+ * We are assuming free_rd_amcache() did clear the cache and left NULL
+ * in rd_amcache.
+ */
+ Assert(rel->rd_amcache == NULL);
+ }
+ else
+ {
+ if (rel->rd_amcache)
+ pfree(rel->rd_amcache);
+ rel->rd_amcache = NULL;
+ }
+}
+
+/*
* Return the current size of `rel` in bytes. If `forkNumber` is
* InvalidForkNumber, return the relation's overall size, otherwise the size
* for the indicated fork.