Performance issue with count distinct