Fix a bug where composite SELECT DISTINCT would return duplicate rows.