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 1lmqHF-00059k-Sx for pgsql-performance@arkaria.postgresql.org; Sat, 29 May 2021 04:08:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lmqHD-00060T-JD for pgsql-performance@arkaria.postgresql.org; Sat, 29 May 2021 04:08:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmqHD-00060J-B3 for pgsql-performance@lists.postgresql.org; Sat, 29 May 2021 04:08:43 +0000 Received: from aws.mailpen.com ([52.43.43.172] helo=aws2.mailpen.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lmqH2-0005zr-Ud for pgsql-performance@lists.postgresql.org; Sat, 29 May 2021 04:08:42 +0000 Received: from [172.20.70.208] (unknown [50.35.114.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by aws2.mailpen.com (Postfix) with ESMTPSA id 24A45C7E921 for ; Fri, 28 May 2021 21:08:29 -0700 (PDT) Subject: Re: AWS forcing PG upgrade from v9.6 a disaster To: pgsql-performance@lists.postgresql.org References: <88dec70b-eb63-0b72-0b5d-253851ef127b@mailpen.com> <163214e4-0588-230b-9ed5-f682087e0e18@wi3ck.info> <4e238cc5-f63e-0435-63bf-2515500d5424@dunslane.net> <20210528213052.GC5649@momjian.us> From: "Dean Gibson (DB Administrator)" Organization: UltiMeth Systems Message-ID: Date: Fri, 28 May 2021 21:08:28 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------0C4DEE6194A0C5AA172C71B5" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------0C4DEE6194A0C5AA172C71B5 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 2021-05-28 19:43, Christophe Pettus wrote: > ... > The most common reason for this kind of inexplicable stuff after an RDS upgrade is, as others have said, parameter changes, since you get a new default parameter group after the upgrade. > > That being said, this does look like something happened to the planner to cause it to pick a worse plan in v13. The deeply nested views make it kind of hard to pin down, but the core issue appears to be in the "good" plan, it evaluates the _Club.club_count > 5 relatively early, which greatly limits the number of rows that it handles elsewhere in the query. Why the plan change, I can't say. > > It might be worth creating a materialized CTE that grabs the "club_count > 5" set and uses that, instead of having it at the top level predicates. I spent quite a bit of time over the past five days experimenting with various parameter values, to no avail, but I don't mind trying some more. I have other queries that fail even more spectacularly, & they all seem to involve a generated table like the "club" one in my example.  I have an idea that I might try, in effectively changing the order of evaluation.  I'll have to think about that.  Thanks for the suggestion!  However, one "shouldn't" have to tinker with the order of stuff in SQL;  that's one of the beauties of the language: the "compiler" (planner) is supposed to figure that all out.  And for me, that's been true for the past 15 years with PostgreSQL. Note that this problem is not unique to v13.  It happened with upgrades to v10, 11, &12.  So, some fundamental change was made back then (at least in the RDS version).  Since I need a bulletproof backup past next January, I think my next task will be to get an EC2 instance running v9.6, where AWS can't try to upgrade it.  Then, at my leisure, I can fiddle with upgrading. --------------0C4DEE6194A0C5AA172C71B5 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 2021-05-28 19:43, Christophe Pettus wrote:
...
The most common reason for this kind of inexplicable stuff after an RDS upgrade is, as others have said, parameter changes, since you get a new default parameter group after the upgrade.

That being said, this does look like something happened to the planner to cause it to pick a worse plan in v13.  The deeply nested views make it kind of hard to pin down, but the core issue appears to be in the "good" plan, it evaluates the _Club.club_count > 5 relatively early, which greatly limits the number of rows that it handles elsewhere in the query.    Why the plan change, I can't say.

It might be worth creating a materialized CTE that grabs the "club_count > 5" set and uses that, instead of having it at the top level predicates.

I spent quite a bit of time over the past five days experimenting with various parameter values, to no avail, but I don't mind trying some more.

I have other queries that fail even more spectacularly, & they all seem to involve a generated table like the "club" one in my example.  I have an idea that I might try, in effectively changing the order of evaluation.  I'll have to think about that.  Thanks for the suggestion!  However, one "shouldn't" have to tinker with the order of stuff in SQL;  that's one of the beauties of the language:  the "compiler" (planner) is supposed to figure that all out.  And for me, that's been true for the past 15 years with PostgreSQL.

Note that this problem is not unique to v13.  It happened with upgrades to v10, 11, &12.  So, some fundamental change was made back then (at least in the RDS version).  Since I need a bulletproof backup past next January, I think my next task will be to get an EC2 instance running v9.6, where AWS can't try to upgrade it.  Then, at my leisure, I can fiddle with upgrading.
--------------0C4DEE6194A0C5AA172C71B5--