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 1sFnU2-0069fz-9Q for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Jun 2024 04:15:15 +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 1sFnTz-00FNEN-VD for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Jun 2024 04:15:12 +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 1sFnTz-00FNEE-LO for pgsql-hackers@lists.postgresql.org; Sat, 08 Jun 2024 04:15:12 +0000 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sFnTt-000G2E-R8 for pgsql-hackers@lists.postgresql.org; Sat, 08 Jun 2024 04:15:11 +0000 Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-4eb0ae42c7bso1438549e0c.1 for ; Fri, 07 Jun 2024 21:15:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717820104; x=1718424904; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=A0/+LVX0eo5TyWcQdM2ziNo7y+getklkzBk+D5s3MfA=; b=MbbH7SqgJBZuQPzfIGDElAGEtgzNvi4zZYnyW0tjcelpHRNctE0BzLdhYfnGfAXdzR bZ7XyIfVSEXWyTibqAYNbbivu8r2yWyHKXH9DkCVuksKEyneABSWIwWdrBHYksGNYb5M HZv6H6meMNm/jqN8dCh2B4IDcHg28roRUYEMrcU22WGLkg9ZmlDMwoxVGfMoTAmibHby O8ZuFcJxl1nKwq5uX/w4YWAg1VjOOYHwcMbNV5zFsQvh/Bac7FSrOPfFfA2Mhf4BaN0S Pd/d0jfqqmiwBpuCG7Sj77IuFjiZv8vPJmGp9xzQQ/sNW0JzwyRPrkRXXNLC53U1lOsM MtYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717820104; x=1718424904; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A0/+LVX0eo5TyWcQdM2ziNo7y+getklkzBk+D5s3MfA=; b=cYypECEfTo7Bc8544IjYjEp7GIaiJC32clrfD7ELThaYB5EPgNF0l4qoFtGE24nuG8 a03c4IvIoY7rtTCroR4OplKquicW427gBludMJ4jFLvXedPkelKOaWjzR70eLHLQQdXA bfwdS6OoWqXyBFyPs42C0Q4+y9yd5kCMMX5tCUj7APSRj+5Y6QZqA0Qiil/LAffZNGRk P1rrm8J6wnwmdS48/aCSnAWiqN99nH6+xEE2KhP1e8jrnli/yVkejHUrWuPzzmE+Lsjo 6XsBcoWiRWDZBENqWxZwILN8aBCFQAdp6KmZD9G+ye96e6EGk+gHF3FaiPYZHHyvO6VC Liow== X-Forwarded-Encrypted: i=1; AJvYcCXGYRge52onhlCQTOlEcUeSbC47wWI8Nb9MVUdJlhqrSLrO0sCFpPVUvZYDkEbi1oHKvHKHuLQ6Py0BnZiKqF0aiE10dQ6PaCA7bGJsupZVhyHA X-Gm-Message-State: AOJu0YzUO50XZV6LuyrYGI4JMcFBZ56BIzGVRxhteDt8NmgXHHogy3nu goI9FRzdGQ1t+VlOscVb6Bbb6N4DDV6pWMLhLrSSExke/7wU8HDwguZ/xvdI6fKruMzE60Z2TG+ oCHI4n9mT195QkempcWCkRGiqmss= X-Google-Smtp-Source: AGHT+IFdm/AJLwDwvexUkvC02iJxJQY9t3EqNQlfWZAOMiP83rXHQvEqaLKs+ZKK2UUFhte8OFIdncVwoi6ItbDtnj8= X-Received: by 2002:a05:6122:21a4:b0:4eb:5bd4:ddbe with SMTP id 71dfb90a1353d-4eb5bd4e0famr2793372e0c.6.1717820104220; Fri, 07 Jun 2024 21:15:04 -0700 (PDT) MIME-Version: 1.0 References: <78d824e0-b21e-480d-a252-e4b84bc2c24b@illuminatedcomputing.com> <69f0a887-a4ed-49cf-9d63-923891006658@illuminatedcomputing.com> <216627.1717791128@sss.pgh.pa.us> In-Reply-To: <216627.1717791128@sss.pgh.pa.us> From: jian he Date: Sat, 8 Jun 2024 12:14:53 +0800 Message-ID: Subject: Re: altering a column's collation leaves an invalid foreign key To: Tom Lane Cc: Paul Jungwirth , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Jun 8, 2024 at 4:12=E2=80=AFAM Tom Lane wrote: > > jian he writes: > >> * in TryReuseForeignKey, we can pass the information that our primary > >> key old collation is nondeterministic > >> and old collation !=3D new collation to the foreign key constraint. > > I have a basic question about this: why are we allowing FKs to be > based on nondeterministic collations at all? ISTM that that breaks > the assumption that there is exactly one referenced row for any > referencing row. > for FKs nondeterministic, I think that would require the PRIMARY KEY collation to not be indeterministic also. for example: CREATE COLLATION ignore_accent_case (provider =3D icu, deterministic =3D false, locale =3D 'und-u-ks-level1'); DROP TABLE IF EXISTS fktable, pktable; CREATE TABLE pktable (x text COLLATE ignore_accent_case PRIMARY KEY); CREATE TABLE fktable (x text REFERENCES pktable on update cascade on delete cascade); INSERT INTO pktable VALUES ('A'); INSERT INTO fktable VALUES ('a'); INSERT INTO fktable VALUES ('A'); update pktable set x =3D '=C3=85'; table fktable; 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'), ('=C3=85'); INSERT INTO fktable VALUES ('A'); begin; delete from pktable where x =3D '=C3=85'; TABLE fktable; rollback; begin; delete from pktable where x =3D 'A'; TABLE fktable; rollback;