In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `TABLE1` ADD INDEX `table1_idx_bltid` (`bltid`);
ALTER TABLE `TABLE2` ADD INDEX `table2_idx_id_status` (`id`,`status`);
ALTER TABLE `TABLE3` ADD INDEX `table3_idx_schdlid` (`schdlid`);
ALTER TABLE `TABLE5` ADD INDEX `table5_idx_id` (`id`);
ALTER TABLE `TABLE6` ADD INDEX `table6_idx_id` (`id`);
ALTER TABLE `TABLE7` ADD INDEX `table7_idx_id` (`id`);
SELECT
sum(this_.a + this_.b + this_.c + this_.d + this_.e + this_.f + this_.g + this_.h + this_.i + this_.j) AS sent,
sum(this_.a + this_.b + this_.c + this_.d + this_.e) AS delivered,
d2_.name AS y2_,
d2_.id AS y3_,
concat(CAST(b4_.id AS char),
'.',
c1_.name,
'.',
cs5_.name,
'_',
date_format(b4_.createddate,
'%Y-%b-%d %H:%i:%s')) AS allias_concat,
b4_.id AS y5_,
this_.year AS y6_,
this_.month AS y7_,
this_.day AS y8_,
this_.weekday AS y9_,
this_.weekofmonth AS y10_,
this_.bltid AS y11_,
b4_.id AS y12_,
c1_.name AS y13_,
cs5_.name AS y14_,
b4_.createddate AS y15_,
cs5_.subject AS y16_,
d2_.name AS y17_
FROM
TABLE1 this_
INNER JOIN
TABLE2 c1_
ON this_.cgnid = c1_.id
INNER JOIN
TABLE3 b4_
ON this_.bltid = b4_.id
INNER JOIN
TABLE4 csc6_
ON b4_.schdlid = csc6_.id
INNER JOIN
TABLE5 cs5_
ON this_.constid = cs5_.id
LEFT OUTER JOIN
TABLE6 f3_
ON this_.fid = f3_.id
INNER JOIN
TABLE7 d2_
ON this_.dptid = d2_.id
WHERE
(
f3_.name <> 'TRASH'
OR c1_.fid = 0
)
AND c1_.status <> 'K'
AND d2_.id IN (
1
)
AND (
(
b4_.createddate BETWEEN '2015-02-01 10:30:00' AND '2015-05-13 10:29:59'
AND csc6_.isrealtime = 'N'
)
OR (
csc6_.isrealtime = 'Y'
AND this_.bltdate BETWEEN '2015-02-01 10:30:00' AND '2015-05-13 10:29:59'
)
)
GROUP BY
d2_.id,
concat(CAST(b4_.id AS char),
'.',
c1_.name,
'.',
cs5_.name,
'_',
date_format(b4_.createddate,
'%Y-%b-%d %H:%i:%s')),
b4_.id,
this_.year,
this_.month,
this_.day,
this_.bltid
ORDER BY
NULL LIMIT 20001