v9-0002-instrumentation-Drop-INSTR_TIME_SET_CURRENT_LAZY-.patch

application/octet-stream

Filename: v9-0002-instrumentation-Drop-INSTR_TIME_SET_CURRENT_LAZY-.patch
Type: application/octet-stream
Part: 1
Message: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc?

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v9-0002
Subject: instrumentation: Drop INSTR_TIME_SET_CURRENT_LAZY macro
File+
src/backend/executor/instrument.c 7 3
src/include/portability/instr_time.h 0 6
From ef3f117ad153890f7536b7959e1a33e497b3a7f6 Mon Sep 17 00:00:00 2001
From: Lukas Fittl <lukas@fittl.com>
Date: Tue, 24 Feb 2026 15:58:57 -0800
Subject: [PATCH v9 2/7] instrumentation: Drop INSTR_TIME_SET_CURRENT_LAZY
 macro

This macro had exactly one user in InstrStartNode, and the caller can
instead use INSTR_TIME_IS_ZERO / INSTR_TIME_SET_CURRENT directly.

This supports a future change that intends to modify the time source being
used in the InstrStartNode case.

Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by:
Discussion:
---
 src/backend/executor/instrument.c    | 10 +++++++---
 src/include/portability/instr_time.h |  6 ------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c
index edab92a0ebe..332fbc6be03 100644
--- a/src/backend/executor/instrument.c
+++ b/src/backend/executor/instrument.c
@@ -67,9 +67,13 @@ InstrInit(Instrumentation *instr, int instrument_options)
 void
 InstrStartNode(Instrumentation *instr)
 {
-	if (instr->need_timer &&
-		!INSTR_TIME_SET_CURRENT_LAZY(instr->starttime))
-		elog(ERROR, "InstrStartNode called twice in a row");
+	if (instr->need_timer)
+	{
+		if (!INSTR_TIME_IS_ZERO(instr->starttime))
+			elog(ERROR, "InstrStartNode called twice in a row");
+		else
+			INSTR_TIME_SET_CURRENT(instr->starttime);
+	}
 
 	/* save buffer usage totals at node entry, if needed */
 	if (instr->need_bufusage)
diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h
index 490593d1825..dbd989cc002 100644
--- a/src/include/portability/instr_time.h
+++ b/src/include/portability/instr_time.h
@@ -19,8 +19,6 @@
  *
  * INSTR_TIME_SET_CURRENT(t)		set t to current time
  *
- * INSTR_TIME_SET_CURRENT_LAZY(t)	set t to current time if t is zero,
- *									evaluates to whether t changed
  *
  * INSTR_TIME_ADD(x, y)				x += y
  *
@@ -168,12 +166,8 @@ GetTimerFrequency(void)
 
 #define INSTR_TIME_IS_ZERO(t)	((t).ticks == 0)
 
-
 #define INSTR_TIME_SET_ZERO(t)	((t).ticks = 0)
 
-#define INSTR_TIME_SET_CURRENT_LAZY(t) \
-	(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
-
 
 #define INSTR_TIME_ADD(x,y) \
 	((x).ticks += (y).ticks)
-- 
2.47.1