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-15T06:51:48Z
Lists: pgsql-hackers
On Tue, Apr 15, 2025 at 1:45 PM Pavel Stehule <pavel.stehule@gmail.com> wrote: >> >> 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 don't think it is the correct fix. > > because then fails CREATE INDEX qqindxname > > The motivation for usage --clean and --if-exists option is possibility to call restore idempotently. It should not fail when I do restore in an empty database, and it shouldn't fail if I do restore in an existing database. > I am not sure what you mean fails ``CREATE INDEX qqindxname`` ? for example: >> >> 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); with the patch, pg_dump output will be ``` DROP INDEX IF EXISTS public.tp_a_idx; DROP TABLE IF EXISTS public.tp_11; DROP TABLE IF EXISTS public.tp; .... CREATE INDEX tp_a_idx ON ONLY public.tp USING btree (a); CREATE INDEX tp_11_a_idx ON public.tp_11 USING btree (a); ALTER INDEX public.tp_a_idx ATTACH PARTITION public.tp_11_a_idx; ``` What's your expectation?
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