Re: BUG #18402: Attaching a new partition doesn't reuse the prebuilt index on said partition

Поиск
Список
Период
Сортировка
От Euler Taveira
Тема Re: BUG #18402: Attaching a new partition doesn't reuse the prebuilt index on said partition
Дата
Msg-id 0370353a-56a3-4fb7-aa12-46422d05b2b5@app.fastmail.com
обсуждение исходный текст
Ответ на BUG #18402: Attaching a new partition doesn't reuse the prebuilt index on said partition  (PG Bug reporting form <noreply@postgresql.org>)
Список pgsql-bugs
On Wed, Mar 20, 2024, at 11:29 AM, PG Bug reporting form wrote:
CREATE TABLE master_2026 (LIKE master INCLUDING DEFAULTS INCLUDING
CONSTRAINTS);
ALTER TABLE master_2026 ADD CONSTRAINT master_2026_ck CHECK (millesime =
'2026');
DO 
$do$
BEGIN
      INSERT INTO master_2026 VALUES (generate_series(1,100000), '2026');
END
$do$;
CREATE UNIQUE INDEX CONCURRENTLY master_2026_pkey ON master_2026 (id,
millesime);
ALTER TABLE master ATTACH PARTITION master_2026 FOR VALUES IN ('2026');

You don't add a primary key or unique constraint here. Hence, the ALTER TABLE ..
ATTACH PARTITION doesn't consider the master_2026_pkey as a candidate for
primary key index. Add the following command and your index will be used.

ALTER TABLE master_2026
        ADD CONSTRAINT master_2026_pk PRIMARY KEY USING INDEX master_2026_pkey;

See [1]. Documentation [2] says

UNIQUE and PRIMARY KEY constraints from the parent table will be created in the
partition, if they don't already exist.




--
Euler Taveira

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Regression tests fail with musl libc because libpq.so can't be loaded
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #18407: ALTER TABLE SET SCHEMA on foreign table with SERIAL column does not move sequence to new schema