mirror of
https://github.com/postgres/postgres.git
synced 2025-11-03 09:13:20 +03:00
Support Parallel Append plan nodes.
When we create an Append node, we can spread out the workers over the subplans instead of piling on to each subplan one at a time, which should typically be a bit more efficient, both because the startup cost of any plan executed entirely by one worker is paid only once and also because of reduced contention. We can also construct Append plans using a mix of partial and non-partial subplans, which may allow for parallelism in places that otherwise couldn't support it. Unfortunately, this patch doesn't handle the important case of parallelizing UNION ALL by running each branch in a separate worker; the executor infrastructure is added here, but more planner work is needed. Amit Khandekar, Robert Haas, Amul Sul, reviewed and tested by Ashutosh Bapat, Amit Langote, Rafia Sabih, Amit Kapila, and Rajkumar Raghuwanshi. Discussion: http://postgr.es/m/CAJ3gD9dy0K_E8r727heqXoBmWZ83HwLFwdcaSSmBQ1+S+vRuUQ@mail.gmail.com
This commit is contained in:
@@ -242,6 +242,7 @@ _copyAppend(const Append *from)
|
||||
*/
|
||||
COPY_NODE_FIELD(partitioned_rels);
|
||||
COPY_NODE_FIELD(appendplans);
|
||||
COPY_SCALAR_FIELD(first_partial_plan);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
@@ -1249,6 +1249,44 @@ list_copy_tail(const List *oldlist, int nskip)
|
||||
return newlist;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sort a list using qsort. A sorted list is built but the cells of the
|
||||
* original list are re-used. The comparator function receives arguments of
|
||||
* type ListCell **
|
||||
*/
|
||||
List *
|
||||
list_qsort(const List *list, list_qsort_comparator cmp)
|
||||
{
|
||||
ListCell *cell;
|
||||
int i;
|
||||
int len = list_length(list);
|
||||
ListCell **list_arr;
|
||||
List *new_list;
|
||||
|
||||
if (len == 0)
|
||||
return NIL;
|
||||
|
||||
i = 0;
|
||||
list_arr = palloc(sizeof(ListCell *) * len);
|
||||
foreach(cell, list)
|
||||
list_arr[i++] = cell;
|
||||
|
||||
qsort(list_arr, len, sizeof(ListCell *), cmp);
|
||||
|
||||
new_list = (List *) palloc(sizeof(List));
|
||||
new_list->type = list->type;
|
||||
new_list->length = len;
|
||||
new_list->head = list_arr[0];
|
||||
new_list->tail = list_arr[len - 1];
|
||||
|
||||
for (i = 0; i < len - 1; i++)
|
||||
list_arr[i]->next = list_arr[i + 1];
|
||||
|
||||
list_arr[len - 1]->next = NULL;
|
||||
pfree(list_arr);
|
||||
return new_list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Temporary compatibility functions
|
||||
*
|
||||
|
||||
@@ -399,6 +399,7 @@ _outAppend(StringInfo str, const Append *node)
|
||||
|
||||
WRITE_NODE_FIELD(partitioned_rels);
|
||||
WRITE_NODE_FIELD(appendplans);
|
||||
WRITE_INT_FIELD(first_partial_plan);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -1600,6 +1600,7 @@ _readAppend(void)
|
||||
|
||||
READ_NODE_FIELD(partitioned_rels);
|
||||
READ_NODE_FIELD(appendplans);
|
||||
READ_INT_FIELD(first_partial_plan);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user