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 1shIbZ-00FzJP-Ax for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Aug 2024 00:56:41 +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 1shIbX-007fPa-1V for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Aug 2024 00:56: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 1shIbW-007fOf-K8 for pgsql-hackers@lists.postgresql.org; Fri, 23 Aug 2024 00:56:39 +0000 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1shIbU-000z1O-Aw for pgsql-hackers@lists.postgresql.org; Fri, 23 Aug 2024 00:56:37 +0000 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-e16582cb9f9so1134727276.0 for ; Thu, 22 Aug 2024 17:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724374595; x=1724979395; 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=qqXnUqeqQ+kVMjCs1kxrlUMIPXhqlj5QBdXgni37ybM=; b=YI+wtIMVnxUHtNN4Rll5CujBfg59U5ahK8YhOOTBkJ+jvcL9BsBzuOFw4URRRLB2Yq mpwqBOIjGPqJ+JcJzaB8QHdJeZfcg8tv3AwzzBkfGGF0rI/viZVSdlU8Np09wG4YwL/0 50llqo2h1db70JrWZ96p+R8zgM1u/PQafT5NxnCNVdrgrGX3erGGhXqSe5VVxQdJIhNn R6QyobYjWZ7yYt8msjiYKU4NNQgb3FzydeO9MMiXiM9txBDN3f2ucZx4uNr7mAgXcPMv 7tMuG/2K4fPrNb4JUgwFLeBNX3eiXAcHDK+YobSoSF0gA/iXifjQXVy5T35wEOVwKwYr BgqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724374595; x=1724979395; 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=qqXnUqeqQ+kVMjCs1kxrlUMIPXhqlj5QBdXgni37ybM=; b=CiXdZlijK+TkHmkmaR4kmqvQNXk8x/Kci6JPSJ1ZEeVXlbsvGtRhPHomFdy9zphgyk 0BOgXLdPrCCdGKcJ1PzQgBlbWfitRPcxs/U1Pm59wblS8oO/gG2QNwsDuQ8kXVbZ+i07 wE+NpoUbGLcrbade3r2KJQXn2qIq+9Dvw8AVYZ/aKmZivm8JpIq8PhouocEtVVJB/SrU tyAj591z8doNnzCqhjnJxRwWJIOrUFerZNqGbjRLBt/7k9xctOQ+bQel9Vis4KVmM+BQ 5VfkLdGTKr+vEuJW1DrKIv3q0U0cKGL2n5mLvO46sQ9ASsCaIE5kymlHQI5BUmmRl425 C+4g== X-Forwarded-Encrypted: i=1; AJvYcCXM+duqjsSrjy17sq/VwKl/H8nX3bFGbPOZHDh55WmIsJ50hicE+rlE5qw7wB7R9ewLHEfkleus+hdtxdrH@lists.postgresql.org X-Gm-Message-State: AOJu0YxHjO/x5+6+Fq5vmmA9+kIZkgL1A2b1qXUkseITNlAcz01HzLEC BSKKNX0wOpcZ12HZ2y//naV3DrVzB4sjLhVgxeCbmkBNZlzfKvRNuQHa/ZfWHCxBsJMD8CCObXC +6ok98RTrqwi4nq3e0O9bhdoO+yv01sEgTMxn9A== X-Google-Smtp-Source: AGHT+IFO88OfhSfzjlmcvWWfjXa4L4lhm0nKx3/ckMCLtXWZL6ZJBKDKWXQalferHq6wThP8n92cxXkG604tm4goT2s= X-Received: by 2002:a05:6902:993:b0:e11:7f9a:1b82 with SMTP id 3f1490d57ef6-e17a78e590cmr886914276.14.1724374595501; Thu, 22 Aug 2024 17:56:35 -0700 (PDT) MIME-Version: 1.0 References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org> <171085858750.2046434.12246066729700037354.pgcf@coridan.postgresql.org> <909e16b4-9eda-435c-b033-8294ae4adc05@postgrespro.ru> <3a4b9c1c-3edf-4e29-9629-b4113aefb0f3@postgrespro.ru> <20240808171351.a9.nmisch@google.com> <19c1e04c-2012-4475-8460-821dd633a6ce@postgrespro.ru> <768cbb42-d3f8-45de-89ad-72861f078dc2@postgrespro.ru> In-Reply-To: From: Alexander Korotkov Date: Fri, 23 Aug 2024 03:56:23 +0300 Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Robert Haas Cc: Pavel Borisov , Dmitry Koval , Noah Misch , 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 Thu, Aug 22, 2024 at 8:25=E2=80=AFPM Robert Haas = wrote: > > On Thu, Aug 22, 2024 at 12:43=E2=80=AFPM Alexander Korotkov > wrote: > > Thank you for your feedback. Yes, it seems that there is not enough > > time to even carefully analyze all the issues in these features. The > > rule of thumb I can get from this experience is "think multiple times > > before accessing something already opened by its name". I'm going to > > revert these features during next couple days. > > Thanks, and sorry about that. I would say even "think multiple times" > is possibly not strong enough -- it might almost be "just don't ever > do it". Even if (in some particular case) the invalidation mechanism > seems to protect you from getting wrong answers, there are often holes > in that, specifically around search_path =3D foo, bar and you're > operating on an object in schema bar and an identically-named object > is created in schema foo at just the wrong time. Sometimes there are > problems even when search_path is not involved, but when it is, there > are more. > > Here, aside from the name lookup issues, there are also problems with > expression evaluation: we can't split partitions without reindexing > rows that those partitions contain, and it is critical to think > through which is going to do the evaluation and make sure it's > properly sandboxed. I think we might need > SECURITY_RESTRICTED_OPERATION here. > > Another thing I want to highlight if you do have another go at this > patch is that it's really critical to think about where every single > property of the newly-created tables comes from. The original patch > didn't consider relpersistence or tableam, and here I just discovered > that owner is also an issue that probably needs more consideration, > but it goes way beyond that. For example, I was surprised to discover > that if I put per-partition constraints or triggers on a partition and > then split it, they were not duplicated to the new partitions. Now, > maybe that's actually the behavior we want -- I'm not 100% positive -- > but it sure wasn't what I was expecting. If we did duplicate them when > splitting, then what's supposed to happen when merging occurs? That is > not at all obvious, at least to me, but it needs careful thought. ACLs > and rules and default values and foreign keys (both outbond and > inbound) all need to be considered too, along with 27 other things > that I'm sure I'm not thinking about right now. Some of this behavior > should probably be explicitly documented, but all of it should be > considered carefully enough before commit to avoid surprises later. I > say that both from a security point of view and also just from a user > experience point of view. Even if things aren't insecure, they can > still be annoying, but it's not uncommon in cases like this for > annoying things to turn out to also be insecure. > > Finally, if you do revisit this, I believe it would be a good idea to > think a bit harder about how data is moved around. My impression (and > please correct me if I am mistaken) is that currently, any split or > merge operation rewrites all the data in the source partition(s). If a > large partition is being split nearly equally, I think that has a good > chance of being optimal, but I think that might be the only case. 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. > You basically dodge everything in the previous paragraph in one shot, > and it seems like it would also be faster. Splitting there's no > similar get-out-of-jail free card, at least not that I can see. Even > if you add syntax that splits a partition by using INSERT/DELETE to > move some rows to a newly-created partition, you still have to make at > least one new partition. But possibly that syntax is worth having > anyway, because it would be a lot quicker in the case of a highly > asymmetric split. On the other hand, maybe even splits are much more > likely and we don't really need it. I don't know. Thank you for so valuable feedback! When I have another go over this patch I will ensure this is addressed. ------ Regards, Alexander Korotkov Supabase