SELECT t1.*FROM t1 LEFT JOIN t2 ON t2.capital_unique_code = t1.unique_codeWHERE t1.trade_date >= '2020-12-24' AND t1.trade_date <= '2020-12-24' AND t1.capital_account IN ('95200078801700000859', 'dev@souche.com', 'sousou@souche.com')ORDER BY t1.trade_date, t1.trade_time, t1.idLIMIT 50 图上sql t1. unique_code utf8mb4 字符集t2. capital_unique_code是utf8支付集 因为字符集不一致 导致了索引失效 +----+-------------+-------+------------+-------+--------------------------------+--------------------------------+---------+------+---------+----------+-----------------------------------------------------------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+-------+------------+-------+--------------------------------+--------------------------------+---------+------+---------+----------+-----------------------------------------------------------------+| 1 | SIMPLE | t1 | NULL | range | idx_trade_date_capital_account | idx_trade_date_capital_account | 257 | NULL | 34 | 100.00 | Using index condition; Using temporary; Using filesort || 1 | SIMPLE | t2 | NULL | index | NULL | uniq_key | 303 | NULL | 2348088 | 100.00 | Using where; Using index; Using join buffer (Block Nested Loop) |+----+-------------+-------+------------+-------+--------------------------------+--------------------------------+---------+------+---------+----------+-----------------------------------------------------------------+ 修改字符集为一致之后 +----+-------------+-------+------------+-------+--------------------------------+--------------------------------+---------+---------------------------+------+----------+---------------------------------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+-------+------------+-------+--------------------------------+--------------------------------+---------+---------------------------+------+----------+---------------------------------------+| 1 | SIMPLE | t1 | NULL | range | idx_trade_date_capital_account | idx_trade_date_capital_account | 257 | NULL | 34 | 100.00 | Using index condition; Using filesort || 1 | SIMPLE | t2 | NULL | ref | uniq_key | uniq_key | 403 | sfs_server.t1.unique_code | 1 | 100.00 | Using where; Using index |+----+-------------+-------+------------+-------+--------------------------------+--------------------------------+---------+---------------------------+------+----------+---------------------------------------+
多表关联时因为字符集不一致导致索引失效
来源:这里教程网
时间:2026-03-01 15:32:06
作者:
编辑推荐:
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 业内人士认为集成电路erp产品选型关键的四要素!
业内人士认为集成电路erp产品选型关键的四要素!
26-03-01 - 关于MySQL5.7版本varchar字段宽度扩容的一些相关知识与实践-yh
- MySQL binlog_ignore_db 参数最全解析
MySQL binlog_ignore_db 参数最全解析
26-03-01 - 在线教育系统搭建的好处
在线教育系统搭建的好处
26-03-01 - 集成电路行业怎么看ERP软件实施商的资质?
集成电路行业怎么看ERP软件实施商的资质?
26-03-01 - 自媒体多平台同步系统,同步分发多个自媒体平台内容
自媒体多平台同步系统,同步分发多个自媒体平台内容
26-03-01 - 一款SQL自动检查神器,再也不用担心SQL出错了
一款SQL自动检查神器,再也不用担心SQL出错了
26-03-01 - 直播教育系统开发有发展市场吗?能够给用户带来什么?
直播教育系统开发有发展市场吗?能够给用户带来什么?
26-03-01 - Shell脚本监控MySQL主从状态
Shell脚本监控MySQL主从状态
26-03-01 - 10分钟让你明白MySQL是如何利用索引的
10分钟让你明白MySQL是如何利用索引的
26-03-01
