mirror of
https://github.com/postgres/postgres.git
synced 2025-05-17 06:41:24 +03:00
Revert "Fix an O(N^2) problem in foreign key references".
Commit 5ddc72887a012f6a8b85707ef27d85c274faf53d 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.
This commit is contained in:
parent
ca445043e7
commit
be136b2430
@ -182,7 +182,6 @@ typedef struct RI_CompareHashEntry
|
||||
* ----------
|
||||
*/
|
||||
static HTAB *ri_constraint_cache = NULL;
|
||||
static long ri_constraint_cache_seq_count = 0;
|
||||
static HTAB *ri_query_cache = NULL;
|
||||
static HTAB *ri_compare_cache = NULL;
|
||||
|
||||
@ -215,7 +214,6 @@ static bool ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup,
|
||||
static bool ri_AttributesEqual(Oid eq_opr, Oid typeid,
|
||||
Datum oldvalue, Datum newvalue);
|
||||
|
||||
static void ri_InitConstraintCache(void);
|
||||
static void ri_InitHashTables(void);
|
||||
static void InvalidateConstraintCacheCallBack(Datum arg, int cacheid, uint32 hashvalue);
|
||||
static SPIPlanPtr ri_FetchPreparedPlan(RI_QueryKey *key);
|
||||
@ -2934,20 +2932,6 @@ InvalidateConstraintCacheCallBack(Datum arg, int cacheid, uint32 hashvalue)
|
||||
|
||||
Assert(ri_constraint_cache != NULL);
|
||||
|
||||
/*
|
||||
* Prevent an O(N^2) problem when creating large amounts of foreign
|
||||
* key constraints with ALTER TABLE, like it happens at the end of
|
||||
* a pg_dump with hundred-thousands of tables having references.
|
||||
*/
|
||||
ri_constraint_cache_seq_count += hash_get_num_entries(ri_constraint_cache);
|
||||
if (ri_constraint_cache_seq_count > 1000000)
|
||||
{
|
||||
hash_destroy(ri_constraint_cache);
|
||||
ri_InitConstraintCache();
|
||||
ri_constraint_cache_seq_count = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
hash_seq_init(&status, ri_constraint_cache);
|
||||
while ((hentry = (RI_ConstraintInfo *) hash_seq_search(&status)) != NULL)
|
||||
{
|
||||
@ -3341,28 +3325,6 @@ ri_NullCheck(HeapTuple tup,
|
||||
}
|
||||
|
||||
|
||||
/* ----------
|
||||
* ri_InitConstraintCache
|
||||
*
|
||||
* Initialize ri_constraint_cache when new or being rebuilt.
|
||||
*
|
||||
* This needs to be done from two places, so split it out to prevent drift.
|
||||
* ----------
|
||||
*/
|
||||
static void
|
||||
ri_InitConstraintCache(void)
|
||||
{
|
||||
HASHCTL ctl;
|
||||
|
||||
memset(&ctl, 0, sizeof(ctl));
|
||||
ctl.keysize = sizeof(Oid);
|
||||
ctl.entrysize = sizeof(RI_ConstraintInfo);
|
||||
ctl.hash = oid_hash;
|
||||
ri_constraint_cache = hash_create("RI constraint cache",
|
||||
RI_INIT_CONSTRAINTHASHSIZE,
|
||||
&ctl, HASH_ELEM | HASH_FUNCTION);
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* ri_InitHashTables -
|
||||
*
|
||||
@ -3374,7 +3336,13 @@ ri_InitHashTables(void)
|
||||
{
|
||||
HASHCTL ctl;
|
||||
|
||||
ri_InitConstraintCache();
|
||||
memset(&ctl, 0, sizeof(ctl));
|
||||
ctl.keysize = sizeof(Oid);
|
||||
ctl.entrysize = sizeof(RI_ConstraintInfo);
|
||||
ctl.hash = oid_hash;
|
||||
ri_constraint_cache = hash_create("RI constraint cache",
|
||||
RI_INIT_CONSTRAINTHASHSIZE,
|
||||
&ctl, HASH_ELEM | HASH_FUNCTION);
|
||||
|
||||
/* Arrange to flush cache on pg_constraint changes */
|
||||
CacheRegisterSyscacheCallback(CONSTROID,
|
||||
|
Loading…
x
Reference in New Issue
Block a user