Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8cc6016

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 e96f524 commit 8cc6016

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
@@ -5941,48 +5941,6 @@ RelationIdIsInInitFile(Oid relationId)
59415941
return RelationSupportsSysCache(relationId);
59425942
}
59435943

5944-
/*
5945-
* Tells whether any index for the relation is unlogged.
5946-
*
5947-
* Note: There doesn't seem to be any way to have an unlogged index attached
5948-
* to a permanent table, but it seems best to keep this general so that it
5949-
* returns sensible results even when they seem obvious (like for an unlogged
5950-
* table) and to handle possible future unlogged indexes on permanent tables.
5951-
*/
5952-
bool
5953-
RelationHasUnloggedIndex(Relation rel)
5954-
{
5955-
List *indexoidlist;
5956-
ListCell *indexoidscan;
5957-
bool result = false;
5958-
5959-
indexoidlist = RelationGetIndexList(rel);
5960-
5961-
foreach(indexoidscan, indexoidlist)
5962-
{
5963-
Oid indexoid = lfirst_oid(indexoidscan);
5964-
HeapTuple tp;
5965-
Form_pg_class reltup;
5966-
5967-
tp = SearchSysCache1(RELOID, ObjectIdGetDatum(indexoid));
5968-
if (!HeapTupleIsValid(tp))
5969-
elog(ERROR, "cache lookup failed for relation %u", indexoid);
5970-
reltup = (Form_pg_class) GETSTRUCT(tp);
5971-
5972-
if (reltup->relpersistence == RELPERSISTENCE_UNLOGGED)
5973-
result = true;
5974-
5975-
ReleaseSysCache(tp);
5976-
5977-
if (result == true)
5978-
break;
5979-
}
5980-
5981-
list_free(indexoidlist);
5982-
5983-
return result;
5984-
}
5985-
59865944
/*
59875945
* Invalidate (remove) the init file during commit of a transaction that
59885946
* 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
@@ -606,7 +606,6 @@ typedef struct ViewOptions
606606
/* routines in utils/cache/relcache.c */
607607
extern void RelationIncrementReferenceCount(Relation rel);
608608
extern void RelationDecrementReferenceCount(Relation rel);
609-
extern bool RelationHasUnloggedIndex(Relation rel);
610609
extern List *RelationGetRepsetList(Relation rel);
611610

612611
#endif /* REL_H */

src/include/utils/snapmgr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
RelationNeedsWAL(rel) \
4242
&& !IsCatalogRelation(rel) \
4343
&& !RelationIsAccessibleInLogicalDecoding(rel) \
44-
&& !RelationHasUnloggedIndex(rel) \
4544
)
4645

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

0 commit comments

Comments
 (0)