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

前端 未结 8 2016
借酒劲吻你
借酒劲吻你 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 <your fields> 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.

    0 讨论(0)
  • 2020-11-30 23:48

    Depending on your version of SQL server, simply putting your query into a stored procedure may make a big difference. Try this after you have tried the other optimizations first.(Yes, I know there are cached execution plans and other internal server optimizations, but in my practical real-world experience, stored procedures can execute faster.)

    0 讨论(0)
提交回复
热议问题