Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eK4BB-0003n9-40 for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Nov 2017 15:21:41 +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 1eK4BA-0005tZ-Dc for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Nov 2017 15:21:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eK4BA-0005tP-4L for pgsql-hackers@lists.postgresql.org; Wed, 29 Nov 2017 15:21:40 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eK4B6-0005wm-Ka for pgsql-hackers@postgresql.org; Wed, 29 Nov 2017 15:21:38 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 951DC5F795; Wed, 29 Nov 2017 10:21:35 -0500 (EST) Date: Wed, 29 Nov 2017 10:21:35 -0500 From: Stephen Frost To: Robert Haas Cc: Sergei Kornilov , "pgsql-hackers@postgresql.org" Subject: Re: using index or check in ALTER TABLE SET NOT NULL Message-ID: <20171129152135.GN4628@tamriel.snowman.net> References: <81911511895540@web58j.yandex.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wCcyVEMiq6dzt3Xj" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --wCcyVEMiq6dzt3Xj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Robert, * Robert Haas (robertmhaas@gmail.com) wrote: > On Tue, Nov 28, 2017 at 1:59 PM, Sergei Kornilov wrote: > > I write patch to speed up ALTER TABLE SET NOT NULL by check existed che= ck constraints or indexes. Huge phase 3 with verify table data will be skip= ped if table has valid check constraint cover "alteredfield IS NOT NULL" co= ndition or by SPI query if found index with compatible condition or regular= amsearchnulls index on processed field. >=20 > Doing this based on the existence of a valid constraint which implies > that no nulls can be present seems like a good idea. Doing it based > on an index scan doesn't necessarily seem like a good idea. We have > no guarantee at all that the index scan will be faster than scanning > the table would have been, and a single table scan can do multiple > verification steps if, for example, multiple columns are set NOT NULL > at the same time. Isn't the first concern addressed by using SPI..? As for the second concern, couldn't that be done with a more complicated query through SPI, though things might have to be restructured some to make it possible to do that. Just, generally speaking, this is definitely something that I think we want and neither of the above concerns seem like they're technical reasons why we can't use something like this approach, just needs to perhaps be reworked to handle multiple columns in a single query. Thanks! Stephen --wCcyVEMiq6dzt3Xj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJaHtB/AAoJEO1sijiDR2RVphIQAKwCyFyIrAR8qpmk1ZB1AICJ SsXVwf2sc/3KpLT3vrmpIk13jLc0VpeCh2y2rb9ssenkpYe7bacoB0+riY/pXRcD zAOzOIIgf6/UpI9Cg1bMqkIHnjAzKgKrvOas3oGdyizQayrWMuMb2Z8EMsUeXOf+ dq7PCQdU3QRRLVfd1o7l5uj1eIcUdEuqCAJjJsvk4iqGTGwvjAGupIbKx5y9+r6r WqlSe9VPhn4CYyNQbM5gNSMyCqPSieTqKyJY4TT+ZRsLObYKhenii7pseWxTooiJ gJyQXKhR46r4/tETWYfa2BFG7o0g0mCykbyFrBv108z/lG/hRXiHGBbIbFStJS2b iZqBjf2MpcH5K0DoBhC0pH5aphbxGtLwuNnl8wmhMSvrtf47oaWAPW7RauVU/lNt vcwNFqKPx5d8Vb9+0qgjiu1KYrYP4j1IHuaZ4aAFafrtYXJQbLBsAn1JgglEpjo3 JNQgI3MlHmD2//mw0IOERjumnTPn/+0Va3bsbDXyBIRaIq1cISuU5XFGrt6I9jnM inzKSGc8fudFhcMR3M2Q6PiWbaAiqkw+ErKQj6uwByoFKuB4JqwYa6Dinkdv7YA5 7ywx3Jyq4k0ZtR68nK0H0dvuUUelVdo9QYcrHkPBd0xW3RKqkpwN7r1Z65XACREN I09PUPIiTAJvyspjcqxN =3w2d -----END PGP SIGNATURE----- --wCcyVEMiq6dzt3Xj--