Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rp6YO-0054x8-Hr for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Mar 2024 13:09:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rp6YN-00EZU5-35 for pgsql-bugs@arkaria.postgresql.org; Tue, 26 Mar 2024 13:09:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rp6YM-00EZTm-PO for pgsql-bugs@lists.postgresql.org; Tue, 26 Mar 2024 13:09:22 +0000 Received: from smtp2-g21.free.fr ([2a01:e0c:1:1599::11]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rp6YE-006aNS-Uh for pgsql-bugs@lists.postgresql.org; Tue, 26 Mar 2024 13:09:21 +0000 Received: from zimbra-e1-02.priv.proxad.net (unknown [172.20.243.240]) by smtp2-g21.free.fr (Postfix) with ESMTP id 4DB7F200595 for ; Tue, 26 Mar 2024 14:09:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1711458552; bh=DTaH++zCazWRHqS9Y0MvEK7pEVMzKxakHhZwW2M2N68=; h=Date:From:To:In-Reply-To:References:Subject:From; b=ME7zFiAR/QvkiENRqc8miOKjtJMjfaD5ReNxUz/WJMVNB+3y5CUy9PjPN6+EkXfpy 4zzZc+EEYdMorODAWrY5O34wbL1XiZSE5MITZbUXHr6FCHBcjHeCijo90nBGbeOhcV HbatgKL3hW8h0272UaRpMSWX14MUH6cB51M+BfukQZMfMM9GUMTqc9vBWQ0HMTtzhg Hamj36q3512YqFoV/utj8m/Kz1oGziyTfHzNvjphLuPsStBYUVMzIoOBAgYtw/R3U5 93CjyRO+g7cu4pUBxXue+S17tKjssvyOAmTmghomI69UAhxYurpGplC06loxvS/5fC PMPi1Uy2csuVg== Date: Tue, 26 Mar 2024 14:09:11 +0100 (CET) From: gparc@free.fr To: pgsql-bugs Message-ID: <621556601.826991929.1711458551936.JavaMail.zimbra@free.fr> In-Reply-To: <18402-23452305346476d6@postgresql.org> References: <18402-23452305346476d6@postgresql.org> Subject: Re: BUG #18402: Attaching a new partition doesn't reuse the prebuilt index on said partition MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [145.242.20.121] X-Mailer: Zimbra 9.0.0_GA_1337 (ZimbraWebClient - FF115 (Linux)/9.0.0_GA_1337) Thread-Topic: BUG #18402: Attaching a new partition doesn't reuse the prebuilt index on said partition Thread-Index: MoR/qSVpV+/BNAUa9xjw0seRFYxfrQ== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, is there a week retention before this report is delivered to the mailing li= st ? Regards Gilles ----- Mail original ----- > De: "PG Bug reporting form" > =C3=80: "pgsql-bugs" > Cc: "gparc" > Envoy=C3=A9: Mercredi 20 Mars 2024 15:29:14 > Objet: BUG #18402: Attaching a new partition doesn't reuse the prebuilt i= ndex on said partition > The following bug has been logged on the website: >=20 > Bug reference: 18402 > Logged by: Gilles PARC > Email address: gparc@online.fr > PostgreSQL version: 16.2 > Operating system: Linux > Description: >=20 > Example : >=20 > First I create a list partitioned table and fill it > CREATE TABLE master > ( > id integer NOT NULL, > millesime varchar(4) NOT NULL, > CONSTRAINT master_pk PRIMARY KEY (id, millesime) > ) partition by list (millesime); >=20 > CREATE TABLE master_2022 PARTITION OF master FOR VALUES IN ('2022'); > CREATE TABLE master_2023 PARTITION OF master FOR VALUES IN ('2023'); > CREATE TABLE master_2024 PARTITION OF master FOR VALUES IN ('2024'); > CREATE TABLE master_2025 PARTITION OF master FOR VALUES IN ('2025'); >=20 > DO > $do$ > BEGIN > FOR i IN 2022..2025 LOOP > INSERT INTO master VALUES (generate_series(1,100000), i::varchar); > END LOOP; > END > $do$; >=20 > I now list the created indexes: > \diS+ master* > List of relations > Schema | Name | Type | Owner | Table | > Persistence | Access method | Size | Description > --------+------------------+-------------------+----------+-------------+= -------------+---------------+---------+------------- > public | master_2022_pkey | index | postgres | master_2022 | > permanent | btree | 3088 kB | > public | master_2023_pkey | index | postgres | master_2023 | > permanent | btree | 3088 kB | > public | master_2024_pkey | index | postgres | master_2024 | > permanent | btree | 3088 kB | > public | master_2025_pkey | index | postgres | master_2025 | > permanent | btree | 3088 kB | > public | master_pk | partitioned index | postgres | master | > permanent | btree | 0 bytes | > (5 rows) >=20 >=20 > Now I prepare a new 2026 partition with correct constraints and indexes a= nd > attach it : >=20 > CREATE TABLE master_2026 (LIKE master INCLUDING DEFAULTS INCLUDING > CONSTRAINTS); > ALTER TABLE master_2026 ADD CONSTRAINT master_2026_ck CHECK (millesime = =3D > '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'); > ALTER TABLE master_2026 DROP CONSTRAINT master_2026_ck; >=20 > But now, when I list the indexes again, I see that my unique index above = is > not considered to use > and a new one is created (master_2026_pkey1). > \diS+ master* > Schema | Name | Type | Owner | Table | > Persistence | Access method | Size | Description > --------+-------------------+-------------------+----------+-------------= +-------------+---------------+---------+------------- > public | master_2022_pkey | index | postgres | master_2022 | > permanent | btree | 3088 kB | > public | master_2023_pkey | index | postgres | master_2023 | > permanent | btree | 3088 kB | > public | master_2024_pkey | index | postgres | master_2024 | > permanent | btree | 3088 kB | > public | master_2025_pkey | index | postgres | master_2025 | > permanent | btree | 3088 kB | > public | master_2026_pkey | index | postgres | master_2026 | > permanent | btree | 3104 kB | > public | master_2026_pkey1 | index | postgres | master_2026 | > permanent | btree | 3104 kB | > public | master_pk | partitioned index | postgres | master | > permanent | btree | 0 bytes | > (7 rows) >=20 > why is it so ? >=20 > Bug or Feature ? > Regards > Gilles