From 87ae9e72654ddddf25433b8a178e9268cf03f5b5 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 16 Apr 2013 15:01:21 +0300 Subject: [PATCH] Remove some unused and seldom used fields from RelationAmInfo. This saves some memory from each index relcache entry. At least on a 64-bit machine, it saves just enough to shrink a typical relcache entry's memory usage from 2k to 1k. That's nice if you have a lot of backends and a lot of indexes. --- src/backend/access/index/indexam.c | 19 +++++++++++++------ src/include/utils/rel.h | 10 ++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index ce94649281..b87815544d 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -114,6 +114,13 @@ do { \ } \ } while(0) +#define GET_UNCACHED_REL_PROCEDURE(pname) \ +do { \ + if (!RegProcedureIsValid(indexRelation->rd_am->pname)) \ + elog(ERROR, "invalid %s regproc", CppAsString(pname)); \ + fmgr_info(indexRelation->rd_am->pname, &procedure); \ +} while(0) + #define GET_SCAN_PROCEDURE(pname) \ do { \ procedure = &scan->indexRelation->rd_aminfo->pname; \ @@ -671,14 +678,14 @@ index_bulk_delete(IndexVacuumInfo *info, void *callback_state) { Relation indexRelation = info->index; - FmgrInfo *procedure; + FmgrInfo procedure; IndexBulkDeleteResult *result; RELATION_CHECKS; - GET_REL_PROCEDURE(ambulkdelete); + GET_UNCACHED_REL_PROCEDURE(ambulkdelete); result = (IndexBulkDeleteResult *) - DatumGetPointer(FunctionCall4(procedure, + DatumGetPointer(FunctionCall4(&procedure, PointerGetDatum(info), PointerGetDatum(stats), PointerGetDatum((Pointer) callback), @@ -698,14 +705,14 @@ index_vacuum_cleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats) { Relation indexRelation = info->index; - FmgrInfo *procedure; + FmgrInfo procedure; IndexBulkDeleteResult *result; RELATION_CHECKS; - GET_REL_PROCEDURE(amvacuumcleanup); + GET_UNCACHED_REL_PROCEDURE(amvacuumcleanup); result = (IndexBulkDeleteResult *) - DatumGetPointer(FunctionCall2(procedure, + DatumGetPointer(FunctionCall2(&procedure, PointerGetDatum(info), PointerGetDatum(stats))); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 1fd3f67b1e..632743af94 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -47,8 +47,8 @@ typedef LockInfoData *LockInfo; /* - * Cached lookup information for the index access method functions defined - * by the pg_am row associated with an index relation. + * Cached lookup information for the frequently used index access method + * functions, defined by the pg_am row associated with an index relation. */ typedef struct RelationAmInfo { @@ -60,13 +60,7 @@ typedef struct RelationAmInfo FmgrInfo amendscan; FmgrInfo ammarkpos; FmgrInfo amrestrpos; - FmgrInfo ambuild; - FmgrInfo ambuildempty; - FmgrInfo ambulkdelete; - FmgrInfo amvacuumcleanup; FmgrInfo amcanreturn; - FmgrInfo amcostestimate; - FmgrInfo amoptions; } RelationAmInfo; -- 2.40.0