pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Johnston <polobo@yahoo.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key
Date: Tue, 18 Mar 2014 01:15:20 -0400
Message-ID: <19933.1395119720@sss.pgh.pa.us> (raw)
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>
	<D0A66CF0-AD34-4647-9C05-1317ECFB97DC@pgexperts.com>
	<14341.1395105679@sss.pgh.pa.us>
	<CAHBAh5sd9BK=7qfjTDYBLSAtBh78rtnMSaGFoyfOb2S29FDxoQ@mail.gmail.com>
	<1395116664140-5796526.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

David Johnston <polobo@yahoo.com> 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



view thread (9+ messages)

Message-ID: <19933.1395119720@sss.pgh.pa.us>
Permalink:  ../19933.1395119720@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19933.1395119720@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, polobo@yahoo.com
  Subject: Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key
  In-Reply-To: <19933.1395119720@sss.pgh.pa.us>
  References: <20140317185255.20724.49675@wrigleys.postgresql.org> <25726.1395082770@sss.pgh.pa.us> <7FBC4B95-6AF6-4CFC-A4E2-DE7D9C30AB4B@pgexperts.com> <D0A66CF0-AD34-4647-9C05-1317ECFB97DC@pgexperts.com> <14341.1395105679@sss.pgh.pa.us> <CAHBAh5sd9BK=7qfjTDYBLSAtBh78rtnMSaGFoyfOb2S29FDxoQ@mail.gmail.com> <1395116664140-5796526.post@n5.nabble.com> <19933.1395119720@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox