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.96) (envelope-from ) id 1vfwoz-006LdR-0L for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 09:05:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfwoy-009Ctn-0Q for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 09:05:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vfwox-009Ctf-1u for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 09:05:44 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vfwos-000Lpt-17 for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 09:05:42 +0000 Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 387C07A00CC; Wed, 14 Jan 2026 04:05:38 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Wed, 14 Jan 2026 04:05:38 -0500 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=1768381538; x= 1768467938; bh=Qxv1qNJTopAsHvJFQ7Q71qMiAevAk/NOzXPqzAp6z/I=; b=l Yypry0c4ytK5JpdGSJ/c6RN3bkeluyqexA6o2A/6cqlPIAEEaCC/Q6hvxslwLSX5 gSieIyY45NalPURRceUjWkCzKI2QyGO5IG5KUl4I2xSdOo5aYzUe/3+71pzFXZpG aKDSPksS5R9RFsndRvo6okGgpR78vqNprfNVYuxmGXI1hOcVJzLBdiFqwGtCiGBS Ckruo+oNALy/30GSim0brLay/Xf6K8pfMWbcbrwIzKtaE+acMtEb+5qMiwrExap1 ji72UvYa/waf8wa7obH8mjTz74TtZ/bXl/q4kw4cUeuR9D+KwOOAuTSUd6OIKuIV A0iwGKqXTSiqetdsaTcow== 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=fm2; t=1768381538; x=1768467938; bh=Q xv1qNJTopAsHvJFQ7Q71qMiAevAk/NOzXPqzAp6z/I=; b=SOn9Kt83CHmQGrtmt 6N0tPW3nuTQHT7jqMGiwxExgjpMcadNcBU0R7k93XVv2MXY7B/ePVoEBHGA2XirZ Y/Z7nXrgh9WD+Bo/NwefbjPAXgOumYLVrvyYZS3NSql/7t2mlrfcTMjQ5zxcBSs6 4rakMnEjmGOIsBwsftCw6JbuVWvtEDCWn0FkRfiaFATIMevhFH7Pz6ljW79CQQmd WczFZbrQZ7+m/8LUQXwjc+FK6J0WbVpPc93yGV7AZW0xcmJfPWR570a/Y+1amSTB Rf5XupABO//gNY9zr85lEDXFndIyWp1ZFJYWa/Wst4L32KKLC/iL7zByo2zo+UTP 5TxZw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduvddvjeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeetuedvheffkeevgfeuheevteevkefggedttdeufeeuheduuddthfef fffhjeefffenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv sehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehjihgrnhdruhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgt ohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtgh hrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Jan 2026 04:05:37 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1768381535; bh=u5zwZCRj3FQ6u+eZG5GaYkJnfhDGQrPQtuXH85lloHk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=eKBV2QAfSEGKmdUJsgnMpHMKR58cuSL5liYKDrcDlY9dhotz8Ep1cbkvy4TT8p1+A BbM6dXUb1Y7MFBJUWJaapcrfq3Jm37lcsD9War6G+bPjAE9lxnozNlIz67e+gEaloR 8kWhclT0DYQ3eNOoMLLcEyuhMGs1Ju9arZ3IYQmNvfWPrn8MPhomu32PIvNkVA9Su+ DUvREbdtCbJn6Gj7Uk4pH+0+eoYoR3KvdSRWg82tMoO7zMnUQVR3MyxMTeOFEquhkw tEZSTUzwgnDbV7QpqLgqATuKb7CchIvykttFbjaIFscIPVFVJIjNDoudSf/6Iy4fUe y9SC06w8rE2vA== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id 3B3C17A; Wed, 14 Jan 2026 10:05:35 +0100 (CET) Date: Wed, 14 Jan 2026 10:05:35 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: jian he Cc: PostgreSQL Hackers Subject: Re: using index to speedup add not null constraints to a table Message-ID: <202601140902.x7lh6iq42pwq@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202601131715.cheonohttbyj@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-Jan-13, Álvaro Herrera wrote: > However, if we do this, then I think computing notnull_attrs is > pointless. So we should only change the order: do this new check > first, and if we find that any new not-null column is on a generated > column, then we compute both notnull_virtual_attrs and notnull_attrs. > No? Oh, another thing we should do is have a first pass that verifies whether all columns have an appropriate index, without scanning any of them; only if we verify that they all have one (and no generated column is involved) then we start scanning the indexes. Otherwise we waste time scanning one index and verify that it contains no null values, only to realize that the next column does not have an appropriate index to use, and thus we must scan the table. Then the first index scan is wasted work. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom." (Isaac Asimov)