社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

为什么mysql连接查询-完全扫描不使用索引

jaechoi • 5 年前 • 1949 次点击  

当我只在一个表中选择查询时,我们得到了使用索引的响应,但是当在查询中使用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_索引” 但它使用全扫描…

我不知道为什么?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40198
 
1949 次点击  
文章 [ 3 ]  |  最新文章 5 年前