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 `sessions` ADD INDEX `sessions_idx_str_session_date_e` (`str_to_date_concat_date_format_session`,`date_format_session_stop_e`);
ALTER TABLE `sessions` ADD INDEX `sessions_idx_str_session_date_d` (`str_to_date_concat_date_format_session`,`date_format_session_stop_y_m_d`);
SELECT
date_format(t.`session_stop`,
'%d') AS `session_stop`,
sum(t.`energy_used` / 1000) AS `csum`,
(SELECT
(SUM(a.`energy_used`) / 1000)
FROM
`sessions` a
WHERE
a.date_format_session_stop_y_m_d <= a.date_format_session_stop_y_m_d
AND t.str_to_date_concat_date_format_session = str_to_date(concat(date_format(now(), '%Y-%m'), '-01'), '%Y-%m-%d')
ORDER BY
str_to_date(date_format(a.`session_stop`,
'%e'),
'%d') ASC) AS `sum`
FROM
`sessions` t
WHERE
t.str_to_date_concat_date_format_session = str_to_date(concat(date_format(now(), '%Y-%m'), '-01'), '%Y-%m-%d')
GROUP BY
t.date_format_session_stop_e
ORDER BY
str_to_date(date_format(t.`session_stop`,
'%d'),
'%d') ASC