From 07cd2d2cdf99a1b9cece7539ad883d3cdae7cdc4 Mon Sep 17 00:00:00 2001 From: Shibagaki Koshi Date: Tue, 13 Oct 2026 22:04:55 +0900 Subject: [PATCH v1] reindexdb: Fix schema name lookup in parallel mode Parallel schema reindexing compares command-line arguments directly with pg_namespace.nspname, whereas serial mode passes them to REINDEX SCHEMA. Quoted and unquoted mixed-case names can therefore be interpreted differently, and missing schemas are silently ignored in parallel mode. Resolve schema arguments through regnamespace and filter by namespace OID, as vacuumdb does. Keep existing empty schemas successful. Extend the existing parallel schema test for case folding and add tests for quoted names and a missing schema alongside an empty schema. --- src/bin/scripts/reindexdb.c | 9 ++++++++- src/bin/scripts/t/090_reindexdb.pl | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 843cc502f6..d37f8906b3 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -681,14 +681,21 @@ get_parallel_tables_list(PGconn *conn, ReindexType type, CppAsString2(RELKIND_MATVIEW) ")\n" " AND c.relpersistence != " CppAsString2(RELPERSISTENCE_TEMP) "\n" - " AND ns.nspname IN ("); + " AND ns.oid IN ("); + /* + * Resolve each schema name as an identifier, rather than + * comparing it literally with nspname. This also makes a + * nonexistent schema an error, even if there are no tables. + */ for (cell = user_list->head; cell; cell = cell->next) { if (cell != user_list->head) appendPQExpBufferChar(&catalog_query, ','); appendStringLiteralConn(&catalog_query, cell->val, conn); + appendPQExpBufferStr(&catalog_query, + "::pg_catalog.regnamespace"); } appendPQExpBufferStr(&catalog_query, ")\n" diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl index b78f31b379..84cc2163a3 100644 --- a/src/bin/scripts/t/090_reindexdb.pl +++ b/src/bin/scripts/t/090_reindexdb.pl @@ -292,12 +292,12 @@ $node->issues_sql_like( [ 'reindexdb', '--jobs' => '2', - '--schema' => 's1', + '--schema' => 'S1', '--schema' => 's2', 'postgres', ], qr/statement:\ REINDEX TABLE s1.t1;/, - 'parallel reindexdb for schemas does a per-table REINDEX'); + 'parallel reindexdb folds unquoted schema names to lower case'); $node->command_fails( [ 'reindexdb', @@ -310,6 +310,27 @@ $node->command_fails( 'parallel reindexdb for indices concurrently'); $node->command_ok([ 'reindexdb', '--jobs' => '2', '--schema' => 's3' ], 'parallel reindexdb with empty schema'); + +$node->issues_sql_like( + [ + 'reindexdb', + '--jobs' => '2', + '--schema' => '"s1"', + 'postgres', + ], + qr/statement:\ REINDEX TABLE s1.t1;/, + 'parallel reindexdb with quoted schema name'); +$node->command_fails_like( + [ + 'reindexdb', + '--jobs' => '2', + '--schema' => 's3', + '--schema' => 'missing_schema', + 'postgres', + ], + qr/schema "missing_schema" does not exist/, + 'parallel reindexdb with empty and nonexistent schemas'); + $node->command_ok( [ 'reindexdb', base-commit: f1eafd911ddde87f84672b5bf227a3e6cae6331f -- 2.34.1