Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJlry-0005wv-5q for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 19:48:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJlrv-0007Ro-Mb for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 19:48:35 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJlrv-0007Re-Eb for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 19:48:35 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eJlrr-0001ZC-LR for pgsql-general@postgresql.org; Tue, 28 Nov 2017 19:48:34 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 2921A4CBDF; Tue, 28 Nov 2017 20:48:29 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id yfGWMta2egPh; Tue, 28 Nov 2017 20:48:25 +0100 (CET) Message-ID: <1511898504.2375.6.camel@cybertec.at> Subject: Re: Plan for update ... where a is not distinct from b From: Laurenz Albe To: "Peter J. Holzer" , pgsql-general@postgresql.org Date: Tue, 28 Nov 2017 20:48:24 +0100 In-Reply-To: <20171128085016.ia7x25ty5krlykeh@hjp.at> References: <20171128085016.ia7x25ty5krlykeh@hjp.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter J. Holzer wrote: > I noticed that an update was taking a long time and found this: > > UPDATE public.facttable_imf_ifs p > SET [...lots of columns...] > FROM cleansing.cls_imf_ifs_facttable_imf_ifs c, cleansing.cleansing_change_type ct > WHERE > (p.macrobondtimeseries is not distinct from c.macrobondtimeseries) AND (p.date is not distinct from c.date) > AND c.cleansing_change_type_id = ct.cleansing_change_type_id > AND ct.cleansing_change_type_desc_short IN ('UPDATED_NEW') It is kind of ugly, and I didn't test it, but here is an idea: Suppose we know a value that cannot occur in both p.date and c.date. Then you could write WHERE coalesce(p.date, '0044-03-15 BC') = coalesce(c.date, '0044-03-15 BC') and create an index on the coalesce expressions to facilitate a merge join. Yours, Laurenz Albe