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 `contacts` ADD INDEX `contacts_idx_id` (`id`);
ALTER TABLE `contacts2tags` ADD INDEX `contacts2tags_idx_contactid` (`contactid`);
SELECT
*
FROM
(SELECT
*,
IF(contacts.first_name LIKE 'Partha S'
OR contacts.last_name LIKE 'Partha S'
OR contacts.phone_number LIKE 'Partha S'
OR contacts.mobile_number LIKE 'Partha S'
OR contacts.email_address LIKE 'Partha S'
OR contacts.address LIKE 'Partha S'
OR contacts.organization LIKE 'Partha S'
OR contacts.other LIKE 'Partha S'
OR contacts.sector LIKE 'Partha S'
OR contacts.designation LIKE 'Partha S'
OR concat(contacts.first_name,
' ',
contacts.last_name) LIKE 'Partha S'
OR concat(contacts.last_name,
' ',
contacts.first_name) LIKE 'Partha S',
1,
0) AS exact,
IF((contacts.first_name LIKE '%Partha%'
OR contacts.last_name LIKE '%Partha%'
OR contacts.phone_number LIKE '%Partha%'
OR contacts.mobile_number LIKE '%Partha%'
OR contacts.email_address LIKE '%Partha%'
OR contacts.address LIKE '%Partha%'
OR contacts.organization LIKE '%Partha%'
OR contacts.other LIKE '%Partha%'
OR contacts.sector LIKE '%Partha%'
OR contacts.designation LIKE '%Partha%')
AND (contacts.first_name LIKE '%S%'
OR contacts.last_name LIKE '%S%'
OR contacts.phone_number LIKE '%S%'
OR contacts.mobile_number LIKE '%S%'
OR contacts.email_address LIKE '%S%'
OR contacts.address LIKE '%S%'
OR contacts.organization LIKE '%S%'
OR contacts.other LIKE '%S%'
OR contacts.sector LIKE '%S%'
OR contacts.designation LIKE '%S%'),
1,
0) AS normal
FROM
contacts
WHERE
EXISTS (
SELECT
DISTINCT 1
FROM
contacts AS contacts1
WHERE
(
(
tagid IN (
178
)
)
AND (
contacts.id = contacts1.id
)
)
AND (
EXISTS (
SELECT
1
FROM
contacts2tags
WHERE
contacts1.id = contacts2tags.contactid
)
)
)
) d
WHERE
exact = 1
OR normal = 1
ORDER BY
exact DESC,
d.last_name ASC LIMIT 0,
20