I wrote codes to search for a keyword from different tables. This is my code :
$stmt = $conn->prepare("SELECT DISTINCT rest.*,
MATCH(rest.resname, rest.address) AGAINST(:keyword) as a,
MATCH(cuisine.cuisine) AGAINST(:keyword) as b,
MATCH(recc.recc) AGAINST(:keyword) as c,
MATCH(emenu.menu, emenu.menudesc) AGAINST(:keyword) as d,
MATCH(facilities.fac) AGAINST(:keyword) as e,
MATCH(serv.service) AGAINST(:keyword) as f
FROM rest
INNER JOIN cuisine ON rest.resID = cuisine.resID
INNER JOIN recc ON rest.resID = recc.resID
INNER JOIN emenu ON rest.resID = emenu.resID
INNER JOIN facilities ON rest.resID = facilities.resID
INNER JOIN serv ON rest.resID = serv.resID
WHERE
(
MATCH(rest.resname, rest.address) AGAINST(:keyword)
OR MATCH(cuisine.cuisine) AGAINST(:keyword)
OR MATCH(recc.recc) AGAINST(:keyword)
OR MATCH(emenu.menu, emenu.menudesc) AGAINST(:keyword)
OR MATCH(facilities.fac) AGAINST(:keyword)
OR MATCH(serv.service) AGAINST(:keyword)
)
AND (aktif = :aktif) AND (negeri = :negeri) GROUP BY resID ORDER BY resID DESC LIMIT :rowsperpage OFFSET :offset");
$stmt->bindValue(':keyword', $_GET["keyword"], PDO::PARAM_STR);
$stmt->bindValue(':negeri', $negeri, PDO::PARAM_STR);
$stmt->bindValue(':aktif', $active, PDO::PARAM_STR);
$stmt->bindValue(':rowsperpage', (int) $rowsperpage, PDO::PARAM_INT);
$stmt->bindValue(':offset', (int) $offset, PDO::PARAM_INT);
$stmt->execute();
There were 6 tables involved in this query.
When I run this, the search runs so slow.
Can you tell me how to solve this? and how do you create index in phpMyAdmin table?