On 2020-Jan-27, Alvaro Herrera wrote:
> Actually looking again, getRecordTimestamp is looking pretty strange.
> It looks much more natural by using nested switch/case blocks, as with
> this diff. I think the compiler does a better job this way too.
I hadn't noticed I forgot to attach the diff here :-(
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 0bc3d8cec5..1a165701ae 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -5566,33 +5566,43 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
static bool
getRecordTimestamp(XLogReaderState *record, TimestampTz *recordXtime)
{
- uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
- uint8 xact_info = info & XLOG_XACT_OPMASK;
- uint8 rmid = XLogRecGetRmid(record);
+ RmgrId rmid = XLogRecGetRmid(record);
+ uint8 info;
- if (rmid == RM_XLOG_ID && info == XLOG_RESTORE_POINT)
+ switch (rmid)
{
- *recordXtime = ((xl_restore_point *) XLogRecGetData(record))->rp_time;
- return true;
- }
- if (rmid == RM_XLOG_ID && (info == XLOG_CHECKPOINT_ONLINE ||
- info == XLOG_CHECKPOINT_SHUTDOWN))
- {
- *recordXtime =
- time_t_to_timestamptz(((CheckPoint *) XLogRecGetData(record))->time);
- return true;
- }
- if (rmid == RM_XACT_ID && (xact_info == XLOG_XACT_COMMIT ||
- xact_info == XLOG_XACT_COMMIT_PREPARED))
- {
- *recordXtime = ((xl_xact_commit *) XLogRecGetData(record))->xact_time;
- return true;
- }
- if (rmid == RM_XACT_ID && (xact_info == XLOG_XACT_ABORT ||
- xact_info == XLOG_XACT_ABORT_PREPARED))
- {
- *recordXtime = ((xl_xact_abort *) XLogRecGetData(record))->xact_time;
- return true;
+ case RM_XLOG_ID:
+ info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
+
+ switch (info)
+ {
+ case XLOG_RESTORE_POINT:
+ *recordXtime = ((xl_restore_point *) XLogRecGetData(record))->rp_time;
+ return true;
+ case XLOG_CHECKPOINT_ONLINE:
+ case XLOG_CHECKPOINT_SHUTDOWN:
+ *recordXtime =
+ time_t_to_timestamptz(((CheckPoint *) XLogRecGetData(record))->time);
+ return true;
+ }
+ break;
+
+ case RM_XACT_ID:
+ info = XLogRecGetInfo(record) & XLOG_XACT_OPMASK;
+
+ switch (info)
+ {
+ case XLOG_XACT_COMMIT:
+ case XLOG_XACT_COMMIT_PREPARED:
+ *recordXtime = ((xl_xact_commit *) XLogRecGetData(record))->xact_time;
+ return true;
+
+ case XLOG_XACT_ABORT:
+ case XLOG_XACT_ABORT_PREPARED:
+ *recordXtime = ((xl_xact_abort *) XLogRecGetData(record))->xact_time;
+ return true;
+ }
+ break;
}
return false;
}