Skip to content

Commit a83af9e

Browse files
committed
Merge branch 'merge_concurrent' of github.com:postgrespro/pg_pathman into merge_concurrent
2 parents e155266 + 6f83fe1 commit a83af9e

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ More interesting features are yet to come. Stay tuned!
3535

3636
## Roadmap
3737

38+
* Provide a way to create user-defined partition creation\destruction callbacks (issue [#22](https://github.com/postgrespro/pg_pathman/issues/22))
3839
* Implement LIST partitioning scheme;
3940
* Optimize hash join (both tables are partitioned by join key).
4041

@@ -63,7 +64,7 @@ Done! Now it's time to setup your partitioning schemes.
6364
create_hash_partitions(relation REGCLASS,
6465
attribute TEXT,
6566
partitions_count INTEGER,
66-
partition_name TEXT DEFAULT NULL)
67+
partition_name TEXT DEFAULT NULL)
6768
```
6869
Performs HASH partitioning for `relation` by integer key `attribute`. The `partitions_count` parameter specifies the number of partitions to create; it cannot be changed afterwards. If `partition_data` is `true` then all the data will be automatically copied from the parent table to partitions. Note that data migration may took a while to finish and the table will be locked until transaction commits. See `partition_table_concurrently()` for a lock-free way to migrate data.
6970

@@ -75,7 +76,7 @@ create_range_partitions(relation REGCLASS,
7576
count INTEGER DEFAULT NULL
7677
partition_data BOOLEAN DEFAULT true)
7778

78-
create_range_partitions(relation TEXT,
79+
create_range_partitions(relation REGCLASS,
7980
attribute TEXT,
8081
start_value ANYELEMENT,
8182
interval INTERVAL,
@@ -162,15 +163,15 @@ drop_range_partition(partition TEXT)
162163
Drop RANGE partition and all its data.
163164

164165
```plpgsql
165-
attach_range_partition(relation TEXT,
166-
partition TEXT,
166+
attach_range_partition(relation REGCLASS,
167+
partition REGCLASS,
167168
start_value ANYELEMENT,
168169
end_value ANYELEMENT)
169170
```
170171
Attach partition to the existing RANGE-partitioned relation. The attached table must have exactly the same structure as the parent table, including the dropped columns.
171172

172173
```plpgsql
173-
detach_range_partition(partition TEXT)
174+
detach_range_partition(partition REGCLASS)
174175
```
175176
Detach partition from the existing RANGE-partitioned relation.
176177

@@ -349,7 +350,7 @@ SELECT tableoid::regclass AS partition, * FROM partitioned_table;
349350

350351
- All running concurrent partitioning tasks can be listed using the `pathman_concurrent_part_tasks` view:
351352
```plpgsql
352-
postgres=# SELECT * FROM pathman_concurrent_part_tasks;
353+
SELECT * FROM pathman_concurrent_part_tasks;
353354
userid | pid | dbid | relid | processed | status
354355
--------+------+-------+-------+-----------+---------
355356
dmitry | 7367 | 16384 | test | 472000 | working

README.rus.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ More interesting features are yet to come. Stay tuned!
3838

3939
## Roadmap
4040

41+
* Предоставить возможность установки пользовательских колбеков на создание\уничтожение партиции (issue [#22](https://github.com/postgrespro/pg_pathman/issues/22))
4142
* LIST-секционирование;
4243
* Оптимизация hash join для случая, когда обе таблицы секционированы по ключу join’а.
4344

@@ -65,7 +66,7 @@ CREATE EXTENSION pg_pathman;
6566
create_hash_partitions(relation REGCLASS,
6667
attribute TEXT,
6768
partitions_count INTEGER,
68-
partition_name TEXT DEFAULT NULL)
69+
partition_name TEXT DEFAULT NULL)
6970
```
7071
Выполняет HASH-секционирование таблицы `relation` по целочисленному полю `attribute`. Параметр `partitions_count` определяет, сколько секций будет создано. Если `partition_data` установлен в значение `true`, то данные из родительской таблицы будут автоматически распределены по секциям. Стоит иметь в виду, что миграция данных может занять некоторое время, а данные заблокированы. Для конкурентной миграции данных см. функцию `partition_table_concurrently()`.
7172

@@ -77,7 +78,7 @@ create_range_partitions(relation REGCLASS,
7778
count INTEGER DEFAULT NULL
7879
partition_data BOOLEAN DEFAULT true)
7980

80-
create_range_partitions(relation TEXT,
81+
create_range_partitions(relation REGCLASS,
8182
attribute TEXT,
8283
start_value ANYELEMENT,
8384
interval INTERVAL,
@@ -164,20 +165,20 @@ drop_range_partition(partition TEXT)
164165
Удаляет RANGE секцию вместе с содержащимися в ней данными.
165166

166167
```plpgsql
167-
attach_range_partition(relation TEXT,
168-
partition TEXT,
168+
attach_range_partition(relation REGCLASS,
169+
partition REGCLASS,
169170
start_value ANYELEMENT,
170171
end_value ANYELEMENT)
171172
```
172173
Присоединяет существующую таблицу `partition` в качестве секции к ранее секционированной таблице `relation`. Структура присоединяемой таблицы должна в точности повторять структуру родительской.
173174

174175
```plpgsql
175-
detach_range_partition(partition TEXT)
176+
detach_range_partition(partition REGCLASS)
176177
```
177178
Отсоединяет секцию `partition`, после чего она становится независимой таблицей.
178179

179180
```plpgsql
180-
disable_pathman_for(relation TEXT)
181+
disable_pathman_for(relation REGCLASS)
181182
```
182183
Отключает механизм секционирования `pg_pathman` для заданной таблицы. При этом созданные ранее секции остаются без изменений.
183184

@@ -348,7 +349,7 @@ SELECT tableoid::regclass AS partition, * FROM partitioned_table;
348349

349350
- Получить все текущие процессы конкурентного секционирования можно из представления `pathman_concurrent_part_tasks`:
350351
```plpgsql
351-
postgres=# SELECT * FROM pathman_concurrent_part_tasks;
352+
SELECT * FROM pathman_concurrent_part_tasks;
352353
userid | pid | dbid | relid | processed | status
353354
--------+------+-------+-------+-----------+---------
354355
dmitry | 7367 | 16384 | test | 472000 | working

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ fill_prel_with_partitions(const Oid *partitions,
384384
DisablePathman(); /* disable pg_pathman since config is broken */
385385
ereport(ERROR,
386386
(errmsg("Unknown partitioning type for relation \"%s\"",
387-
get_rel_name_or_relid(prel->key)),
387+
get_rel_name_or_relid(PrelParentRelid(prel))),
388388
errhint(INIT_ERROR_HINT)));
389389
}
390390
}
@@ -430,7 +430,7 @@ fill_prel_with_partitions(const Oid *partitions,
430430
DisablePathman(); /* disable pg_pathman since config is broken */
431431
elog(ERROR, "pg_pathman's cache for relation \"%s\" "
432432
"has not been properly initialized",
433-
get_rel_name_or_relid(prel->key));
433+
get_rel_name_or_relid(PrelParentRelid(prel)));
434434
}
435435
}
436436
#endif

src/nodes_common.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ get_partition_oids(List *ranges, int *n, const PartRelationInfo *prel)
248248
Oid *result = (Oid *) palloc(allocated * sizeof(Oid));
249249
Oid *children = PrelGetChildrenArray(prel);
250250

251+
/* If required, add parent to result */
252+
Assert(INITIAL_ALLOC_NUM >= 1);
253+
if (prel->enable_parent)
254+
result[used++] = PrelParentRelid(prel);
255+
256+
/* Deal with selected partitions */
251257
foreach (range_cell, ranges)
252258
{
253259
uint32 i;
@@ -366,6 +372,10 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
366372
{
367373
Plan *child_plan = (Plan *) lfirst(lc2);
368374
RelOptInfo *child_rel = ((Path *) lfirst(lc1))->parent;
375+
Oid child_relid;
376+
377+
/* Fetch relid of the 'child_rel' */
378+
child_relid = root->simple_rte_array[child_rel->relid]->relid;
369379

370380
/* Replace rel's tlist with a matching one */
371381
if (!cscan->scan.plan.targetlist)
@@ -380,6 +390,10 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
380390
if (!cscan->custom_scan_tlist)
381391
cscan->custom_scan_tlist = replace_tlist_varnos(child_plan->targetlist,
382392
rel);
393+
394+
/* If this is a plan for parent table, fill it with quals */
395+
if (PrelParentRelid(prel) == child_relid)
396+
child_plan->qual = get_actual_clauses(clauses);
383397
}
384398
}
385399

src/pg_pathman.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,13 @@ create_partitions_internal(Oid relid, Datum value, Oid value_type)
916916
elog(ERROR, "Could not connect using SPI");
917917

918918
/* while (value >= MAX) ... */
919-
spawn_partitions(prel->key, value, max_rvalue, prel->atttype,
920-
&interval_type_cmp, interval_binary,
919+
spawn_partitions(PrelParentRelid(prel), value, max_rvalue,
920+
prel->atttype, &interval_type_cmp, interval_binary,
921921
interval_type, true, &partid);
922922

923923
/* while (value < MIN) ... */
924-
spawn_partitions(prel->key, value, min_rvalue, prel->atttype,
925-
&interval_type_cmp, interval_binary,
924+
spawn_partitions(PrelParentRelid(prel), value, min_rvalue,
925+
prel->atttype, &interval_type_cmp, interval_binary,
926926
interval_type, false, &partid);
927927

928928
SPI_finish(); /* close SPI connection */

src/relation_info.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ typedef enum
9696
* PartRelationInfo field access macros.
9797
*/
9898

99+
#define PrelParentRelid(prel) ( (prel)->key )
100+
99101
#define PrelGetChildrenArray(prel) ( (prel)->children )
100102

101103
#define PrelGetRangesArray(prel) ( (prel)->ranges )
@@ -111,7 +113,7 @@ PrelLastChild(const PartRelationInfo *prel)
111113

112114
if (PrelChildrenCount(prel) == 0)
113115
elog(ERROR, "pg_pathman's cache entry for relation %u has 0 children",
114-
prel->key);
116+
PrelParentRelid(prel));
115117

116118
return PrelChildrenCount(prel) - 1; /* last partition */
117119
}
@@ -161,7 +163,7 @@ FreeChildrenArray(PartRelationInfo *prel)
161163
Oid child = (prel)->children[i];
162164

163165
/* If it's *always been* relid's partition, free cache */
164-
if (prel->key == get_parent_of_partition(child, NULL))
166+
if (PrelParentRelid(prel) == get_parent_of_partition(child, NULL))
165167
forget_parent_of_partition(child, NULL);
166168
}
167169

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy