Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j72Cl-0000sJ-Us for pgsql-performance@arkaria.postgresql.org; Wed, 26 Feb 2020 19:18:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j72Ck-0001ZK-AP for pgsql-performance@arkaria.postgresql.org; Wed, 26 Feb 2020 19:18:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j72Cj-0001ZD-Tu for pgsql-performance@lists.postgresql.org; Wed, 26 Feb 2020 19:18:46 +0000 Received: from mout.perfora.net ([74.208.4.197]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j72Cg-0000Yd-Ot for pgsql-performance@postgresql.org; Wed, 26 Feb 2020 19:18:44 +0000 Received: from [IPv6:2607:fb90:a83e:a0f0:91b4:f441:50bf:7423] ([172.58.187.235]) by mrelay.perfora.net (mreueus004 [74.208.5.2]) with ESMTPA (Nemesis) id 1MnJ28-1jnp9D1E1s-00jEd4; Wed, 26 Feb 2020 20:18:35 +0100 Content-Type: multipart/alternative; boundary=Apple-Mail-81BAAA59-CA2A-45F8-99DB-067B3D9DA137 Content-Transfer-Encoding: 7bit From: "MichaelDBA@sqlexec.com" Mime-Version: 1.0 (1.0) Subject: Re: much slower query in production Date: Wed, 26 Feb 2020 14:18:31 -0500 Message-Id: <69844C34-DF13-46E6-BE7C-C9DABE19D391@sqlexec.com> References: Cc: Guillaume Cottenceau , postgres performance list In-Reply-To: To: Michael Lewis X-Mailer: iPhone Mail (17D50) X-Provags-ID: V03:K1:XkmJs5PFXs9KNfOITC7r1JBj0E0xiLVdr5S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TuquZaHfRZj5ILJhJnM9iRMjuN4kYbJ7rKRBwDG6iVvhrQGXWqVv List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail-81BAAA59-CA2A-45F8-99DB-067B3D9DA137 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Vacuum everything that you restored Sent from my iPhone > On Feb 26, 2020, at 1:19 PM, Michael Lewis wrote: >=20 > =EF=BB=BF >> UPDATE multicards >> SET defacements =3D COALESCE( count, 0 ) >> FROM ( SELECT multicard_uid, COUNT(*) AS count FROM tickets GROUP BY mu= lticard_uid ) AS sub >> WHERE uid =3D multicard_uid OR multicard_uid is null; >=20 > I expect this should work. Not sure of performance of course. --Apple-Mail-81BAAA59-CA2A-45F8-99DB-067B3D9DA137 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Vacuum everything that you restored

=
Sent from my iPhone

On Feb 26, 2020, at 1:19 PM, Michael Lewis <mlewis@entrata.c= om> wrote:

=EF=BB=BF
UPDATE multicards
   SET defacements =3D COALESCE( count, 0 )
  FROM ( SELECT multicard_uid, COUNT(*) AS count FROM tickets GROUP BY m= ulticard_uid ) AS sub
 WHERE uid =3D multicard_uid OR multicard_uid is null;
=

I expect this should work. Not sure of performance of co= urse.
= --Apple-Mail-81BAAA59-CA2A-45F8-99DB-067B3D9DA137--