MySQL noob here.
I'm trying to run the following statement to sakila database
EXPLAIN SELECT * FROM actor as a
INNER JOIN film_actor as fa on a.actor_id = fa.actor_id
INNER JOIN film AS f ON fa.film_id = f.film_id;
And the output is
id| select_type| table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra
'1', 'SIMPLE', 'a', NULL, 'ALL', 'PRIMARY', NULL, NULL, NULL, '200', '100.00', NULL
'1', 'SIMPLE', 'fa', NULL, 'ref', 'PRIMARY,idx_fk_film_id', 'PRIMARY', '2', 'sakila.a.actor_id', '27', '100.00', NULL
'1', 'SIMPLE', 'f', NULL, 'eq_ref','PRIMARY', 'PRIMARY', '2', 'sakila.fa.film_id', '1', '100.00', NULL
actor table contains actor_id as PK.
film_actor table contains actor_id and film_id as a composite primary key plus idx_fk_film_id as an index on film_id attribute.
film table contains film_id as PK.
When I look at the query plan I noticed that there's ALL under the type column for the actor table which means a full table scan, does anyone know why MySQL didn't use the index on actor_id to search? Does MySQL execute the query from the first line to the bottom line sequentially shown in the output (Although the ids are all 1)?
actoris quite small: only 200 rows.sakila.a.actor_idunder therefcolumn is in the same row with tablefa(film_actortable) instead ofactor?sakila.a.actor_idshould be indexed inactortable. I don't get it. Does it meanfilm_actor_tableis using the index ofactortable?sakila.actor_idis short forsakila.actor.actor_id. This is just the database.table.column which is referring to this join column.