Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uj2BI-001vxP-0R for pgsql-docs@arkaria.postgresql.org; Mon, 04 Aug 2025 20:53:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uj2BF-0057Bd-Nb for pgsql-docs@arkaria.postgresql.org; Mon, 04 Aug 2025 20:53:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uj2BF-0057BV-61 for pgsql-docs@lists.postgresql.org; Mon, 04 Aug 2025 20:53:13 +0000 Received: from sonic319-26.consmr.mail.bf2.yahoo.com ([74.6.131.81] helo=sonic.asd.mail.yahoo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uj2BB-000lCs-1E for pgsql-docs@lists.postgresql.org; Mon, 04 Aug 2025 20:53:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1754340786; bh=4N7HT80TbwnfedeHUqwEjbo3geb2hsknWxI9+0IGesI=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject:Reply-To; b=HKFU4oHD1PI1dWQk+aFXQ3Ltc/KNUiwL7pywnVBQjpd0KgV9MnHZgLWNdG6gYt/xIPSVNYxE45R1uqz1XxmNAuC3ovK7V5HZETW0ir14B6IHwHuUNQNX7gcyG6YQB/fkvCOSp/rLuRtnxz977i32kWsT87KpFRi65z8VJm6PIgpT2h6z/BGiKzXBQe2aWHeVQsXL+gLWtYJQIQY5eOsW+cjp4uYAYN5Lfm81TC2NSUvM7y0+6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Pm_n3IzLdSrPGDSTxinhYZ7sZFZK0QqOR7uLKsgUzjALgE llTokDlHxkqO0l2sTxLjf3KIRYpyz_Tu5T0pCcuBWeA9oU5_vdYuqPFF7NXdft7LbnMTQ5B_cavS 6G50SuuaBtoal3nG7knIRDZ.BHpa4DXuNQlmw8ZrwI5M7s4vb.aX3FXH4akrG_Vz5eT2t4ZUrn4h Z7PjmUpi8mZT4owOQTl83vzMIksPvdWWqC61yu4sOainfRJuGqkcbet4q2wF0jDQSmvjTMzYrk7F 2LiD55O7l673sR8psZgj4jEj1suRLWfpmjr6ZjEm7wAOEaGkP83wrtfq_DtO3_tgzgk7Vt_HNRng _30jEpQcjZ7okvsOj_yl1oZnhc1nnMfEvcQCBNzDu6tD9ZwiKayCLfakde0jcJWXPemEAvvqPbGS jTWI1mP2wuCbGom6AlrB.mcMcEbQ7mkG2dVQj0xZqN43OaZNdQP9v45FF55Yf06xQfHa_ximKb24 m6To9yWp9zfk5tNkv8bVBKQGHGTxfpiYzaqQuJFDs6mL3JGMvv8vPry17kXVIKXp_L8U9oO0vQFB SOnunlKqVohgNa4Xq82l5kgB9IVesEF514yz5iZ2S1zcKQVxP5qI4L55F2hHbl5EXNMGXnxUWPHk 46st6y8C9DMa5MjzKuQpjIeUgnsQtDadThZKK7S.cn50SXP63UM0jw23iSUhCCdr6I622ZrmHDKJ 9Zjk1lp9R56SanPiABNWZD9XnTftHvhVRAGrE.SzQYHk6tG..49Dh1MGlOA4ftQ-- X-Sonic-MF: X-Sonic-ID: 5173c2aa-0a37-4498-adbb-a75f88feef1e Received: from sonic.gate.mail.ne1.yahoo.com by sonic319.consmr.mail.bf2.yahoo.com with HTTP; Mon, 4 Aug 2025 20:53:06 +0000 Date: Mon, 4 Aug 2025 20:52:57 +0000 (UTC) From: Shuyu Pan To: =?UTF-8?Q?=C3=81lvaro_Herrera?= Cc: "David G. Johnston" , PostgreSQL Documentation Message-ID: <1128760489.1007960.1754340777935@mail.yahoo.com> In-Reply-To: <202508041132.d5q2a4nyt22v@alvherre.pgsql> References: <1167230960.326897.1753987280731@mail.yahoo.com> <202508041132.d5q2a4nyt22v@alvherre.pgsql> Subject: Re: further clarification: alter table alter column set not null - table scan is skipped MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1007959_2030446360.1754340777934" X-Mailer: WebService/1.1.24260 YahooMailIosMobile Content-Length: 5693 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_1007959_2030446360.1754340777934 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks a lot=C2=A0=C3=81lvaro for preparing=C2=A0the clarification so quick= ly. Looking forward to the release. If=C2=A0we mark a=C2=A0column to skip table=C2=A0scan during drop (phase 0)= =C2=A0and later=C2=A0skip the=C2=A0table=C2=A0scan when=C2=A0setting=C2=A0a= ttributes (phase 7), we will=C2=A0not risk data corruption if the Access Ex= clusive lock is never released between phase 0 and 7. Sent from Yahoo Mail for iPhone On Monday, August 4, 2025, 04:32, =C3=81lvaro Herrera wrote: On 2025-Jul-31, Shuyu Pan wrote: > I like your versions that emphasize: don=E2=80=99t drop the constraint in= the > same alter table set no null=C2=A0command.=C2=A0 Similar to=C2=A0David=E2= =80=99s point, I > spent some time trying to figure out a simple refactoring=C2=A0to carry t= he > optimization all the way to the end but it might require executing > =E2=80=9Cset not null=E2=80=9D sooner which has a big impact. Another opt= ion is only > implement a special treatment for this specific=C2=A0use case but it is a > code smell to me. Oh yeah, delaying the drop is much more likely to break other things.=C2=A0= I was more thinking along the lines of maintaining a list of columns that are known non-null at the start of the command (a bitmapset actually). This could be computed in ALTER TABLE phase 1, and used later to determine that no scans are needed.=C2=A0 But this is a lot of mechanism which is useless 99% of the time, and moreso now that you can directly add the NOT NULL constraints as NOT VALID to start with, which saves having to mess with a separate CHECK constraint. > I believe a small=C2=A0clarification for the doc entry=C2=A0is the most e= fficient thing. Okay, I've pushed the change to all branches using David Johnston's suggested wording. Thank you all! --=20 =C3=81lvaro Herrera=C2=A0 =C2=A0 =C2=A0 =C2=A0 Breisgau, Deutschland=C2=A0 = =E2=80=94=C2=A0 https://www.EnterpriseDB.com/ ------=_Part_1007959_2030446360.1754340777934 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks a lot =C3=81lvaro for preparing the clarification so quick= ly. Looking forward to the release.

If we mark a col= umn to skip table scan during drop (phase 0) and later skip = the table scan when setting attributes (phase 7), we wi= ll not risk data corruption if the Access Exclusive lock is never rele= ased between phase 0 and 7.



On M= onday, August 4, 2025, 04:32, =C3=81lvaro Herrera <alvherre@kurilemu.de&= gt; wrote:

On 2025-Jul-31, Shu= yu Pan wrote:

> I like your versions that emphasize: don=E2=80=99= t drop the constraint in the
> same alter table set no null comm= and.  Similar to David=E2=80=99s point, I
> spent some time= trying to figure out a simple refactoring to carry the
> optimi= zation all the way to the end but it might require executing
> =E2=80= =9Cset not null=E2=80=9D sooner which has a big impact. Another option is o= nly
> implement a special treatment for this specific use case b= ut it is a
> code smell to me.

Oh yeah, delaying the drop is m= uch more likely to break other things.  I
was more thinking along t= he lines of maintaining a list of columns that
are known non-null at the= start of the command (a bitmapset actually).
This could be computed in = ALTER TABLE phase 1, and used later to
determine that no scans are neede= d.  But this is a lot of mechanism
which is useless 99% of the time= , and moreso now that you can directly
add the NOT NULL constraints as N= OT VALID to start with, which saves
having to mess with a separate CHECK= constraint.

> I believe a small clarification for the doc e= ntry is the most efficient thing.

Okay, I've pushed the change = to all branches using David Johnston's
suggested wording.

Thank y= ou all!

--
=C3=81lvaro Herrera        Breisg= au, Deutschland  =E2=80=94  https://www.EnterpriseDB.com/
------=_Part_1007959_2030446360.1754340777934--