aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/ts_cache.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-01-20 13:44:49 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-01-20 13:45:10 -0500
commitd5b31cc32b0762fa8920a9c1f70af2f82fb0aaa5 (patch)
tree335b946b09527d8faddd18ca40017fecd69ef6e9 /src/backend/utils/cache/ts_cache.c
parent0a2da5282a2372b651e2096f16d97d6029e5f54f (diff)
downloadpostgresql-d5b31cc32b0762fa8920a9c1f70af2f82fb0aaa5.tar.gz
postgresql-d5b31cc32b0762fa8920a9c1f70af2f82fb0aaa5.zip
Fix an O(N^2) performance issue for sessions modifying many relations.
AtEOXact_RelationCache() scanned the entire relation cache at the end of any transaction that created a new relation or assigned a new relfilenode. Thus, clients such as pg_restore had an O(N^2) performance problem that would start to be noticeable after creating 10000 or so tables. Since typically only a small number of relcache entries need any cleanup, we can fix this by keeping a small list of their OIDs and doing hash_searches for them. We fall back to the full-table scan if the list overflows. Ideally, the maximum list length would be set at the point where N hash_searches would cost just less than the full-table scan. Some quick experimentation says that point might be around 50-100; I (tgl) conservatively set MAX_EOXACT_LIST = 32. For the case that we're worried about here, which is short single-statement transactions, it's unlikely there would ever be more than about a dozen list entries anyway; so it's probably not worth being too tense about the value. We could avoid the hash_searches by instead keeping the target relcache entries linked into a list, but that would be noticeably more complicated and bug-prone because of the need to maintain such a list in the face of relcache entry drops. Since a relcache entry can only need such cleanup after a somewhat-heavyweight filesystem operation, trying to save a hash_search per cleanup doesn't seem very useful anyway --- it's the scan over all the not-needing-cleanup entries that we wish to avoid here. Jeff Janes, reviewed and tweaked a bit by Tom Lane
Diffstat (limited to 'src/backend/utils/cache/ts_cache.c')
0 files changed, 0 insertions, 0 deletions