Skip to content

Commit 3d9e8db

Browse files
committed
Revert "Fix an O(N^2) problem in foreign key references".
Commit 5ddc728 does not actually work because it will happily blow away ri_constraint_cache entries that are in active use in outer call levels. In any case, it's a very ugly, brute-force solution to the problem of limiting the cache size. Revert until it can be redesigned.
1 parent 6820094 commit 3d9e8db

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

src/backend/utils/adt/ri_triggers.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ typedef struct RI_CompareHashEntry
183183
* ----------
184184
*/
185185
static HTAB *ri_constraint_cache = NULL;
186-
static long ri_constraint_cache_seq_count = 0;
187186
static HTAB *ri_query_cache = NULL;
188187
static HTAB *ri_compare_cache = NULL;
189188

@@ -216,7 +215,6 @@ static bool ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup,
216215
static bool ri_AttributesEqual(Oid eq_opr, Oid typeid,
217216
Datum oldvalue, Datum newvalue);
218217

219-
static void ri_InitConstraintCache(void);
220218
static void ri_InitHashTables(void);
221219
static void InvalidateConstraintCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
222220
static SPIPlanPtr ri_FetchPreparedPlan(RI_QueryKey *key);
@@ -2947,20 +2945,6 @@ InvalidateConstraintCacheCallBack(Datum arg, int cacheid, uint32 hashvalue)
29472945

29482946
Assert(ri_constraint_cache != NULL);
29492947

2950-
/*
2951-
* Prevent an O(N^2) problem when creating large amounts of foreign
2952-
* key constraints with ALTER TABLE, like it happens at the end of
2953-
* a pg_dump with hundred-thousands of tables having references.
2954-
*/
2955-
ri_constraint_cache_seq_count += hash_get_num_entries(ri_constraint_cache);
2956-
if (ri_constraint_cache_seq_count > 1000000)
2957-
{
2958-
hash_destroy(ri_constraint_cache);
2959-
ri_InitConstraintCache();
2960-
ri_constraint_cache_seq_count = 0;
2961-
return;
2962-
}
2963-
29642948
hash_seq_init(&status, ri_constraint_cache);
29652949
while ((hentry = (RI_ConstraintInfo *) hash_seq_search(&status)) != NULL)
29662950
{
@@ -3380,15 +3364,13 @@ ri_NullCheck(HeapTuple tup,
33803364

33813365

33823366
/* ----------
3383-
* ri_InitConstraintCache
3384-
*
3385-
* Initialize ri_constraint_cache when new or being rebuilt.
3367+
* ri_InitHashTables -
33863368
*
3387-
* This needs to be done from two places, so split it out to prevent drift.
3369+
* Initialize our internal hash tables.
33883370
* ----------
33893371
*/
33903372
static void
3391-
ri_InitConstraintCache(void)
3373+
ri_InitHashTables(void)
33923374
{
33933375
HASHCTL ctl;
33943376

@@ -3398,20 +3380,6 @@ ri_InitConstraintCache(void)
33983380
ri_constraint_cache = hash_create("RI constraint cache",
33993381
RI_INIT_CONSTRAINTHASHSIZE,
34003382
&ctl, HASH_ELEM | HASH_BLOBS);
3401-
}
3402-
3403-
/* ----------
3404-
* ri_InitHashTables -
3405-
*
3406-
* Initialize our internal hash tables.
3407-
* ----------
3408-
*/
3409-
static void
3410-
ri_InitHashTables(void)
3411-
{
3412-
HASHCTL ctl;
3413-
3414-
ri_InitConstraintCache();
34153383

34163384
/* Arrange to flush cache on pg_constraint changes */
34173385
CacheRegisterSyscacheCallback(CONSTROID,

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