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 1jT9Zi-0005BX-DB for pgsql-performance@arkaria.postgresql.org; Mon, 27 Apr 2020 19:37:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jT9Zf-00066N-Fz for pgsql-performance@arkaria.postgresql.org; Mon, 27 Apr 2020 19:37:51 +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 1jT9Zf-000655-4r for pgsql-performance@lists.postgresql.org; Mon, 27 Apr 2020 19:37:51 +0000 Received: from post.visena.com ([46.226.10.50]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.92) (envelope-from ) id 1jT9Zb-0004WE-Jt for pgsql-performance@lists.postgresql.org; Mon, 27 Apr 2020 19:37:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:In-Reply-To:Message-ID:Cc:To:From:Date; bh=EsXkadUtneI76u2bZdvtjjAXj77IhZGBG9OD/zTKBDc=; b=HReJ81LB05UJiEqkMP0j+r+aCEUsCHtJaTyi0e/dMYsrwPbA59hrn1vZ07A2QIU/mlSnJGWtabTMWPMtv+TzO+HR6f4/Rh69XN6z2bhICLtF7rWY+ipz7YzF22k1ePAKUVZa/myAwTCH1bawlCgcdqBNqWTAgsob7xu7nkzdjYM=; Received: from [10.0.1.10] (helo=tc7-visena.wh.internal.visena.com) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1jT9ZW-0006Tr-8o; Mon, 27 Apr 2020 21:37:42 +0200 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jT9ZW-00007q-6n; Mon, 27 Apr 2020 21:37:42 +0200 Date: Mon, 27 Apr 2020 21:37:41 +0200 (CEST) From: Andreas Joseph Krogh To: Justin Pryzby Cc: Jean-Christophe Boggio , pgsql-performance@lists.postgresql.org Message-ID: In-Reply-To: <20200427181034.GA28974@telsasoft.com> Subject: Re: Recursive query slow on strange conditions MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_0_217694631.1588016261980" X-Mailer: Visena Mail 2.2.283 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_0_217694631.1588016261980 Content-Type: multipart/related; boundary="----=_Part_1_348687660.1588016262015" ------=_Part_1_348687660.1588016262015 Content-Type: multipart/alternative; boundary="----=_Part_2_113349374.1588016262045" ------=_Part_2_113349374.1588016262045 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 mandag 27. april 2020 kl. 20:10:34, skrev Justin Pryzby < pryzby@telsasoft.com >:=20 On Mon, Apr 27, 2020 at 07:49:50PM +0200, Jean-Christophe Boggio wrote: > I have a performance/regression problem on a complicated query (placed i= nto > a function) when some tables are empty. > I first sent a message to the pgsql-bugs mailing list : >=20 https://www.postgresql.org/message-id/16390-e9866af103d5a03a%40postgresql.o= rg =3D> BUG #16390: Regression between 12.2 and 11.6 on a recursive query : v= ery=20 slow and overestimation of rows The most obvious explanation is due to this change: https://www.postgresql.org/docs/12/release-12.html |Allow common table expressions (CTEs) to be inlined into the outer query= =20 (Andreas Karlsson, Andrew Gierth, David Fetter, Tom Lane) |Specifically, CTEs are automatically inlined if they have no side-effects= ,=20 are not recursive, and are referenced only once in the query. Inlining can = be=20 prevented by specifying MATERIALIZED, or forced for multiply-referenced CTE= s by=20 specifying NOT MATERIALIZED. Previously, CTEs were never inlined and were= =20 always evaluated before the rest of the query.=20 The OP's query is recursive, sow no inlining will take place...=20 -- Andreas Joseph Krogh=20 ------=_Part_2_113349374.1588016262045 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 mandag 27. april 2020 kl. 20:10:34, skrev Justin Pryzby <pryzby@telsasoft.com>:
On = Mon, Apr 27, 2020 at 07:49:50PM +0200, Jean-Christophe Boggio wrote:
> I have a performance/regression problem on a complicated query (placed= into
> a function) when some tables are empty.

> I first sent a message to the pgsql-bugs mailing list :
> https://www.postgresql.org/message-id/16390-e9866af103d5a03a%40postgre= sql.org
=3D> BUG #16390: Regression between 12.2 and 11.6 on a recursive query := very slow and overestimation of rows

The most obvious explanation is due to this change:
https://www.postgresql.org/docs/12/release-12.html
|Allow common table expressions (CTEs) to be inlined into the outer query (= Andreas Karlsson, Andrew Gierth, David Fetter, Tom Lane)
|Specifically, CTEs are automatically inlined if they have no side-effects,= are not recursive, and ar= e referenced only once in the query. Inlining can be prevented by specifyin= g MATERIALIZED, or forced for multiply-referenced CTEs by specifying NOT MA= TERIALIZED. Previously, CTEs were never inlined and were always evaluated b= efore the rest of the query.
=C2=A0
The OP's query=C2=A0is=C2=A0recursive, sow no inlining will t= ake place...
=C2=A0
">
--
Andreas Joseph Krogh
=C2=A0
------=_Part_2_113349374.1588016262045-- ------=_Part_1_348687660.1588016262015-- ------=_Part_0_217694631.1588016261980--