mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
Revert: Allow table AM to store complex data structures in rd_amcache
This commit reverts 02eb07ea89 per review by Andres Freund. Discussion: https://postgr.es/m/20240410165236.rwyrny7ihi4ddxw4%40awork3.anarazel.de
This commit is contained in:
parent
8dd0bb84da
commit
922c4c461d
@ -2656,7 +2656,6 @@ static const TableAmRoutine heapam_methods = {
|
|||||||
.index_validate_scan = heapam_index_validate_scan,
|
.index_validate_scan = heapam_index_validate_scan,
|
||||||
.relation_analyze = heapam_analyze,
|
.relation_analyze = heapam_analyze,
|
||||||
|
|
||||||
.free_rd_amcache = NULL,
|
|
||||||
.relation_size = table_block_relation_size,
|
.relation_size = table_block_relation_size,
|
||||||
.relation_needs_toast_table = heapam_relation_needs_toast_table,
|
.relation_needs_toast_table = heapam_relation_needs_toast_table,
|
||||||
.relation_toast_am = heapam_relation_toast_am,
|
.relation_toast_am = heapam_relation_toast_am,
|
||||||
|
11
src/backend/utils/cache/relcache.c
vendored
11
src/backend/utils/cache/relcache.c
vendored
@ -2269,7 +2269,9 @@ RelationReloadIndexInfo(Relation relation)
|
|||||||
RelationCloseSmgr(relation);
|
RelationCloseSmgr(relation);
|
||||||
|
|
||||||
/* Must free any AM cached data upon relcache flush */
|
/* Must free any AM cached data upon relcache flush */
|
||||||
table_free_rd_amcache(relation);
|
if (relation->rd_amcache)
|
||||||
|
pfree(relation->rd_amcache);
|
||||||
|
relation->rd_amcache = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it's a shared index, we might be called before backend startup has
|
* If it's a shared index, we might be called before backend startup has
|
||||||
@ -2489,7 +2491,8 @@ RelationDestroyRelation(Relation relation, bool remember_tupdesc)
|
|||||||
pfree(relation->rd_options);
|
pfree(relation->rd_options);
|
||||||
if (relation->rd_indextuple)
|
if (relation->rd_indextuple)
|
||||||
pfree(relation->rd_indextuple);
|
pfree(relation->rd_indextuple);
|
||||||
table_free_rd_amcache(relation);
|
if (relation->rd_amcache)
|
||||||
|
pfree(relation->rd_amcache);
|
||||||
if (relation->rd_fdwroutine)
|
if (relation->rd_fdwroutine)
|
||||||
pfree(relation->rd_fdwroutine);
|
pfree(relation->rd_fdwroutine);
|
||||||
if (relation->rd_indexcxt)
|
if (relation->rd_indexcxt)
|
||||||
@ -2551,7 +2554,9 @@ RelationClearRelation(Relation relation, bool rebuild)
|
|||||||
RelationCloseSmgr(relation);
|
RelationCloseSmgr(relation);
|
||||||
|
|
||||||
/* Free AM cached data, if any */
|
/* Free AM cached data, if any */
|
||||||
table_free_rd_amcache(relation);
|
if (relation->rd_amcache)
|
||||||
|
pfree(relation->rd_amcache);
|
||||||
|
relation->rd_amcache = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Treat nailed-in system relations separately, they always need to be
|
* Treat nailed-in system relations separately, they always need to be
|
||||||
|
@ -687,14 +687,6 @@ 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().
|
* See table_relation_size().
|
||||||
*
|
*
|
||||||
@ -1816,32 +1808,6 @@ table_relation_analyze(Relation relation, AcquireSampleRowsFunc *func,
|
|||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
* Return the current size of `rel` in bytes. If `forkNumber` is
|
||||||
* InvalidForkNumber, return the relation's overall size, otherwise the size
|
* InvalidForkNumber, return the relation's overall size, otherwise the size
|
||||||
|
@ -221,12 +221,10 @@ typedef struct RelationData
|
|||||||
* rd_amcache is available for index and table AMs to cache private data
|
* rd_amcache is available for index and table AMs to cache private data
|
||||||
* about the relation. This must be just a cache since it may get reset
|
* about the relation. This must be just a cache since it may get reset
|
||||||
* at any time (in particular, it will get reset by a relcache inval
|
* at any time (in particular, it will get reset by a relcache inval
|
||||||
* message for the relation). If used for table AM it must point to a
|
* message for the relation). If used, it must point to a single memory
|
||||||
* single memory chunk palloc'd in CacheMemoryContext, or more complex
|
* chunk palloc'd in CacheMemoryContext, or in rd_indexcxt for an index
|
||||||
* data structure in that memory context to be freed by free_rd_amcache
|
* relation. A relcache reset will include freeing that chunk and setting
|
||||||
* method. If used for index AM it must point to a single memory chunk
|
* rd_amcache = NULL.
|
||||||
* palloc'd in rd_indexcxt memory context. A relcache reset will include
|
|
||||||
* freeing that chunk and setting rd_amcache = NULL.
|
|
||||||
*/
|
*/
|
||||||
void *rd_amcache; /* available for use by index/table AM */
|
void *rd_amcache; /* available for use by index/table AM */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user