Re: [HACKERS] pg_index updates and SI invalidation
"Pavan Deolasee" <[EMAIL PROTECTED]> 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 ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org
Re: [HACKERS] 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> http://momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [HACKERS] pg_index updates and SI invalidation
On 4/3/07, Bruce Momjian <[EMAIL PROTECTED]> 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 pg_index_SI_inval_v2.patch Description: Binary data ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [HACKERS] pg_index updates and SI invalidation
Where are we on this? --- Tom Lane wrote: > "Pavan Deolasee" <[EMAIL PROTECTED]> writes: > > On 3/28/07, Tom Lane <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> http://momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---(end of broadcast)--- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match
Re: [HACKERS] pg_index updates and SI invalidation
"Pavan Deolasee" <[EMAIL PROTECTED]> writes: > On 3/28/07, Tom Lane <[EMAIL PROTECTED]> 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
Re: [HACKERS] pg_index updates and SI invalidation
On 3/28/07, Tom Lane <[EMAIL PROTECTED]> 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: [HACKERS] pg_index updates and SI invalidation
"Pavan Deolasee" <[EMAIL PROTECTED]> 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 ---(end of broadcast)--- TIP 2: Don't 'kill -9' the postmaster
Re: [HACKERS] pg_index updates and SI invalidation
On 3/26/07, Tom Lane <[EMAIL PROTECTED]> 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 pg_index_SI_inval.patch Description: Binary data ---(end of broadcast)--- TIP 5: don't forget to increase your free space map settings
Re: [HACKERS] pg_index updates and SI invalidation
"Pavan Deolasee" <[EMAIL PROTECTED]> writes: > On 3/26/07, Tom Lane <[EMAIL PROTECTED]> 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 ---(end of broadcast)--- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly
Re: [HACKERS] pg_index updates and SI invalidation
On 3/26/07, Tom Lane <[EMAIL PROTECTED]> 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: [HACKERS] pg_index updates and SI invalidation
"Pavan Deolasee" <[EMAIL PROTECTED]> 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 ---(end of broadcast)--- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate
[HACKERS] pg_index updates and SI invalidation
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