
MySQL 索引面试必问实战也常用最左前缀法则很多人一知半解今天用最简单的话讲透看完就会用。一、什么是最左前缀联合索引a,b,c必须从最左边的字段开始匹配中间不能断才能命中索引。比如索引idx_date_area_amount(date, area, amount)命中索引的情况where date ?where date ? and area ?where date ? and area ? and amount ?不命中 / 部分命中where area ?缺最左 datewhere date ? and amount ?中间断了 area二、建索引原则高频查询字段放最前面等值查询放前面范围查询放后面联合索引字段不要太多3 个以内最合适三、实战示例-- 建联合索引高频字段在前 CREATE INDEX idx_date_area ON t_order(date, area); -- 命中索引 SELECT * FROM t_order WHERE date 2026-03-19 AND area 华东; -- 不命中索引 SELECT * FROM t_order WHERE area 华东;四、避坑不要建无用索引拖慢写入不要把低基数字段性别、状态放前面查询时严格遵循最左匹配最左前缀是 MySQL 索引最基础的知识点面试能说清实战能用对索引效率直接拉满。