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.94.2) (envelope-from ) id 1qdSLF-003TFx-Ep for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 09:27:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qdSLD-000Yy8-Lw for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 09:27:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdSLC-000YxY-Np for pgsql-hackers@lists.postgresql.org; Tue, 05 Sep 2023 09:27:23 +0000 Received: from mail-177131.yeah.net ([123.58.177.131]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qdSL6-002q53-Fw for pgsql-hackers@postgresql.org; Tue, 05 Sep 2023 09:27:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yeah.net; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=uKkRKFHizTvm8phfcqu9cMn586Cg5ulg3GF4f2iqbBQ=; b=Y9wMLPsK9nBteqEHQ5BRBPgvw/1PqKhUgRYX8iKTLt8H5myT4ud19JFWQQrPUr M3NGLBF7haFCN28PjUQ6DPI3DXjK0xBojmZoq/L2RhfeRuUdYVV0pa43tWBVEYYd 3PCBQSxader8cU88AxQSISkWhee/zxlEuPjdpTOwq/Mdw= Received: from [192.168.1.101] (unknown [218.68.219.191]) by smtp1 (Coremail) with SMTP id ClUQrAB3MKBo9PZkBDBHBg--.17485S2; Tue, 05 Sep 2023 17:27:05 +0800 (CST) Message-ID: <41d536d6-bd24-6e73-880d-0b0917054fec@yeah.net> Date: Tue, 5 Sep 2023 17:27:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: Improving the heapgetpage function improves performance in common scenarios To: John Naylor Cc: pgsql-hackers References: Content-Language: en-US From: Quan Zongliang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:ClUQrAB3MKBo9PZkBDBHBg--.17485S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tr18ZF17JF4Dtr1ruFyxuFg_yoW8KFy7pF W5JF1akrZ5JayUtr1kZw1vvF47ur4rJr47AFn8ZrWUZ3y5W3Z2yFyxGrsxCaykGr4rCryS va1jqr909a4kZ37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jgEfOUUUUU= X-Originating-IP: [218.68.219.191] X-CM-SenderInfo: htxd06xrqjzxxdqjq5hhdkh0dhw/1tbiFRvhJF6NmV2NoAABsw List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023/9/5 16:15, John Naylor wrote: > > On Thu, Aug 24, 2023 at 5:55 PM Quan Zongliang > wrote: > > > In the function heapgetpage. If a table is not updated very frequently. > > Many actions in tuple loops are superfluous. For all_visible pages, > > loctup does not need to be assigned, nor does the "valid" variable. > > CheckForSerializableConflictOutNeeded from > > HeapCheckForSerializableConflictOut function, it only need to inspect at > > Thanks for submitting! A few weeks before this, there was another > proposal, which specializes code for all paths, not just one. That patch > also does so without duplicating the loop: > > https://www.postgresql.org/message-id/20230716015656.xjvemfbp5fysjiea@awork3.anarazel.de > Nice patch. I'm sorry I didn't notice it before. > > the beginning of the cycle only once. Using vtune you can clearly see > > the result (attached heapgetpage.jpg). > > > > So by splitting the loop logic into two parts, the vtune results show > > significant improvement (attached heapgetpage-allvis.jpg). > > For future reference, it's not clear at all from the screenshots what > the improvement will be for the user. In the above thread, the author > shares testing methodology as well as timing measurements. This is > useful for reproducibilty, as well as convincing others that the change > is important. > Here's how I test it EXPLAIN ANALYZE SELECT * FROM orders; Maybe the test wasn't good enough. Although the modified optimal result looks good. Because it fluctuates a lot. It's hard to compare. The results of vtune are therefore used. My patch is mainly to eliminate: 1, Assignment of "loctup" struct variable (in vtune you can see that these 4 lines have a significant overhead: 0.4 1.0 0.2 0.4). 2. Assignment of the "valid" variable.(overhead 0.6) 3. HeapCheckForSerializableConflictOut function call.(overhead 0.6) Although these are not the same overhead from test to test. But all are too obvious to ignore. The screenshots are mainly to show the three improvements mentioned above. I'll also try Andres Freund's test method next. > -- > John Naylor > EDB: http://www.enterprisedb.com