Skip to content

Commit d4d1885

Browse files
committed
Remove a couple of unnecessary calls of CreateCacheMemoryContext. These
probably got there via blind copy-and-paste from one of the legitimate callers, so rearrange and comment that code a bit to make it clearer that this isn't a necessary prerequisite to hash_create. Per observation from Robert Haas.
1 parent c4371cd commit d4d1885

File tree

5 files changed

+32
-38
lines changed

5 files changed

+32
-38
lines changed

src/backend/optimizer/util/predtest.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.27 2009/06/11 14:48:59 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.28 2009/12/27 18:55:52 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1532,9 +1532,6 @@ get_btree_test_op(Oid pred_op, Oid clause_op, bool refute_it)
15321532
/* First time through: initialize the hash table */
15331533
HASHCTL ctl;
15341534

1535-
if (!CacheMemoryContext)
1536-
CreateCacheMemoryContext();
1537-
15381535
MemSet(&ctl, 0, sizeof(ctl));
15391536
ctl.keysize = sizeof(OprProofCacheKey);
15401537
ctl.entrysize = sizeof(OprProofCacheEntry);

src/backend/parser/parse_oper.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.109 2009/06/13 15:42:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_oper.c,v 1.110 2009/12/27 18:55:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1098,9 +1098,6 @@ find_oper_cache_entry(OprCacheKey *key)
10981098
/* First time through: initialize the hash table */
10991099
HASHCTL ctl;
11001100

1101-
if (!CacheMemoryContext)
1102-
CreateCacheMemoryContext();
1103-
11041101
MemSet(&ctl, 0, sizeof(ctl));
11051102
ctl.keysize = sizeof(OprCacheKey);
11061103
ctl.entrysize = sizeof(OprCacheEntry);

src/backend/utils/cache/relcache.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.293 2009/12/07 05:22:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.294 2009/12/27 18:55:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1181,15 +1181,16 @@ LookupOpclassInfo(Oid operatorClassOid,
11811181
/* First time through: initialize the opclass cache */
11821182
HASHCTL ctl;
11831183

1184-
if (!CacheMemoryContext)
1185-
CreateCacheMemoryContext();
1186-
11871184
MemSet(&ctl, 0, sizeof(ctl));
11881185
ctl.keysize = sizeof(Oid);
11891186
ctl.entrysize = sizeof(OpClassCacheEnt);
11901187
ctl.hash = oid_hash;
11911188
OpClassCache = hash_create("Operator class cache", 64,
11921189
&ctl, HASH_ELEM | HASH_FUNCTION);
1190+
1191+
/* Also make sure CacheMemoryContext exists */
1192+
if (!CacheMemoryContext)
1193+
CreateCacheMemoryContext();
11931194
}
11941195

11951196
opcentry = (OpClassCacheEnt *) hash_search(OpClassCache,
@@ -2513,17 +2514,14 @@ RelationBuildLocalRelation(const char *relname,
25132514
void
25142515
RelationCacheInitialize(void)
25152516
{
2516-
MemoryContext oldcxt;
25172517
HASHCTL ctl;
25182518

25192519
/*
2520-
* switch to cache memory context
2520+
* make sure cache memory context exists
25212521
*/
25222522
if (!CacheMemoryContext)
25232523
CreateCacheMemoryContext();
25242524

2525-
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
2526-
25272525
/*
25282526
* create hashtable that indexes the relcache
25292527
*/
@@ -2533,8 +2531,6 @@ RelationCacheInitialize(void)
25332531
ctl.hash = oid_hash;
25342532
RelationIdCache = hash_create("Relcache by OID", INITRELCACHESIZE,
25352533
&ctl, HASH_ELEM | HASH_FUNCTION);
2536-
2537-
MemoryContextSwitchTo(oldcxt);
25382534
}
25392535

25402536
/*

src/backend/utils/cache/ts_cache.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Copyright (c) 2006-2009, PostgreSQL Global Development Group
2121
*
2222
* IDENTIFICATION
23-
* $PostgreSQL: pgsql/src/backend/utils/cache/ts_cache.c,v 1.9 2009/01/01 17:23:50 momjian Exp $
23+
* $PostgreSQL: pgsql/src/backend/utils/cache/ts_cache.c,v 1.10 2009/12/27 18:55:52 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -42,7 +42,6 @@
4242
#include "tsearch/ts_cache.h"
4343
#include "utils/array.h"
4444
#include "utils/builtins.h"
45-
#include "utils/catcache.h"
4645
#include "utils/fmgroids.h"
4746
#include "utils/inval.h"
4847
#include "utils/lsyscache.h"
@@ -119,9 +118,6 @@ lookup_ts_parser_cache(Oid prsId)
119118
/* First time through: initialize the hash table */
120119
HASHCTL ctl;
121120

122-
if (!CacheMemoryContext)
123-
CreateCacheMemoryContext();
124-
125121
MemSet(&ctl, 0, sizeof(ctl));
126122
ctl.keysize = sizeof(Oid);
127123
ctl.entrysize = sizeof(TSParserCacheEntry);
@@ -131,6 +127,10 @@ lookup_ts_parser_cache(Oid prsId)
131127
/* Flush cache on pg_ts_parser changes */
132128
CacheRegisterSyscacheCallback(TSPARSEROID, InvalidateTSCacheCallBack,
133129
PointerGetDatum(TSParserCacheHash));
130+
131+
/* Also make sure CacheMemoryContext exists */
132+
if (!CacheMemoryContext)
133+
CreateCacheMemoryContext();
134134
}
135135

136136
/* Check single-entry cache */
@@ -219,9 +219,6 @@ lookup_ts_dictionary_cache(Oid dictId)
219219
/* First time through: initialize the hash table */
220220
HASHCTL ctl;
221221

222-
if (!CacheMemoryContext)
223-
CreateCacheMemoryContext();
224-
225222
MemSet(&ctl, 0, sizeof(ctl));
226223
ctl.keysize = sizeof(Oid);
227224
ctl.entrysize = sizeof(TSDictionaryCacheEntry);
@@ -233,6 +230,10 @@ lookup_ts_dictionary_cache(Oid dictId)
233230
PointerGetDatum(TSDictionaryCacheHash));
234231
CacheRegisterSyscacheCallback(TSTEMPLATEOID, InvalidateTSCacheCallBack,
235232
PointerGetDatum(TSDictionaryCacheHash));
233+
234+
/* Also make sure CacheMemoryContext exists */
235+
if (!CacheMemoryContext)
236+
CreateCacheMemoryContext();
236237
}
237238

238239
/* Check single-entry cache */
@@ -370,9 +371,6 @@ init_ts_config_cache(void)
370371
{
371372
HASHCTL ctl;
372373

373-
if (!CacheMemoryContext)
374-
CreateCacheMemoryContext();
375-
376374
MemSet(&ctl, 0, sizeof(ctl));
377375
ctl.keysize = sizeof(Oid);
378376
ctl.entrysize = sizeof(TSConfigCacheEntry);
@@ -384,6 +382,10 @@ init_ts_config_cache(void)
384382
PointerGetDatum(TSConfigCacheHash));
385383
CacheRegisterSyscacheCallback(TSCONFIGMAP, InvalidateTSCacheCallBack,
386384
PointerGetDatum(TSConfigCacheHash));
385+
386+
/* Also make sure CacheMemoryContext exists */
387+
if (!CacheMemoryContext)
388+
CreateCacheMemoryContext();
387389
}
388390

389391
/*

src/backend/utils/cache/typcache.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Portions Copyright (c) 1994, Regents of the University of California
3737
*
3838
* IDENTIFICATION
39-
* $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.29 2009/01/01 17:23:50 momjian Exp $
39+
* $PostgreSQL: pgsql/src/backend/utils/cache/typcache.c,v 1.30 2009/12/27 18:55:52 tgl Exp $
4040
*
4141
*-------------------------------------------------------------------------
4242
*/
@@ -109,15 +109,16 @@ lookup_type_cache(Oid type_id, int flags)
109109
/* First time through: initialize the hash table */
110110
HASHCTL ctl;
111111

112-
if (!CacheMemoryContext)
113-
CreateCacheMemoryContext();
114-
115112
MemSet(&ctl, 0, sizeof(ctl));
116113
ctl.keysize = sizeof(Oid);
117114
ctl.entrysize = sizeof(TypeCacheEntry);
118115
ctl.hash = oid_hash;
119116
TypeCacheHash = hash_create("Type information cache", 64,
120117
&ctl, HASH_ELEM | HASH_FUNCTION);
118+
119+
/* Also make sure CacheMemoryContext exists */
120+
if (!CacheMemoryContext)
121+
CreateCacheMemoryContext();
121122
}
122123

123124
/* Try to look up an existing entry */
@@ -249,8 +250,8 @@ lookup_type_cache(Oid type_id, int flags)
249250
* Set up fmgr lookup info as requested
250251
*
251252
* Note: we tell fmgr the finfo structures live in CacheMemoryContext,
252-
* which is not quite right (they're really in DynaHashContext) but this
253-
* will do for our purposes.
253+
* which is not quite right (they're really in the hash table's private
254+
* memory context) but this will do for our purposes.
254255
*/
255256
if ((flags & TYPECACHE_EQ_OPR_FINFO) &&
256257
typentry->eq_opr_finfo.fn_oid == InvalidOid &&
@@ -424,15 +425,16 @@ assign_record_type_typmod(TupleDesc tupDesc)
424425
/* First time through: initialize the hash table */
425426
HASHCTL ctl;
426427

427-
if (!CacheMemoryContext)
428-
CreateCacheMemoryContext();
429-
430428
MemSet(&ctl, 0, sizeof(ctl));
431429
ctl.keysize = REC_HASH_KEYS * sizeof(Oid);
432430
ctl.entrysize = sizeof(RecordCacheEntry);
433431
ctl.hash = tag_hash;
434432
RecordCacheHash = hash_create("Record information cache", 64,
435433
&ctl, HASH_ELEM | HASH_FUNCTION);
434+
435+
/* Also make sure CacheMemoryContext exists */
436+
if (!CacheMemoryContext)
437+
CreateCacheMemoryContext();
436438
}
437439

438440
/* Find or create a hashtable entry for this hash class */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy