From ab02952b9c71b9a90a056bd9bcbd553d1ba4bdd6 Mon Sep 17 00:00:00 2001 From: Shibagaki Koshi Date: Tue, 13 Oct 2026 22:04:55 +0900 Subject: [PATCH v2] 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 | 27 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 843cc502f65..d37f8906b33 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 b78f31b3795..531421fe6cd 100644 --- a/src/bin/scripts/t/090_reindexdb.pl +++ b/src/bin/scripts/t/090_reindexdb.pl @@ -270,6 +270,8 @@ $node->safe_psql( CREATE INDEX i2 ON s2.t2(id); -- empty schema CREATE SCHEMA s3; + CREATE SCHEMA "S1x"; + CREATE TABLE "S1x".t1x(id integer); |); $node->command_fails( @@ -292,12 +294,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 +312,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' => '"S1x"', + 'postgres', + ], + qr/statement:\ REINDEX TABLE "S1x".t1x;/, + '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.43.5