Junior — Middle
Which command is used to determine the indexes involved in the executed SQL query?
sobes.tech AI
Answer from AI
To determine the indexes involved in a running SQL query, the EXPLAIN command is usually used. It shows the execution plan of the query, including information about index usage.
Example for MySQL:
EXPLAIN SELECT * FROM users WHERE email = 'example@example.com';
The result will show which indexes are used, the type of table access, and other details that help optimize the query.
In PHP, to execute such a query, you can use PDO or mysqli, for example:
$stmt = $pdo->query("EXPLAIN SELECT * FROM users WHERE email = 'example@example.com'");
$explain = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($explain);
This will help understand which indexes are involved and how to optimize the query.