EXPLAIN SELECT
z_resnav.ResCode,
j_syscourse.`name`,
z_resnav.StructCode,
z_resource.Title,
z_resource.keyWord,
z_resource.Des AS des,
z_resource.FPath,
z_resource.Fname,
z_resource.`displayLevel` AS reslevel,
x_resourcetype.MType AS colteachingtype
FROM
`z_resnav`
INNER JOIN z_resource ON z_resnav.ResCode = z_resource.ResCode
INNER JOIN j_syscourse ON z_resnav.StructCode = j_syscourse.tfcode
INNER JOIN x_resourcetype ON z_resource.mtype = x_resourcetype.`ID`
WHERE
z_resource.flag = 0
AND z_resnav.flag = 0
AND StructCode LIKE 'RJCZ020110%'
AND z_resource.fromflag < 5运行结果:
1 SIMPLE z_resnav range resnav_idx2,resnav_idx4,resnav_idx7 resnav_idx4 765 27222 Using where
1 SIMPLE j_syscourse ref syscourse_IDX3 syscourse_IDX3 601 beijingbeiwa.z_resnav.StructCode 1 Using where
1 SIMPLE z_resource ref res_idx2,res_idx4,res_idx8,res_idx16,res_idx17 res_idx2 301 beijingbeiwa.z_resnav.ResCode 1 Using where
1 SIMPLE x_resourcetype eq_ref PRIMARY PRIMARY 4 beijingbeiwa.z_resource.MType 1
查询时间:36.227秒,共1738条记录

解决方案 »

  1.   

    贴出所有的show index from ...以供分析。 
      

  2.   

    Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
    z_resource 0 PRIMARY 1 Id A 1708879 BTREE
    z_resource 0 res_idx 1 Id A 1708879 BTREE
    z_resource 0 res_idx2 1 ResCode A 1708879 YES BTREE
    z_resource 1 res_idx3 1 oldMType A 18 BTREE
    z_resource 1 res_idx4 1 fromflag A 18 BTREE
    z_resource 1 res_idx4 2 Id A 1708879 BTREE
    z_resource 1 res_idx5 1 isDWJ A 18 BTREE
    z_resource 1 res_idx6 1 Fname A 1708879 255 YES BTREE
    z_resource 1 res_idx7 1 FPath A 81375 255 YES BTREE
    z_resource 1 res_idx8 1 MType A 18 YES BTREE
    z_resource 1 res_idx9 1 Title A 1708879 YES BTREE
    z_resource 1 res_idx10 1 keyWord A 1708879 YES BTREE
    z_resource 1 res_idx12 1 FileExt A 18 YES BTREE
    z_resource 1 res_idx13 1 displayLevel A 18 YES BTREE
    z_resource 1 res_idx14 1 Provider A 18 YES BTREE
    z_resource 1 res_idx14 2 displayIndex A 18 YES BTREE
    z_resource 1 res_idx15 1 Fullpath A 1708879 255 YES BTREE
    z_resource 1 res_idx16 1 Flag A 18 BTREE
    z_resource 1 res_idx17 1 fromflag A 18 BTREE
    z_resnav 0 PRIMARY 1 Id A 2596966 BTREE
    z_resnav 0 resnav_idx 1 Id A 2596966 BTREE
    z_resnav 1 resnav_idx2 1 ResCode A 2596966 BTREE
    z_resnav 1 resnav_idx3 1 SysCourseId A 18549 YES BTREE
    z_resnav 1 resnav_idx4 1 StructCode A 70188 BTREE
    z_resnav 1 resnav_idx5 1 xueke A 17 YES BTREE
    z_resnav 1 resnav_idx6 1 Subject A 17 YES BTREE
    z_resnav 1 resnav_idx7 1 Flag A 17 BTREE
    j_syscourse 0 PRIMARY 1 Id A 47947 BTREE
    j_syscourse 1 syscourse_IDX1 1 SubjectId A 22 BTREE
    j_syscourse 1 syscourse_IDX2 1 TermId A 5 BTREE
    j_syscourse 1 syscourse_IDX3 1 TFcode A 47947 YES BTREE
    j_syscourse 1 syscourse_IDX4 1 PnodeId A 11986 YES BTREE
    j_syscourse 1 syscourse_idx5 1 Name A 23973 YES BTREE
    x_resourcetype 0 PRIMARY 1 ID A 58 BTREE