# SQL 语句执行计划不准 - 索引分析（B）

+ 使用强制 hint 进行执行,执行时间由 63 秒降低为 6.3 秒

```
mysql> select count(*)
    -> from tods.bus_jijin_trade_record a   use index(idx_bus_jijin_trade_record_upt), tods.bus_jijin_info b 
    -> where a.fund_code=b.fund_code  and a.type in ('PURCHASE','APPLY')  
    -> and a.status='CANCEL_SUCCESS' and   a.pay_confirm_status = 1 
    -> and a.cancel_app_no is not null and   a.id >=  177045000  
    -> and a.updated_at >   date_sub(now(), interval 48 hour) ;
+----------+
| count(*) |
+----------+
|      709 |
+----------+
1 row in set (6.27 sec)
```

-------------------------------------------------------------
```
mysql> select count(*)
    -> from tods.bus_jijin_trade_record a   use index(idx_bus_jijin_trade_record_upt), tods.bus_jijin_info b 
    -> where a.fund_code=b.fund_code  and a.type in ('PURCHASE','APPLY')  
    -> and a.status='CANCEL_SUCCESS' and   a.pay_confirm_status = 1 
    -> and a.cancel_app_no is not null and   a.id >=  177045000  
    -> and a.updated_at >   date_sub(now(), interval 48 hour) ;
+----------+
| count(*) |
+----------+
|      709 |
+----------+
1 row in set (6.27 sec)
```

按照上面两个条件分别查询数据分区情况。我们可以看到通过最后的一个谓词条件 id >= 177045000，大概有 1.4 亿条的记录。通过 updated_at > date_sub(now(), interval 48 hour) 过滤出来的记录相对较少，只有 70 万条。那么此时，表 bus_jijin_trade_record 有 1.7 亿的数据量，应该走 updated_at 字段上的索引。
我们可以考虑强制使用索引。使用强制 hint 进行执行，6.27 秒就执行完成了，速度从之前 63s 到现在的 6.3s，提升了 10 倍。
