Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL0Jl-0007Rd-Ha for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Jan 2023 11:21:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pL0Ji-00019e-Us for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Jan 2023 11:21:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL0Ji-00019U-JW for pgsql-hackers@lists.postgresql.org; Thu, 26 Jan 2023 11:21:18 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pL0Jg-0005FW-CC for pgsql-hackers@postgresql.org; Thu, 26 Jan 2023 11:21:17 +0000 Received: by mail-ej1-x62a.google.com with SMTP id ud5so4189129ejc.4 for ; Thu, 26 Jan 2023 03:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fTXFNsLGJj+NKOAcgLi7AOX4AKnvBIHqljq5wzd8/TE=; b=L8wNeinfMK5NgTLuisglTNJdSA7oZp0nLxjqqUPZAPLveMwLYBQxWMEkpPi0Gr8qjx pdxa6btCOc5QsweZB898EzqJ+G+XUfO/fPV4Lf6UzJ8wKmuQfdN3zVNm0+25nHGgyk6j 4yhcvlEu1JubEY5O8D8hx7gk9qlOSfnNdcwQq6WKHrAco1Nxsa437K4Gu30uj0Dknjll a1FIfZbieVKFHcywP6M8kOVDjeWl8KzOTvjbI4NV6x37ddpWUJJ6Pwrrr6RWwlYRLS2z dzHsFFPZoAKV4Ge0EASDd8YCkkAbLC4sFCUpRMWyVQLtcpw/Y0edvHg/5MRcpPRKW3oA gx7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fTXFNsLGJj+NKOAcgLi7AOX4AKnvBIHqljq5wzd8/TE=; b=w84YZOzzUtZd2si6SyFGt1HS7QdCn1OCPhKxzfYOvZsaXT+4/N1GugBq1oG3+PN5iv qX2I1UiZ1qUCP8Li8xyoH+Q/XE78aykqWO2yaqBHYJcipOhqJry+laoJ9cTqxk2h4YIh eDWLOp7aqTMsm/FDFm8RcPDwWS67HfEntUh44ELUkE5pt17Swz9tFOVNhXK0sGnJdDL6 SIektHpEKwmI4C1l1C0t2v22wIy8Q+lBNJSdskic8cR/6HcI0B8GwWVp6VPAJcADuSX0 SWUDjT+QwUp3Y4bQ8YCRBuFGoNa2qIum0ldFa9QaFeXQn+/Eki2DujXWa9iiy5+VLAYt CeNA== X-Gm-Message-State: AFqh2krexB6sjZj+sDhbun8RYYpTvemq0rGAD4d8SctJaX7QEa0I2Nj9 jhMQT9FnOG3CdrZFtt8ZcYY= X-Google-Smtp-Source: AMrXdXuX6z+ic6Bsn9pDKgzYvDMYQEpFiUkxLdjXFj5tW28JCaLDQ9QAY+RDLHFyCXAEAHZEF9DCaQ== X-Received: by 2002:a17:907:2b01:b0:877:6e09:468d with SMTP id gc1-20020a1709072b0100b008776e09468dmr24236601ejc.7.1674732074766; Thu, 26 Jan 2023 03:21:14 -0800 (PST) Received: from [172.16.209.129] ([165.225.27.1]) by smtp.gmail.com with ESMTPSA id y14-20020a17090668ce00b0084d3bf4498csm448717ejr.140.2023.01.26.03.21.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Jan 2023 03:21:14 -0800 (PST) Message-ID: <3ac157f7-085d-e071-45fc-b87cd306360c@gmail.com> Date: Thu, 26 Jan 2023 12:21:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc? Content-Language: en-US To: Andres Freund Cc: Tom Lane , Robert Haas , vignesh C , Lukas Fittl , Michael Paquier , Ibrar Ahmed , Maciek Sakrejda , pgsql-hackers@postgresql.org References: <20230113195547.k4nlrmawpijqwlsa@awork3.anarazel.de> <20230117164758.gx4uuzhk5grw7zea@awork3.anarazel.de> <3044621.1673976417@sss.pgh.pa.us> <20230117185053.owqxw4ebp5ny6zhd@awork3.anarazel.de> <51876d9a-6812-24b6-57ab-a555e85afb6b@gmail.com> <20230121041613.xhjfzk7iobhpqm3u@awork3.anarazel.de> <20230121053157.hsdemsvq7oqydfl6@awork3.anarazel.de> <7c5f2170-f99d-5cd2-cb80-375155107ca7@gmail.com> <20230123203006.qgqhtxh447qoj4yr@awork3.anarazel.de> From: David Geier In-Reply-To: <20230123203006.qgqhtxh447qoj4yr@awork3.anarazel.de> 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 Hi, On 1/23/23 21:30, Andres Freund wrote: > That's been the case since my first post in the thread :). Mainly, it seems > easier to detect underflow cases during subtraction that way. And the factor > of 2 in range doesn't change a whole lot. I just realized it the other day :). >>>> If you have time to look at the pg_test_timing part, it'd be >>>> appreciated. That's a it larger, and nobody looked at it yet. So I'm a bit >>>> hesitant to push it. >>> I haven't yet pushed the pg_test_timing (nor it's small prerequisite) >>> patch. >>> >>> I've attached those two patches. Feel free to include them in your series if >>> you want, then the CF entry (and thus cfbot) makes sense again... >> I'll include them in my new patch set and also have a careful look at them. I reviewed the prerequisite patch which introduces INSTR_TIME_SET_SECONDS(), as well as the pg_test_timing patch. Here my comments: - The prerequisite patch looks good me. - By default, the test query in the pg_test_timing doc runs serially. What about adding SET max_parallel_workers_per_gather = 0 to make sure it really always does (e.g. on a system with different settings for parallel_tuple_cost / parallel_setup_cost)? Otherwise, the numbers will be much more flaky. - Why have you added a case distinction for diff == 0? Have you encountered this case? If so, how? Maybe add a comment. - To further reduce overhead we could call INSTR_TIME_SET_CURRENT() multiple times. But then again: why do we actually care about the per-loop time? Why not instead sum up diff and divide by the number of iterations to exclude all the overhead in the first place? - In the computation of the per-loop time in nanoseconds you can now use INSTR_TIME_GET_NANOSEC() instead of INSTR_TIME_GET_DOUBLE() * NS_PER_S. The rest looks good to me. The rebased patches are part of the patch set I sent out yesterday in reply to another mail in this thread. -- David Geier (ServiceNow)