I have a MySQL inner joins that hops 4 tables like this:
Select users.id as id, import_logs.id as import_log_id from users
inner join user_infos on users.id = user_infos.user_id
inner join import_entries on user_info.entry_id = import_entries.entry_id
inner join import_logs on import_entries.import_id = import_logs.id
where users.org_id = 100 and improt_logs.import_date > '2017-01-01'
Basically I have a users
table that is linked to user_infos
table through id. user_infos
is linked to import_entries
table through an entry_id
, and import_entries
is linked to import_logs
table through a import_id
. I would like to hop different tables to get user's id and their corresponding import logs import id. Given that there's no other ways to filter down tables further except for users.org_id and import_logs.import_date, how would I optimize this query?
This query runs fine with small tables, but when the table gets big, it can be very slow. Any insights on how to optimize it? (subqueries?)