Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3jsj-0008Sp-FN for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Apr 2017 13:54:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3jsj-0008Hy-1b for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Apr 2017 13:54:53 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3jsi-0008Hn-DL for pgsql-bugs@postgresql.org; Thu, 27 Apr 2017 13:54:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1d3jsf-0000qT-P8 for pgsql-bugs@postgresql.org; Thu, 27 Apr 2017 13:54:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v3RDslTx026799; Thu, 27 Apr 2017 09:54:47 -0400 From: Tom Lane To: Roy Brokvam cc: pgsql-bugs@postgresql.org Subject: Re: Meaning of pg_constraint.conindid for foreign keys In-reply-to: References: Comments: In-reply-to Roy Brokvam message dated "Thu, 27 Apr 2017 12:29:50 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26797.1493301287.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 27 Apr 2017 09:54:47 -0400 Message-ID: <26798.1493301287@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Roy Brokvam writes: > To my surprise, the query did not return any rows, even though I knew the= re > existed indexless foreign keys referencing my table. After investigating > further, saw that conindid contained the oid of the referenced table's > primary key, not the oid of the index "implementing" the foreign key. Not what I see here: regression=3D# create table foo1(f1 int primary key); CREATE TABLE regression=3D# create table foo2(f1 int); CREATE TABLE regression=3D# create unique index on foo2(f1); CREATE INDEX regression=3D# create table bar1 (f1 int references foo1(f1)); CREATE TABLE regression=3D# create table bar2 (f1 int references foo2(f1)); CREATE TABLE regression=3D# select oid,conname,contype,conrelid::regclass,conindid,conin= did::regclass,confrelid::regclass from pg_constraint order by oid desc limi= t 3; oid | conname | contype | conrelid | conindid | conindid | conf= relid=20 --------+--------------+---------+----------+----------+-------------+-----= ------ 232357 | bar2_f1_fkey | f | bar2 | 232353 | foo2_f1_idx | foo2 232345 | bar1_f1_fkey | f | bar1 | 232337 | foo1_pkey | foo1 232338 | foo1_pkey | p | foo1 | 232337 | foo1_pkey | - (3 rows) foo1's pkey constraint has OID 232338, its underlying index has OID 232337, and the latter is what's in conindid for bar1's foreign key constraint. It has to be that way because of the case illustrated by foo2/bar2, where an FK depends on an index that doesn't have a formal constraint associated with it. regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs