Can you please suggest what is the best way to optimize the queries having count or sum functions
Tables A,B
Index Information
Table A
date_id : primary key
year : Index
quarter : Index
month : Index
Table B
PayNumber and date_id : Primary Key (paynumber,date_id)
date_id : Index
status : Index
center_id : Index
select
A.year,
A.quarter,
A.month,
B.status,
count(distinct B.centre_id) as c_centre_id
from
A, B
where
B.date_id = A.date_id and
A.year in ('YR11', 'YR12') and
B.status = '2'
group by
A.year,
A.quarter,
A.month,
B.status;
Its reading approximatly 10 Million rows to get 5 rows resultset because of count function and its taking 7 to 8 sec.
Tables are in MyISAM
MySQL Version : 5.5.x
Thanks....
Tables A,B
Index Information
Table A
date_id : primary key
year : Index
quarter : Index
month : Index
Table B
PayNumber and date_id : Primary Key (paynumber,date_id)
date_id : Index
status : Index
center_id : Index
select
A.year,
A.quarter,
A.month,
B.status,
count(distinct B.centre_id) as c_centre_id
from
A, B
where
B.date_id = A.date_id and
A.year in ('YR11', 'YR12') and
B.status = '2'
group by
A.year,
A.quarter,
A.month,
B.status;
Its reading approximatly 10 Million rows to get 5 rows resultset because of count function and its taking 7 to 8 sec.
Tables are in MyISAM
MySQL Version : 5.5.x
Thanks....
Comment