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 1wB2Oy-000g0t-0P for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Apr 2026 03:19:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wB2Ou-008wY4-2x for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Apr 2026 03:19:21 +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.96) (envelope-from ) id 1wB2Ou-008wXu-1t for pgsql-bugs@lists.postgresql.org; Fri, 10 Apr 2026 03:19:21 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wB2Ot-00000000Hkw-0N8G for pgsql-bugs@lists.postgresql.org; Fri, 10 Apr 2026 03:19:21 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-b9bfcbaa81eso251636666b.1 for ; Thu, 09 Apr 2026 20:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775791156; cv=none; d=google.com; s=arc-20240605; b=DBeRlbkiBCoYEO9Cbli8KBPAkHZbHeu6+zIEYC17QYpKmyuOK+t+fXkpcK+TAPO6lg 8Vj2sN53XXHNatnCoH0q5CAd8FNVnX34eXcOHJJNVrOg7f+gTqiWDZxvQ7Dd+SdLPLYh 2XLCyL7Ku/3Dj9ckXsJwDpPPRWCKQoOtPEjzyQYvW31shERaPjx0wXBR+xFDP02pckNs A25pxuoI1ohhUlggJ2XCLPC+adqGiKPS42zark0xVcwxyLWBVl2SXjBs3VcNu5cWRAiv Ibc+EB0ck4MLwfQvxRNh9LSpAdAfQUH7+zLuMfeOyFFw8yjx91b7xSFqlr2leGVpl4RL DAaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7dnuH/BSOB6UI2uBA2Jnpkl+jqq4Ds5mc6Px81jJi0M=; fh=1G9pQIVqzKXjCxXx78fNJsDzQvs3WN6bzaC7dYqI/z8=; b=RS0p4LlkoucKkVYegQrmJxVJl62nW1LZ3palDo410UMFKmOifhIdz4gsPmS7ZU+BDA 1nLqDLYd13JhEcg2aD/S8gu4M8utEOtJyVly7+wK0HsoNkIGxyJr1teL0N69kUV7ek++ ZkjCPWQV1lCkKoLYvjNGNly10KrI04800Kb1SKpzhFSE9qfMBqZ4zgoIFSlJ+vCxue2B 0MRYmc2Nf3ezFnjPrAvHfF7WexvoTQPyTrp9xC/qoyasxe/923U9hdueN/nNvf68ezUs sBC8DwEtVzrdtNUwyVpM7lc/p5NrlD/bQ1ldGxBklV04id4HEgyJ3H+8XPLMqpIS8sSo nJbA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775791156; x=1776395956; 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=7dnuH/BSOB6UI2uBA2Jnpkl+jqq4Ds5mc6Px81jJi0M=; b=j35ihbwW4gzpaes/v6q8AmTjKwHZfQZkkluIC5tzT4Au4AQZwPpXHXkZSrhnSJ3HLf OVfVIPapXSGFgxgDTR5tGRfKXLbPTv6AqgVkyQoYZCMFUkClCVU4HeKjCNkAnzCdUEdr ndHRuMbgRaBWcK3doRyPUFYAb0fSmKFfzLkzX6Zh1X8zF5V9gVzN+zfX4vsEF0RlDfEq /H2RBn0BVcfKPhLASo3ND6WxeS+nn05dkeDxd1A2y/gfRuZwUq7dzY6n1cy0y8DQblPy 5mw3kL/Ou9UXzxN8+dp/d7PKf9SDJr61DhS+n2fwUuMRxtHL3tLyWszNHXec5L2eGufy 1Cxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775791156; x=1776395956; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7dnuH/BSOB6UI2uBA2Jnpkl+jqq4Ds5mc6Px81jJi0M=; b=mZCS3F86FLxkCGc+0FBtI3yv+t0uCfIX0m2pNMY83upcPh2ErQBuUfF2EWMe8L5D4z YjH2Zx8lKJspoT59nu78YfVOPMrmKsLML4p1NYQHYGlersdziNeWgitgm/RMN1r30eeS MIwVw1S3/zRmJTZFnZarNjJceNo+G6E5W5xfMVbsMhUEh7PoVBvj16qitu0x8SOZthTH myLWjdgOSYWjNyNeiE9o7pIyN+b1z9YUGcTA/5cB2S8QvcS0iZVSqc38ftYzxF56HVKn UQzr6Gs90WwI1BaD4j6cZo192mCAL8erdgoy5oyWkGfe0YonzqUKd/NCTU80EtGkM0al bRWg== X-Forwarded-Encrypted: i=1; AJvYcCUfGHz4qiqosZQolBJHDeikeVzoNXMVwyw84Qsh4siM3dgnOqETb9bIt53Omd9aR3Z2SY8V1rTWXH49@lists.postgresql.org X-Gm-Message-State: AOJu0YxmVlafYHOiwOCyem4a92z9eu+Rx0UUpngB7UlJKSx82R0MYw8U 3JhOLuGqL/KNKRclO4l95x8nltihOr8hhmwK7VJQJHKcCklfyVQyGC7UcooJHUEcWk5Tg0ek+mc dv7Txh8ubU7zodwjOH6u5yi6q3D7FFoE= X-Gm-Gg: AeBDievZa6GrtNkFQjpVy+r6Fba6oAA6Br5k6LJriJi5rWjNK2yWkXvhz+UntKRKnZm ZdJQeihV2Vcg3UPzCdfPko0OSIRWdCLA+9K3V9vdXhnZMz/mfS9jKLRJSBkYfHnIO3sD2l3tJar PE6F+vqWUWnM6cXeV2tXRTzhjk1mgxJn9bbaqetvy8MBU8e1xVFnm3DSPJrR+7J4wS5khJ5gSve bjIPVlIaCXsov5oUMOf2c1ZIrj7EnW56xlIwZt3BGDl3s/TJ+coB7U5ITlGcKMtp/jpEW3eyvTi ZOFx1OGk6rokkhpc8dXU3HpYl1WY9lhfCGtszjGykDiwB0vXAWMzIrqEIvjukL3TgCPrfWAaBEP RVhdl X-Received: by 2002:a17:906:518a:10b0:b96:e11e:97c4 with SMTP id a640c23a62f3a-b9d72793974mr58576866b.20.1775791155817; Thu, 09 Apr 2026 20:19:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Junwang Zhao Date: Fri, 10 Apr 2026 11:19:02 +0800 X-Gm-Features: AQROBzBprmwWLTNCUTXiGOpfg_vm76U9NGK4_dn91vgvaUFSH_aBjVawLoLAO6M Message-ID: Subject: Re: BUG: PostgreSQL 19devel throws internal opfamily error for FK with reordered referenced columns To: Matheus Alcantara Cc: Fredrik Widlert , pgsql-bugs@lists.postgresql.org, Amit Langote 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 Hi Matheus, On Fri, Apr 10, 2026 at 2:13=E2=80=AFAM Matheus Alcantara wrote: > > On Thu Apr 9, 2026 at 12:27 PM -03, Fredrik Widlert wrote: > > Hello, > > > > I believe I may have found a regression in PostgreSQL 19devel, download= ed > > on 2026-04-09 > > from https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.ta= r.gz. > > > > postgres=3D# select version(); > > version > > -----------------------------------------------------------------------= ------------------------------ > > PostgreSQL 19devel on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu > > 13.2.0-23ubuntu4) 13.2.0, 64-bit > > > > > > With the reproducer below, PostgreSQL 18 reports a normal foreign-key > > violation > > at INSERT time, but PostgreSQL 19devel instead throws an internal-looki= ng > > error: > > > > ERROR: operator 98 is not a member of opfamily 1976 > > > > > > > > -- reproducer: > > drop table if exists parent, child; > > > > create table parent ( > > app_id varchar(256) not null, > > report_id smallint not null, > > otype integer not null, > > subtype integer not null, > > ctype integer not null, > > column_name varchar(30) not null, > > primary key (app_id, report_id, otype, subtype, ctype, column_name) > > ); > > > > create table child ( > > app_id varchar(256) not null, > > report_id smallint not null, > > otype integer not null, > > subtype integer not null, > > column_name varchar(30) not null, > > ctype integer, > > -- intentionally swapped: column_name, ctype > > constraint child_fk > > foreign key (app_id, report_id, otype, subtype, column_name, ctyp= e) > > references parent (app_id, report_id, otype, subtype, column_name= , > > ctype) > > ); > > > > > > -- trigger the problem > > insert into child (app_id, report_id, otype, subtype, column_name, ctyp= e) > > values ('DEFAULT_APP', 0, -1, -1, 'ID', -1); > > > > Hi, thanks for reporting the issue. > > This seems to be related to commit 2da86c1ef9b. The issue is that in > ri_populate_fastpath_metadata, the code uses idx_rel->rd_opfamily[i] > where i is the constraint key position, but it should find the actual > index column position for pk_attnums[i]. When FK columns are in a > different order than PK columns, the constraint key position doesn't > match the index column position. Yeah, I can reproduce the issue with a simplified version, that the FK/PK columns are in different order: drop table if exists parent, child; create table parent ( app_id varchar(256) not null, report_id smallint not null, primary key (app_id, report_id) ); create table child ( app_id varchar(256) not null, report_id smallint not null, constraint child_fk foreign key (report_id, app_id) references parent (report_id, app_id) ); insert into child (app_id, report_id) values ('DEFAULT_APP', 0); > > I didn't participate in the discussion of the feature but I studied the > code a little bit after it was committed, so I'm taking a try to fix > this issue with the attached patch, which seems to work for this case. It appears we overlooked this specific case while working on the feature. Your analysis looks correct to me, and I've tested the patch it behaves as expected. The test case you added should effectively guard against this bug. > > CC Junwang Zhao and Amit Langote since they are involved in the original > commit. > > -- > Matheus Alcantara > EDB: https://www.enterprisedb.com --=20 Regards Junwang Zhao