pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix "ANALYZE t, t" inside a transaction block.
3+ messages / 1 participants
[nested] [flat]

* pgsql: Fix "ANALYZE t, t" inside a transaction block.
@ 2019-08-10 15:30 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2019-08-10 15:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix "ANALYZE t, t" inside a transaction block.

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 11d8d72c2 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 23224563d;
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cabe0f298ea7efade11d8171c617e668934d0d09

Modified Files
--------------
src/backend/commands/vacuum.c        | 9 +++++++++
src/test/regress/expected/vacuum.out | 4 ++++
src/test/regress/sql/vacuum.sql      | 4 ++++
3 files changed, 17 insertions(+)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix "ANALYZE t, t" inside a transaction block.
@ 2019-08-10 15:30 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2019-08-10 15:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix "ANALYZE t, t" inside a transaction block.

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 11d8d72c2 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 23224563d;
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

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6ce0366be2a3f92a46202acaba40be3aa72fa073

Modified Files
--------------
src/backend/commands/vacuum.c        | 9 +++++++++
src/test/regress/expected/vacuum.out | 4 ++++
src/test/regress/sql/vacuum.sql      | 4 ++++
3 files changed, 17 insertions(+)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix "ANALYZE t, t" inside a transaction block.
@ 2019-08-10 15:30 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2019-08-10 15:30 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix "ANALYZE t, t" inside a transaction block.

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 11d8d72c2 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 23224563d;
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

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ceb850d4a30c06f2f127487acd898847b80dcfc5

Modified Files
--------------
src/backend/commands/vacuum.c        |  9 +++++++++
src/test/regress/expected/vacuum.out | 16 ++++++++++++++++
src/test/regress/sql/vacuum.sql      | 17 +++++++++++++++++
3 files changed, 42 insertions(+)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-08-10 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-10 15:30 pgsql: Fix "ANALYZE t, t" inside a transaction block. Tom Lane <tgl@sss.pgh.pa.us>
2019-08-10 15:30 pgsql: Fix "ANALYZE t, t" inside a transaction block. Tom Lane <tgl@sss.pgh.pa.us>
2019-08-10 15:30 pgsql: Fix "ANALYZE t, t" inside a transaction block. Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox