I'm trying to build a query for search page this my first query, and this is very fast the results load within Milli seconds
$query is php variable which is search text
$sql="SELECT * FROM
tbl_product
WHERE
((tbl_product.pd_name LIKE '%$query%')
OR (tbl_product.pd_art LIKE '%$query%')
OR (tbl_product.pd_srkw LIKE '%$query%'))
AND pd_bestsell <> 1
ORDER BY RAND()";
But when i build a query with search suggestions table it's very slow and take 2-4 seconds for load. our server is very powerful dedicated one so it cannot be a issue with server.
sgtexts= keep suggestion texts
sgproduct =keep products ids on suggestion table
$sql="SELECT * FROM
tbl_product,tbl_suggetions
WHERE
((tbl_product.pd_name LIKE '%$query%')
OR (tbl_product.pd_art LIKE '%$query%')
OR (tbl_product.pd_srkw LIKE '%$query%')
OR (tbl_suggetions.sgtexts LIKE '%$query%'
AND tbl_product.pd_id=tbl_suggetions.sgproduct))
AND pd_bestsell <> 1
GROUP BY pd_id
ORDER BY RAND()";
can anyone help me for optimize second query please
EXPLAINshould give you the answer. dev.mysql.com/doc/refman/5.7/en/explain.htmltbl_suggetions.sgtextsindexed? And isn't suggetions a typo?