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 1j72VH-0001TZ-U1 for pgsql-performance@arkaria.postgresql.org; Wed, 26 Feb 2020 19:37:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j72VG-0002oR-Dy for pgsql-performance@arkaria.postgresql.org; Wed, 26 Feb 2020 19:37:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j72VG-0002oK-40 for pgsql-performance@lists.postgresql.org; Wed, 26 Feb 2020 19:37:54 +0000 Received: from mail.mnc.ch ([62.2.77.205]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j72VD-00035S-Uf for pgsql-performance@postgresql.org; Wed, 26 Feb 2020 19:37:53 +0000 X-Virus-Scanned: amavisd-new at mnc.ch Sender: gc@mnc.ch Received: by gc-P7xxDM3-G.localdomain (Postfix, from userid 1000) id 1B3E180960; Wed, 26 Feb 2020 20:37:48 +0100 (CET) From: Guillaume Cottenceau To: Michael Lewis Cc: postgres performance list Subject: Re: much slower query in production References: <878skpnx0u.fsf@mnc.ch> <20200226162809.GZ31889@telsasoft.com> <87sgixmdil.fsf@mnc.ch> Date: Wed, 26 Feb 2020 20:37:48 +0100 In-Reply-To: (Michael Lewis's message of "Wed, 26 Feb 2020 11:18:53 -0700") Message-ID: <87o8tlm96b.fsf@mnc.ch> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Lewis writes: > UPDATE multicards > SET defacements = COALESCE( count, 0 ) > FROM ( SELECT multicard_uid, COUNT(*) AS count FROM tickets GROUP BY multicard_uid ) AS sub > WHERE uid = multicard_uid OR multicard_uid is null; > > I expect this should work. Not sure of performance of course. This looked great but as it seems you suspected, it's very slow :/ I interrupted it after 5 minutes run on my dev computer. -- Guillaume Cottenceau