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 1lZm1v-0000rG-7g for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Apr 2021 02:58:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lZm1u-0008Ct-5w for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Apr 2021 02:58:54 +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 1lZm1u-0008Cm-0O for pgsql-bugs@lists.postgresql.org; Fri, 23 Apr 2021 02:58:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lZm1r-00021u-2y for pgsql-bugs@lists.postgresql.org; Fri, 23 Apr 2021 02:58:53 +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 13N2wgr01279477; Thu, 22 Apr 2021 22:58:42 -0400 From: Tom Lane To: David Fetter cc: pgsql-bugs@lists.postgresql.org, postgres@burri.li Subject: Re: BUG #16967: Extremely slow update statement in trigger In-reply-to: <20210423015012.GI2586@fetter.org> References: <16967-39db5f50df41173a@postgresql.org> <20210423015012.GI2586@fetter.org> Comments: In-reply-to David Fetter message dated "Fri, 23 Apr 2021 01:50:12 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1279475.1619146722.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 22 Apr 2021 22:58:42 -0400 Message-ID: <1279476.1619146722@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Fetter writes: > On Fri, Apr 16, 2021 at 04:52:15PM +0000, PG Bug reporting form wrote: >> Bug reference: 16967 >> Logged by: Nicolas Burri >> Email address: postgres@burri.li >> PostgreSQL version: 13.2 >> Operating system: Linux & Windows >> ... > I'm including what I found on dropbox below. In future, please include > the entire content in emails so it stays independent of sites that > might not still be there when people look back. Thanks for putting that into the archives. > I did find something interesting here's the EXPLAIN for the update > that's intended to change everything in the table. Note that the > estimated rows is 1: > shackle@[local]:5414/slow_stmt_triggers(14devel)(110490) # explain u= pdate demo set type =3D 'black' where type=3D'blue'; > QUERY PLAN = > =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90 > Update on demo (cost=3D0.00..3976.35 rows=3D0 width=3D0) > -> Seq Scan on demo (cost=3D0.00..3976.35 rows=3D1 width=3D34) > Filter: ((type)::text =3D 'blue'::text) > (3 rows) Yeah. Of course, the plan for the UPDATE itself looks just the same post-ANALYZE. What we can infer is that the complex query within the trigger function got a really stupid plan when there were no stats, and then a better plan once there were some. > tl;dr: running ANALYZE after a bulk load is a good idea, and I don't > see a bug here. Agreed, there's little evidence here of anything but the known issue that auto-ANALYZE doesn't act instantaneously. If we had an easy way to make that better, we would, but ... regards, tom lane