diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-05-02 21:08:46 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-05-02 21:08:46 +0000 |
commit | 8ec943856a4e94637600fa7cad976281ca3f4071 (patch) | |
tree | c31da55ad5579f6cdf16128c7df4acd509d4978e /src/backend/commands/indexcmds.c | |
parent | 229d33801d9e31c6eda8e54bee23ed056fd2e257 (diff) | |
download | postgresql-8ec943856a4e94637600fa7cad976281ca3f4071.tar.gz postgresql-8ec943856a4e94637600fa7cad976281ca3f4071.zip |
Fix things so that when CREATE INDEX CONCURRENTLY sets pg_index.indisvalid
true at the very end of its processing, the update is broadcast via a
shared-cache-inval message for the index; without this, existing backends that
already have relcache entries for the index might never see it become valid.
Also, force a relcache inval on the index's parent table at the same time,
so that any cached plans for that table are re-planned; this ensures that
the newly valid index will be used if appropriate. Aside from making
C.I.C. behave more reasonably, this is necessary infrastructure for some
aspects of the HOT patch. Pavan Deolasee, with a little further stuff from
me.
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r-- | src/backend/commands/indexcmds.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index ba185431bec..18047a53889 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.157 2007/03/13 00:33:39 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.158 2007/05/02 21:08:45 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,6 +41,7 @@ #include "utils/acl.h" #include "utils/builtins.h" #include "utils/fmgroids.h" +#include "utils/inval.h" #include "utils/lsyscache.h" #include "utils/memutils.h" #include "utils/relcache.h" @@ -514,7 +515,9 @@ DefineIndex(RangeVar *heapRelation, for (ixcnt = 0; ixcnt < snapshot->xcnt; ixcnt++) XactLockTableWait(snapshot->xip[ixcnt]); - /* Index can now be marked valid -- update its pg_index entry */ + /* + * Index can now be marked valid -- update its pg_index entry + */ pg_index = heap_open(IndexRelationId, RowExclusiveLock); indexTuple = SearchSysCacheCopy(INDEXRELID, @@ -535,6 +538,15 @@ DefineIndex(RangeVar *heapRelation, heap_close(pg_index, RowExclusiveLock); /* + * The pg_index update will cause backends (including this one) to update + * relcache entries for the index itself, but we should also send a + * relcache inval on the parent table to force replanning of cached plans. + * Otherwise existing sessions might fail to use the new index where it + * would be useful. + */ + CacheInvalidateRelcacheByRelid(heaprelid.relId); + + /* * Last thing to do is release the session-level lock on the parent table. */ UnlockRelationIdForSession(&heaprelid, ShareUpdateExclusiveLock); |