Skip to content

Commit 720b59b

Browse files
committed
Avoid catalog lookups in RelationAllowsEarlyPruning().
RelationAllowsEarlyPruning() performed a catalog scan, but is used in two contexts where that was a bad idea: 1. In heap_page_prune_opt(), which runs very frequently in some large scans. This caused major performance problems in a field report that was easy to reproduce. 2. In TestForOldSnapshot(), which runs while we hold a buffer content lock. It's not clear if this was guaranteed to be free of buffer deadlock risk. The check was introduced in commit 2cc41ac and defended against a real problem: 9.6's hash indexes have no page LSN and so we can't allow early pruning (ie the snapshot-too-old feature). We can remove the check from all later releases though: hash indexes are now logged, and there is no way to create UNLOGGED indexes on regular logged tables. If a future release allows such a combination, it might need to put a similar check in place, but it'll need some more thought. Back-patch to 10. Author: Thomas Munro Reviewed-by: Tom Lane, who spotted the second problem Discussion: https://postgr.es/m/CA%2BhUKGKT8oTkp5jw_U4p0S-7UG9zsvtw_M47Y285bER6a2gD%2Bg%40mail.gmail.com Discussion: https://postgr.es/m/CAA4eK1%2BWy%2BN4eE5zPm765h68LrkWc3Biu_8rzzi%2BOYX4j%2BiHRw%40mail.gmail.com
1 parent 80d0e5b commit 720b59b

File tree

3 files changed

+0
-44
lines changed

3 files changed

+0
-44
lines changed

src/backend/utils/cache/relcache.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5913,48 +5913,6 @@ RelationIdIsInInitFile(Oid relationId)
59135913
return RelationSupportsSysCache(relationId);
59145914
}
59155915

5916-
/*
5917-
* Tells whether any index for the relation is unlogged.
5918-
*
5919-
* Note: There doesn't seem to be any way to have an unlogged index attached
5920-
* to a permanent table, but it seems best to keep this general so that it
5921-
* returns sensible results even when they seem obvious (like for an unlogged
5922-
* table) and to handle possible future unlogged indexes on permanent tables.
5923-
*/
5924-
bool
5925-
RelationHasUnloggedIndex(Relation rel)
5926-
{
5927-
List *indexoidlist;
5928-
ListCell *indexoidscan;
5929-
bool result = false;
5930-
5931-
indexoidlist = RelationGetIndexList(rel);
5932-
5933-
foreach(indexoidscan, indexoidlist)
5934-
{
5935-
Oid indexoid = lfirst_oid(indexoidscan);
5936-
HeapTuple tp;
5937-
Form_pg_class reltup;
5938-
5939-
tp = SearchSysCache1(RELOID, ObjectIdGetDatum(indexoid));
5940-
if (!HeapTupleIsValid(tp))
5941-
elog(ERROR, "cache lookup failed for relation %u", indexoid);
5942-
reltup = (Form_pg_class) GETSTRUCT(tp);
5943-
5944-
if (reltup->relpersistence == RELPERSISTENCE_UNLOGGED)
5945-
result = true;
5946-
5947-
ReleaseSysCache(tp);
5948-
5949-
if (result == true)
5950-
break;
5951-
}
5952-
5953-
list_free(indexoidlist);
5954-
5955-
return result;
5956-
}
5957-
59585916
/*
59595917
* Invalidate (remove) the init file during commit of a transaction that
59605918
* changed one or more of the relation cache entries that are kept in the

src/include/utils/rel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,5 @@ typedef struct ViewOptions
605605
/* routines in utils/cache/relcache.c */
606606
extern void RelationIncrementReferenceCount(Relation rel);
607607
extern void RelationDecrementReferenceCount(Relation rel);
608-
extern bool RelationHasUnloggedIndex(Relation rel);
609608

610609
#endif /* REL_H */

src/include/utils/snapmgr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
RelationNeedsWAL(rel) \
4141
&& !IsCatalogRelation(rel) \
4242
&& !RelationIsAccessibleInLogicalDecoding(rel) \
43-
&& !RelationHasUnloggedIndex(rel) \
4443
)
4544

4645
#define EarlyPruningEnabled(rel) (old_snapshot_threshold >= 0 && RelationAllowsEarlyPruning(rel))

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