Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

Поиск
Список
Период
Сортировка
От jian he
Тема Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Дата
Msg-id CACJufxHakPGgUHfe4uThY2u_Hzq3YOP9m4B3gjZUTUm2mbVryA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Add SPLIT PARTITION/MERGE PARTITIONS commands  (Dmitry Koval <d.koval@postgrespro.ru>)
Ответы Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Список pgsql-hackers
hi.

static void checkPartition(Relation rel, Oid partRelOid)
function name checkPartition is not ideal, maybe we can change it to
CheckPartitionForMerge or MergePartitionCheck.
(attached v45-002 is error message refactoring for checkPartition,
I didn't change the name though.)


For the command:
ALTER TABLE pk MERGE PARTITIONS (pk_1, pk_2) INTO pk_1;
Acquiring AccessExclusiveLock on the partitions to be merged
(pk_1, pk_2) during transformPartitionCmdForMerge should be fine, IMHO.
Here’s why:

* The merged partitions (pk_1, pk_2) will be dropped in the end, so acquiring
AccessExclusiveLock is unavoidable for ALTER TABLE MERGE PARTITIONS.
* Taking an AccessShareLock first, then later acquiring AccessExclusiveLock
in ATExecMergePartitions unnecessarily wastes resources.
(acquire two locks, one stronger should be enough)
* Acquiring AccessExclusiveLock first helps avoid potential anomalies
caused by concurrent operations.

The attached patch refactors transformPartitionCmdForMerge and
ATExecMergePartitions based on the idea of acquiring AccessExclusiveLock on the
to be merged partitions during transformPartitionCmdForMerge


+ * Callback allows caller to check permissions or acquire additional locks
+ * prior to grabbing the relation lock.
Please see the above comments in RangeVarGetRelidExtended.

+ /*
+ * Search DEFAULT partition in the list. Lock partitions before
+ * calculating the boundary for resulting partition.
+ */
+ partOid = RangeVarGetRelid(name, AccessShareLock, false);
so the above transformPartitionCmdForMerge does not check if the
currently user have permission
or not, directly take a lock on RangeVar, name, which is a bug, we should
first do permission check then acquire a lock.

Вложения

В списке pgsql-hackers по дате отправления: