Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwWHh-0000mh-17 for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 17:35:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fwWHd-00076v-6b for pgsql-bugs@arkaria.postgresql.org; Sun, 02 Sep 2018 17:35:33 +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.89) (envelope-from ) id 1fwWHc-00075h-TA for pgsql-bugs@lists.postgresql.org; Sun, 02 Sep 2018 17:35:33 +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.89) (envelope-from ) id 1fwWHa-0004Q1-2v for pgsql-bugs@postgresql.org; Sun, 02 Sep 2018 17:35:31 +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 w82HZRLN011786; Sun, 2 Sep 2018 13:35:27 -0400 From: Tom Lane To: Alvaro Herrera cc: Andrew Gierth , =?iso-8859-1?Q?Andr=E9_H=E4nsel?= , pgsql-bugs@postgresql.org Subject: Re: Two constraints with the same name not always allowed In-reply-to: <20180902170511.ibjquzhymvnfvkqs@alvherre.pgsql> References: <20180902170511.ibjquzhymvnfvkqs@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Sun, 02 Sep 2018 14:05:11 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11784.1535909727.1@sss.pgh.pa.us> Date: Sun, 02 Sep 2018 13:35:27 -0400 Message-ID: <11785.1535909727@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2018-Sep-02, Tom Lane wrote: >> This also points up the lack of a suitable unique index on pg_constraint. >> It's sort of difficult to figure out what that should look like given that >> pg_constraint contains two quasi-independent collections of constraints, >> but maybe UNIQUE(conrelid,contypid,conname) would serve given the >> reasonable assumption that exactly one of conrelid and contypid is zero. > Hmm ... c.f. 7eca575d1c28. Maybe we should split them out? Are there > reasons to have them together at all? Yeah, I've occasionally thought about replacing pg_constraint with two separate catalogs; we could keep pg_constraint as a union view to avoid breaking clients that look at it. But that'd be kind of a large project, whereas adjusting the set of indexes for a catalog is a pretty simple finger exercise in most cases. (It's also unclear how smart the planner would be about optimizing queries on such a view.) Thinking about the planner angle some more, it seems like probably the most reasonable proposal is to add UNIQUE(conrelid,contypid,conname) replacing pg_constraint_conrelid_index, but keep pg_constraint_contypid_index. While we could teach relevant parts of backend/catalog how to use such a unique index to search for the constraints of a domain, the planner would not know how to optimize SQL queries with "WHERE contypid = xxx" unless we keep that index. It would figure out that "WHERE conrelid = xxx" works with the unique index, though. regards, tom lane