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 1vqwKF-003cpz-12 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 16:47:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqwKD-00FRRu-1e for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 16:47:26 +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 1vqwKD-00FRRm-0f for pgsql-hackers@lists.postgresql.org; Fri, 13 Feb 2026 16:47:26 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vqwK8-00000000WF3-1NAE for pgsql-hackers@postgresql.org; Fri, 13 Feb 2026 16:47:25 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id BD115579399 for ; Fri, 13 Feb 2026 17:47:17 +0100 (CET) Received: from s981.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id A6F945789FE; Fri, 13 Feb 2026 17:47:17 +0100 (CET) Received: from s473.loopia.se (unknown [172.22.191.6]) by s981.loopia.se (Postfix) with ESMTP id A262522B1792; Fri, 13 Feb 2026 17:47:17 +0100 (CET) X-Virus-Scanned: amavisd-new at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s473.loopia.se (amavisd-new); dkim=pass (2048-bit key) header.d=proxel.se Received: from s899.loopia.se ([172.22.191.5]) by s473.loopia.se (s473.loopia.se [172.22.190.13]) (amavisd-new, port 10024) with LMTP id pjd3wjJwSfCd; Fri, 13 Feb 2026 17:47:17 +0100 (CET) X-Loopia-Auth: user X-Loopia-User: andreas@proxel.se X-Loopia-Originating-IP: 147.28.75.140 Received: from [192.168.0.121] (customer-147-28-75-140.stosn.net [147.28.75.140]) (Authenticated sender: andreas@proxel.se) by s899.loopia.se (Postfix) with ESMTPSA id DCFDC2C8BABD; Fri, 13 Feb 2026 17:47:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxel.se; s=loopiadkim1707418970; t=1771001237; bh=+HTWN6608hl79nO/ttS2BByJd6chIgTXW3VJ3mdiId4=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=PDZ5cNGSuTU1GlVJiyINTirIk+t2nhgO6l8aOuIv36bjS/K5JPdaFwE+4WF2UQ8OK LTX9xWa1B1zerFiMbx+OogUAA1oJaQtLi0XGSoIqYwuEMSU1E5vGXMWV5sjwAwNP00 ADTUMsqD1Rpp/qKOQ/M31lVRLTRHSyL9vloWDVZ0DSBLO3x+pNIA2IvIeU2OTmqnqT DpM6MaxR04O7cSi4beeVm9KIDAshHhI/lSnJ42nmrDAkmmpWtQ0pI7XzlhiEd0K90U ksNmRiuVrjmo486UP6h2zRu0OUBuf8ZmZoOh/6HhNvU8H3iN8C/tPW9zcmbol3Aqvw uumcNHkEBi1xA== Message-ID: <67931b8a-27a6-4d68-ae42-2bea87b56569@proxel.se> Date: Fri, 13 Feb 2026 17:47:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc? To: Hannu Krosing , Lukas Fittl Cc: Andres Freund , David Geier , Jakub Wartak , Robert Haas , Pavel Stehule , vignesh C , Michael Paquier , Ibrar Ahmed , Maciek Sakrejda , pgsql-hackers References: <7717ba64-9283-49ec-aa3f-34c6de848b93@gmail.com> <3bdce15d-25ec-4c49-9906-818803462897@gmail.com> <1e0462f0-8274-4d57-aa39-9b6ebeb954da@gmail.com> From: Andreas Karlsson Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/13/26 3:42 PM, Hannu Krosing wrote: > I haven't looked at the code here yet, but when using plain rdtsc on > modern CPUs one sees much more overhead from just the fact that the > code is there than from calling the rdtsc instruction, and the > overhead can vary by orders of magnitude based on how complex the work > is that is timed. > > I discovered this when I timed the (then-)new dead tid lookups in the > Vacuum in Pg 17 and saw significantly larger overhead per lookup when > the lookups themselves were slower, i.e. a case where the lookups were > done in random order (inded was on created on a column filled with > random()) > > So while just a tight loop of N million rtdsc calls will give you the > lower limit, it is likely not very representative of actual overhead. Isn't the same issue still there if you call clock_gettime() but that it is just less noticeable due to the high cost of clock_gettime()? Andreas