Does the following query use full table scan?
If so, is there a way to avoid the full table scan?
SELECT a.title,
COUNT(*) AS `count`
FROM b
JOIN a ON a.id = b.a_id
GROUP BY b.a_id
Please note that following indexes exist:
a PRIMARY id
b PRIMARY c_id THEN a_id
b INDEX a_id
Here are the results of explain:
id select_type table type possible_keys key ref rows extra
--------------------------------------------------------------------------------------
1 SIMPLE b index a_id a_id NULL 7 Using index
1 SIMPLE a eq_ref PRIMARY PRIMARY dev.b.a_id 1
The explain output is pretty clear that it is using indexes at every stage. A full table scan would be indicated by “ALL” under the
typecolumn. This looks like it will use the indexes to access exactly those records from which you need data. (The counting is also done using only the index.) See here for more info on interpreting the output of EXPLAIN.