Mysql解释 - 案例研究

时间:2014-10-16 18:48:55

标签: mysql performance

我有以下解释信息:

1   PRIMARY             <derived2>  ALL         NULL                        NULL            NULL    NULL                    15  
1   PRIMARY             j           eq_ref      PRIMARY                     PRIMARY         4       tmp.sel_job_id          1   
1   PRIMARY             jd          ref         code                        code            768     test_query.j.j_code     2   Using index
2   DERIVED             t           index       NULL                        date_2          9       NULL                    15  Using where
4   DEPENDENT SUBQUERY  jtl         eq_ref      Multiple_keys,tester_id     Multiple_keys   8       test_query.t.id         1   Using where; Using index
3   DEPENDENT SUBQUERY  jtl         eq_ref      Multiple_keys,tester_id     Multiple_keys   8       test_query.t.id         1   Using where; Using index

T表有超过55k的记录和超过60k记录的jtl表,j表有超过100条记录和jd 30条记录。

我的查询是:

SELECT temp_tbl.*, j.name AS job_name, jd.code AS job_details_code FROM ( 
    SELECT t.*, ( 
        SELECT jtl.job_id FROM job_tester_link jtl
        WHERE t.id = jtl.tester_id AND 
            t.id NOT IN (11220012, 11218876, 11340156) AND 
            jtl.job_id = '20' AND 
            t.active = 'Y' LIMIT 1
        ) sel_job_id 
        FROM tester t 
        WHERE ( 
            SELECT jtl.job_id 
            FROM job_tester_link jtl 
            WHERE t.id = jtl.tester_id AND 
                t.id NOT IN (11220012, 11218876, 11340156) AND 
                jtl.job_id = '20' AND 
                t.active = 'Y' 
                LIMIT 1
        ) IS NOT NULL 
        ORDER BY t.date DESC 
        LIMIT 0,15 
    ) temp_tbl 
LEFT JOIN job j ON temp_tbl.sel_job_id = j.id 
LEFT JOIN job_details jd ON j.j_code = jd.code;

我的问题是执行时间(超过3秒)。如何改进此查询? 感谢。

0 个答案:

没有答案