sql query joins multiple tables - too slow (8 tables)

前端 未结 8 2041
借酒劲吻你
借酒劲吻你 2020-11-30 23:22

i\'m trying to join 8 tables into one in order to create index used by other application, my query is like : (my mysql skill\'s very amateur)

SELECT t1_id, t         


        
8条回答
  •  抹茶落季
    2020-11-30 23:46

    How much data are we talking about ? It might be you have a lot of data and as the where clause is being run at the end of the query process you are joining huge volumes of data before filtering it.

    In that case its better to filter the data as soon as possible so if you can restrict the data from T1 in the first inner select all the other joins will join to a more limited set of data.

    Select  from
    (
    Select * from t1 where t1_id = t1_value
    ) t1
    
    Inner join t2
    on t1.ID = t2.ID
    ...
    

    if its not masses of data; check your indexes are correct then check server type things; index fragmentation; disk queues etc.

提交回复
热议问题