create index xxx1 on teacher_info(school,id);
create index xxxs on teacher_level(teacher_id,comment_id);
create index xxxd on teacher_comment(id);

解决方案 »

  1.   

    索引情况如何,在条件字段上建立索引,
    EXPLAIN SQL语句,贴结果
      

  2.   

    首先谢谢回答,这个sql语句有索引,where条件后面的都有
      

  3.   

    贴出你的 show index from ..
    explain select ...
    不要贴图,直接贴文本以供分析。
      

  4.   

    哈哈,再次感谢诸位大大。1. show  index from teacher_info (这样看着比较乱,粘贴出去就好了)
    Table      Non_unique   Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
    teacher_info 0   PRIMARY        1         id         A         913108                  BTREE
    teacher_info 1   loveliness  1         loveliness A         6                  BTREE
    teacher_info 1   schoolkey  1         school         A         915                  BTREE
    teacher_info 1   nameKey  1         name         A         913108                          BTREE
    teacher_info 1   departmentKey  1         department A         13233                          YES  BTREE
    teacher_info 1   isShieldKey  1         is_shield A         6                          YES     BTREE
    teacher_info 1   id          1         id         A         913108                           BTREE
      

  5.   

    2. show  index from teacher_level
    Table       Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
    teacher_level 0        PRIMARY         1          id         A         3420069                  BTREE
    teacher_level 1        user_id         1          user_id A         3420069                  BTREE
    teacher_level 1        teacher_id 1         teacher_id A         3420069                  BTREE
    teacher_level 1        commentkey 1         comment_id A         3420069                  BTREE
      

  6.   

    3. show  index from teacher_comment
    Table         Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
    teacher_comment 0          PRIMARY 1         id         A          3369939         BTREE
    teacher_comment 1          teacher_id 1         teacher_id A           3369939          BTREE
    teacher_comment 1          user_id 1         user_id         A           3369939          BTREE
    teacher_comment 1          schoolkey 1         school_id A           1131                 YES BTREE
    teacher_comment 1          shieldKey 1         is_shield A             18                  YES BTREE
      

  7.   

    您好,之前我确实忘加联合索引了,抱歉,抱歉。但是我加上后,效果不太明显,麻烦您再帮我瞅瞅。
    show  index from teacher_info 
    Table          Non_unique  Key_name Seq_in_index Column_name Collation Cardinality
      Sub_part    Null   Index_Type  
    teacher_info 0   PRIMARY  1  id        A 1016262 BTREE
    teacher_info 1 loveliness 1 loveliness A 10 BTREE
    teacher_info 1 schoolkey 1 school        A 4748 BTREE
    teacher_info 1 nameKey         1 name        A 1016262 BTREE
    teacher_info 1 departmentKey 1 department A 8262 YES BTREE
    teacher_info 1 isShieldKey 1 is_shield A 10 YES BTREE
    teacher_info 1 index_sii 1 school        A 2363 BTREE
    teacher_info 1 index_sii 2 id        A 1016262 BTREE