对以前修复的bug进行重构和调整

This commit is contained in:
luozihao
2022-11-03 10:41:57 +08:00
parent 6179070ae2
commit 7742ea9f3a

View File

@ -170,8 +170,6 @@ static void deinit_optimizer_context(PlannerGlobal* glob);
static void check_index_column();
static bool check_sort_for_upsert(PlannerInfo* root);
static bool IsSupportMakeSort(List* pathkeys);
extern void PushDownFullPseudoTargetlist(PlannerInfo *root, Plan *topNode, Plan *botNode,
List *fullEntryList);
@ -3944,6 +3942,7 @@ static Plan* grouping_planner(PlannerInfo* root, double tuple_fraction)
&ordOperators);
} else {
/* empty window specification, nothing to sort */
current_pathkeys = NIL;
partNumCols = 0;
partColIdx = NULL;
partOperators = NULL;
@ -8092,9 +8091,8 @@ static Plan* mark_windowagg_stream(
Plan* gatherPlan = NULL;
Sort* sortPlan = NULL;
SimpleSort* streamSort = NULL;
bool isSupportMakeSort = IsSupportMakeSort(pathkeys);
if (isSupportMakeSort) {
if (pathkeys != NIL) {
sortPlan = make_sort_from_pathkeys(root, bottomPlan, pathkeys, -1.0);
streamSort = makeNode(SimpleSort);
@ -8112,7 +8110,7 @@ static Plan* mark_windowagg_stream(
* If have pathkeys, we can push down Sort to Datanode and then merge partial
* sorted results in RemoteQuery.
*/
if (isSupportMakeSort) {
if (pathkeys != NIL) {
gatherPlan = make_simple_RemoteQuery((Plan*)sortPlan, root, false);
if (IsA(gatherPlan, RemoteQuery)) {
((RemoteQuery*)gatherPlan)->sort = streamSort;
@ -8126,7 +8124,7 @@ static Plan* mark_windowagg_stream(
if (((unsigned int)u_sess->attr.attr_sql.cost_param & COST_ALTERNATIVE_MERGESORT) ||
root->is_under_recursive_cte) {
gatherPlan = make_stream_plan(root, bottomPlan, NIL, 1.0);
if (isSupportMakeSort)
if (pathkeys != NIL)
gatherPlan = (Plan*)make_sort_from_pathkeys(root, gatherPlan, pathkeys, -1.0);
} else {
bool single_node =
@ -8169,7 +8167,7 @@ static Plan* mark_windowagg_stream(
if (!single_node) {
gatherPlan = make_stream_plan(root, bottomPlan, NIL, 1.0);
pick_single_node_plan_for_replication(gatherPlan);
if (isSupportMakeSort)
if (pathkeys != NIL)
((Stream*)gatherPlan)->sort = streamSort;
} else
gatherPlan = bottomPlan;
@ -14680,16 +14678,3 @@ bool check_stream_for_loop_fetch(Portal portal)
portal->hasStreamForPlpgsql = has_stream;
return has_stream;
}
static bool IsSupportMakeSort(List* pathkeys)
{
ListCell* i = NULL;
foreach (i, pathkeys) {
PathKey* pathkey = (PathKey*)lfirst(i);
if (pathkey != NULL && pathkey->pk_eclass->ec_members != NIL) {
return true;
}
}
return false;
}