Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbCdG-0005qA-Q5 for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Feb 2017 20:44:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cbCdG-0007Wv-77 for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Feb 2017 20:44:58 +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 1cbCca-0006nX-RI for pgsql-bugs@postgresql.org; Tue, 07 Feb 2017 20:44:16 +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 1cbCcU-0002nB-3i for pgsql-bugs@postgresql.org; Tue, 07 Feb 2017 20:44:15 +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 v17Ki7Nt022107; Tue, 7 Feb 2017 15:44:07 -0500 From: Tom Lane To: Tiago Babo cc: Peter Geoghegan , pgsql-bugs@postgresql.org Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT In-reply-to: <499844AD-291B-40F5-9892-E5591736FD2E@gmail.com> References: <20170202140701.1401.31196@wrigleys.postgresql.org> <166D0A9D-162D-4216-9490-3163533166C1@gmail.com> <14575.1486493671@sss.pgh.pa.us> <499844AD-291B-40F5-9892-E5591736FD2E@gmail.com> Comments: In-reply-to Tiago Babo message dated "Tue, 07 Feb 2017 19:33:59 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <22105.1486500247.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 07 Feb 2017 15:44:07 -0500 Message-ID: <22106.1486500247@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 Tiago Babo writes: > Ups, I used the wrong database. I was experimenting with it a bit and did= n=E2=80=99t noticed I was copying from the wrong one. Where is the correct = version (and the one that is giving me those =E2=80=9Crandom=E2=80=9D error= s): > Indexes: > "accounts_pkey" PRIMARY KEY, btree (id) > "index_accounts_on_type_and_identifier" UNIQUE, btree (type, identifi= er) > "uniq_bank_accounts" UNIQUE, btree (type, identifier) WHERE type::tex= t =3D 'BankAccount'::text > "uniq_business_accounts" UNIQUE, btree (type, business_id) WHERE type= ::text =3D 'BusinessAccount'::text > "uniq_person_accounts" UNIQUE, btree (type, person_id) WHERE type::te= xt =3D 'PersonAccount'::text > "index_accounts_on_business_id" btree (business_id) > "index_accounts_on_person_id" btree (person_id) Hm. I looked at infer_arbiter_indexes, which is the place where this particular error is thrown, and realized that my previous assertion was wrong: it *does* try to prove applicability of partial indexes based on the ON CONFLICT WHERE clause. So actually it should be deciding that uniq_person_accounts is a usable unique index --- at least, if you always have "WHERE type =3D 'PersonAccount'" in the ON CONFLICT clause. Maybe you're sometimes leaving that out? (BTW, I would say that uniq_bank_accounts is absolutely not worth its keep given that you have a non-partial unique index on the same two columns. But that seems not very relevant to the current complaint.) 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