pg_index updates and SI invalidation

Started by Pavan Deolaseeabout 19 years ago12 messageshackers
Jump to latest
#1Pavan Deolasee
pavan.deolasee@gmail.com

While experimenting with the proposed CREATE INDEX support with
HOT, I realized that SI invalidation are not sent properly for pg_index
updates.

I noticed the following comment in relcache.c

/*
* RelationReloadClassinfo - reload the pg_class row (only)
*
* This function is used only for indexes. We currently allow only the
* pg_class row of an existing index to change (to support changes of
* owner, tablespace, or relfilenode), not its pg_index row or other
* subsidiary index schema information. Therefore it's sufficient to do
* this when we get an SI invalidation. Furthermore, there are cases
* where it's necessary not to throw away the index information, especially
* for "nailed" indexes which we are unable to rebuild on-the-fly.
*
* We can't necessarily reread the pg_class row right away; we might be
* in a failed transaction when we receive the SI notification. If so,
* RelationClearRelation just marks the entry as invalid by setting
* rd_isvalid to false. This routine is called to fix the entry when it
* is next needed.
*/

From the comment, its clear that we don't expect SI invalidation
to work correctly for pg_index row updates. We are thinking of
adding a new attribute to pg_index row to control the usability of
the index in queries. Is it worth spending time to support SI
invalidation for pg_index updates or should we rather add the
attribute to pg_class though pg_index seems to the right place ?

A side-effect of this limitation is that REINDEX does not make
an index immediately available in the same transaction if REINDEX
is used to fix an earlier failed CREATE INDEX CONCURRENTLY.
Though we set "indisvalid" to 'true' at the end of REINDEX, the
effect is not seen until the transaction completes because of
lack of SI invalidation.

Any suggestions how should I proceed with this ? Should I add
a pg_class attribute or is it worth fixing pg_index SI invalidation ?

Thanks,
Pavan

--

EnterpriseDB http://www.enterprisedb.com

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavan Deolasee (#1)
Re: pg_index updates and SI invalidation

"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

#3Pavan Deolasee
pavan.deolasee@gmail.com
In reply to: Tom Lane (#2)
Re: pg_index updates and SI invalidation

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

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavan Deolasee (#3)
Re: pg_index updates and SI invalidation

"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

#5Pavan Deolasee
pavan.deolasee@gmail.com
In reply to: Tom Lane (#4)
Re: pg_index updates and SI invalidation

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

Attachments:

pg_index_SI_inval.patchapplication/octet-stream; name=pg_index_SI_inval.patchDownload+89-14
#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavan Deolasee (#5)
Re: pg_index updates and SI invalidation

"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

#7Pavan Deolasee
pavan.deolasee@gmail.com
In reply to: Tom Lane (#6)
Re: pg_index updates and SI invalidation

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

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavan Deolasee (#7)
Re: pg_index updates and SI invalidation

"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

#9Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#8)
Re: pg_index updates and SI invalidation

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. +

#10Pavan Deolasee
pavan.deolasee@gmail.com
In reply to: Bruce Momjian (#9)
Re: pg_index updates and SI invalidation

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

Attachments:

pg_index_SI_inval_v2.patchapplication/octet-stream; name=pg_index_SI_inval_v2.patchDownload+63-14
#11Bruce Momjian
bruce@momjian.us
In reply to: Pavan Deolasee (#10)
Re: pg_index updates and SI invalidation

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. +

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavan Deolasee (#10)
Re: pg_index updates and SI invalidation

"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