Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WPmNB-0002wq-QT for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Mar 2014 05:15:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WPmNA-0006bw-61 for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Mar 2014 05:15:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WPmN8-0006bn-7e for pgsql-bugs@postgresql.org; Tue, 18 Mar 2014 05:15:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WPmN0-0002lk-MA for pgsql-bugs@postgresql.org; Tue, 18 Mar 2014 05:15:29 +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 s2I5FKWf019934; Tue, 18 Mar 2014 01:15:20 -0400 From: Tom Lane To: David Johnston cc: pgsql-bugs@postgresql.org Subject: Re: Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key In-reply-to: <1395116664140-5796526.post@n5.nabble.com> References: <20140317185255.20724.49675@wrigleys.postgresql.org> <25726.1395082770@sss.pgh.pa.us> <7FBC4B95-6AF6-4CFC-A4E2-DE7D9C30AB4B@pgexperts.com> <14341.1395105679@sss.pgh.pa.us> <1395116664140-5796526.post@n5.nabble.com> Comments: In-reply-to David Johnston message dated "Mon, 17 Mar 2014 21:24:24 -0700" Date: Tue, 18 Mar 2014 01:15:20 -0400 Message-ID: <19933.1395119720@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 David Johnston writes: > As to Tom's "defined the same way" - does it truly mean "has index" or is it > "has unique index defined as primary"? I ask because depending on how the > data is being used it may be worth it to a caller to force the flag to be > the correct value to avoid subsequent checks. AFAIR, the backend does not use relhaspkey at all. (If it weren't for client-compatibility worries, we'd probably have removed the field altogether long ago.) We do use relhasindex to know whether it's worth looking in pg_index or not when collecting data about a table. Thus the definition that relhasindex *must* be true if there are indexes. If it's true when there are not indexes, though, we just waste one indexed search of pg_index which is not a big deal. I believe the killer reason why relhasindex is inaccurate in this way is that if we didn't define it like that, concurrent CREATE INDEXes on the same table couldn't work. The update that sets relhasindex true is nontransactional, meaning it won't roll back if an index creation fails; but that's needed to avoid having concurrent CREATE INDEXes block each other while trying to update the pg_class row. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs