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 1vDWOI-00AlaZ-IQ for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Oct 2025 23:12:43 +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 1vDWOG-009hv0-K3 for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Oct 2025 23:12:39 +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 1vDWOG-009hus-58 for pgsql-hackers@lists.postgresql.org; Mon, 27 Oct 2025 23:12:39 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vDWOC-0046in-0p for pgsql-hackers@lists.postgresql.org; Mon, 27 Oct 2025 23:12:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1761606748; bh=QC+gocml7cALXZHN5RUfuGD+zcT5BGeJ8jbDyIa2oAw=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=rez55+WtQbOH3bJfcJ71lpE2O8FkJLad51iAAodXF5tw+QZGqJmt/zrf/WimWs203 elUV6u9D4kMg/kd5m8LJ55DOlYIfvQO8j0tHsTmQxi4GLv1/Q0FenJWMKScm0LIQiE iJyEQGngdbyFd2ZFECcq1S/MmpWojSK8yJPuVEUqd9luNLQiXE18h88EJcKnPFqCSQ K8iWSYFtKzFDj3FSZIgF2jjtDjcoAUhUWTUTAFZ6NWf4cm3x9MmLgnckprP/y86PUG 7LTTC+SRvftBqtvO9sH4wRAWpjEqL+Y+B97kEVh8EhmoNIFiXZcMGF13GtjvF5emwu auikkT5x13h0Q== Received: from [172.30.48.218] (debian11-template.l.postgrespro.ru [192.168.2.254]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: d.koval@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id BE6576019E; Tue, 28 Oct 2025 02:12:28 +0300 (MSK) Message-ID: Date: Tue, 28 Oct 2025 02:12:29 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Alexander Korotkov Cc: pgsql-hackers@lists.postgresql.org References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org> <2643645f-2a02-43de-9321-c995ab1b7ef8@postgrespro.ru> <57a94d8a-d7b6-4c5e-9001-be1cd403b172@postgrespro.ru> <54414932-9E82-47AA-902B-2DED18F07F64@gmail.com> <3280c458-a886-4c58-8e2b-4d220b73161d@postgrespro.ru> Content-Language: en-US From: Dmitry Koval In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-KSMG-AntiPhishing: NotDetected, bases: 2025/10/27 22:51:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2025/10/27 19:18:00 #27802467 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Alexander! 1. > The second CommandCounterIncrement() is needed to make the renamed > relation visible within our transaction. Why do we need the first >one? I see tests pass without it. It's strange. If I comment the first "CommandCounterIncrement();", in block ----------------------------------------------------------------------- /* * We must bump the command counter to make the split partition tuple * visible for renaming. */ CommandCounterIncrement(); /* Rename partition. */ sprintf(tmpRelName, "split-%u-%X-tmp", RelationGetRelid(rel), ...); RenameRelationInternal(splitRelOid, tmpRelName, true, false); /* * We must bump the command counter to make the split partition tuple * visible after renaming. */ CommandCounterIncrement(); ----------------------------------------------------------------------- , I got the error "ERROR: tuple already updated by self" in the partition_split.sql test (Ubuntu). If I comment the second "CommandCounterIncrement();", I got the error "ERROR: relation "sales_others" already exists" in the same test. 2. >The branch handling null value in the outer loop, uses null2 flag from >the inner loop. I think for the null value of the outer loop we still >need to run inner loop to search for the matching null value. This code looks a little confusing, but it probably works correctly. This can be verified using two typical examples: ----------------------------------------------------------------------- list1: (NULL, 1) list2: (2, NULL) (1) isnull1 = true, (2) "if (isnull1) lappend(NULL)" ----------------------------------------------------------------------- list1: (1, NULL) list2: (NULL, 2) (1) isnull2 = true, (2) "if (isnull2) lappend(NULL)" ----------------------------------------------------------------------- In both cases, we return from the function immediately after lappend. This works because we need to find exactly one repeating value. -- With best regards, Dmitry Koval Postgres Professional: http://postgrespro.com