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 `user_tasks` ADD INDEX `user_tasks_idx_user_id_status_created_at` (`user_id`,`status`,`created_at`);
ALTER TABLE `user_tasks` ADD INDEX `user_tasks_idx_created_at` (`created_at`);
ALTER TABLE `user_tasks` ADD INDEX `user_tasks_idx_user_id_status_created_at_2` (`user_id`,`status`,`created_at`);
SELECT
TIMEDIFF((SELECT
user_tasks.created_at
FROM
user_tasks
WHERE
user_tasks.user_id = 1
AND user_tasks.`status` = 'pending'
ORDER BY
user_tasks.created_at DESC LIMIT 1),
(SELECT
user_tasks.created_at
FROM
user_tasks
WHERE
user_tasks.user_id = 1
AND user_tasks.`status` = 'pending'
ORDER BY
user_tasks.created_at ASC LIMIT 1)) AS pending_time