Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit541ec18

Browse files
committed
Revert "Fix an O(N^2) problem in foreign key references".
Commit5ddc728 does not actually workbecause it will happily blow away ri_constraint_cache entries that arein 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 parent35d2fc1 commit541ec18

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
@@ -182,7 +182,6 @@ typedef struct RI_CompareHashEntry
182182
* ----------
183183
*/
184184
staticHTAB*ri_constraint_cache=NULL;
185-
staticlongri_constraint_cache_seq_count=0;
186185
staticHTAB*ri_query_cache=NULL;
187186
staticHTAB*ri_compare_cache=NULL;
188187

@@ -215,7 +214,6 @@ static bool ri_KeysEqual(Relation rel, HeapTuple oldtup, HeapTuple newtup,
215214
staticboolri_AttributesEqual(Oideq_opr,Oidtypeid,
216215
Datumoldvalue,Datumnewvalue);
217216

218-
staticvoidri_InitConstraintCache(void);
219217
staticvoidri_InitHashTables(void);
220218
staticvoidInvalidateConstraintCacheCallBack(Datumarg,intcacheid,uint32hashvalue);
221219
staticSPIPlanPtrri_FetchPreparedPlan(RI_QueryKey*key);
@@ -2934,20 +2932,6 @@ InvalidateConstraintCacheCallBack(Datum arg, int cacheid, uint32 hashvalue)
29342932

29352933
Assert(ri_constraint_cache!=NULL);
29362934

2937-
/*
2938-
* Prevent an O(N^2) problem when creating large amounts of foreign
2939-
* key constraints with ALTER TABLE, like it happens at the end of
2940-
* a pg_dump with hundred-thousands of tables having references.
2941-
*/
2942-
ri_constraint_cache_seq_count+=hash_get_num_entries(ri_constraint_cache);
2943-
if (ri_constraint_cache_seq_count>1000000)
2944-
{
2945-
hash_destroy(ri_constraint_cache);
2946-
ri_InitConstraintCache();
2947-
ri_constraint_cache_seq_count=0;
2948-
return;
2949-
}
2950-
29512935
hash_seq_init(&status,ri_constraint_cache);
29522936
while ((hentry= (RI_ConstraintInfo*)hash_seq_search(&status))!=NULL)
29532937
{
@@ -3343,15 +3327,13 @@ ri_NullCheck(HeapTuple tup,
33433327

33443328

33453329
/* ----------
3346-
* ri_InitConstraintCache
3347-
*
3348-
* Initialize ri_constraint_cache when new or being rebuilt.
3330+
* ri_InitHashTables -
33493331
*
3350-
* This needs to be done from two places, so split it out to prevent drift.
3332+
*Initialize our internal hash tables.
33513333
* ----------
33523334
*/
33533335
staticvoid
3354-
ri_InitConstraintCache(void)
3336+
ri_InitHashTables(void)
33553337
{
33563338
HASHCTLctl;
33573339

@@ -3362,20 +3344,6 @@ ri_InitConstraintCache(void)
33623344
ri_constraint_cache=hash_create("RI constraint cache",
33633345
RI_INIT_CONSTRAINTHASHSIZE,
33643346
&ctl,HASH_ELEM |HASH_FUNCTION);
3365-
}
3366-
3367-
/* ----------
3368-
* ri_InitHashTables -
3369-
*
3370-
*Initialize our internal hash tables.
3371-
* ----------
3372-
*/
3373-
staticvoid
3374-
ri_InitHashTables(void)
3375-
{
3376-
HASHCTLctl;
3377-
3378-
ri_InitConstraintCache();
33793347

33803348
/* Arrange to flush cache on pg_constraint changes */
33813349
CacheRegisterSyscacheCallback(CONSTROID,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp