Performance tuning by avoiding distinct

Database

Performance tuning by avoiding distinct


hi,

I have a complex query with multiple columns in the group by clause. Also, in the select list there is a count(distinct), because of which the entire group by aggregation is performed twice.

If I provide a small sample of the query, it is like below:

Select c1, sum(c2), count(c2),count(distinct c4) from ss_tst group by c1

In my actualy query, instead of having only column c1 in the group by clause, there are multiple columns, and the column in the Select count(distinct) is not part of the Group By.
I need to avoid this count distinct as it is causing the entire aggregation to be performed twice.

Kindly provide your suggestions on tuning this query by avoiding the distinct clause.

Thanks in advance!