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 1pUZkl-0001Yu-0B for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Feb 2023 21:00:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pUZkj-0007bb-Op for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Feb 2023 21:00:45 +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 1pUZkj-0007bS-C6 for pgsql-hackers@lists.postgresql.org; Tue, 21 Feb 2023 21:00:45 +0000 Received: from smtp-fw-80007.amazon.com ([99.78.197.218]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pUZkg-0001qI-6V for pgsql-hackers@postgresql.org; Tue, 21 Feb 2023 21:00:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1677013242; x=1708549242; h=message-id:date:mime-version:to:cc:references:from: in-reply-to:content-transfer-encoding:subject; bh=veaNha1BwGpgaZfyftQX8XEFGb55mb4xNr5w9BUvtC0=; b=i0HIPeeDBOqb/TwC0nvl6ecKhbPwH5CTKmFXAsjy6Y1OkOqRE+xrS1uM 0sKe38mY4UsgCFuL5XCtaXOtJzWYlsQhI/+dsrxgiBkZMEDFQ4+I8Av7z 4T7QVTw9g9WpbvpwHL+fiW7nqRX21n7RBK3CkLgyWHJ/y5MZ9dX72p+44 Q=; X-IronPort-AV: E=Sophos;i="5.97,315,1669075200"; d="scan'208";a="184646974" Subject: Re: refactoring relation extension and BufferAlloc(), faster COPY Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-617e30c2.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2023 21:00:36 +0000 Received: from EX13MTAUWC002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-m6i4x-617e30c2.us-east-1.amazon.com (Postfix) with ESMTPS id AD1986377A; Tue, 21 Feb 2023 21:00:34 +0000 (UTC) Received: from EX19D003UWC001.ant.amazon.com (10.13.138.144) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.45; Tue, 21 Feb 2023 21:00:34 +0000 Received: from [10.95.212.163] (10.95.212.163) by EX19D003UWC001.ant.amazon.com (10.13.138.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.24; Tue, 21 Feb 2023 21:00:32 +0000 Message-ID: Date: Tue, 21 Feb 2023 15:00:15 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 To: Andres Freund , , "Thomas Munro" , Melanie Plageman CC: Yura Sokolov , Robert Haas References: <20221029025420.eplyow6k7tgu6he3@awork3.anarazel.de> Content-Language: en-US From: Jim Nasby In-Reply-To: <20221029025420.eplyow6k7tgu6he3@awork3.anarazel.de> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.95.212.163] X-ClientProxiedBy: EX19D042UWA004.ant.amazon.com (10.13.139.16) To EX19D003UWC001.ant.amazon.com (10.13.138.144) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/28/22 9:54 PM, Andres Freund wrote: > b) I found that is quite beneficial to bulk-extend the relation with > smgrextend() even without concurrency. The reason for that is the primarily > the aforementioned dirty buffers that our current extension method causes. > > One bit that stumped me for quite a while is to know how much to extend the > relation by. RelationGetBufferForTuple() drives the decision whether / how > much to bulk extend purely on the contention on the extension lock, which > obviously does not work for non-concurrent workloads. > > After quite a while I figured out that we actually have good information on > how much to extend by, at least for COPY / > heap_multi_insert(). heap_multi_insert() can compute how much space is > needed to store all tuples, and pass that on to > RelationGetBufferForTuple(). > > For that to be accurate we need to recompute that number whenever we use an > already partially filled page. That's not great, but doesn't appear to be a > measurable overhead. Some food for thought: I think it's also completely fine to extend any relation over a certain size by multiple blocks, regardless of concurrency. E.g. 10 extra blocks on an 80MB relation is 0.1%. I don't have a good feel for what algorithm would make sense here; maybe something along the lines of extend = max(relpages / 2048, 128); if extend < 8 extend = 1; (presumably extending by just a couple extra pages doesn't help much without concurrency).