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 1wB3hH-000hDe-14 for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Apr 2026 04:42:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wB3hF-009LT8-2A for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Apr 2026 04:42:22 +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 1wB3hF-009LSc-1F for pgsql-bugs@lists.postgresql.org; Fri, 10 Apr 2026 04:42:22 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wB3hE-00000000IMS-01Eg for pgsql-bugs@lists.postgresql.org; Fri, 10 Apr 2026 04:42:22 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-3590042fa8eso1310991a91.1 for ; Thu, 09 Apr 2026 21:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775796138; cv=none; d=google.com; s=arc-20240605; b=KmOtIoQHLNA2VPNl4ayjU/redEs/ADIRlxwgm/3hB+IvJ5ndp6RyfnHg3mc2WqFCXy ANVkXtFaUE22n68X7B+xx9TGrYM2qdenb79c/3OVLf34jBm8U4H6LJfmFBQIn7x+fNcJ cPqA0vqzmKomrCs4DiFHSEaxcJu8LAa9tTz1XBv2uh05bNS2xvgo5NbWz143SIlICAVa 6Jp4CM5/eIadmGHt9MkqXYUMVBUjDyqVOocpfwbSPg2RIdwYQWsj71m49gf/wpjuJn1b CB5kxe94TqiElQXnY40fsr5+RLlYGZgVq7/F5ebWc3w63qmuVGIogc16+P4LDtTjiOf+ D+kQ== 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=dyh4iwqsMbPBGrxpn0aav2T7NlX8KT3e1ulYv3vtSOc=; fh=oZC6lzdW0jPHgPbMyyCVRrM6NwKIx16CdAuSsHDzreg=; b=dvIMHjir1cD1joME9FAQsNJg7aE+JgYNEr1FbzZ6DADsrwLac7SWml5cnHAmzzp2o7 PNLMnAk/SApewfaQLF1XmU73gG1RQ/Nta9D2O4y+zd8Q98zPDjGw9HgyKwVVIsK3p8Sp oXExqPm0nwdH/sc7oidAU/ElbwxvF3y7xSWkptK5kqSKV9fYEt3d6oKF+6BCY0CKsD9Q rIKgRG7GYSDUVEvbA1nvfPyYHqOLeEY55gyF+Gd8CxTPqN/zGStIl2mB0DQtTsndVNCl XYwkcsOaAnvYpT3MuNKHEsnDxjgoI3cZZmUhZ5Q1K2+3Od/ZP+muH4wYRsyB8ilMmkt2 QaDA==; 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=1775796138; x=1776400938; 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=dyh4iwqsMbPBGrxpn0aav2T7NlX8KT3e1ulYv3vtSOc=; b=I1NkGr6YHR6vwQzwh4KpZCvQZ6B/6woV7ZLOqR13ZozAE/5EUHsdziGgKvgHFGVPGy kcNnaQdwzn7IcZegJvKbAQJHAkaBXEmOY1mQZ9rqsjvw3eNFAt/cDGvILeZf8LWK/Q8T vYq62aews4bht4l13NN3d9qsBXRiKurk5eTHt/3T/FbqdhkUpCumMm6gq62tNsTi1fJ+ 2USn0r1v1yfyAXN00hcHgdmKpBebh0tS7p6VG3HPOvvTEuApEGYOuj/mk9A3fzZ8k/OL sbYv0r6CnAzUb1LqqLKOyAWckBjOjik02INNqajOWPqur8su0WQHN7l0IrwUUcb4t+dy TZrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775796138; x=1776400938; 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=dyh4iwqsMbPBGrxpn0aav2T7NlX8KT3e1ulYv3vtSOc=; b=FC+opWHnyJM9uo7YyVeHu8+yN0AyTyS6qOoNrTyrfIqGXIxSjAp3jJFBnG14u9x9ON SviLA9xEbLvEt5v9JROGcWpTfOQPwny3QK4heyOsnKnIo96G+cKpVKBtuYyfApS7T8Ok y5Z+uPfUILGh5V/6ZSzEPXFn6EyjUDdORay0kGuE7+L5S5FL/qh9/3XGlBZppSOeFd/5 6+whY8EFEELufIuJCUJfGm57kxDVyW8Tb1JxvQF6ghchNmUDOZWoIEnJiBJQgpOwT/Le V0tonqiZJnoYs9hTJXY4TGAZMXV8rZ9G78lQl9mMHmVWUS6arhhCyxtH1oI2LBHuaFOY G1ZA== X-Forwarded-Encrypted: i=1; AJvYcCVpFVdHdT8d3gBlQ3Htfa/v1aeLGQ4ASNiMaGZK6Z5QksblCZ4MTDbdZH+0hEhGkUrmUg/QtOYOpfLh@lists.postgresql.org X-Gm-Message-State: AOJu0Yx41gKRiCjWXVBylzHosroSLdtjxST+XIhs+Umaul0rtrXh6ZgJ Xb0ZhoD7lF4U7P8XyKTDYUIy//vb4UaCYuIPhAVJ18RVKbvHfhIUV9qRVyPQeivbCPpCOxkESRY OQrYZ9ss2QOUFWFHunZT8mmHSSHttsmw= X-Gm-Gg: AeBDieuvIy+xxOI03/6RDMmhogHBck8ENbA2isVYABvHpUj+fruQs2SKLZFY9o4nfHh m2cTWpQtao81Qr4xYm1dnYHouzS/nllm/A9zEaJZJM9t8sgJhcqtXFgVJw3YwT/HKYe/1X/FJeQ GpX9yl39N2B3Yn7HDiP56l5cvQAPlmG87y6MrmDDYZMvxGyuXxHMiLbw5ca3NERIiE6CwO6Jueu 9S81JfWLMwD26zGT0P6qt00U0/6UEwHfMhoyAv3EBI6+fSVn9ny1qcJ58O/+EvMAS2bJdeLZBuD sdLH71AnTs4tyBY6U2i2WK5dpvhqwitWU9ncEC6jddYj8QNlSqLXa8FNesBw3+hL X-Received: by 2002:a17:90a:f945:b0:35d:9c32:6219 with SMTP id 98e67ed59e1d1-35e427d7f46mr1957804a91.9.1775796137726; Thu, 09 Apr 2026 21:42:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Langote Date: Fri, 10 Apr 2026 13:42:01 +0900 X-Gm-Features: AQROBzBMQqf-QGya2Tjlqk7dVpE7Vy2ZSC2gVFoFn6pJ_1h_czc42Vtw72D7rLg Message-ID: Subject: Re: BUG: PostgreSQL 19devel throws internal opfamily error for FK with reordered referenced columns To: Junwang Zhao Cc: Matheus Alcantara , Fredrik Widlert , pgsql-bugs@lists.postgresql.org 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 Fri, Apr 10, 2026 at 12:19=E2=80=AFPM Junwang Zhao w= rote: > 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, downlo= aded > > > on 2026-04-09 > > > from https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.= tar.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-loo= king > > > 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_nam= e) > > > ); > > > > > > 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, ct= ype) > > > references parent (app_id, report_id, otype, subtype, column_na= me, > > > ctype) > > > ); > > > > > > > > > -- trigger the problem > > > insert into child (app_id, report_id, otype, subtype, column_name, ct= ype) > > > 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. Thanks Junwang for checking. I've just pushed this: 980c1a85d819. Thanks Matheus again for the quick patch and Fredrik for the report. --=20 Thanks, Amit Langote