Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vqhFT-00G3mz-1k for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 00:41:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqhFS-00Bo5D-25 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 00:41:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vqhFR-00Bo54-2N for pgsql-hackers@lists.postgresql.org; Fri, 13 Feb 2026 00:41:31 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vqhFP-00000000P5l-2ZiC for pgsql-hackers@postgresql.org; Fri, 13 Feb 2026 00:41:30 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 037E81400093; Thu, 12 Feb 2026 19:41:25 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 12 Feb 2026 19:41:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1770943284; x=1771029684; bh=Xctx47SSII tsxeFKj1omgcmnTRFTEoB5xH/Hmlh393o=; b=BolIR4jRGUViO5HTjKwYIzAGdp 0dnlCI0Iyvp7F7ecp2i/VuTOwUWcbKjA3qAlfvdJfuwPcL9pdFTUAKRQBXi+47qR pyd48Ylv97cGnhU9QKrQ4XGqrtRIT57d/NNt4unBvHK9wZXgNz77uOhQrUOQKcNU LCJsXjjbFbjJy/uI3KB2bQxw0QnBQgc6JP/hkmUzMl5dQMDHCimH9hEIFMsioX6R o4OmR0SZJHOUkBefVAJyPmqPFuViPx2GKSglOUDbEYL2mdS/JQPt3lZivfenIeuN VinBgUj6F4+xP8U0Om+A3F2X5OmwyGE9msPf7Guh8uybPNM2r5yCpU5hzJNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1770943284; x=1771029684; bh=Xctx47SSIItsxeFKj1omgcmnTRFTEoB5xH/ Hmlh393o=; b=p9mu4yVmiJCg1Bg9YmRuwSzsdpacaYqCWym/MqhwKke2aB3xBNi bZyVyDWSPmGCyi6Kf4Z79u9Oyo9wH/RujMOr7eIa+kxtdQZYiTmkcDhAgqsPPg3k gWLEymaQy7poG9qOqdcXw4f7PAk4N7gBsD+npual8EPpkSkY7Ja5OG9ZOD252mYF +f6mV6kkJI7bdZCuj94u5bj4yhC2buedsdj3M5Apz1wp9q4ZUO4IpVW/0l+wy/8l aLp+qN9qlpwp0YqUVTNSnVwiSyGuccrZLmZhb+9b1Au5HPS15NLZOn7mfmCAFZwJ qtc5eWFAPixysgRl+j2mbTt2UeBfJOqwEVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvtdeikeefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepvdfffeevhfetveffgeeiteefhfdtvdffjeevhfeuteegleduheetveduieet tddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeduuddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhgrkhhusgdrfigrrhhtrghksegvnhhtvghrph hrihhsvggusgdrtghomhdprhgtphhtthhopehluhhkrghssehfihhtthhlrdgtohhmpdhr tghpthhtohepghgvihgurghvrdhpghesghhmrghilhdrtghomhdprhgtphhtthhopehisg hrrghrrdgrhhhmrggusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhdrshgrkhhrvghj uggrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphgrvhgvlhdrshhtvghhuhhlvgesgh hmrghilhdrtghomhdprhgtphhtthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgt ohhmpdhrtghpthhtohepvhhighhnvghshhdvudesghhmrghilhdrtghomhdprhgtphhtth hopehhrghnnhhukhesghhoohhglhgvrdgtohhm X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Feb 2026 19:41:23 -0500 (EST) Date: Thu, 12 Feb 2026 19:41:22 -0500 From: Andres Freund To: Lukas Fittl Cc: David Geier , Jakub Wartak , Hannu Krosing , Robert Haas , Pavel Stehule , vignesh C , Michael Paquier , Ibrar Ahmed , Maciek Sakrejda , pgsql-hackers Subject: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc? Message-ID: References: <7717ba64-9283-49ec-aa3f-34c6de848b93@gmail.com> <3bdce15d-25ec-4c49-9906-818803462897@gmail.com> <1e0462f0-8274-4d57-aa39-9b6ebeb954da@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-02-12 08:05:27 -0800, Lukas Fittl wrote: > On master (88327092ff0), I'm getting 23.54 ns from pg_test_timing - vs > with 0002 applied, this slows to 25.74 ns. I've tried to see if the > "unlikely(..)" we added in pg_ticks_to_ns is the problem (since in the > clock_gettime() case we'd always be running into that branch due to > the size of the nanoseconds value), but no luck - I think the extra > multiplication/division itself is the problem. > > Any ideas how we could do this differently? The problem looks to be that you're going to take the slowpath when using clock_gettime(), unless you booted within the last three days, because pg_test_timing() is doing INSTR_TIME_SET_CURRENT(temp); cur = INSTR_TIME_GET_NANOSEC(temp); Which will require reducing time-since-boot in nanoseconds (with CLOCK_MONOTONIC) via pg_ticks_to_ns() overflow logic, as the way max_ticks_no_overflow is set in 0001, it'll overflow after a few days of runtime. This can largely be addressed by keeping prev and cur in the instr_time domain and only converting the difference to nanoseconds. I wonder if pg_test_timing should have a small loop with a fixed count to determine the timing without all the overhead the existing loop has... Greetings, Andres Freund