Re: pg_dump --if-exists --clean when drop index that is partition of a partitioned index
jian he <jian.universality@gmail.com>
From: jian he <jian.universality@gmail.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-04-15T05:33:09Z
Lists: pgsql-hackers
Attachments
- v1-0001-fix-pg_dump-clean-on-index-inheritance-hierarchie.patch (text/x-patch) patch v1-0001
On Mon, Apr 14, 2025 at 2:09 PM Pavel Stehule <pavel.stehule@gmail.com> wrote: > > Hi > > po 14. 4. 2025 v 7:54 odesílatel jian he <jian.universality@gmail.com> napsal: >> >> hi. >> >> CREATE TABLE tp(c int, a int, b int) PARTITION BY RANGE (b); >> CREATE TABLE tp_1(c int, a int, b int); >> ALTER TABLE tp ATTACH PARTITION tp_1 FOR VALUES FROM (0) TO (1); >> CREATE INDEX t_a_idx ON tp_1(a); >> CREATE INDEX tp_a_idx ON tp(a); >> >> pg_dump --schema=public --if-exists --clean --no-statistics >> --no-owner --no-data --table-and-children=tp > 1.sql >> pg_dump output file 1.sql excerpts: >> ---- >> DROP INDEX IF EXISTS public.t_a_idx; >> DROP INDEX IF EXISTS public.tp_a_idx; >> DROP TABLE IF EXISTS public.tp_1; >> DROP TABLE IF EXISTS public.tp; >> ---- >> if you execute the >> DROP INDEX IF EXISTS public.t_a_idx; >> >> ERROR: cannot drop index t_a_idx because index tp_a_idx requires it >> HINT: You can drop index tp_a_idx instead. >> >> Is this pg_dump output what we expected? >> > > It is a bug, I think, the implementation of these parts of code is older than partitioning support, and doesn't do necessary detach. > seems pretty easy to fix. we only need dropStmt when IndxInfo->parentidx oid is invalid. + if (!OidIsValid(indxinfo->parentidx)) + appendPQExpBuffer(delq, "DROP INDEX %s;\n", qqindxname); I have tested the above changes on PG11, master.
Commits
-
Fix pg_dump --clean with partitioned indexes.
- 1fc3403626d4 18.0 landed
- a25f21d99adf 16.9 landed
- 7144cd53821f 15.13 landed
- 6a3e57865fc0 13.21 landed
- 3424c1075e4a 17.5 landed
- 148cc0105dce 14.18 landed