I have a site in Laravel that does the following SQL queries, and combined they take like 1.8 seconds. The execution time is taken from the profiler toolbar
675.81ms
SELECT definitions.*, terms.term, GROUP_CONCAT(DISTINCT(tags.name) SEPARATOR ",") AS tags FROM definitions INNER JOIN terms ON terms.id = definitions.term_id LEFT JOIN definition_tag ON definitions.id = definition_tag.definition_id LEFT JOIN tags ON tags.id = definition_tag.tag_id WHERE approved = 1 GROUP BY definitions.id ORDER BY id ASC LIMIT 2
0.21ms
SELECT * FROM `settings` WHERE `name` = 'no_homepage_random' LIMIT 1
636.11ms
SELECT definitions.*, terms.term, GROUP_CONCAT(DISTINCT(tags.name) SEPARATOR ",") AS tags FROM definitions INNER JOIN terms ON terms.id = definitions.term_id LEFT JOIN definition_tag ON definitions.id = definition_tag.definition_id LEFT JOIN tags ON tags.id = definition_tag.tag_id WHERE approved = 1 GROUP BY definitions.id ORDER BY RAND() LIMIT 1
628.68ms
SELECT definitions.*, terms.term, GROUP_CONCAT(DISTINCT(tags.name) SEPARATOR ",") AS tags FROM definitions INNER JOIN terms ON terms.id = definitions.term_id LEFT JOIN definition_tag ON definitions.id = definition_tag.definition_id LEFT JOIN tags ON tags.id = definition_tag.tag_id WHERE approved = 1 GROUP BY definitions.id ORDER BY id DESC LIMIT 3
I want to speed up sql queries in general, and also im kinda confused why it only takes 0.0049 seg running the same queries in phpmyadmin. Website is in a shared hosting. What can I do to improve?