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 1rcGCg-001q26-92 for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Feb 2024 02:49:55 +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 1rcGCd-000T3g-H5 for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Feb 2024 02:49:51 +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 1rcGCd-000T3X-3D for pgsql-hackers@lists.postgresql.org; Tue, 20 Feb 2024 02:49:51 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rcGCZ-007cMp-6b for pgsql-hackers@postgresql.org; Tue, 20 Feb 2024 02:49:49 +0000 Received: from [172.30.0.166] (unknown [172.30.0.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 62DA0E20E21; Tue, 20 Feb 2024 05:49:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1708397382; bh=KL566L4ot/vwA8VAd+2t2+px3S2gQe4y2yJTNFOiQd0=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=UnDDcl7Un03ollRqRs5lSUokY5/Rdj9IAsq2auCnn3ib5KrJh8gcNMWrLxJKvq3tD 8CHRJ2P3VWR72c4NyhHedqB14AX8N4noUraLlMLGH6ZG3SFYk8EWizG0TU9CSYYALn mgkoptiCHzqnKPdn8p5fAhE2mtXc31Lh0++L20mMnMVDOTRssYsAUBqxZhydvoxbUB aea096mlvmT+P7YBXCzCkqRVwTe5brzzr+fZUJyjvcSvQq2oo9gSAvjeLNYvgXstGB r7CKdX0mbATdNJ5WTrfTnejG5/e/Bh9hiqipCn//kq/Buv08Fyy+2G9e5Oo54R+TqY k+5mpCaNinPNg== Message-ID: Date: Tue, 20 Feb 2024 09:49:38 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Memory consumed by paths during partitionwise join planning Content-Language: en-US To: Ashutosh Bapat Cc: David Rowley , pgsql-hackers References: <182fbad0-f3f6-4692-8fc4-778378e1db01@postgrespro.ru> From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 19/2/2024 19:25, Ashutosh Bapat wrote: > On Fri, Feb 16, 2024 at 8:42 AM Andrei Lepikhov > wrote: >> Live example: right now, I am working on the code like MSSQL has - a >> combination of NestLoop and HashJoin paths and switching between them in >> real-time. It requires both paths in the path list at the moment when >> extensions are coming. Even if one of them isn't referenced from the >> upper pathlist, it may still be helpful for the extension. > > There is no guarantee that every path presented to add_path will be > preserved. Suboptimal paths are freed as and when add_path discovers > that they are suboptimal. So I don't think an extension can rely on > existence of a path. But having a refcount makes it easy to preserve > the required paths by referencing them. I don't insist, just provide my use case. It would be ideal if you would provide some external routines for extensions that allow for sticking the path in pathlist even when it has terrible cost estimation. > >> >>>> About partitioning. As I discovered planning issues connected to >>>> partitions, the painful problem is a rule, according to which we are >>>> trying to use all nomenclature of possible paths for each partition. >>>> With indexes, it quickly increases optimization work. IMO, this can help >>>> a 'symmetrical' approach, which could restrict the scope of possible >>>> pathways for upcoming partitions if we filter some paths in a set of >>>> previously planned partitions. >>> >>> filter or free? >> Filter. >> I meant that Postres tries to apply IndexScan, BitmapScan, >> IndexOnlyScan, and other strategies, passing throughout the partition >> indexes. The optimizer spends a lot of time doing that. So, why not >> introduce a symmetrical strategy and give away from the search some >> indexes of types of scan based on the pathifying experience of previous >> partitions of the same table: if you have dozens of partitions, Is it >> beneficial for the system to find a bit more optimal IndexScan on one >> partition having SeqScans on 999 other? >> > IIUC, you are suggesting that instead of planning each > partition/partitionwise join, we only create paths with the strategies > which were found to be optimal with previous partitions. That's a good > heuristic but it won't work if partition properties - statistics, > indexes etc. differ between groups of partitions. Sure, but the "Symmetry" strategy assumes that on the scope of a thousand partitions, especially with parallel append involved, it doesn't cause sensible performance degradation if we find a bit suboptimal path in a small subset of partitions. Does it make sense? As I see, when people use 10-100 partitions for the table, they usually strive to keep indexes symmetrical for all partitions. -- regards, Andrei Lepikhov Postgres Professional