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 1uMldR-0039Kz-7b for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jun 2025 10:46:17 +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 1uMldP-00B86e-5W for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Jun 2025 10:46:15 +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 1uMldO-00B86W-SA for pgsql-hackers@lists.postgresql.org; Wed, 04 Jun 2025 10:46:15 +0000 Received: from mail-vk1-xa2c.google.com ([2607:f8b0:4864:20::a2c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uMldN-000A39-1U for pgsql-hackers@lists.postgresql.org; Wed, 04 Jun 2025 10:46:15 +0000 Received: by mail-vk1-xa2c.google.com with SMTP id 71dfb90a1353d-52eec011ff2so2278779e0c.1 for ; Wed, 04 Jun 2025 03:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749033970; x=1749638770; 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=XmHGffkDtGBY3brd19Mv8Mn0RtWiACCT/ffzLZQdBZM=; b=V7DIooYlo56X0kUGbFN3zyOrt9AUwvwdcA3j40oscDjE4omOC9TJh6XCrsSCLxG2NO zZjyg1xam2XYzHI6kv3+rd9sGd4S3HoH/XlG+KGoaqovGHAvkHGGuhPFadfEyY1ngUVx i00ND5IBZ0wsxFTSRj9ii5hwEbkjfkzOwQiMs/FZgMLQOyawxyxzRxNfdLKciQfgj9Pw s9/5hHKzvYAwB69xOjVWlk1Uethj++Q0sZMZMSuqDvTI4qZoFBUVhHOSBmbb5pc4w8G8 ekP4z61LfxidXRFkvUUPQncsk516te8Sj/qltLbJMfksi9GJsCBxJtZEHZrMb+PaBifm JagA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749033970; x=1749638770; 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=XmHGffkDtGBY3brd19Mv8Mn0RtWiACCT/ffzLZQdBZM=; b=U8pNotyclkCjiTnceXrgfXGzwtxEnVNhSeNTiSHehEDYqmHnCrwC+OTt0A6TPcsp32 EPrb6BbzRs5+9XFO+YRDhGfBPrgI/l8W2eFcPd8+mVtFiceo41ZooBdYo5UOdC1fdhcJ FLdDPI6u+K1JWHGmVFdTVXyPjBUydsrcGaBMQWhHzVfwXur0nwhEYuae2SQVvxfBsbt+ YhE+h3GdYQxabN30oD5ecv70IgArpF8LygIUqiIWytxJ4eadbOblH8yRTlND6n8GLxTx eiLQa6R8HhMdXCw2hoq2G17U2flAtiCqi5sAjDXAcxEQ1p0qkdVBv/F9SyMFVfr7iW/J KU0w== X-Gm-Message-State: AOJu0YwSlLX3NAg0HCAvc95nZqzzBfEf86WdaUl2qjqno5IhBpzOwhiD UWg8Zqy1h7CbIpW8VxMyGFLPePKIkVvyK+ljJMI6y2lZN2uGpTSBWF7lJGwyT0qVWmxyUyA7zqi fo3tctqvCnapSmS1DlTFH/ApaZYeGWk2UTLYMTJkzGw== X-Gm-Gg: ASbGncuRtQIHHqYcvVGPWyfKOW6ghmE9YP/xGhT37KPvkoREHGE4FgN0ylXSkvQ5QQY CbBQLPN/klz7VvwYrkDvOmbzlLJ+L3ZQyyb+CUX0/4AYLlItAzxj2XE9dYoD3Nfp4LxD8FwKJoo nRpzmABG02I+zeNRYBxKl0gqfpmbmlc02AImfz0sr2+I6yJm4XUpTJJWJa7wxcncU= X-Google-Smtp-Source: AGHT+IFC86g/FcXxjrx5dsmOkVPOWBTkyMacT/19qvsXjJwudb+z7mSWGJrsd6lqb9PZY3TWRd4tMbJDfbrkwE7tlLU= X-Received: by 2002:a05:6122:201f:b0:520:6773:e5ea with SMTP id 71dfb90a1353d-530c7369529mr1655419e0c.7.1749033969805; Wed, 04 Jun 2025 03:46:09 -0700 (PDT) MIME-Version: 1.0 References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org> <859476bf-3cb0-455e-b093-b8ab5ef17f0e@postgrespro.ru> <4e2764f7-f6be-478f-8d7f-f921dbd10f5f@postgrespro.ru> <7fdaf3e8-4c05-4739-bee6-98acc068d1c7@postgrespro.ru> <4433b492-9e97-4334-96d9-ddaaa5083099@postgrespro.ru> In-Reply-To: <4433b492-9e97-4334-96d9-ddaaa5083099@postgrespro.ru> From: jian he Date: Wed, 4 Jun 2025 18:45:32 +0800 X-Gm-Features: AX0GCFsrOj4Rh7dvTMbjndlEqUOBxpIfG5fUF4bZF4e3eNnMyqwfKOs5KmNpUhw Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Dmitry Koval Cc: 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 On Wed, Jun 4, 2025 at 4:53=E2=80=AFAM Dmitry Koval wrote: > Added some changes to documentation. > Patches are attached to the email. > hi. I haven't touched v39-0002 yet. The following are reviews of v39-0001. +CREATE INDEX sales_range_sales_date_idx ON sales_range USING btree (sales_date); +INSERT INTO sales_range VALUES (1, 'May', 1000, '2022-01-31'); +INSERT INTO sales_range VALUES (2, 'Smirnoff', 500, '2022-02-10'); +INSERT INTO sales_range VALUES (3, 'Ford', 2000, '2022-04-30'); you can put it into one INSERT. like INSERT INTO sales_range VALUES (1, 'May', 1000, '2022-01-31'), (1, 'May', 1000, '2022-01-31'); which can make the regress test faster. (apply the logic to other places in src/test/regress/sql/partition_merge.sq= l) + key =3D RelationGetPartitionKey(parent); + strategy =3D get_partition_strategy(key); + + if (strategy =3D=3D PARTITION_STRATEGY_HASH) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("partition of hash-partitioned table cannot be merged"))); This error case doesn't seem to have a related test, and adding one would be great. per https://www.postgresql.org/docs/current/error-message-reporting.html "The extra parentheses were required before PostgreSQL version 12, but are now optional." so now you can remove the extra parentheses. + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("partition of hash-partitioned table cannot be merged")); + if (!partRel->rd_rel->relispartition) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("\"%s\" is not a partition", + RelationGetRelationName(partRel)))); + + if (get_partition_parent(partRelOid, false) !=3D RelationGetRelid(rel)) + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_TABLE), + errmsg("relation \"%s\" is not a partition of relation \"%s\"", + RelationGetRelationName(partRel), + RelationGetRelationName(rel)))); we can make the first error message like the second one. errmsg("\"%s\" is not a partition of \"%s\"....) + case AT_MergePartitions: + { + PartitionCmd *partcmd =3D (PartitionCmd *) cmd->def; + + if (list_length(partcmd->partlist) < 2) + ereport(ERROR, + (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), + errmsg("list of new partitions should contain at least two items"))); This also seems to have no tests. adding a dummy one should be ok. We added List *partlist into PartitionCmd typedef struct PartitionCmd { NodeTag type; RangeVar *name; /* name of partition to attach/detach */ PartitionBoundSpec *bound; /* FOR VALUES, if attaching */ List *partlist; /* list of partitions, for MERGE/SPLIT * PARTITION command */ bool concurrent; } PartitionCmd; then in src/backend/parser/gram.y we should use cmd->partlist =3D NIL; instead of cmd->partlist =3D NULL; We also need comments explaining PartitionCmd.name meaning for ALTER TABLE MERGE PARTITIONS INTO? transformPartitionCmdForMerge + partOid =3D RangeVarGetRelid(name, NoLock, false); here "NoLock" seems not right? For example, after "RangeVarGetRelid(name, NoLock, false);" before checkPartition, I drop the table test.t in another session. i got the following error: ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, test.t) INTO sales_feb_mar_apr2022; ERROR: could not open relation with OID 18164