mirror of https://github.com/postgres/postgres
This fixes two issues with the handling of VacuumParams in vacuum_rel(). This code path has the idea to change the passed-in pointer of VacuumParams for the "truncate" and "index_cleanup" options for the relation worked on, impacting the two following scenarios where incorrect options may be used because a VacuumParams pointer is shared across multiple relations: - Multiple relations in a single VACUUM command. - TOAST relations vacuumed with their main relation. The problem is avoided by providing to the two callers of vacuum_rel() copies of VacuumParams, before the pointer is updated for the "truncate" and "index_cleanup" options. The refactoring of the VACUUM option and parameters done inmaster0d83138974
did not introduce an issue, but it has encouraged the problem we are dealing with in this commit, withb84dbc8eb8
for "truncate" anda96c41feec
for "index_cleanup" that have been added a couple of years after the initial refactoring. HEAD will be improved with a different patch that hardens the uses of VacuumParams across the tree. This cannot be backpatched as it introduces an ABI breakage. The backend portion of the patch has been authored by Nathan, while I have implemented the tests. The tests rely on injection points to check the option values, making them faster, more reliable than the tests originally proposed by Shihao, and they also provide more coverage. This part can only be backpatched down to v17. Reported-by: Shihao Zhong <zhong950419@gmail.com> Author: Nathan Bossart <nathandbossart@gmail.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAGRkXqTo+aK=GTy5pSc-9cy8H2F2TJvcrZ-zXEiNJj93np1UUw@mail.gmail.com Backpatch-through: 13
parent
82015fd9bd
commit
661643deda
@ -0,0 +1,122 @@ |
||||
-- Tests for VACUUM |
||||
CREATE EXTENSION injection_points; |
||||
SELECT injection_points_set_local(); |
||||
injection_points_set_local |
||||
---------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_attach('vacuum-index-cleanup-auto', 'notice'); |
||||
injection_points_attach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_attach('vacuum-index-cleanup-disabled', 'notice'); |
||||
injection_points_attach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_attach('vacuum-index-cleanup-enabled', 'notice'); |
||||
injection_points_attach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_attach('vacuum-truncate-auto', 'notice'); |
||||
injection_points_attach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_attach('vacuum-truncate-disabled', 'notice'); |
||||
injection_points_attach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_attach('vacuum-truncate-enabled', 'notice'); |
||||
injection_points_attach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
-- Check state of index_cleanup and truncate in VACUUM. |
||||
CREATE TABLE vac_tab_on_toast_off(i int, j text) WITH |
||||
(autovacuum_enabled=false, |
||||
vacuum_index_cleanup=true, toast.vacuum_index_cleanup=false, |
||||
vacuum_truncate=true, toast.vacuum_truncate=false); |
||||
CREATE TABLE vac_tab_off_toast_on(i int, j text) WITH |
||||
(autovacuum_enabled=false, |
||||
vacuum_index_cleanup=false, toast.vacuum_index_cleanup=true, |
||||
vacuum_truncate=false, toast.vacuum_truncate=true); |
||||
-- Multiple relations should use their options in isolation. |
||||
VACUUM vac_tab_on_toast_off, vac_tab_off_toast_on; |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-enabled |
||||
NOTICE: notice triggered for injection point vacuum-truncate-enabled |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-disabled |
||||
NOTICE: notice triggered for injection point vacuum-truncate-disabled |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-disabled |
||||
NOTICE: notice triggered for injection point vacuum-truncate-disabled |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-enabled |
||||
NOTICE: notice triggered for injection point vacuum-truncate-enabled |
||||
-- Check "auto" case of index_cleanup and "truncate" controlled by |
||||
-- its GUC. |
||||
CREATE TABLE vac_tab_auto(i int, j text) WITH |
||||
(autovacuum_enabled=false, |
||||
vacuum_index_cleanup=auto, toast.vacuum_index_cleanup=auto); |
||||
SET vacuum_truncate = false; |
||||
VACUUM vac_tab_auto; |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-auto |
||||
NOTICE: notice triggered for injection point vacuum-truncate-disabled |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-auto |
||||
NOTICE: notice triggered for injection point vacuum-truncate-disabled |
||||
SET vacuum_truncate = true; |
||||
VACUUM vac_tab_auto; |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-auto |
||||
NOTICE: notice triggered for injection point vacuum-truncate-enabled |
||||
NOTICE: notice triggered for injection point vacuum-index-cleanup-auto |
||||
NOTICE: notice triggered for injection point vacuum-truncate-enabled |
||||
RESET vacuum_truncate; |
||||
DROP TABLE vac_tab_auto; |
||||
DROP TABLE vac_tab_on_toast_off; |
||||
DROP TABLE vac_tab_off_toast_on; |
||||
-- Cleanup |
||||
SELECT injection_points_detach('vacuum-index-cleanup-auto'); |
||||
injection_points_detach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_detach('vacuum-index-cleanup-disabled'); |
||||
injection_points_detach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_detach('vacuum-index-cleanup-enabled'); |
||||
injection_points_detach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_detach('vacuum-truncate-auto'); |
||||
injection_points_detach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_detach('vacuum-truncate-disabled'); |
||||
injection_points_detach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
SELECT injection_points_detach('vacuum-truncate-enabled'); |
||||
injection_points_detach |
||||
------------------------- |
||||
|
||||
(1 row) |
||||
|
||||
DROP EXTENSION injection_points; |
@ -0,0 +1,47 @@ |
||||
-- Tests for VACUUM |
||||
|
||||
CREATE EXTENSION injection_points; |
||||
|
||||
SELECT injection_points_set_local(); |
||||
SELECT injection_points_attach('vacuum-index-cleanup-auto', 'notice'); |
||||
SELECT injection_points_attach('vacuum-index-cleanup-disabled', 'notice'); |
||||
SELECT injection_points_attach('vacuum-index-cleanup-enabled', 'notice'); |
||||
SELECT injection_points_attach('vacuum-truncate-auto', 'notice'); |
||||
SELECT injection_points_attach('vacuum-truncate-disabled', 'notice'); |
||||
SELECT injection_points_attach('vacuum-truncate-enabled', 'notice'); |
||||
|
||||
-- Check state of index_cleanup and truncate in VACUUM. |
||||
CREATE TABLE vac_tab_on_toast_off(i int, j text) WITH |
||||
(autovacuum_enabled=false, |
||||
vacuum_index_cleanup=true, toast.vacuum_index_cleanup=false, |
||||
vacuum_truncate=true, toast.vacuum_truncate=false); |
||||
CREATE TABLE vac_tab_off_toast_on(i int, j text) WITH |
||||
(autovacuum_enabled=false, |
||||
vacuum_index_cleanup=false, toast.vacuum_index_cleanup=true, |
||||
vacuum_truncate=false, toast.vacuum_truncate=true); |
||||
-- Multiple relations should use their options in isolation. |
||||
VACUUM vac_tab_on_toast_off, vac_tab_off_toast_on; |
||||
|
||||
-- Check "auto" case of index_cleanup and "truncate" controlled by |
||||
-- its GUC. |
||||
CREATE TABLE vac_tab_auto(i int, j text) WITH |
||||
(autovacuum_enabled=false, |
||||
vacuum_index_cleanup=auto, toast.vacuum_index_cleanup=auto); |
||||
SET vacuum_truncate = false; |
||||
VACUUM vac_tab_auto; |
||||
SET vacuum_truncate = true; |
||||
VACUUM vac_tab_auto; |
||||
RESET vacuum_truncate; |
||||
|
||||
DROP TABLE vac_tab_auto; |
||||
DROP TABLE vac_tab_on_toast_off; |
||||
DROP TABLE vac_tab_off_toast_on; |
||||
|
||||
-- Cleanup |
||||
SELECT injection_points_detach('vacuum-index-cleanup-auto'); |
||||
SELECT injection_points_detach('vacuum-index-cleanup-disabled'); |
||||
SELECT injection_points_detach('vacuum-index-cleanup-enabled'); |
||||
SELECT injection_points_detach('vacuum-truncate-auto'); |
||||
SELECT injection_points_detach('vacuum-truncate-disabled'); |
||||
SELECT injection_points_detach('vacuum-truncate-enabled'); |
||||
DROP EXTENSION injection_points; |
Loading…
Reference in new issue