提交 b0359e69 编写于 作者: S Sambitesh Dash 提交者: Dhanashree Kashid

Randomize output segment for non-master gather motion

Via https://github.com/greenplum-db/gporca/pull/400, ORCA will optimize
DML queries by enforcing a gather on segment instead of master, whenever
possible.

Previous to this commit, ORCA always picked the first segment to gather
on while translating the DXL-GatherMotion node to GPDB motion node.

This commit uses GPDB's hash function to select the segment to gather
on, in a round-robin fashion starting with a random segment index. This
will ensure that concurrent DML queries issued via a same session, will
be gathered on different segments to distribute the workload.
Signed-off-by: NDhanashree Kashid <dkashid@pivotal.io>
上级 a341621d
......@@ -2824,6 +2824,27 @@ gpdb::CdbHashConst
return 0;
}
// pick a segment randomly from a pool of segments using GPDB's hash function
int32
gpdb::CdbHashRandom
(
int num_segments
)
{
GP_WRAP_START;
{
CdbHash *pcdbhash = makeCdbHash(num_segments);
cdbhashinit(pcdbhash);
cdbhashnokey(pcdbhash);
return cdbhashreduce(pcdbhash);
}
GP_WRAP_END;
return 0;
}
// hash a list of const values with GPDB's hash function
int32
gpdb::CdbHashConstList
......
......@@ -1960,6 +1960,21 @@ CTranslatorDXLToPlStmt::TranslateDXLMotion
motion->motionType = MOTIONTYPE_FIXED;
// get segment id
INT segid = CDXLPhysicalGatherMotion::Cast(motion_dxlop)->IOutputSegIdx();
// if it's a gather on a segment, pick a segment from
// available segments using GPDB's hash function.
// This function outputs a segment index in a round
// robin fashion using a random segment index as the
// starting point.
// This ensures that concurrent DML queries issued via
// a same session, use a different output segment each
// time a gather on segment is needed.
if (segid >= 0)
{
segid = gpdb::CdbHashRandom(m_num_of_segments);
GPOS_ASSERT(segid >= 0);
}
motion->numOutputSegs = 1;
motion->outputSegIdx = (INT *) gpdb::GPDBAlloc(sizeof(INT));
*(motion->outputSegIdx) = segid;
......
......@@ -595,7 +595,10 @@ namespace gpdb {
// hash a const value with GPDB's hash function
int32 CdbHashConst(Const *constant, int num_segments);
// pick a random segment from a pool of segments using GPDB's hash function
int32 CdbHashRandom(int num_segments);
// hash a list of const values with GPDB's hash function
int32 CdbHashConstList(List *constants, int num_segments);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册