当前位置:网站首页>mysql强制走索引
mysql强制走索引
2022-07-20 17:34:00 【Mckay88】
在一张表中,仅有千万级别的数据,现在我有一个SQL语句,我该增加的索引都增加了,但是执行速度很慢,我们经过分析执行的SQL语句得到如下:
是因为,在查询的时候,使用的索引错误了,也可以强制其走指定的索引:
select * from table force index(idx_start_date) where …
总结
根据实际的情况,需要控制IN查询的范围。原因有以下几点
1. IN 的条件过多,会导致索引失效,走索引扫描
2. IN 的条件过多,返回的数据会很多,可能会导致应用堆内内存溢出。
所以必须要控制好IN的查询个数
不过id In(‘1’,‘2’, …,‘1000’ )这种语句,最好数量控制在一千以内,再多的话,sql效率就会下降。如果有需求超过一千以上,说明楼主需要冗余字段了,比如冗余你业务场景中的用户账号ID。
至于楼上建议join联表的,我觉得如果表数量级在10万级别还可以;一旦达到百万级,联表就是灾难。
in 实在显示不了,试试left join on 连接一下吧
边栏推荐
猜你喜欢
数据采集与预处理课设——人在回路的气温数据动态处理与可视化
[cloud native • Devops] master the continuous integration tool Jenkins
[excel] SUMIF merge cells
Support vector machine learning notes (2) parameter comparison and face recognition project
线程池学习
Maixll dock barcode recognition
WinForm UI interface design routine - multi thread access UI control
When does MySQL use table locks and row locks?
Segment tree - interval modification tree
C语言程序的编译(预处理) —— 下
随机推荐
Basic usage of async function and await expression in ES6
NeRF数据集介绍
event. target
[cloud native • Devops] master the continuous integration tool Jenkins
[ruoyi] Popover
数据库系统概论--分析题
go mod安装报错的解决方案
美团住宿业务数据治理体系化思考与实践
Four redis cluster schemes you must know and their advantages and disadvantages
考研-数据库
2022年备战金九银十,Android从基础到架构进阶全方面面试题解析(含答案及源码)
线程池学习
Quantum Source:致力于抢先实现百万光量子比特
[thymeleaf] basic objects: base objects
CAD打断命令
Spend 29million dollars! Israel establishes quantum computing research and Development Center
ESP32 485空气温湿度测试
In that year, the story behind the opening of wild cattle in the Spring Festival Gala
[MySQL] get table information and all column names
综述 | 实例分割研究