mirror of https://github.com/postgres/postgres
As introduced bypull/177/headf9900df5f9
, a REINDEX CONCURRENTLY job done for an index with predicates or expressions would set PROC_IN_SAFE_IC in its MyProc->statusFlags, causing it to be ignored by other concurrent operations. Such concurrent index rebuilds should never be ignored, as a predicate or an expression could call a user-defined function that accesses a different table than the table where the index is rebuilt. A test that uses injection points is added, backpatched down to 17. Michail has proposed a different test, but I have added something simpler with more coverage. Oversight inf9900df5f9
. Author: Michail Nikolaev Discussion: https://postgr.es/m/CANtu0oj9A3kZVduFTG0vrmGnKB+DCHgEpzOp0qAyOgmks84j0w@mail.gmail.com Backpatch-through: 14
parent
dd8bea88ab
commit
5bbdfa8a18
@ -0,0 +1,51 @@ |
|||||||
|
-- Tests for REINDEX CONCURRENTLY |
||||||
|
CREATE EXTENSION injection_points; |
||||||
|
-- Check safety of indexes with predicates and expressions. |
||||||
|
SELECT injection_points_set_local(); |
||||||
|
injection_points_set_local |
||||||
|
---------------------------- |
||||||
|
|
||||||
|
(1 row) |
||||||
|
|
||||||
|
SELECT injection_points_attach('reindex-conc-index-safe', 'notice'); |
||||||
|
injection_points_attach |
||||||
|
------------------------- |
||||||
|
|
||||||
|
(1 row) |
||||||
|
|
||||||
|
SELECT injection_points_attach('reindex-conc-index-not-safe', 'notice'); |
||||||
|
injection_points_attach |
||||||
|
------------------------- |
||||||
|
|
||||||
|
(1 row) |
||||||
|
|
||||||
|
CREATE SCHEMA reindex_inj; |
||||||
|
CREATE TABLE reindex_inj.tbl(i int primary key, updated_at timestamp); |
||||||
|
CREATE UNIQUE INDEX ind_simple ON reindex_inj.tbl(i); |
||||||
|
CREATE UNIQUE INDEX ind_expr ON reindex_inj.tbl(ABS(i)); |
||||||
|
CREATE UNIQUE INDEX ind_pred ON reindex_inj.tbl(i) WHERE mod(i, 2) = 0; |
||||||
|
CREATE UNIQUE INDEX ind_expr_pred ON reindex_inj.tbl(abs(i)) WHERE mod(i, 2) = 0; |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_simple; |
||||||
|
NOTICE: notice triggered for injection point reindex-conc-index-safe |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_expr; |
||||||
|
NOTICE: notice triggered for injection point reindex-conc-index-not-safe |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_pred; |
||||||
|
NOTICE: notice triggered for injection point reindex-conc-index-not-safe |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_expr_pred; |
||||||
|
NOTICE: notice triggered for injection point reindex-conc-index-not-safe |
||||||
|
-- Cleanup |
||||||
|
SELECT injection_points_detach('reindex-conc-index-safe'); |
||||||
|
injection_points_detach |
||||||
|
------------------------- |
||||||
|
|
||||||
|
(1 row) |
||||||
|
|
||||||
|
SELECT injection_points_detach('reindex-conc-index-not-safe'); |
||||||
|
injection_points_detach |
||||||
|
------------------------- |
||||||
|
|
||||||
|
(1 row) |
||||||
|
|
||||||
|
DROP TABLE reindex_inj.tbl; |
||||||
|
DROP SCHEMA reindex_inj; |
||||||
|
DROP EXTENSION injection_points; |
@ -0,0 +1,28 @@ |
|||||||
|
-- Tests for REINDEX CONCURRENTLY |
||||||
|
CREATE EXTENSION injection_points; |
||||||
|
|
||||||
|
-- Check safety of indexes with predicates and expressions. |
||||||
|
SELECT injection_points_set_local(); |
||||||
|
SELECT injection_points_attach('reindex-conc-index-safe', 'notice'); |
||||||
|
SELECT injection_points_attach('reindex-conc-index-not-safe', 'notice'); |
||||||
|
|
||||||
|
CREATE SCHEMA reindex_inj; |
||||||
|
CREATE TABLE reindex_inj.tbl(i int primary key, updated_at timestamp); |
||||||
|
|
||||||
|
CREATE UNIQUE INDEX ind_simple ON reindex_inj.tbl(i); |
||||||
|
CREATE UNIQUE INDEX ind_expr ON reindex_inj.tbl(ABS(i)); |
||||||
|
CREATE UNIQUE INDEX ind_pred ON reindex_inj.tbl(i) WHERE mod(i, 2) = 0; |
||||||
|
CREATE UNIQUE INDEX ind_expr_pred ON reindex_inj.tbl(abs(i)) WHERE mod(i, 2) = 0; |
||||||
|
|
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_simple; |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_expr; |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_pred; |
||||||
|
REINDEX INDEX CONCURRENTLY reindex_inj.ind_expr_pred; |
||||||
|
|
||||||
|
-- Cleanup |
||||||
|
SELECT injection_points_detach('reindex-conc-index-safe'); |
||||||
|
SELECT injection_points_detach('reindex-conc-index-not-safe'); |
||||||
|
DROP TABLE reindex_inj.tbl; |
||||||
|
DROP SCHEMA reindex_inj; |
||||||
|
|
||||||
|
DROP EXTENSION injection_points; |
Loading…
Reference in new issue