# Suboptimal Sql Statement Execution Plan


![right](./student-guide/diagram/20-background-01-01.png)

```
SELECT COUNT(*)
  FROM tods.bus_jijin_trade_record a, 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);
```

------------------------------------------------------------

scenario there are frequent reads and writes on the target column

```
SELECT COUNT(*)
  FROM tods.bus_jijin_trade_record a, 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);
```

This is a query that relates two tables. Let's take a look at the characteristics of this query:
  - On the trade table we created a primary key for the ID column and a non-unique index for the UPDATE_AT column
  - On the info table we created the primary key of the ID column
  - This is an association between a large table and a small table. The scale is very different, and the big table has 170 million records
