diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c index 2398bdabf0d..00d65a53aca 100644 --- a/src/backend/executor/nodeSort.c +++ b/src/backend/executor/nodeSort.c @@ -263,10 +263,10 @@ ExecInitSort(Sort *node, EState *estate, int eflags) outerTupDesc = ExecGetResultType(outerPlanState(sortstate)); /* - * We perform a Datum sort when we're sorting just a single column, - * otherwise we perform a tuple sort. + * We perform a Datum sort when we're sorting just a single column by a + * single key, otherwise we perform a tuple sort. */ - if (outerTupDesc->natts == 1) + if (outerTupDesc->natts == 1 && node->numCols == 1) sortstate->datumSort = true; else sortstate->datumSort = false;