Huge tables in Tag Historian

Hi all:

I have an issue with a huge database of tag historian with Millions of registers. I am trying to find the the root cause of this huge tables . I suspect some History scanclass can has any bad setup.

In this case i am working directly with mysql . However i just only get time out in my queries.

For example i try:

select tagid,count(tagid) from sqlt_data_1_20190227 group by tagid

Any ideas?
Thanks in advance,