Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key

From: Jeff Frost <jeff(at)pgexperts(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key
Date: 2014-03-18 03:38:40
Message-ID: 5D7E698A-360C-491A-92C4-AB745A65D436@pgexperts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


On Mar 17, 2014, at 6:21 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Jeff Frost <jeff(at)pgexperts(dot)com> writes:
>> Interestingly, on 9.1.11, I have a table where the pkey was added after the fact, then dropped, but it still shows as relhaspkey even though I manually vacuumed it:
>
> IIRC, VACUUM only clears relhaspkey if there are *no* indexes left --- it
> doesn't bother to check whether there's one calling itself indisprimary.
> We could possibly change that but it's not clear that it's worth any
> effort, given that the column would still have to be defined the same
> way.
>

Yep, that appears to be the case:

pkey_test=# create table foo ( bar serial primary key, baz int);
NOTICE: CREATE TABLE will create implicit sequence "foo_bar_seq" for serial column "foo.bar"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
CREATE TABLE
pkey_test=# create index on foo(baz);
CREATE INDEX
pkey_test=# alter table foo drop constraint foo_pkey;
ALTER TABLE
pkey_test=# vacuum foo;
VACUUM
pkey_test=# select relname, relhaspkey FROM pg_class where relname = 'foo';
relname | relhaspkey
---------+------------
foo | t
(1 row)

pkey_test=# drop index foo_baz_idx ;
'DROP INDEX
pkey_test=# vacuum foo;
VACUUM
pkey_test=# select relname, relhaspkey FROM pg_class where relname = 'foo';
relname | relhaspkey
---------+------------
foo | f
(1 row)

And it's probably not worth the effort to change.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Venkata Balaji Nagothi 2014-03-18 03:47:34 Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key
Previous Message vwu98034 2014-03-18 03:18:40 BUG #9611: Current jdbc driver doesn't support any classes in Java 8 java.time