0

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?)

WABBIT0111
  • 2,233
  • 2
  • 18
  • 30
  • 1
    Can you do an `EXPLAIN` of your query and edit your question with the result? – Guillaume F. Mar 13 '17 at 04:10
  • Questions about query performance ALWAYS require SHOW CREATE TABLE statements for ALL relevant tables, as well as the result of the EXPLAIN. Also, NEVER use SELECT *. Instead, always name and properly identify the columns you actually want returned. – Strawberry Mar 13 '17 at 06:35
  • Some cases sub-queries performance is better then too many joins. Please post Table Schema with data. – Muhammed Imran Hussain Mar 14 '17 at 17:25

0 Answers0