VID-1240 Make sure we count distinct and don't do unecessary LEFT JOINs