当我只在一个表中选择查询时,我们得到了使用索引的响应,但是当在查询中使用join statemnt时,mysql会对表进行完全扫描吗?
第一查询
select *
from t_deposit_trx
where remit_tx_id = '3a33ff14-8d31-45d0-b64f-8a251c4b19a5'
1个简单的T_存款参考T_存款T_汇款ID_指数
使用索引条件的t_deposit_trx_remit_tx_id_index 110 const 1
第二查询
select tx_id
from t_settle_trx
where report_date >= '2019-03-01'
and report_date <= '2019-03-16'
and tx_type = 'CANCEL'
1个简单的t_结算t_trx range t_结算t_trx_report_date_tx_type_index t_结算t_trx_report_date_tx_type_index 196 5263使用索引条件
2查询操作良好。
使用指数和速度都很好。
但是加入两张桌子,很慢。
select * from t_deposit_trx
force index (t_deposit_trx_remit_tx_id_index)
where remit_tx_id in (
select tx_id
from t_settle_trx
where report_date >= '2019-03-01'
and report_date <= '2019-03-02'
and tx_type = 'CANCEL'
)
一级T_矿床,全部55724
1个主t_结算t_trx range t_结算t_trx_report_date_tx_type_index t_结算t_trx_report_date_tx_type_index 196 299,使用索引条件;使用where;firstmatch(t_deposit_trx);使用连接缓冲区(flat,bnl join)
我们可以看到上面的结果。
t_settle_trx use range scan and get tx_id and next我希望查询使用索引
“t_settle_trx_report_date_tx_type_索引”
但它使用全扫描…
我不知道为什么?