WL#3220: Loose index scan for aggregate functions

Affects: Server-5.5   —   Status: Complete

Currently MySQL executes COUNT(DISTINCT expr1, ..., exprN) by executing
a table or index scan that fills a temporary data structure (table or
tree) with all distinct values, and then returning the count of the
distinct values in that temporary data structure.

In cases when there are applicable indexes it is possible to execute
such queries much faster via the "loose index scan" technique employed
for execution of GROUP BY and DISTINCT queries, as implemented by
WL#1724.

This task should extend the loose index scan access method implemented
for GROUP BY/DISTINCT queries (WL#1724), so that it can be used to
optimize and execute queries with COUNT(DISTINCT ...).

If time permits, the task should also apply the same optimization to
queries with AVG(DISTINCT ...) and SUM(DISTINCT ...). Finally, it
might be also quite easy to extend the task to compute
GROUP_CONCAT([DISTINCT] expr, ...) expressions via the same technique,
depending on how different is its implementation from that of COUNT,
AVG and SUM.