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 1sjIzo-00H9pM-4u for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Aug 2024 13:46:00 +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 1sjIzm-005Jvf-AJ for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Aug 2024 13:45:58 +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 1sjIzm-005JvX-0R for pgsql-hackers@lists.postgresql.org; Wed, 28 Aug 2024 13:45:58 +0000 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sjIzd-001qm7-RP for pgsql-hackers@lists.postgresql.org; Wed, 28 Aug 2024 13:45:56 +0000 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-690ad83d4d7so61317307b3.3 for ; Wed, 28 Aug 2024 06:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724852749; x=1725457549; 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=H6TnIgVMlRUnymQzKOwzBSCxINntudE9N2f37IIi0WM=; b=MK7lEvPGeyuNClu4DQpBhmeHoYvqiMMPdPQrKLrI+sVuphrxTV1zraCNPhRKKx7Vo5 dsP73ekNhDPwACJwmHwfndzlnreUfmZMK4dpMSg5Rrk6FT0G1HvLKoe4d1hFHbE8bx0G U78axGDVxgttPyuRx1DVUgxO/MGDmt4QOy2n5kfNlIsbSfq3kVAamXtScWwEXMcFAnmW sjzPwmhDKKJep0/eOinq2R1yjENaGRS+tJEO7V8RuUWbmif3GaRVEe1giB901bAz5cZW YMsQiup5wTM59W55PWqo4/7HXZSuo6eElEcSI0KSUX6uajp5a7d4aPFswI6PlUpVZQde YQyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724852749; x=1725457549; 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=H6TnIgVMlRUnymQzKOwzBSCxINntudE9N2f37IIi0WM=; b=JeJH6hf4ufODlUR1VJtjDLqG9ndKcQTcADUeyiECDJmMCZuAic/twpt8QV6pxOyGci NUHCSam+rqeBBUc1C4z7CZeUldqGtnvh2s5Evqv+M7rRbJoddoAL4zYgWXDhxbWElM7R LCAQCQsnJvWfVvmun7Q29zF2xdbEzjZwEsn4Y3Ro7mY32F7rM1R8AEG26Gqhk/X6BhTL A6IzSDDIhlJA0CjCVaFYxweYRhElIUX+eBZthWQy+GakQaGUD8/wQu+deD87+NBby5G/ pXDjBAqK3CzcYSKxzUvc8aZWQ7kESb23xD1jlQgHURt/AvVU10hsoXO5Am8F2uOiOa2C OISQ== X-Forwarded-Encrypted: i=1; AJvYcCXMCKxLeq1xN8W0L7MTD54uLKxxSTKLp3cf47hJMoyGftecmcn5fEHcQ955k3tAqoZU+7QFQoILu8WASIud@lists.postgresql.org X-Gm-Message-State: AOJu0YxIvzIB7ImPye1++QBpaBxCf4lS4xfeEn0Ekvs5esp0ePz0cisz +ShRCmLNCeVpQZ1++ivrHNJR+kogkYuPQd+0nfiDzZheU2M5cSSckrNiM+LN5qiQKcNq3ooosLl Okcpovpdy8syewihCpmikYteXmiI= X-Google-Smtp-Source: AGHT+IHhMGW+mHr5WDyLNb/bJeuNKdU7o243bgc8SvZONgvbqKMdM6TSLBbBd/TkGTo09aqndWYCXO9b89YhEX4Ey7c= X-Received: by 2002:a05:690c:448c:b0:65f:8209:3ede with SMTP id 00721157ae682-6c62906569emr217813337b3.44.1724852748995; Wed, 28 Aug 2024 06:45:48 -0700 (PDT) MIME-Version: 1.0 References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org> <20240808171351.a9.nmisch@google.com> <19c1e04c-2012-4475-8460-821dd633a6ce@postgrespro.ru> <768cbb42-d3f8-45de-89ad-72861f078dc2@postgrespro.ru> <859476bf-3cb0-455e-b093-b8ab5ef17f0e@postgrespro.ru> In-Reply-To: <859476bf-3cb0-455e-b093-b8ab5ef17f0e@postgrespro.ru> From: Robert Haas Date: Wed, 28 Aug 2024 09:45:36 -0400 Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Dmitry Koval Cc: Alexander Korotkov , 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 Tue, Aug 27, 2024 at 2:24=E2=80=AFPM Dmitry Koval wrote: > They contains changes from reverted commits 1adf16b8fb, 87c21bb941, and > subsequent fixes and improvements including df64c81ca9, c99ef1811a, > 9dfcac8e15, 885742b9f8, 842c9b2705, fcf80c5d5f, 96c7381c4c, f4fc7cb54b, > 60ae37a8bc, 259c96fa8f, 449cdcd486, 3ca43dbbb6, 2a679ae94e, 3a82c689fd, > fbd4321fd5, d53a4286d7, c086896625, 4e5d6c4091. > I didn't include fix 04158e7fa3 into patches because Robert Haas > objected to its use. To be clear, I'm not against 04158e7fa3. I just don't think it fixes everyt= hing. > 1. Function createPartitionTable() should be rewritten using partitioned > table OID (not name) and without using ProcessUtility(). Agree. > 2. Should it be considered an error when we split a partition owned by > another user and get partitions that owned by our user? > (I think this is not a problem. Perhaps disallow merging other users' > partitions would be too strict a restriction.) > > 3. About the functional index "create index on foo (run_me(a));". > (Should we disallow merging of another user's partitions when > partitioned table has functional indexes? SECURITY_RESTRICTED_OPERATION?) > > 4. Need to decide what is correct in case there are per-partition > constraints or triggers on a split partition. They not duplicated to the > new partitions now. (But might be in this case we should have an error > or warning?) I think we want to avoid giving errors or warnings. For all of these cases, and others, we need to consider what the expected behavior is, and have test cases and documentation as appropriate. But we shouldn't think of it as "let's make it fail if the user does something that's not safe" but rather "let's figure out how to make it safe." > 5. "If we're merging partitions, wouldn't it be better to adjust the > constraints on the first partition - or perhaps the largest partition if > we want to be clever -- and insert the data from all of the others into > it? Maybe that would even have syntax that puts the user in control of > which partition survives, e.g. ALTER TABLE tab1 MERGE PARTITION part1 > WITH part2, part3, .... That would also make it really obvious to the > user what all of the properties of part1 will be after the merge: they > will be exactly the same as they were before the merge, except that the > partition constraint will have been adjusted." > (Similar optimization was proposed in [3] but was rejected [4]). Interesting. Maybe it would be a good idea to set up some test cases to see which approach is better in different cases. Like try moving data from foo1 to foo2 with DELETE..INSERT vs. creating a new table with CTAS from foo1 UNION ALL foo2 and then indexing it. I think Alexander has a good point there, but I think my point is good too so I'm not sure which way wins. --=20 Robert Haas EDB: http://www.enterprisedb.com