From 087730d937698cf858e5da308c434ce2fadb5502 Mon Sep 17 00:00:00 2001 From: chenze Date: Thu, 4 Feb 2021 11:20:24 +0800 Subject: [PATCH] The switchToPresortedPrefixMode function invoked in the incremental sort using ordered index will perform errors in specific cases, as follows: After reading the last tuple and judging that it does not belong to the previous group, the program breaks from the for loop. However, because the lastTuple has been set to true, the subsequent process will mistakenly think that the tuple has been put into prefixsort_state. --- src/backend/executor/nodeIncrementalSort.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/executor/nodeIncrementalSort.c b/src/backend/executor/nodeIncrementalSort.c index b53f8a0181..6f4bde1809 100644 --- a/src/backend/executor/nodeIncrementalSort.c +++ b/src/backend/executor/nodeIncrementalSort.c @@ -392,7 +392,11 @@ switchToPresortedPrefixMode(PlanState *pstate) * out its tuples, so this reference is safe. We do need to * reset the group pivot tuple though since we've finished the * current prefix key group. + * + * But we need to reset the lastTuple flag to avoid misjudging + * that we have finished all sorts. */ + lastTuple = false; ExecClearTuple(node->group_pivot); break; } -- 2.17.1