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 1uP1Mk-00FrAX-RU for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Jun 2025 15:58:22 +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 1uP1Mi-006Fnr-9K for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Jun 2025 15:58:20 +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 1uP1Mh-006Flv-UZ for pgsql-hackers@lists.postgresql.org; Tue, 10 Jun 2025 15:58:20 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uP1Mg-001GE0-21 for pgsql-hackers@lists.postgresql.org; Tue, 10 Jun 2025 15:58:20 +0000 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-606fdbd20afso11096069a12.1 for ; Tue, 10 Jun 2025 08:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749571096; x=1750175896; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/X9JShdCl6SETH63FpgqJemR393Ff0Ps5Ha42wbRTms=; b=KqaRmGoh60Mi4M0sBSnGV2rDMCytx9Q4pm0fN/YYPItYAExpIkjZbW7KARKXgLWqUo anGAIxh/fk6z8a+Rol7AcauEUopGj4ED2WLGAK/54aQoxZUeKFGnQsK42p5a2CggVf+N naroq0K0djhjgPlgU5645sTFjqZnbv/YjUz5jrRftjiEgsdrsRDHGtp/NpjNlJUklmfq t9TaKGZlKcomRc4Wx/d1xfMHo4PObWXZOmEO2BKmnw2kiwwg1iahGFDTmHXc9O1r0vpU 0pXmEVv1yg6zaCXxdO0+NjmX6a3lD4Yauv53zi6Yix0SC4MnwSirBB/5EPXPTb+dP+jf XIkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749571096; x=1750175896; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/X9JShdCl6SETH63FpgqJemR393Ff0Ps5Ha42wbRTms=; b=tVB3aNz8FNmEVJbnVjIuCRJHY/BqXjMvz7OauLqjy0RCGgkHfSFEgsrpgSpdIhjzLC 580TsWNsCK0AwpTIviqqNAjGUedibhU4piDsCHfmZf/6MqJ2QdnOAjCvPt/a0MHncbSt 7lIE1XDaFBZ0gBLLYjLRQzj4eTMV/laQ9RmEh4o+5V4iZWituxRlC8y5LgJciinbExAu mHN1Cd9+4J9dWloxu69dHeCIb/KbA9VNuVDNHOAk2uLDcJ0bni/gcViesqoqLCnq3hI3 HzLQR68Z4b9gCjyh5/2IS/SaU2+KRREoiklOeZ4YRQkUy/FhsPxYF6VZomFGGkiAWgcr Pmhw== X-Forwarded-Encrypted: i=1; AJvYcCU4ttmyU3uBKnXcK2ZtnhOzVGtBMcfqQsc1GQrPCu5vvbBrSan9ie3JHp7R0iAGSZFFzP647iwB9Qx2LKQu@lists.postgresql.org X-Gm-Message-State: AOJu0YxHxZ/BVb9Ty691uAOdsuuGrybjkdZVAxdDOysz6+ydq3jyES6S DKzrM2A9tHP2YeuzrV1MuVr+qTrCXP5ZaC2eYNWyOZTKr/uXjMYjUZbzAncUFXO7beBtJTHQjFJ cQBwc2Sgo6ywJU2/9tXxDRKjhgQfBdrU= X-Gm-Gg: ASbGnctcM9v94ha/aNgGFrtQm+dL5/FqWIhdcFZTso4/6DcgZu+UTVH57otZBCcC5TU +IbBK/wTljFEa7Nnj7acYMDjxyV/4q1i/XYjaajLrNDsojL6z4XniwPc4koXxCIKqSYz+YZkkep PQ9ywILu575fPx0YdyYMpVMDZGplQRrHf1q5WH9EygAw== X-Google-Smtp-Source: AGHT+IHUQa4j2ovAwMtAfM3bh0Kc5rzWD09ef0LUq+6TbY/IibSmamOGNAKbfoE74i3rcEupV8JIFkOSnPo/0M7XsGI= X-Received: by 2002:a17:907:cd0d:b0:adb:469d:2221 with SMTP id a640c23a62f3a-ade1ab07c65mr1629113566b.45.1749571096240; Tue, 10 Jun 2025 08:58:16 -0700 (PDT) MIME-Version: 1.0 References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org> <4e2764f7-f6be-478f-8d7f-f921dbd10f5f@postgrespro.ru> <7fdaf3e8-4c05-4739-bee6-98acc068d1c7@postgrespro.ru> <4433b492-9e97-4334-96d9-ddaaa5083099@postgrespro.ru> <67ecf5fb-e63d-4284-be75-d0479eef81aa@postgrespro.ru> <884bcf9e-d6e3-4b0c-8dcb-7f2110070ac9@postgrespro.ru> In-Reply-To: <884bcf9e-d6e3-4b0c-8dcb-7f2110070ac9@postgrespro.ru> From: Junwang Zhao Date: Tue, 10 Jun 2025 23:58:04 +0800 X-Gm-Features: AX0GCFuPL6GXTTRueUdZd4RJHdfqm7Msxt7rs4ujKtWLs7dwSjIWl4swRrMhyyw Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Dmitry Koval Cc: jian he , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Dmitry, On Tue, Jun 10, 2025 at 6:48=E2=80=AFAM Dmitry Koval wrote: > > Hi, Jian He! > > Thanks for the suggestions and patches! > This email contains comments to three emails (05/06/2025). > I hope to read two emails (for 06/06/2025) tomorrow. > > 1. > >What should we do when any to be merged partition has constraints? > >... > >Maybe this is expected, but we need to mention it somewhere and have > >some tests on it saying that MERGE PARTITIONS will effectively drop > >the partitions, so if any object depends on that partition > >then MERGE PARTITIONS can not be done. > > Added following phrases to the documentation (I hope this should be > enough?): > > If merged partitions have individual constraints, those constraints will > be dropped because command uses partitioned table as a model to create > the constraints. > If merged partitions have some objects dependent on them, the command > can not be done (CASCADE is not used, an error will be returned). > > > 2. > > ... so this error check can be performed as early as the > >transformPartitionCmdForMerge stage? > > Function createPartitionTable will be used for various other cases > besides MERGE PARTITIONS: for SPLIT PARTITION, for PARTITION BY > REFERENCE (I hope). > So I think it's better to minimize the amount of code and not move the > same one check into different functions (transformPartitionCmdForMerge, > transformPartitionCmdForSplit, ...). > > > 3. > >i think, we can do the following way: > >if (modelRel->rd_rel->relam) > > elog(ERROR, "error"); > >relamId =3D modelRel->rd_rel->relam; > > Can you clarify what is reason to change the current AM-logic for > creating a new partition? > > + /* Look up the access method for new relation. */ > + relamId =3D (modelRel->rd_rel->relam !=3D InvalidOid) ? > modelRel->rd_rel->relam : HEAP_TABLE_AM_OID; > > (If AM is set for a partitioned table, then use it, otherwise use AM for > heap tables.) > > > 4. > > Attached is some refactoring in moveMergedTablesRows, hope it's > straightforward. > > Thanks, these changes are useful. > > > 5. > >bug in transformPartitionCmdForMerge "equal(name, name2))" > > ... > >ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, > >public.sales_feb2022) INTO sales_feb_mar2022; > >ERROR: lower bound of partition "sales_feb2022" conflicts with upper > >bound of previous partition "sales_feb2022" > >in this context. "sales_feb2022" is the same as "public.sales_feb2022". > > Added check and test for this case. > > > 6. > >When using ALTER TABLE ... MERGE PARTITIONS, some of the new > >partition's properties will not be inherited from to be merged > >partitions; instead, they will be directly copied from the root > >partitioned table. > >So we need to test this behavior. > >The attached test file is for test table properties: > >(COMMENTS, COMPRESSION, DEFAULTS, GENERATED, STATISTICS, STORAGE). > > Some tests already exist (GENERATED, DEFAULTS) - see > partition_merge.sql, lines after: > > +-- Test for: > +-- * composite partition key; > +-- * GENERATED column; > +-- * column with DEFAULT value. > ... > > But the complex test is probably also interesting. > Test added. > > -- > > Similar changes are made for the second commit (SPLIT PARTITION). > > -- > With best regards, > Dmitry Koval > > Postgres Professional: http://postgrespro.com I had one trivial comment and a question if you don't mind. + /* If existing rel is temp, it must belong to this session */ + if (modelRel->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP && + !modelRel->rd_islocaltemp) + ereport(ERROR, + errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot create as partition of temporary relation of another session")); Would it be better to use RELATION_IS_OTHER_TEMP in this case? I noticed that while other parts of tablecmds.c don=E2=80=99t use the macro= , all other files consistently use RELATION_IS_OTHER_TEMP. + /* + * We intended to create the partition with the same persistence as the + * parent table, but we still need to recheck because that might be + * affected by the search_path. If the parent is permanent, so must be + * all of its partitions. + */ I have trouble understanding how this is possible, can you kindly give me some guidance on this logic? --=20 Regards Junwang Zhao