aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ri_triggers.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-09-15 11:08:56 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-09-15 11:09:15 -0400
commit3d9e8db9e56beb0501d168779ae9644587924061 (patch)
treed7dfab72e709ff9868e18f2561f976ff8b0da163 /src/backend/utils/adt/ri_triggers.c
parent6820094d1ad37429f910cf46e9f3771ebe93347c (diff)
downloadpostgresql-3d9e8db9e56beb0501d168779ae9644587924061.tar.gz
postgresql-3d9e8db9e56beb0501d168779ae9644587924061.zip
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.
Diffstat (limited to 'src/backend/utils/adt/ri_triggers.c')
-rw-r--r--src/backend/utils/adt/ri_triggers.c38
1 files changed, 3 insertions, 35 deletions
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c
index 0469522a567..61edde9c5d3 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -183,7 +183,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;
@@ -216,7 +215,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);
@@ -2947,20 +2945,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)
{
@@ -3380,15 +3364,13 @@ ri_NullCheck(HeapTuple tup,
/* ----------
- * ri_InitConstraintCache
- *
- * Initialize ri_constraint_cache when new or being rebuilt.
+ * ri_InitHashTables -
*
- * This needs to be done from two places, so split it out to prevent drift.
+ * Initialize our internal hash tables.
* ----------
*/
static void
-ri_InitConstraintCache(void)
+ri_InitHashTables(void)
{
HASHCTL ctl;
@@ -3398,20 +3380,6 @@ ri_InitConstraintCache(void)
ri_constraint_cache = hash_create("RI constraint cache",
RI_INIT_CONSTRAINTHASHSIZE,
&ctl, HASH_ELEM | HASH_BLOBS);
-}
-
-/* ----------
- * ri_InitHashTables -
- *
- * Initialize our internal hash tables.
- * ----------
- */
-static void
-ri_InitHashTables(void)
-{
- HASHCTL ctl;
-
- ri_InitConstraintCache();
/* Arrange to flush cache on pg_constraint changes */
CacheRegisterSyscacheCallback(CONSTROID,