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 1uitQO-00HFVU-M9 for pgsql-docs@arkaria.postgresql.org; Mon, 04 Aug 2025 11:32:17 +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 1uitQN-000uTT-DW for pgsql-docs@arkaria.postgresql.org; Mon, 04 Aug 2025 11:32:15 +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 1uitQM-000uT8-JZ for pgsql-docs@lists.postgresql.org; Mon, 04 Aug 2025 11:32:15 +0000 Received: from fout-b4-smtp.messagingengine.com ([202.12.124.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uitQJ-000guY-1z for pgsql-docs@lists.postgresql.org; Mon, 04 Aug 2025 11:32:14 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id E74E51D00150; Mon, 4 Aug 2025 07:32:08 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Mon, 04 Aug 2025 07:32:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm1; t=1754307128; x= 1754393528; bh=+tJp3Zylvq6RkMZQhfwzbNZ8g5SQnen5DYwbrI55UkM=; b=S UhStgR9TVMTv3LjBPcZI9EEoyRvGYgFr92wOmBryrILZeTqJATn/We/Cshy7WmxZ P/TzgXObma5sd/0gMGkUnBEje7KwthY+kgQFyXC2II3nSSYl+vLKVYjRcAI/czZ5 rehQk3erMMHiKvJr+HtA3ZHFRlFB0rveZzK+xnVQhZ3M0EyLtb7xNhIMs1xMsrst If4YY1stfdyxIu2d/UQcSGIHFsfMfRbQ/ovsttJ5vXiOzZmvQ8n6PT92CeokliEU qessP5OhSdMkLl7Dl1zC8zabByzvuCqk3XKJEWo0T4LaL1nF/aRGGxoJ/wdvLhZJ QqO1+hsaI9CUzz/0ZwT/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1754307128; x=1754393528; bh=+ tJp3Zylvq6RkMZQhfwzbNZ8g5SQnen5DYwbrI55UkM=; b=fWzQAuq1e4UFkMnIH huSwlDqyAheYkDRjyQJ9/J9QfI3HdvWOYZx7FZ7EKhQeEJAfBJhh78hZwoou+JoR r7tyhSn0V3Yzndtf3WqUCD5nr37VVzCbAo3iWYA2dzVZZje7a6W/eKgX+c9rcyUe m6a3sanQfF44Gsdy+8B+YVtHOp4Ek+yd6xI+/2s6+vZwEeUWYjW6HpmQFwym4h/M I0aiJvnW7Co01UdgF06xxtTHjldhONCAQHTp640v6ogXFMNNK9CAa3raaHQs45mf iCxJ5Rmd+ZsDFqCffZHK95dt97+xdvAdMU8o1mTeMRTVZltoMowxji8oYkXnXzlL 8xzdQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduuddvudekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeetuedvheffkeevgfeuheevteevkefggedttdeufeeuheduuddthfef fffhjeefffenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv sehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegurghvihgurdhgrdhjohhhnhhsthhonhesghhmrghilhdrtgho mhdprhgtphhtthhopehpghhsqhhlqdguohgtsheslhhishhtshdrphhoshhtghhrvghsqh hlrdhorhhgpdhrtghpthhtohepphhshidvtddttdhushgrseihrghhohhordgtohhm X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Aug 2025 07:32:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1754307126; bh=pQCSt9iElS+Ymi4jruJJzvHv1xL75H8fTzVW4mM5Ug8=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=igjQ5oMUCHKMJHoK5l3a7REMcl1KhfS8tk3/DE55n7pFHzdbP0mIe6JwhYD0JbCiA 2SQZ/nSE05MwTWMumPLPbRo+ky3cTHQbOjxktxk/iNU6c07Zuqt5iM92/lkgbQWBAJ 9axlDb9srBNkapCLlb3bqXwx4F7v6ek6GmTz4THVBA4TpWX+i7+SBFCgjU+7rHqWCU FEnjH4Pm2Mi7uki1h04IVHGh/WQnU4l3mwe4PqQsrXc9xSO7cFHCDxRQvfp9WCkbni 05g4ymJ5LUnVDX5x2ZX9XOZCn0zxUYyuGdBY+hXaJcTEIvfTpLj0O/g+zTgoJIw2Wh Gy5/Qu4iNQXLg== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id D45FF90; Mon, 4 Aug 2025 13:32:06 +0200 (CEST) Date: Mon, 4 Aug 2025 13:32:06 +0200 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Shuyu Pan Cc: "David G. Johnston" , PostgreSQL Documentation Subject: Re: further clarification: alter table alter column set not null - table scan is skipped Message-ID: <202508041132.d5q2a4nyt22v@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1167230960.326897.1753987280731@mail.yahoo.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-Jul-31, Shuyu Pan wrote: > I like your versions that emphasize: don’t drop the constraint in the > same alter table set no null command. Similar to David’s point, I > spent some time trying to figure out a simple refactoring to carry the > optimization all the way to the end but it might require executing > “set not null” sooner which has a big impact. Another option is only > implement a special treatment for this specific use case but it is a > code smell to me. Oh yeah, delaying the drop is much more likely to break other things. 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. 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 clarification for the doc entry is the most efficient thing. Okay, I've pushed the change to all branches using David Johnston's suggested wording. Thank you all! -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/