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:
CREATE INDEX loan_idx_id_sender_id_receiver ON Loan (id_sender,id_receiver);
SELECT
User.name
FROM
User
WHERE
EXISTS (
SELECT
1
FROM
Loan
WHERE
(
Loan.id_receiver IN (
SELECT
DISTINCT id_receiver
WHERE
date BETWEEN '2014-01-01 00:00:00' AND '2014-12-31 23:59:59'
)
AND Loan.id_receiver IN (
SELECT
DISTINCT id_receiver
WHERE
date BETWEEN '2015-01-01 00:00:00' AND '2015-12-31 23:59:59'
)
)
AND (
User.id = Loan.id_sender
)
)