Re: pg_dump --if-exists --clean when drop index that is partition of a partitioned index - Mailing list pgsql-hackers

From jian he
Subject Re: pg_dump --if-exists --clean when drop index that is partition of a partitioned index
Date
Msg-id CACJufxEprq_NN3=FT9pJJo_y5gqDUMc8jwqeE9tw-vNBgOdraA@mail.gmail.com
Whole thread Raw
In response to Re: pg_dump --if-exists --clean when drop index that is partition of a partitioned index  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: pg_dump --if-exists --clean when drop index that is partition of a partitioned index
List 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
failwhen 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?



pgsql-hackers by date:

Previous
From: Andrey Borodin
Date:
Subject: Re: Call for Posters: PGConf.dev 2025
Next
From: Fujii Masao
Date:
Subject: Re: Conflicting updates of command progress