I've got a database with movies, and I wanted to extract every person, who starred in movies from the year 2004, ordered by birth. I've tried different querys which are doing the same, but the first one takes more than 10 times longer to execute than the other. Can someone explain why this happens? (I was using the DB Browser for SQLite, but on the CLI the same thing happens)
First query (exec time about 12-13 Seconds):
SELECT DISTINCT people.name
FROM people
JOIN stars ON people.id = stars.person_id
JOIN movies ON movies.id = stars.movie_id
WHERE movies.year = 2004
ORDER BY people.birth
Second query (exec time about 1-2 Seconds)
SELECT DISTINCT people.name
FROM movies
JOIN stars ON movies.id = stars.movie_id
JOIN people ON stars.person_id = people.id
WHERE movies.year = 2004
ORDER BY people.birth
DB File: Google Drive (Dont know where to host this any other way sorry :/ )