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 1vAxRb-008GbZ-R1 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 21:29:31 +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 1vAxRa-004b03-Kb for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Oct 2025 21:29:29 +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.94.2) (envelope-from ) id 1vAxRa-004azs-Ae for pgsql-hackers@lists.postgresql.org; Mon, 20 Oct 2025 21:29:29 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vAxRX-003Il6-0j for pgsql-hackers@lists.postgresql.org; Mon, 20 Oct 2025 21:29:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 59KLTMSa376919; Mon, 20 Oct 2025 17:29:23 -0400 From: Tom Lane To: Dimitrios Apostolou cc: Chao Li , Nathan Bossart , Thomas Munro , pgsql-hackers@lists.postgresql.org Subject: Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward In-reply-to: References: <2edb7a57-b225-3b23-a680-62ba90658fec@gmx.net> <1282067.1744651649@sss.pgh.pa.us> <5ed51587-5a24-4d79-e36e-927620d0e3a2@gmx.net> <72d2c81b-a0fe-3d99-9dd4-0d771e6e673e@gmx.net> <1po8os49-r63o-2923-p37n-12698o1qn7p0@tzk.arg> <3515357.1760128017@sss.pgh.pa.us> <3698234.1760149336@sss.pgh.pa.us> <3686.1760232320@sss.pgh.pa.us> <717335.1760389672@sss.pgh.pa.us> Comments: In-reply-to Dimitrios Apostolou message dated "Mon, 20 Oct 2025 22:50:44 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <376917.1760995762.1@sss.pgh.pa.us> Date: Mon, 20 Oct 2025 17:29:22 -0400 Message-ID: <376918.1760995762@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dimitrios Apostolou writes: > + /* Dump buffer if full */ > + if (nonecs->bufdata >= nonecs->buflen) > Shouldn't this be equality check instead: > if (nonecs->bufdata == nonecs->buflen) Old defensive-programming habit. The invariant we want to establish is that there's some space available, ie nonecs->bufdata < nonecs->buflen and if we just test for equality then we haven't proven that. Agreed that bufdata shouldn't ever be greater than buflen, but if it somehow is, an equality test here would contribute to making things worse (writing ever further past the buffer) not better. > And possibly also assert(nonecs->bufdata <= nonecs->buflen) ? Maybe, but that code is simple enough that I didn't see a big need for an assertion check. regards, tom lane