From 402afad6c124d2b74a5a82e36e017d2dedb0186d Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 9 Dec 2014 16:40:39 +0900 Subject: [PATCH] Fix a couple of bugs in REINDEX SCHEMA The following issues are fixed: - The key scan used was using a filter on relation relkind, but that's not actually necessary as a filter is applied when building the list of OIDs reindexed. - Regression test checking permission of reindexed schema was broken - Upgrade client_min_messages to 'warning' per complaints from jaragundi and leech as the table reindex ordering is not entirely guaranteed (we may as well here use a plpgsql function that does check if relfilenode has been changed for the reindexed relations. --- src/backend/commands/indexcmds.c | 8 ++------ src/test/regress/expected/create_index.out | 21 +++++++++------------ src/test/regress/sql/create_index.sql | 10 ++++++---- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index a3e8a15..9b07216 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1867,16 +1867,12 @@ ReindexObject(const char *objectName, ReindexObjectType objectKind) */ if (objectKind == REINDEX_OBJECT_SCHEMA) { - scan_keys = palloc(sizeof(ScanKeyData) * 2); + scan_keys = palloc(sizeof(ScanKeyData)); ScanKeyInit(&scan_keys[0], Anum_pg_class_relnamespace, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(objectOid)); - ScanKeyInit(&scan_keys[1], - Anum_pg_class_relkind, - BTEqualStrategyNumber, F_CHAREQ, - 'r'); - num_keys = 2; + num_keys = 1; } else num_keys = 0; diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out index ebac939..418b0ec 100644 --- a/src/test/regress/expected/create_index.out +++ b/src/test/regress/expected/create_index.out @@ -2834,31 +2834,28 @@ explain (costs off) -- -- REINDEX SCHEMA -- +SET client_min_messages TO 'warning'; REINDEX SCHEMA schema_to_reindex; -- failure, schema does not exist ERROR: schema "schema_to_reindex" does not exist CREATE SCHEMA schema_to_reindex; -CREATE TABLE schema_to_reindex.table1(col1 SERIAL PRIMARY KEY); -CREATE TABLE schema_to_reindex.table2(col1 SERIAL PRIMARY KEY, col2 VARCHAR(100) NOT NULL); -CREATE INDEX ON schema_to_reindex.table2(col2); +CREATE TABLE schema_to_reindex.table(col1 SERIAL PRIMARY KEY); +CREATE MATERIALIZED VIEW schema_to_reindex.matview AS SELECT col1 FROM schema_to_reindex.table; +CREATE INDEX ON schema_to_reindex.matview(col1); REINDEX SCHEMA schema_to_reindex; -NOTICE: table "schema_to_reindex.table1" was reindexed -NOTICE: table "schema_to_reindex.table2" was reindexed BEGIN; REINDEX SCHEMA schema_to_reindex; -- failure, cannot run in a transaction ERROR: REINDEX SCHEMA cannot run inside a transaction block END; +RESET client_min_messages; -- Failure for unauthorized user -CREATE ROLE reindexuser login; +CREATE ROLE user_reindex login; SET SESSION ROLE user_reindex; -ERROR: role "user_reindex" does not exist REINDEX SCHEMA schema_to_reindex; -NOTICE: table "schema_to_reindex.table1" was reindexed -NOTICE: table "schema_to_reindex.table2" was reindexed +ERROR: must be owner of schema schema_to_reindex -- Clean up RESET ROLE; DROP ROLE user_reindex; -ERROR: role "user_reindex" does not exist DROP SCHEMA schema_to_reindex CASCADE; NOTICE: drop cascades to 2 other objects -DETAIL: drop cascades to table schema_to_reindex.table1 -drop cascades to table schema_to_reindex.table2 +DETAIL: drop cascades to table schema_to_reindex."table" +drop cascades to materialized view schema_to_reindex.matview diff --git a/src/test/regress/sql/create_index.sql b/src/test/regress/sql/create_index.sql index 1cd57da..dd348b5 100644 --- a/src/test/regress/sql/create_index.sql +++ b/src/test/regress/sql/create_index.sql @@ -968,18 +968,20 @@ explain (costs off) -- -- REINDEX SCHEMA -- +SET client_min_messages TO 'warning'; REINDEX SCHEMA schema_to_reindex; -- failure, schema does not exist CREATE SCHEMA schema_to_reindex; -CREATE TABLE schema_to_reindex.table1(col1 SERIAL PRIMARY KEY); -CREATE TABLE schema_to_reindex.table2(col1 SERIAL PRIMARY KEY, col2 VARCHAR(100) NOT NULL); -CREATE INDEX ON schema_to_reindex.table2(col2); +CREATE TABLE schema_to_reindex.table(col1 SERIAL PRIMARY KEY); +CREATE MATERIALIZED VIEW schema_to_reindex.matview AS SELECT col1 FROM schema_to_reindex.table; +CREATE INDEX ON schema_to_reindex.matview(col1); REINDEX SCHEMA schema_to_reindex; BEGIN; REINDEX SCHEMA schema_to_reindex; -- failure, cannot run in a transaction END; +RESET client_min_messages; -- Failure for unauthorized user -CREATE ROLE reindexuser login; +CREATE ROLE user_reindex login; SET SESSION ROLE user_reindex; REINDEX SCHEMA schema_to_reindex; -- 2.2.0