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 1t9kam-00C0Ty-KW for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Nov 2024 12:29:28 +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 1t9kai-0011nq-VR for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Nov 2024 12:29:25 +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 1t9kah-0011l2-NC for pgsql-hackers@lists.postgresql.org; Sat, 09 Nov 2024 12:29:25 +0000 Received: from fout-a4-smtp.messagingengine.com ([103.168.172.147]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t9kab-000y3k-CU for pgsql-hackers@lists.postgresql.org; Sat, 09 Nov 2024 12:29:22 +0000 Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id A5190138022C; Sat, 9 Nov 2024 07:29:15 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sat, 09 Nov 2024 07:29:15 -0500 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=1731155355; x=1731241755; bh=n FxHBQKsvT9v8uHPVI1xE0VcLGKn9iAeLl1updLEQUc=; b=nkcnVstx25oxpbN1h QtokfUQLoG9bwUgbWK+vMyjrbcY6LAxxRUTBqMcoQj4pKIYS+s1iykaLCC94PUhl KfjSBs8Dwyok4znmfVtHI28F5pHUX4GKcHb2YRLWvhJwe8w9HWVTFuI6pHwk71Cd ketyDEHVJ9gfoqhDfpglh1qGZ23CkBdtFnXIf/7m8Yyddok/cvHrldqQ2AVjMpa4 89ks8BLondteoF9Z/kwDvbM72lorOKH9NqaBnDu2PODMFo6cdHPiYcNiIVh3tMee 2Et2VQAJV5q2ZXEVQI0kmNCJ3XOpEez1GKFKb48Yd+Nnl+HRh5tKw5au/oCtBXKc sG8+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdekgdegtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecu hfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrd hnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfej jefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprh hishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtg hpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhirghnrdhunhhi vhgvrhhsrghlihhthiesghhmrghilhdrtghomhdprhgtphhtthhopehtnhgurhifrghngh esghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhs thhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopehtghhlsehsshhsrdhpgh hhrdhprgdruhhs X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 9 Nov 2024 07:29:15 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1731155352; bh=rQTKdBUQ9d9xjDF7Vsq3QAgoO4TCc42b3pKgA/qYrOc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=QyMtimiCrFys15N+7dur+QQFZwr+gIp220b46cHvFpbvEZf913U2Br9zQK5n1h/3d VditSjFiSvkChA/z7CRxoXLt1vw/7cZ4u7tD9qOkINXc9wmvBQRD1RLaXXMhGyXqiz YSmVgRvUuxVy1OwtOJ1Wf3NaxjvMWBpk3i/ZUtpvYUt/WgfLhmLE8d7jPPS88xdoW5 MprVGlWkjZsOKc6QaUb+ELLHtBapFxmMCNnsEZjDs9k1uJrNv78ovQ5wp0UNtcbqlT 9e8ivsWSGx81HIW5Y/7kdZch0O1IIWTd//FyXFvnh7jiO5HnV8bDNA3JG6DdoGWLNq YP0TuBV9b0ozg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 9D0C4E3; Sat, 9 Nov 2024 13:29:12 +0100 (CET) Date: Sat, 9 Nov 2024 13:29:12 +0100 From: Alvaro Herrera To: Tom Lane Cc: jian he , Pg Hackers , Tender Wang Subject: Re: not null constraints, again Message-ID: <202411091229.k6wy32lley63@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3649828.1731083171@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Nov-08, Tom Lane wrote: > Alvaro Herrera writes: > > But we'll see what else the buildfarm has to say now that I pushed it ... > > A lot of the buildfarm is saying > > adder | 2024-11-08 13:04:39 | ../pgsql/src/backend/catalog/pg_constraint.c:708:37: warning: comparison is always true due to limited range of data type [-Wtype-limits] > > which evidently is about this: > > Assert(colnum > 0 && colnum <= MaxAttrNumber); Hah. > The memcpy right before that doesn't seem like project style either. > Most other places that are doing similar things just cast the > ARR_DATA_PTR to the right pointer type and dereference it. Hmm, yeah, that's easily removed, diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c index e953000c01d..043bf7c24dd 100644 --- a/src/backend/catalog/pg_constraint.c +++ b/src/backend/catalog/pg_constraint.c @@ -704,11 +704,7 @@ extractNotNullColumn(HeapTuple constrTup) ARR_DIMS(arr)[0] != 1) elog(ERROR, "conkey is not a 1-D smallint array"); - memcpy(&colnum, ARR_DATA_PTR(arr), sizeof(AttrNumber)); - Assert(colnum > 0 && colnum <= MaxAttrNumber); - - if ((Pointer) arr != DatumGetPointer(adatum)) - pfree(arr); /* free de-toasted copy, if any */ + colnum = ((AttrNumber *) ARR_DATA_PTR(arr))[0]; return colnum; } I notice I cargo-culted a "free de-toasted copy", but I think it's impossible to end up with a toasted datum here, because the column is guaranteed to have only one element, so not a candidate for toasting. But also, if we don't free it (in case somebody does an UPDATE to the catalog with a large array), nothing happens, because memory is going to be released soon anyway, by the error that results by conkey not being one element long. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Si quieres ser creativo, aprende el arte de perder el tiempo"