/*
* seqam_local_alloc()
*
- * Allocate new range of values for a local sequence.
+ * Allocate a new range of values for a local sequence.
*/
Datum
seqam_local_alloc(PG_FUNCTION_ARGS)
logit = true;
}
else if (sequence_needs_wal(seqh))
- {
fetch = log = fetch + SEQ_LOG_VALS;
- logit = true;
- }
/* Fetch new result value if is_called. */
if (is_called)
* Force the change to be WAL-logged, if we the tuple hasn't been logged
* since the last checkpoint.
*/
- if (RelationNeedsWAL(seqh->rel) && sequence_needs_wal(seqh))
+ if (sequence_needs_wal(seqh))
do_wal = true;
/*
}
/*
- * Returns true if sequence was not WAL logged since checkpoint
+ * Returns true, if the next update to the sequence tuple needs to be
+ * WAL-logged because it's the first update after a checkpoint.
+ *
+ * The sequence AM can use this as a hint, if it wants to piggyback some extra
+ * actions on WAL-logged updates.
+ *
+ * NB: This is just a hint. even when sequence_needs_wal() returns 'false',
+ * sequence_save_tuple might decide to WAL-log an update anyway.
*/
bool
sequence_needs_wal(SequenceHandle *seqh)
{
Page page;
- XLogRecPtr redoptr = GetRedoRecPtr();
+ XLogRecPtr redoptr;
Assert(BufferIsValid(seqh->buf));
+ if (!RelationNeedsWAL(seqh->rel))
+ return false;
+
page = BufferGetPage(seqh->buf);
+ redoptr = GetRedoRecPtr();
return (PageGetLSN(page) <= redoptr);
}