1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Add a Gather Merge executor node.

Like Gather, we spawn multiple workers and run the same plan in each
one; however, Gather Merge is used when each worker produces the same
output ordering and we want to preserve that output ordering while
merging together the streams of tuples from various workers.  (In a
way, Gather Merge is like a hybrid of Gather and MergeAppend.)

This works out to a win if it saves us from having to perform an
expensive Sort.  In cases where only a small amount of data would need
to be sorted, it may actually be faster to use a regular Gather node
and then sort the results afterward, because Gather Merge sometimes
needs to wait synchronously for tuples whereas a pure Gather generally
doesn't.  But if this avoids an expensive sort then it's a win.

Rushabh Lathia, reviewed and tested by Amit Kapila, Thomas Munro,
and Neha Sharma, and reviewed and revised by me.

Discussion: http://postgr.es/m/CAGPqQf09oPX-cQRpBKS0Gq49Z+m6KBxgxd_p9gX8CKk_d75HoQ@mail.gmail.com
This commit is contained in:
Robert Haas
2017-03-09 07:40:36 -05:00
parent a72f0365db
commit 355d3993c5
27 changed files with 1355 additions and 16 deletions

View File

@ -457,6 +457,35 @@ _outGather(StringInfo str, const Gather *node)
WRITE_BOOL_FIELD(invisible);
}
static void
_outGatherMerge(StringInfo str, const GatherMerge *node)
{
int i;
WRITE_NODE_TYPE("GATHERMERGE");
_outPlanInfo(str, (const Plan *) node);
WRITE_INT_FIELD(num_workers);
WRITE_INT_FIELD(numCols);
appendStringInfoString(str, " :sortColIdx");
for (i = 0; i < node->numCols; i++)
appendStringInfo(str, " %d", node->sortColIdx[i]);
appendStringInfoString(str, " :sortOperators");
for (i = 0; i < node->numCols; i++)
appendStringInfo(str, " %u", node->sortOperators[i]);
appendStringInfoString(str, " :collations");
for (i = 0; i < node->numCols; i++)
appendStringInfo(str, " %u", node->collations[i]);
appendStringInfoString(str, " :nullsFirst");
for (i = 0; i < node->numCols; i++)
appendStringInfo(str, " %s", booltostr(node->nullsFirst[i]));
}
static void
_outScan(StringInfo str, const Scan *node)
{
@ -2016,6 +2045,17 @@ _outLimitPath(StringInfo str, const LimitPath *node)
WRITE_NODE_FIELD(limitCount);
}
static void
_outGatherMergePath(StringInfo str, const GatherMergePath *node)
{
WRITE_NODE_TYPE("GATHERMERGEPATH");
_outPathInfo(str, (const Path *) node);
WRITE_NODE_FIELD(subpath);
WRITE_INT_FIELD(num_workers);
}
static void
_outNestPath(StringInfo str, const NestPath *node)
{
@ -3473,6 +3513,9 @@ outNode(StringInfo str, const void *obj)
case T_Gather:
_outGather(str, obj);
break;
case T_GatherMerge:
_outGatherMerge(str, obj);
break;
case T_Scan:
_outScan(str, obj);
break;
@ -3809,6 +3852,9 @@ outNode(StringInfo str, const void *obj)
case T_LimitPath:
_outLimitPath(str, obj);
break;
case T_GatherMergePath:
_outGatherMergePath(str, obj);
break;
case T_NestPath:
_outNestPath(str, obj);
break;