Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaMt2-0001jn-2O for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Sep 2022 19:57:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oaMt0-0007r5-AC for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Sep 2022 19:56:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaMsz-0007qq-VC for pgsql-hackers@lists.postgresql.org; Mon, 19 Sep 2022 19:56:58 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oaMsx-0007HI-Fi for pgsql-hackers@lists.postgresql.org; Mon, 19 Sep 2022 19:56:56 +0000 Received: by mail-lj1-x22a.google.com with SMTP id h3so494075lja.1 for ; Mon, 19 Sep 2022 12:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=0zXhT/aWRdo17Ikg0EPK1/1EgucIFA6pcWEwqVAeq1I=; b=AmQET9V8P7Lb8E6xsYFkSkVpuPzph6lGOY+yAM81vS69ZTpKCQyT8v1tOiWNbyeoUv Dnw7zk0WaxkgleRJ+hp3fLZ+L1zkQeTNkVidDBFW514sqO6s/XuhP3Ou9eEwYotv3Tzo ES4JC4L0RL1R+QpP1FdhUreVHh5R/NdNolkQehNC14tc/BpEz2YU2xlMX+PORSA7NgX4 dnlyiUBx0tvzWkXBPwcUSc4EiPeBth/p7loizW0XcLhUL1uc12bN7LXIu1gBKCQ0lFsL w1YKu1hQDA6e943qGTohx/6xkNtT+x38Ei5AKPLVMXyHT30NF8HwK1toDv7WB4Vb370h 5/4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=0zXhT/aWRdo17Ikg0EPK1/1EgucIFA6pcWEwqVAeq1I=; b=onkRbWgzbmrP07Lxhoe4nPeq1eG7nXiwBlE8fBzKsMgdewaZXlTcwxHe+820B0Y2eW hhXdsPxmOJgz6VXyxCWhaa7aoWvmmToH1CdWE+B+9J9mDx+wlvjskZfJjpuxzGL4OmS7 6rB37k2t19uW0cHpVBNb0Aoox0ucH78nSwiWRSGusrQCRb/MTcOCX9tylr6XVcJo4r8a Rq2S2meQAlxo4qselMTsQ9L6I4Ju7tm95CB8lT4TXpLp52iYHUGDJFUCxlK0a8gPS4Tn EkYhKleRSNDwFUqqcSgZKpeoXa4GZy5qcNRqG4TuvWAgkY6+ia4+VMNnFRqBkAwt3LUd nwfw== X-Gm-Message-State: ACrzQf0Ks3KKdsMDwPJXzoCj31FwicZGeN1m5wgU6NlMG3fR6jkeYAyr 3E4rc/1rmmSbwVOGJvtWyqH2uudNQRCJOTLb6/0= X-Google-Smtp-Source: AMsMyM6E3WhO7hpNlCxMKoK1fkSjyS3MZ7+zcvfztDRcimhs/MWUgF8dSo0uz+3o+3ZNaKM7Iae89sSp6W1X83JWXIg= X-Received: by 2002:a2e:575c:0:b0:26a:9f39:b3f7 with SMTP id r28-20020a2e575c000000b0026a9f39b3f7mr5892182ljd.315.1663617413921; Mon, 19 Sep 2022 12:56:53 -0700 (PDT) MIME-Version: 1.0 References: <163714495450.16056.3566953095730878367@malur.postgresql.org> In-Reply-To: From: Robert Haas Date: Mon, 19 Sep 2022 15:56:42 -0400 Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Dmitry Koval Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, May 31, 2022 at 5:33 AM Dmitry Koval wrote: > There are not many commands in PostgreSQL for working with partitioned > tables. This is an obstacle to their widespread use. > Adding SPLIT PARTITION/MERGE PARTITIONS operations can make easier to > use partitioned tables in PostgreSQL. > (This is especially important when migrating projects from ORACLE DBMS.) > > SPLIT PARTITION/MERGE PARTITIONS commands are supported for range > partitioning (BY RANGE) and for list partitioning (BY LIST). > For hash partitioning (BY HASH) these operations are not supported. This may be a good idea, but I would like to point out one disadvantage of this approach. If you know that a certain partition is not changing, and you would like to split it, you can create two or more new standalone tables and populate them from the original partition using INSERT .. SELECT. Then you can BEGIN a transaction, DETACH the existing partitions, and ATTACH the replacement ones. By doing this, you take an ACCESS EXCLUSIVE lock on the partitioned table only for a brief period. The same kind of idea can be used to merge partitions. It seems hard to do something comparable with built-in DDL for SPLIT PARTITION and MERGE PARTITION. You could start by taking e.g. SHARE lock on the existing partition(s) and then wait until the end to take ACCESS EXCLUSIVE lock on the partitions, but we typically avoid such coding patterns, because the lock upgrade might deadlock and then a lot of work would be wasted. So most likely with the approach you propose here you will end up acquiring ACCESS EXCLUSIVE lock at the beginning of the operation and then shuffle a lot of data around while still holding it, which is pretty painful. Because of this problem, I find it hard to believe that these commands would get much use, except perhaps on small tables or in non-production environments, unless people just didn't know about the alternatives. That's not to say that something like this has no value. As a convenience feature, it's fine. It's just hard for me to see it as any more than that. -- Robert Haas EDB: http://www.enterprisedb.com