数据库开启了慢查询,long_query_time设为0.1s,能记录到一些100ms左右的慢查询,但没有大于1秒的慢查询记录。
A表查询语句:
select f1,f2,f3 from A where code= ? and latest = 1;
A表上为code和latest 创建了联合索引,explain显示使用了索引,其中f1,f2,f3要查的为业务字段;latest字段取值只有0和1,explain结果如下:
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
| 1 | SIMPLE | A | NULL | ref | index_code_latest | index_code_latest | 1023 | const | 1 | 10.00 | Using where |
B表查询语句 :
select id,f1,f2,...,f15 from B where match(f1) against (?) and latest = 1
B表f1是字段是一个text字段,在上面建立了全文索引,B表一共查询了15个字段;latest字段取值只有0和1;explain结果如下:
| id | select_type | table | partitions | type | possible_keys | key
| key_len | ref | rows | filtered | Extra |
| 1 | SIMPLE | B| NULL | fulltext | ft_f1 | ft_f1 | 0 | const | 1 | 10.00 | Using where; Ft_hints: sorted |