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 `notes` ADD INDEX `notes_idx_start_time` (`start_time`);
SELECT
(a.start_time + a.duration) AS free_after
FROM
notes a
WHERE
NOT EXISTS (
SELECT
1
FROM
notes b
WHERE
b.start_time BETWEEN (a.start_time + a.duration) AND (
a.start_time + a.duration
) + INTERVAL '$duration' SECOND
)
AND (
a.start_time + a.duration
) BETWEEN '$begin_time' AND '$end_time'