diff --git a/src/gausskernel/optimizer/prep/preprownum.cpp b/src/gausskernel/optimizer/prep/preprownum.cpp index 83b59d27b..3f5cbd929 100644 --- a/src/gausskernel/optimizer/prep/preprownum.cpp +++ b/src/gausskernel/optimizer/prep/preprownum.cpp @@ -51,8 +51,8 @@ void preprocess_rownum(PlannerInfo *root, Query *parse) if (quals == NULL) { return; } - /* If it includes {order by} or {group by}, can not be rewrited */ - if ((parse->sortClause != NULL) || (parse->groupClause != NULL)) { + /* If it includes aggregation function or {order by} or {group by}, can not be rewrited */ + if (parse->hasAggs || (parse->sortClause != NULL) || (parse->groupClause != NULL)) { return; } if (parse->limitCount != NULL) { diff --git a/src/gausskernel/runtime/executor/execAmi.cpp b/src/gausskernel/runtime/executor/execAmi.cpp index 5d0e4aaa8..12e7d0257 100644 --- a/src/gausskernel/runtime/executor/execAmi.cpp +++ b/src/gausskernel/runtime/executor/execAmi.cpp @@ -270,7 +270,9 @@ void ExecReScan(PlanState* node) } /* reset the rownum */ - node->ps_rownum = 0; + if (!node->do_not_reset_rownum) { + node->ps_rownum = 0; + } /* * If we have changed parameters, propagate that info. diff --git a/src/gausskernel/runtime/executor/nodePartIterator.cpp b/src/gausskernel/runtime/executor/nodePartIterator.cpp index 85a1260c8..158bfc77e 100644 --- a/src/gausskernel/runtime/executor/nodePartIterator.cpp +++ b/src/gausskernel/runtime/executor/nodePartIterator.cpp @@ -98,6 +98,7 @@ TupleTableSlot* ExecPartIterator(PartIteratorState* node) TupleTableSlot* slot = NULL; PartIterator* pi_node = (PartIterator*)node->ps.plan; EState* state = node->ps.lefttree->state; + node->ps.lefttree->do_not_reset_rownum = true; bool orig_early_free = state->es_skip_early_free; PlanState* noden = (PlanState*)node->ps.lefttree; diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index e494ecd71..e0b3eb751 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -1238,7 +1238,7 @@ typedef struct PlanState { List* plan_issues; bool recursive_reset; /* node already reset? */ bool qual_is_inited; - + bool do_not_reset_rownum; int64 ps_rownum; /* store current rownum */ } PlanState;