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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key
Дата
Msg-id 19933.1395119720@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key  (David Johnston <polobo@yahoo.com>)
Список pgsql-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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: David Johnston
Дата:
Сообщение: Re: BUG #9606: pg_class relhaspkey column not updated on removal of primary key
Следующее
От: jesse.denardo@myfarms.com
Дата:
Сообщение: BUG #9616: Materialized view with indexes unable to load from pg_dump