Reputation: 742
The following query is running very slowly despite mytable being indexed on recdate
(mytable has > 60 M records) query takes almost 7 minutes.
select to_char(recdate, 'yyyy'), count(*)
from mytable
group by to_char(recdate, 'yyyy')
Upvotes: 1
Views: 442
Reputation: 175666
You didn't provide execution plan, but I guess function-based index would cover
CREATE INDEX mytable_idx ON mytable( to_char(recdate,'yyyy'));
query:
select to_char(recdate,'yyyy'),count(*)
from mytable
group by to_char(recdate,'yyyy')
Upvotes: 2