diff --git a/src/backend/executor/execGrouping.c b/src/backend/executor/execGrouping.c
index 7233f1e3c0..774e4de882 100644
--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -62,13 +62,15 @@ execTuplesMatchPrepare(TupleDesc desc,
 					   const Oid *collations,
 					   PlanState *parent)
 {
-	Oid		   *eqFunctions = (Oid *) palloc(numCols * sizeof(Oid));
+	Oid		   *eqFunctions;
 	int			i;
 	ExprState  *expr;
 
 	if (numCols == 0)
 		return NULL;
 
+	eqFunctions = (Oid *) palloc(numCols * sizeof(Oid));
+
 	/* lookup equality functions */
 	for (i = 0; i < numCols; i++)
 		eqFunctions[i] = get_opcode(eqOperators[i]);
