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 1uaans-007Ioe-Kj for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jul 2025 14:02:12 +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 1uaanp-008gwc-Q6 for pgsql-hackers@arkaria.postgresql.org; Sat, 12 Jul 2025 14:02:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uaanp-008gvM-Du for pgsql-hackers@lists.postgresql.org; Sat, 12 Jul 2025 14:02:10 +0000 Received: from mail-vk1-xa2d.google.com ([2607:f8b0:4864:20::a2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uaano-006vpG-0u for pgsql-hackers@lists.postgresql.org; Sat, 12 Jul 2025 14:02:09 +0000 Received: by mail-vk1-xa2d.google.com with SMTP id 71dfb90a1353d-5315acf37b6so1252937e0c.2 for ; Sat, 12 Jul 2025 07:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752328927; x=1752933727; 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=572ugwuSAflLxkXMRmPVieLTXzNqsHS1y5KMc7JzPL4=; b=nk2z9W2dK8naYB76HA3PKfNV6DGq8BM/eRJpprU1NE2OkFmQoZuLHHfCdP63KcVrCT xto+/sCjtvGG3dL0J71cCKg1MMeTgPu7DBjtvnEBXXsfZXis4BRBOpScFIhqZMROC9Ox VZW9uSmzOjbBnJN1rtQaj775+8YDMP42BjIEwMZynJ7RBBw7WveSa7/dbKG0mIlpKj4V 3IXlDsg1eFgkNDIRlu6XABtC8XDg4Omy8XEj0zU85F7WT48ub0f4O1g/yIurpsmVJ7ot YgekDYwQQKOC+M2ZwS9oeGfV0ePGdI0QcaUEdFDhbN6yDKxD/EcMF1sgBMwCY1PcoVL7 WGKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752328927; x=1752933727; 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=572ugwuSAflLxkXMRmPVieLTXzNqsHS1y5KMc7JzPL4=; b=rGQUbj5DW0I7dPJMts8JtuE5TPfK/FUaR/6Xhll7D01hpiyiPK/0Yn4K0yyinhmcer aIWuNxYJRtz7Ol92X32nciHkGg9SIVfLl2m7MGTuo1imormTFAlLD8d8CKoC4PO7qI3F 46FG5OXcV8lvD/7y+ZCGJ1OJtLVs4N51YD6UowJTP7/o2MaMfsTz4HRY+QiQTc8Nlc3W Gw6DQMlIOxbtmTS+/ODXjaHdN7JeJ7nbX+rOvnHlV/DnbFeK4ePmD6Iwx2sLDAbEaGRM pOjk8Wk6mNhV7nhGiH3T+vkHmbBpU8gbvfbNqAiRVIM2kRA6y5jI/HY0K2/U89Z4a6TW aRvA== X-Gm-Message-State: AOJu0Yz/ZDyIefWHDXQ0WSV5QYgrGVY79DM9bOoq9F7BUZRqy6lWKEPF y9uSTwU7u6rgJYTjbqcrROD1XSYXN0YUMX7ZKmcq0UklEyhsG8ErSC8RmrLhtR6InPk2jlPq0Zb 3M6E30/zxAF5NUzC0/KC++qrdAUYMcYS6MhIxCBttMg== X-Gm-Gg: ASbGncsUKRle2l0mXCO3vxkf0s0YjK9lZv0YQ0kr65Kxg1/mqoxXzigoMJx70429EYx YtAw8edEV/Vty587i/NEk7GnovWENFsfIz0vvuJrMU9n/sodgPLmQHApES8SLVliOJNIuA/jq06 w/LEid+pvTh0hGddoNIDArtNfLHlziBK2wcDOLdd3l8/80/KGL2USZjNnSUeN++upZiJ1uQvD+m Iw9xXtyXa1Ez8ezDjQD0qNHSnn3lQq4QW6H X-Google-Smtp-Source: AGHT+IH7jv0uQUrryb5X3JkXl4Pc1SrXFblZ8LYFMBZ7YMPGREVNL0XPCfYb+D1GOgxMJVdSXTCp6L8F28HNuwH0wpg= X-Received: by 2002:a05:6122:3c55:b0:530:7a17:88ca with SMTP id 71dfb90a1353d-535f476de4cmr5046327e0c.9.1752328920038; Sat, 12 Jul 2025 07:02:00 -0700 (PDT) MIME-Version: 1.0 References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org> <1e74c9fd-830e-4544-b0de-e49ea4b04029@postgrespro.ru> <9c1b75f1-5c40-4a86-9a61-a4b3f1d7ec60@postgrespro.ru> <7e1c67b8-ceba-4a04-964a-853eedeb02cc@postgrespro.ru> <0b3907b4-83b9-4873-9feb-2b60b29cda33@postgrespro.ru> <4f19550b-eb41-4649-8bf5-566dc020a720@postgrespro.ru> In-Reply-To: From: jian he Date: Sat, 12 Jul 2025 22:01:22 +0800 X-Gm-Features: Ac12FXyEizgAJ6icMZ72HtvnHytrhlPro3qUXQoMltlaYt4PfIhTQP8mvr7YZz0 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 25, 2025 at 5:28=E2=80=AFAM Dmitry Koval wrote: > > Hi! > Thanks for notes! > hi. +static void +transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcm= d) +{ + + /* Is current partition a DEFAULT partition? */ + defaultPartOid =3D get_default_oid_from_partdesc(RelationGetPartitionDesc(parent, true)); + this comment seems wrong? it should be "does this partitioned table (parent) have a default partition= ? + 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 error message is not good, IMHO. I don't really have any good ideas th= ough. if we polish this message later, now we can add a comment: "FIXME improve this error message". in ATExecMergePartitions we have: RangeVarGetAndCheckCreationNamespace(cmd->name, NoLock, &existingRelid)= ; it will call RangeVarAdjustRelationPersistence after it, the cmd->name->relpersistence will be set properly. so the following in createPartitionTable can be checked way earlier. /* * 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. */ if (parent_rel->rd_rel->relpersistence !=3D RELPERSISTENCE_TEMP && newRel->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP) ereport(ERROR, errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot create a temporary relation as partition of permanent relation \"%s\"", RelationGetRelationName(parent_rel))); /* Permanent rels cannot be partitions belonging to temporary parent */ if (newRel->rd_rel->relpersistence !=3D RELPERSISTENCE_TEMP && parent_rel->rd_rel->relpersistence =3D=3D RELPERSISTENCE_TEMP) ereport(ERROR, errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot create a permanent relation as partition of temporary relation \"%s\"", RelationGetRelationName(parent_rel))); after createPartitionTable->heap_create_with_catalog do the error check see= ms unintuitive to me. it can be checked right after RangeVarGetAndCheckCreationNamespace.