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 1s14Qg-009CrX-Iu for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Apr 2024 13:18:54 +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 1s14Qd-00D1LE-Qk for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Apr 2024 13:18:52 +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 1s14Qd-00D1L5-H9 for pgsql-hackers@lists.postgresql.org; Sun, 28 Apr 2024 13:18:52 +0000 Received: from charmander.telsasoft.com ([50.244.222.1] helo=pryzbyj2023.telsasoft) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s14QW-000Vgz-Ob for pgsql-hackers@lists.postgresql.org; Sun, 28 Apr 2024 13:18:51 +0000 Received: by pryzbyj2023.telsasoft (Postfix, from userid 1000) id 421082ECE; Sun, 28 Apr 2024 08:18:42 -0500 (CDT) Date: Sun, 28 Apr 2024 08:18:42 -0500 From: Justin Pryzby To: Alexander Korotkov Cc: Dmitry Koval , Alexander Lakhin , Robert Haas , Tomas Vondra , Alvaro Herrera , pgsql-hackers@lists.postgresql.org Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands Message-ID: References: <56e0000c-6b39-44ce-90b4-d3c3062e408c@postgrespro.ru> <5dee3937-8e9f-cca4-11fb-737709a92b37@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="3XiaetL0RzE8cJWP" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --3XiaetL0RzE8cJWP Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Apr 28, 2024 at 04:04:54AM +0300, Alexander Korotkov wrote: > Hi Justin, > > Thank you for your review. Please check v9 of the patchset [1]. > > On Wed, Apr 24, 2024 at 11:26 PM Justin Pryzby wrote: > > This patch also/already fixes the schema issue I reported. Thanks. > > > > If you wanted to include a test case for that: > > > > begin; > > CREATE SCHEMA s; > > CREATE SCHEMA t; > > CREATE TABLE p(i int) PARTITION BY RANGE(i); > > CREATE TABLE s.c1 PARTITION OF p FOR VALUES FROM (1)TO(2); > > CREATE TABLE s.c2 PARTITION OF p FOR VALUES FROM (2)TO(3); > > ALTER TABLE p MERGE PARTITIONS (s.c1, s.c2) INTO s.c1; -- misbehaves if merging into the same name as an existing partition > > \d+ p > > ... > > Partitions: c1 FOR VALUES FROM (1) TO (3) > > There is already a test which checks merging into the same name as an > existing partition. And there are tests with schema-qualified names. > I'm not yet convinced we need a test with both these properties > together. I mentioned that the combination of schemas and merge-into-same-name is what currently doesn't work right. > > Also, extended stats objects are currently cloned to new child tables. > > But I suggested in [0] that they probably shouldn't be. > > I will explore this. Do we copy extended stats when we do CREATE > TABLE ... PARTITION OF? I think we need to do the same here. Right, they're not copied because an extended stats objs on the parent does something different than putting stats objects on each child. I've convinced myself that it's wrong to copy the parent's stats obj. If someone wants stats objects on each child, they'll have to handle them specially after MERGE/SPLIT, just as they would for per-child defaults/constraints/etc. On Sun, Apr 28, 2024 at 04:04:54AM +0300, Alexander Korotkov wrote: > On Wed, Apr 24, 2024 at 11:26 PM Justin Pryzby wrote: > > This patch adds documentation saying: > > + Any indexes, constraints and user-defined row-level triggers that exist > > + in the parent table are cloned on new partitions [...] > > > > Which is good to say, and addresses part of my message [0] > > [0] ZiJW1g2nbQs9ekwK@pryzbyj2023 > > Makes sense. Extracted this into a separate patch in v10. I adjusted the language some and fixed a typo in the commit message. s/parition/partition/ -- Justin --3XiaetL0RzE8cJWP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Document-the-way-partition-MERGE-SPLIT-operations-cr.patch" From e00033fc4b8254c70bf8a3d41d513edd9540e2d7 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Sun, 28 Apr 2024 03:39:30 +0300 Subject: [PATCH] Document the way partition MERGE/SPLIT operations create new partitions Reported-by: Justin Pryzby Discussion: https://postgr.es/m/ZilrByTp-pbz6Mvf%40pryzbyj2023 --- doc/src/sgml/ref/alter_table.sgml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index fe36ff82e52..fc2dfffe49f 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -1153,6 +1153,12 @@ WITH ( MODULUS numeric_literal, REM splitting we have a partition with the same name). Only simple, non-partitioned partition can be split. + + The new partitions will be created the same as tables created with the + SQL command CREATE TABLE partition_nameN (LIKE name INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY). + The indexes and identity are created later, after moving the data + into the new partitions. + This command acquires an ACCESS EXCLUSIVE lock. @@ -1213,6 +1219,12 @@ WITH ( MODULUS numeric_literal, REM can have the same name as one of the merged partitions. Only simple, non-partitioned partitions can be merged. + + The new partition will be created the same as a table created with the + SQL command CREATE TABLE partition_name (LIKE name INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY). + The indexes and identity are created later, after moving the data + into the new partition. + This command acquires an ACCESS EXCLUSIVE lock. -- 2.42.0 --3XiaetL0RzE8cJWP--