improved performance of DISTINCT metric function