mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Don't reset relhasindex for partitioned tables on ANALYZE
Commit 0e69f705cc
introduced code to analyze partitioned table;
however, that code fails to preserve pg_class.relhasindex correctly.
Fix by observing whether any indexes exist rather than accidentally
falling through to assuming none do.
Backpatch to 14.
Author: Alexander Pyhalov <a.pyhalov@postgrespro.ru>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Reviewed-by: Zhihong Yu <zyu@yugabyte.com>
Discussion: https://postgr.es/m/CALNJ-vS1R3Qoe5t4tbzxrkpBtzRbPq1dDcW4RmA_a+oqweF30w@mail.gmail.com
This commit is contained in:
@@ -199,6 +199,28 @@ VACUUM ANALYZE vacparted(a,b,a);
|
||||
ERROR: column "a" of relation "vacparted" appears more than once
|
||||
ANALYZE vacparted(a,b,b);
|
||||
ERROR: column "b" of relation "vacparted" appears more than once
|
||||
-- partitioned table with index
|
||||
CREATE TABLE vacparted_i (a int primary key, b varchar(100))
|
||||
PARTITION BY HASH (a);
|
||||
CREATE TABLE vacparted_i1 PARTITION OF vacparted_i
|
||||
FOR VALUES WITH (MODULUS 2, REMAINDER 0);
|
||||
CREATE TABLE vacparted_i2 PARTITION OF vacparted_i
|
||||
FOR VALUES WITH (MODULUS 2, REMAINDER 1);
|
||||
INSERT INTO vacparted_i SELECT i, 'test_'|| i from generate_series(1,10) i;
|
||||
VACUUM (ANALYZE) vacparted_i;
|
||||
VACUUM (FULL) vacparted_i;
|
||||
VACUUM (FREEZE) vacparted_i;
|
||||
SELECT relname, relhasindex FROM pg_class
|
||||
WHERE relname LIKE 'vacparted_i%' AND relkind IN ('p','r')
|
||||
ORDER BY relname;
|
||||
relname | relhasindex
|
||||
--------------+-------------
|
||||
vacparted_i | t
|
||||
vacparted_i1 | t
|
||||
vacparted_i2 | t
|
||||
(3 rows)
|
||||
|
||||
DROP TABLE vacparted_i;
|
||||
-- multiple tables specified
|
||||
VACUUM vaccluster, vactst;
|
||||
VACUUM vacparted, does_not_exist;
|
||||
|
@@ -170,6 +170,22 @@ VACUUM (FREEZE) vacparted;
|
||||
VACUUM ANALYZE vacparted(a,b,a);
|
||||
ANALYZE vacparted(a,b,b);
|
||||
|
||||
-- partitioned table with index
|
||||
CREATE TABLE vacparted_i (a int primary key, b varchar(100))
|
||||
PARTITION BY HASH (a);
|
||||
CREATE TABLE vacparted_i1 PARTITION OF vacparted_i
|
||||
FOR VALUES WITH (MODULUS 2, REMAINDER 0);
|
||||
CREATE TABLE vacparted_i2 PARTITION OF vacparted_i
|
||||
FOR VALUES WITH (MODULUS 2, REMAINDER 1);
|
||||
INSERT INTO vacparted_i SELECT i, 'test_'|| i from generate_series(1,10) i;
|
||||
VACUUM (ANALYZE) vacparted_i;
|
||||
VACUUM (FULL) vacparted_i;
|
||||
VACUUM (FREEZE) vacparted_i;
|
||||
SELECT relname, relhasindex FROM pg_class
|
||||
WHERE relname LIKE 'vacparted_i%' AND relkind IN ('p','r')
|
||||
ORDER BY relname;
|
||||
DROP TABLE vacparted_i;
|
||||
|
||||
-- multiple tables specified
|
||||
VACUUM vaccluster, vactst;
|
||||
VACUUM vacparted, does_not_exist;
|
||||
|
Reference in New Issue
Block a user