1

I want to see the execution plan of a query to find out why it is slow, but ANALYZE does not seem to work, it throws an error on the same query that EXPLAIN accepts.

MariaDB [dbx]> explain select `id` from `pics` where `user_id` = '3';
+------+-------------+-------+------+---------------+---------+---------+-------+------+-------+
| id   | select_type | table | type | possible_keys | key     | key_len | ref   | rows | Extra |
+------+-------------+-------+------+---------------+---------+---------+-------+------+-------+
|    1 | SIMPLE      | pics  | ref  | user_id       | user_id | 4       | const | 1087 |       |
+------+-------------+-------+------+---------------+---------+---------+-------+------+-------+
1 row in set (0.00 sec)

MariaDB [dbx]> analyze select `id` from `pics` where `user_id` = '3';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select `id` from `pics` where `user_id` = '3'' at line 1

I use mysql Ver 15.1 Distrib 10.0.14-MariaDB, for Linux (x86_64) using readline 5.1

1 Answer 1

1

EXPLAIN will get the execution plan for a query

ANALYZE TABLE recalculates the index statistics. So just run

ANALYZE TABLE `pics`;

Give it a Try !!!

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.