Eng 6436 distinct reroute

I do not get what you mean, the case that you mention seems not fall into the IF case.

if (groupbyElement == null && havingElement == null && m_distinct) {}

It only handles the query without GROUP BY, without HAVING, but it has a DISTINCT. The others cases stay unchanged.