• Tom Lane's avatar
    Fix "ANALYZE t, t" inside a transaction block. · cabe0f29
    Tom Lane authored
    This failed with either "tuple already updated by self" or "duplicate
    key value violates unique constraint", depending on whether the table
    had previously been analyzed or not.  The reason is that ANALYZE tried
    to insert or update the same pg_statistic rows twice, and there was no
    CommandCounterIncrement between.  So add one.  The same case works fine
    outside a transaction block, because then there's a whole transaction
    boundary between, as a consequence of the way VACUUM works.
    
    This issue has been latent all along, but the problem was unreachable
    before commit 11d8d72c added the ability to specify multiple tables
    in ANALYZE.  We could, perhaps, alternatively fix it by adding code to
    de-duplicate the list of VacuumRelations --- but that would add a
    lot of overhead to work around dumb commands, so it's not attractive.
    
    Per bug #15946 from Yaroslav Schekin.  Back-patch to v11.
    
    (Note: in v11 I also back-patched the test added by commit 23224563;
    otherwise the problem doesn't manifest in the test I added, because
    "vactst" is empty when the tests for multiple ANALYZE targets are
    reached.  That seems like not a very good thing anyway, so I did this
    rather than rethinking the choice of test case.)
    
    Discussion: https://postgr.es/m/15946-5c7570a2884a26cf@postgresql.org
    cabe0f29
vacuum.out 14.1 KB