目标
分析模糊查询sql的索引利用问题,执行计划结果含义学习可参考博客https://blog.csdn.net/da_guo_li/article/details/79008016
对于建立索引意见,参考博客
https://blog.csdn.net/wulex/article/details/69540136
ddl
CREATE TABLE
tbl_merchant
(
ID bigint NOT NULL AUTO_INCREMENT,
CREATE_TIME DATETIME DEFAULT CURRENT_TIMESTAMP,
LAST_UPDATE_TIME DATETIME DEFAULT CURRENT_TIMESTAMP,
MERCHANT_NO VARCHAR(128) NOT NULL,
MERCHANT_NAME VARCHAR(64) NOT NULL,
CONTACT_NAME VARCHAR(64),
CONTACT_PHONE VARCHAR(128),
PLATFORM_KEY VARCHAR(2048),
STATUS VARCHAR(32) NOT NULL,
SHORT_NAME VARCHAR(128),
MERCHANT_MODEL VARCHAR(128),
CHECK_GROUP VARCHAR(32),
PRIMARY KEY (ID),
CONSTRAINT merchant_no_index UNIQUE (MERCHANT_NO),
INDEX TBL_MERCHAN_CREATE_TIME_INDEX (CREATE_TIME),
INDEX TBL_MERCHAN_LAST_UPDATE_TIME_INDEX (LAST_UPDATE_TIME)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
分析举例
针对merchant_no进行sql
explain SELECT * FROM tbl_merchant where merchant_no like '512312312321132%';
explain SELECT * FROM tbl_merchant where merchant_no like '%512312312321132';
所以,模糊查询一样遵循左前缀原则,必须保证值左侧固定索引才生效
网友评论