mysql联合索引经典实例

某表有二个索引,一个是a,b,c三字段联合索引,一个是c字段单独索引,请问下列sql语句,能否使用上索引?

  1. where a=1 and b=2 and c=3 (使用联合索引)

  2. where a = 1 and b>2 and c=3 (使用c索引)

  3. where a > 1 and b=2 and c=3 (使用c索引)

  4. where a > 1 and b=2 and c>3 (不使用索引)

  5. where a>1 and b!=2 (不使用索引)

  6. where a!=1 and b>1 (不使用索引)

  7. where b = 1 and a = 2 (使用联合索引)

  8. where b = 1 (不使用索引)

  9. where a = 1 (使用联合索引、若a字段存在单独索引,此处仍优先使用联合索引)

  10. where c = 1 order by b (使用c索引)

  11. where c = 1 order by a (使用c索引)

  12. where b = 1 order by a (不使用索引)

  13. where b = 1 order by c (不使用索引)

  14. where b = 1 group by c (使用c索引)

备注:

  1. 范围查询用不上索引。
  2. 联合索引中,若存在范围查询时,优先使用其他准确查找字段中的单独索引。
  3. 联合索引中,若a,b,c、 a,b、 a,c、 a 组合(即含有a字段的组合)均为精确查找,则使用联合索引。(与where语句中三个字段出现的顺序无关)
  4. 联合索引中,若字段组合中不含有a字段且b、c字段均无单独字段索引,则不使用索引。
相关推荐
anew___1 小时前
《数据库原理》精要解读(七)—— 数据库设计:从蓝图到现实的系统工程
数据库·oracle
独隅1 小时前
MySQL 接入不同 AI 大模型进行数据管理的全面指南(MySQL + AI)
数据库·人工智能·mysql
方也_arkling1 小时前
【Java-Day02】语法篇:变量/数据类型/标识符/运算符/类型转换
java·开发语言
go不是csgo1 小时前
GORM 上手:一个 main.go 跑通 Go 数据库增删改查
jvm·数据库·golang
学代码的真由酱1 小时前
WebSocket背景知识及简单实现-Java
java·websocket
lld9510271 小时前
(一)云回测:量化策略上线前的必经之路
java·服务器·数据库
云云只是个程序马喽2 小时前
海外短剧系统开发_云微传媒:多语言短剧平台定制与变现解决方案
java·php
plainGeekDev2 小时前
RecyclerView.Adapter → ListAdapter
java·kotlin·gradle
J2虾虾2 小时前
Spring AI Alibaba - 人工介入(Human-in-the-Loop)
java·人工智能·spring