wire_local_seq.diff
text/plain
Filename: wire_local_seq.diff
Type: text/plain
Part: 0
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 2a8e64c7279..1c219ce319d 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1872,12 +1872,24 @@ RelationInitSequenceAccessMethod(Relation relation)
Oid tableam_handler;
Assert(RELKIND_HAS_SEQUENCE_AM(relation->rd_rel->relkind));
+ Assert(relation->rd_rel->relam != InvalidOid);
/*
- * Look up the sequence access method, save the OID of its handler
- * function.
+ * Fast path for the built-in "seqlocal" AM: avoid two syscache lookups
+ * and a name-based pg_am scan on every cold-cache open of a sequence
+ * using the default access method.
+ *
+ * This mirrors the catalog-relation fast path in
+ * RelationInitTableAccessMethod() above.
*/
- Assert(relation->rd_rel->relam != InvalidOid);
+ if (relation->rd_rel->relam == LOCAL_SEQUENCE_AM_OID)
+ {
+ relation->rd_amhandler = F_SEQ_LOCAL_SEQUENCEAM_HANDLER;
+ relation->rd_sequenceam = GetSequenceAmRoutine(relation->rd_amhandler);
+ relation->rd_tableam = GetTableAmRoutine(F_HEAP_TABLEAM_HANDLER);
+ return;
+ }
+
relation->rd_amhandler = GetSequenceAmRoutineId(relation->rd_rel->relam);
/*