1 Use Subqueries to Count Distinct 50X Faster
2 Let's start with a simple query we run all the time: Which dashboards do most users visit?
3 It's slow because the database is iterating over all the logs and all the dashboards, then joining them, then sorting them, all before getting down ..