This change looks wrong. The only case when finalNeedFix changes whether a projection node is needed is when handleMVBasedMultiPartQuery put the reagg at the root of the plan.  It should not change this test for any other agg that might be at the top of the plan. It would be better to keep this test as it is. Instead, handleMVBasedMultiPartQuery can detect when it needs a projection node above the reagg and can add one there immediately. Actually, this should be very simple since the outputschema for that projection node should be just the outputschema based on the original matview's scan columns (without the extra group by columns).