]> granicus.if.org Git - postgresql/commitdiff
Add table relcache invalidation to index builds.
authorPeter Geoghegan <pg@bowt.ie>
Fri, 3 Aug 2018 21:45:11 +0000 (14:45 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Fri, 3 Aug 2018 22:11:31 +0000 (15:11 -0700)
It's necessary to make sure that owning tables have a relcache
invalidation prior to advancing the command counter to make
newly-entered catalog tuples for the index visible.  inval.c must be
able to maintain the consistency of the local caches in the event of
transaction abort.  There is usually only a problem when CREATE INDEX
transactions abort, since there is a generic invalidation once we reach
index_update_stats().

This bug is of long standing.  Problems were made much more likely by
the addition of parallel CREATE INDEX (commit 9da0cc35284), but it is
strongly suspected that similar problems can be triggered without
involving plan_create_index_workers().  (plan_create_index_workers()
triggers a relcache build or rebuild, which previously only happened in
rare edge cases.)

Author: Peter Geoghegan
Reported-By: Luca Ferrari
Diagnosed-By: Andres Freund
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAKoxK+5fVodiCtMsXKV_1YAKXbzwSfp7DgDqUmcUAzeAhf=HEQ@mail.gmail.com
Backpatch: 9.3-

src/backend/catalog/index.c

index 8b276bc430f16d691192b6f83abb80e7fc5b4723..2dad7b059e9fec1ec1a1fb2fa0218ae3a9d41d95 100644 (file)
@@ -978,6 +978,12 @@ index_create(Relation heapRelation,
                                                !concurrent && !invalid,
                                                !concurrent);
 
+       /*
+        * Register relcache invalidation on the indexes' heap relation, to
+        * maintain consistency of its index list
+        */
+       CacheInvalidateRelcache(heapRelation);
+
        /* update pg_inherits, if needed */
        if (OidIsValid(parentIndexRelid))
                StoreSingleInheritance(indexRelationId, parentIndexRelid, 1);