Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: 2025-05-21 14:54:48
Message-ID: CACJufxE9FDqaE=xbxT-Ujk_G=wW-PeW0TrOB11E8n3-A+FP-GA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 21, 2025 at 8:30 PM Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru> wrote:
>
> Hi!
>
> >per https://www.postgresql.org/docs/current/sql-altertable.html
> >"You must own the table to use ALTER TABLE."
> >That means the current user must own the to be SPLITed partition.
>
> Last statement may be incorrect (if the logic is different).
> Current user can attach another user's partition. If current user can
> change (attach) another user's partition, why can't he split the
> partition? After attach, partition is part of current user's table, and
> current user can change his own table. (Moreover, the owner of the new
> partitions is the same as the owner of the split partition.)
>
> --

I think if he can attach another partition, then he can split the partition.
currently ALTER TABLE ATTACH PARTITION requires the current user
both own the partitioned table and the to be attached partition.

for example:

begin;
create role alice;
create role bob;
GRANT all privileges on schema public to alice;
GRANT all privileges on schema public to bob;
set role bob;
create table at_partitioned (a int, b text) partition by range (a);
set role alice;
create table at_part_2 (b text, a int);
set role bob;
alter table at_partitioned attach partition at_part_2 for values from
(1000) to (2000); --should error
rollback;

----------------
begin;
create role alice;
create role bob;
GRANT all privileges on schema public to alice;
GRANT all privileges on schema public to bob;
set role bob;
create table at_partitioned (a int, b text) partition by range (a);
set role alice;
create table at_part_2 (b text, a int);
alter table at_partitioned attach partition at_part_2 for values from
(1000) to (2000); --should error
rollback;

P.S. maybe using sql examples can illustrate the idea more intuitively,
sometimes words may cause confusion.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Scott Mead 2025-05-21 14:55:08 Re: Disable parallel query by default
Previous Message Robert Haas 2025-05-21 14:28:47 Re: plan shape work