Обсуждение: pg_index updates and SI invalidation

Поиск
Список
Период
Сортировка

pg_index updates and SI invalidation

От
"Pavan Deolasee"
Дата:
<br clear="all" /><br />While experimenting with the proposed CREATE INDEX support with<br />HOT, I realized that SI
invalidationare not sent properly for pg_index<br />updates.<br /><br />I noticed the following comment in relcache.c
<br/><br />/*<br /> * RelationReloadClassinfo - reload the pg_class row (only)<br /> *<br /> *  This function is used
onlyfor indexes.  We currently allow only the<br /> *  pg_class row of an existing index to change (to support changes
of<br /> *  owner, tablespace, or relfilenode), not its pg_index row or other<br /> *  subsidiary index schema
information. Therefore it's sufficient to do<br /> *  this when we get an SI invalidation.  Furthermore, there are
cases<br /> *  where it's necessary not to throw away the index information, especially<br /> *  for "nailed" indexes
whichwe are unable to rebuild on-the-fly.<br /> *<br /> *  We can't necessarily reread the pg_class row right away; we
mightbe <br /> *  in a failed transaction when we receive the SI notification.  If so,<br /> *  RelationClearRelation
justmarks the entry as invalid by setting<br /> *  rd_isvalid to false.  This routine is called to fix the entry when
it<br /> *  is next needed.<br /> */<br /><br />From the comment, its clear that we don't expect SI invalidation<br
/>towork correctly for pg_index row updates. We are thinking of<br />adding a new attribute to pg_index row to control
theusability of <br />the index in queries. Is it worth spending time to support SI<br />invalidation for pg_index
updatesor should we rather add the<br />attribute to pg_class though pg_index seems to the right place ?<br /><br />A
side-effectof this limitation is that REINDEX does not make <br />an index immediately available in the same
transactionif REINDEX<br />is used to fix an earlier failed CREATE INDEX CONCURRENTLY.<br />Though we set "indisvalid"
to'true' at the end of REINDEX, the<br /> effect is not seen until the transaction completes because of<br />lack of SI
invalidation.<br /><br />Any suggestions how should I proceed with this ? Should I add<br />a pg_class attribute or is
itworth fixing pg_index SI invalidation ? <br /><br />Thanks,<br />Pavan<br /><br />-- <br /><br />EnterpriseDB     <a
href="http://www.enterprisedb.com">http://www.enterprisedb.com</a>

Re: pg_index updates and SI invalidation

От
Tom Lane
Дата:
"Pavan Deolasee" <pavan.deolasee@gmail.com> writes:
> While experimenting with the proposed CREATE INDEX support with
> HOT, I realized that SI invalidation are not sent properly for pg_index
> updates.

Hmm ... actually, CREATE INDEX CONCURRENTLY gets this wrong already, no?
I suspect that sessions existing at the time C.I.C is done will never
see the new index as valid, unless something else happens to make them
drop and rebuild their relcache entries for it.
        regards, tom lane


Re: pg_index updates and SI invalidation

От
"Pavan Deolasee"
Дата:

On 3/26/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Hmm ... actually, CREATE INDEX CONCURRENTLY gets this wrong already, no?
I suspect that sessions existing at the time C.I.C is done will never
see the new index as valid, unless something else happens to make them
drop and rebuild their relcache entries for it.

 

Yes, C.I.C gets it wrong. I  confirmed that new index is seen as invalid
for existing sessions. Is it something we should fix ?

Thanks,
Pavan



--

EnterpriseDB     http://www.enterprisedb.com

Re: pg_index updates and SI invalidation

От
Tom Lane
Дата:
"Pavan Deolasee" <pavan.deolasee@gmail.com> writes:
> On 3/26/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Hmm ... actually, CREATE INDEX CONCURRENTLY gets this wrong already, no?

> Yes, C.I.C gets it wrong. I  confirmed that new index is seen as invalid
> for existing sessions. Is it something we should fix ?

Certainly.

It might be feasible to have RelationReloadClassinfo re-read the
pg_index row and apply only the updates for specific known-changeable
columns.  The stuff it's worried about is the subsidiary data such
as support function fmgr lookup records, but we don't need those to
change on the fly.
        regards, tom lane


Re: pg_index updates and SI invalidation

От
"Pavan Deolasee"
Дата:


On 3/26/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:


It might be feasible to have RelationReloadClassinfo re-read the
pg_index row and apply only the updates for specific known-changeable
columns.  The stuff it's worried about is the subsidiary data such
as support function fmgr lookup records, but we don't need those to
change on the fly.



Here is a patch  which fixes this. We re-read part of the pg_index
row and update rd_index with the new data. I tested REINDEX and CIC
and both seems to work fine with the patch applied.

Tom, does this look good ?

Thanks,
Pavan

--

EnterpriseDB     http://www.enterprisedb.com
Вложения

Re: pg_index updates and SI invalidation

От
Tom Lane
Дата:
"Pavan Deolasee" <pavan.deolasee@gmail.com> writes:
> Here is a patch  which fixes this. We re-read part of the pg_index
> row and update rd_index with the new data. I tested REINDEX and CIC
> and both seems to work fine with the patch applied.

> Tom, does this look good ?

It seems a bit brute-force.  Why didn't you use SearchSysCache(INDEXRELID)
the same as RelationInitIndexAccessInfo does?  And what's the point of
the extra tuple copy step, instead of assigning the values into the
cache entry immediately?
        regards, tom lane


Re: pg_index updates and SI invalidation

От
"Pavan Deolasee"
Дата:


On 3/28/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:


It seems a bit brute-force.  Why didn't you use SearchSysCache(INDEXRELID)
the same as RelationInitIndexAccessInfo does?


I tried that initially, but it gets into infinite recursion during initdb.
 

And what's the point of
the extra tuple copy step, instead of assigning the values into the
cache entry immediately?


Oops, sorry. Thats a copy-paste error. We certainly don't need
to copy the tuple.


Thanks,
Pavan

--

EnterpriseDB     http://www.enterprisedb.com

Re: pg_index updates and SI invalidation

От
Tom Lane
Дата:
"Pavan Deolasee" <pavan.deolasee@gmail.com> writes:
> On 3/28/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> It seems a bit brute-force.  Why didn't you use SearchSysCache(INDEXRELID)
>> the same as RelationInitIndexAccessInfo does?

> I tried that initially, but it gets into infinite recursion during initdb.

[squint...]  How can that fail during a reload if it worked the first
time?  Needs a closer look at what's happening.
        regards, tom lane


Re: pg_index updates and SI invalidation

От
Bruce Momjian
Дата:
Where are we on this?

---------------------------------------------------------------------------

Tom Lane wrote:
> "Pavan Deolasee" <pavan.deolasee@gmail.com> writes:
> > On 3/28/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> It seems a bit brute-force.  Why didn't you use SearchSysCache(INDEXRELID)
> >> the same as RelationInitIndexAccessInfo does?
> 
> > I tried that initially, but it gets into infinite recursion during initdb.
> 
> [squint...]  How can that fail during a reload if it worked the first
> time?  Needs a closer look at what's happening.
> 
>             regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faq

--  Bruce Momjian  <bruce@momjian.us>          http://momjian.us EnterpriseDB
http://www.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: pg_index updates and SI invalidation

От
"Pavan Deolasee"
Дата:

On 4/3/07, Bruce Momjian <bruce@momjian.us> wrote:

Where are we on this?

---------------------------------------------------------------------------

Tom Lane wrote:
>
> [squint...]  How can that fail during a reload if it worked the first
> time?  Needs a closer look at what's happening.
>

Please see the attached updated patch, based on Tom's comments.

Attempt to reload index information for system indexes such as
pg_class_oid_index can cause infinite recursion. But I realized that
we don't need to reload system index information because we
neither allow CREATE INDEX or CIC on system relations. Only
REINDEX is allowed which does not need any reload. So we skip
index information reload for system relations.

Thanks,
Pavan

--

EnterpriseDB     http://www.enterprisedb.com
Вложения

Re: pg_index updates and SI invalidation

От
Bruce Momjian
Дата:
Your patch has been added to the PostgreSQL unapplied patches list at:
http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

---------------------------------------------------------------------------


Pavan Deolasee wrote:
> On 4/3/07, Bruce Momjian <bruce@momjian.us> wrote:
> >
> >
> > Where are we on this?
> >
> >
> > ---------------------------------------------------------------------------
> >
> > Tom Lane wrote:
> > >
> > > [squint...]  How can that fail during a reload if it worked the first
> > > time?  Needs a closer look at what's happening.
> > >
> >
> 
> Please see the attached updated patch, based on Tom's comments.
> 
> Attempt to reload index information for system indexes such as
> pg_class_oid_index can cause infinite recursion. But I realized that
> we don't need to reload system index information because we
> neither allow CREATE INDEX or CIC on system relations. Only
> REINDEX is allowed which does not need any reload. So we skip
> index information reload for system relations.
> 
> Thanks,
> Pavan
> 
> -- 
> 
> EnterpriseDB     http://www.enterprisedb.com

[ Attachment, skipping... ]

--  Bruce Momjian  <bruce@momjian.us>          http://momjian.us EnterpriseDB
http://www.enterprisedb.com
 + If your life is a hard drive, Christ can be your backup. +


Re: pg_index updates and SI invalidation

От
Tom Lane
Дата:
"Pavan Deolasee" <pavan.deolasee@gmail.com> writes:
> Please see the attached updated patch, based on Tom's comments.

> Attempt to reload index information for system indexes such as
> pg_class_oid_index can cause infinite recursion. But I realized that
> we don't need to reload system index information because we
> neither allow CREATE INDEX or CIC on system relations. Only
> REINDEX is allowed which does not need any reload. So we skip
> index information reload for system relations.

Applied with revisions --- mostly, trying to keep the comments in sync
with the code.  I also added a forced relcache inval on the index's
parent table at the end of CREATE INDEX CONCURRENTLY; this is to flush
cached plans and allow the newly valid index to be considered in
replanning.  (The relcache inval on the index won't do it, since by
definition the index is not mentioned in any such plan...)
        regards, tom lane