Improved aggregation optimizer

Improved aggregation optimizer- less queries, fixed MySQLOptimizer tuples=n optimization not being called