Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJnDh-0003P1-PI for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 21:15:09 +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 1eJnDg-00044P-PQ for pgsql-general@arkaria.postgresql.org; Tue, 28 Nov 2017 21:15:08 +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 1eJnDg-00043R-IO for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 21:15:08 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eJnDS-0003SH-LH for pgsql-general@lists.postgresql.org; Tue, 28 Nov 2017 21:15:02 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id C15FC1502; Tue, 28 Nov 2017 22:14:53 +0100 (CET) Date: Tue, 28 Nov 2017 22:14:53 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Plan for update ... where a is not distinct from b Message-ID: <20171128211453.ymxi2q2d5pgqf3d5@hjp.at> References: <20171128085016.ia7x25ty5krlykeh@hjp.at> <1511898504.2375.6.camel@cybertec.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rvlgaqa56pmbonxq" Content-Disposition: inline In-Reply-To: <1511898504.2375.6.camel@cybertec.at> User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --rvlgaqa56pmbonxq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2017-11-28 20:48:24 +0100, Laurenz Albe wrote: > Peter J. Holzer wrote: > > I noticed that an update was taking a long time and found this: > >=20 > > UPDATE public.facttable_imf_ifs p > > SET [...lots of columns...] > > FROM cleansing.cls_imf_ifs_facttable_imf_ifs c, cleansing.cleansing_cha= nge_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 =3D ct.cleansing_change_type_id > > AND ct.cleansing_change_type_desc_short IN ('UPDATED_NEW') >=20 > It is kind of ugly, and I didn't test it, but here is an idea: >=20 > Suppose we know a value that cannot occur in both p.date and c.date. >=20 > Then you could write >=20 > WHERE coalesce(p.date, '0044-03-15 BC') =3D coalesce(c.date, '0044-03-= 15 BC') >=20 > and create an index on the coalesce expressions to facilitate > a merge join. Yes, that would work. However in most cases these queries are automatically generated from the tables so determining "impossible" values is not generally possible. I don't think it is necessary, though. Replacing (A is not distinct from B) with (A =3D B or A is null and B is null) usually produces an acceptable plan (indeed, I had that before, I replaced it with is not distinct to clean it up) and when a column has a not null constraint I can simply use (A =3D B). (I should probably do this automatically - currently I need to pass a flag to the query generator, and that's a bit error prone) hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --rvlgaqa56pmbonxq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlod0cYACgkQ8g5IURL+ KF1ntA//SB7uNeCrvPYKTAfSm6jHlxxyfx8Vnu5hof6ysfJpq/GIDZ32qprf2EIm aEr7u8MomdMviwbFkOK0mWH9t6a4ZU1Io/3YNtAHcUIHwwrLl4YHspm+NqBCOKeI VvBtdXFe3X+i4RE+ifIs8+Iz2bK/KqaTlWEEdkvUx/WJ4fSN0X4T5Ngsl94+VccF Il9y2nnh8Jzd1qOrrg+eQrG9jud9p+mriaxArG2KFeiCUwGwvijHLA6Df/st5igV bVi++RvjC1kk4cAMd+Osa8lHZoMV6GUpw3Q7FZnUrnXNSXvvC5BeSLzZFRO9UKK9 /gtsk7z1/rKqxdwUVfvDVnQBiVRIK7YOh3tUcStH9B8/MepuaDP40AC1QBLFJXYQ pd68ZlCqefxX1a9BCYhryiKM3/GLggN2Ej16k2F7o7Mu9/kESLcRMU3lXQZ/g0e1 72yzttA0FwKEUKKQh9E7hd6kphaKtt2r01/weQka22cBCbQwIZY+7CgjwgR33hbU d1q9JfvRc6umjgKXQwb5GEDDFYWBydsro1OZNBsFClKOrrEmsOjq9G/Tceq+DxnG 3KIy/ttrOGfcqtshtrsxiSxXjglkOoClPBTK9K0I4GxAchAGItJRdvMFnLBpb/tC /hv4l8wvE3kFZ0ouvBNDYupAuev/vbagWmooYYu9elTm045V8ys= =fNhj -----END PGP SIGNATURE----- --rvlgaqa56pmbonxq--