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 1tvD6f-00261b-9w for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 10:26:33 +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 1tvD6e-001jFT-5I for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 10:26:32 +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.94.2) (envelope-from ) id 1tvD6d-001jFK-QA for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 10:26:31 +0000 Received: from fhigh-a8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tvD6c-0006i3-06 for pgsql-hackers@postgresql.org; Thu, 20 Mar 2025 10:26:30 +0000 Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfhigh.phl.internal (Postfix) with ESMTP id 2D6761140192; Thu, 20 Mar 2025 06:26:29 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Thu, 20 Mar 2025 06:26:29 -0400 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=fm1; t=1742466389; x=1742552789; bh=D 3m6aIJPj09WUARaSqMQFA/VPNoicerxXcKiYd7rh5w=; b=BiBQ6Y40rIKcYe1RD r1850n3UZHXnjI+EkHnfkKRZhTpVYa21NasPwzfv2T2jVzWpUwr1ZcVRUoecfYhm ZzdemX5Pq/1vlnW/6sUiTFy3rMQj/pIDtegpX8CHZD0J3WrN1lT4/Qurw2geeLhH hW77pD1y3qCEQmrP7wu6Kq9DLfFPuM26awCaVQZLe3U2HoMJb/PTC6xxaje4YbM/ SJQ3zZ7LQ7/Pvtf4WTNtLcnUsPCPuVdi6oR2rymx4dGEAZaPEmT2Ug2v4W/aBJFn Cqf6LN2MJfl2AdzWDWUn1ZDpHEZAe3sk1eibsSL5x4eAAmhid4wNoGLJOL12kjHR GI9AA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugeejleejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddt jeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlh hvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffeh fffhjeejhffgieeuueekjeekfffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvg hrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsg gprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehjihgrnhdr uhhnihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtoheprhhushhhrg gshhdrlhgrthhhihgrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgr tghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 20 Mar 2025 06:26:28 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1742466386; bh=SswJ7m0NT70MuvP37JGF/brV8gjKY3l/4jE1WiDTRvE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NG99zexABVnST+IrxxDh646ZTSV8IejfqjLwgjQClxkIaqvwfgO/nhiucJ9t9lsHs /anoGxuCn020NUgzWLrEENrFGU5OKT0JBB+wuqdS8TA/E+U/puv5DodJrlXgaD/ZVn 35BhDPn3AjyKxq35teytRs4IVZSqRnitLlilqMR9A3XmSOFVS4AQNrodo8Ew7gSRQk 8qgFgjQGIB2rsfo9Eis0zxf1gdVAyTf8j8TK0bfQQIJIRGy7g7GFxB5+lD9mq0PrD4 jVzp8nZ3jMofpBnBoiBaC1nkDZwPl4z0Kj7Lz4nq2/e/4EULy+jhDoq/stT/hYGqb9 q2b337AicEHpg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 9D54B87; Thu, 20 Mar 2025 11:26:26 +0100 (CET) Date: Thu, 20 Mar 2025 11:26:26 +0100 From: Alvaro Herrera To: Rushabh Lathia Cc: jian he , PostgreSQL Hackers Subject: Re: Support NOT VALID / VALIDATE constraint options for named NOT NULL constraints Message-ID: <202503201026.6lzmnbhxfovj@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello On 2025-Mar-20, Rushabh Lathia wrote: > Attached is another version of the patch (WIP), where I have > introduced a new catalog column, pg_attribute.attinvalidnotnull > (boolean). This column will default to FALSE but will be set to TRUE > when an INVALID NOT NULL constraint is created. With this approach, > we can avoid performing extra scans on the catalog table to identify > INVALID NOT NULL constraints, ensuring there is no performance impact. I find this a reasonable way forward. We won't impact any applications that are currently relying on the boolean semantics of attnotnull, while still allowing the backend to know the real status of the constraint without having to scan pg_constraint for it. I also checked the struct layout, which is currently struct FormData_pg_attribute { Oid attrelid; /* 0 4 */ NameData attname; /* 4 64 */ /* --- cacheline 1 boundary (64 bytes) was 4 bytes ago --- */ Oid atttypid; /* 68 4 */ int16 attlen; /* 72 2 */ int16 attnum; /* 74 2 */ int32 atttypmod; /* 76 4 */ int16 attndims; /* 80 2 */ _Bool attbyval; /* 82 1 */ char attalign; /* 83 1 */ char attstorage; /* 84 1 */ char attcompression; /* 85 1 */ _Bool attnotnull; /* 86 1 */ _Bool atthasdef; /* 87 1 */ _Bool atthasmissing; /* 88 1 */ char attidentity; /* 89 1 */ char attgenerated; /* 90 1 */ _Bool attisdropped; /* 91 1 */ _Bool attislocal; /* 92 1 */ /* XXX 1 byte hole, try to pack */ int16 attinhcount; /* 94 2 */ Oid attcollation; /* 96 4 */ /* size: 100, cachelines: 2, members: 20 */ /* sum members: 99, holes: 1, sum holes: 1 */ /* last cacheline: 36 bytes */ }; Since there's a one-byte hole after the lot of bools/chars, the new bool will use it and this won't enlarge the storage, neither in memory nor on disk. I have not reviewed this patch in detail yet. Thank you! -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/