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 1sJUY3-005BeK-UV for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jun 2024 08:50:40 +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 1sJUY0-00A0gS-3z for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jun 2024 08:50:37 +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 1sJUXy-00A0gJ-If for pgsql-hackers@lists.postgresql.org; Tue, 18 Jun 2024 08:50:36 +0000 Received: from fout6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJUXv-002G70-9z for pgsql-hackers@lists.postgresql.org; Tue, 18 Jun 2024 08:50:34 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id E7B6B1380452; Tue, 18 Jun 2024 04:50:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 18 Jun 2024 04:50:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm1; t=1718700628; x=1718787028; bh=SK2dNCv4ygKbpJOborPzMbmh4QYgWMI1 hP+iax8RYnE=; b=B5oytf/ZTYRYedDEgQST2Z4TtiXI5udfHHPAoDOAjpXqblmZ nA76KPcrWsxSNLyQSm14gZ/5jtrJrgR04pDgNsMakMtyFez9MUTZc4Zs776Z9YcC lhKlllgbbiCEdzK8VYayWxbnzPgJdnqsxkMbnT0LUNc2s3MnEuLptn3cDndbh4VX pilpzJGH4jk3eAmLpU+BZ5CHB9/tM2NU4c6oZda6oX/ppGxmxPV6DrEI7iOr3SJw B4la1mFjNk0IJlW1w3VJIjdaLK0eTHi8pItUSR583Sp31XhShIdqOuGQE3+UzzmQ TwaJFejvzoVOCcrWsm8BQbVvd6aUwrjJsNTwAg== 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 :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1718700628; x= 1718787028; bh=SK2dNCv4ygKbpJOborPzMbmh4QYgWMI1hP+iax8RYnE=; b=d FvQG9DspLqjlx+O9QFuXyOEEm1wDz9lfaQJTvnn8iX2VZpsbo3nJjVAvZEnC+D+j q7leSncrwKappmdGHxQwgvklI8aQn0L/+sVnw/ryAsxf1F7RARcNVudZC/iI/V1X m7FIRYiSxjTpwiUJQf27Mqtk8KPul6GYVFWMoVKY+u/gS7rYLvNqqEZdNhpad1Bv MXGMSp3t5Of1pTC5s9j//fPTiyzkncB+1uDG0GajIVdxgImu0QSSU7Qlpx2Ej055 aK5tA2VR45778e3nxEdOc+2XJJJeI3Th2r4EVgUMH21FlqeezgERD7ktl0QkQtge /XJnhaZLbBmjddCwrvRJw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvjedgtdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpefrvght vghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgh eqnecuggftrfgrthhtvghrnhepjefhveehtdetgfffhffhfeefgffghffflefgieeuueek hedvhedvfeehffdvfeeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 18 Jun 2024 04:50:27 -0400 (EDT) Message-ID: Date: Tue, 18 Jun 2024 10:50:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: altering a column's collation leaves an invalid foreign key To: jian he , Tom Lane Cc: Paul Jungwirth , PostgreSQL Hackers References: <78d824e0-b21e-480d-a252-e4b84bc2c24b@illuminatedcomputing.com> <69f0a887-a4ed-49cf-9d63-923891006658@illuminatedcomputing.com> <216627.1717791128@sss.pgh.pa.us> Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 08.06.24 06:14, jian he wrote: > if FK is nondeterministic, then it looks PK more like FK. > the following example, one FK row is referenced by two PK rows. > > DROP TABLE IF EXISTS fktable, pktable; > CREATE TABLE pktable (x text COLLATE "C" PRIMARY KEY); > CREATE TABLE fktable (x text COLLATE ignore_accent_case REFERENCES > pktable on update cascade on delete cascade); > INSERT INTO pktable VALUES ('A'), ('Å'); > INSERT INTO fktable VALUES ('A'); Yes, this is a problem. The RI checks are done with the collation of the primary key. The comment at ri_GenerateQualCollation() says "the SQL standard specifies that RI comparisons should use the referenced column's collation". But this is not what it says in my current copy. ... [ digs around ISO archives ] ... Yes, this was changed in SQL:2016 to require the collation on the PK side and the FK side to match at constraint creation time. The argument made is exactly the same we have here. This was actually already the rule in SQL:1999 but was then relaxed in SQL:2003 and then changed back because it was a mistake. We probably don't need to enforce this for deterministic collations, which would preserve some backward compatibility. I'll think some more about what steps to take to solve this and what to do about back branches etc.