1 先建表,插入数据,建索引,脚本如下:
--建表 create table User( id bigint auto_increment primary key, name nvarchar(100), age int, position nvarchar(100) ); --插入数据 INSERT INTO User (name, age, position) SELECT CONCAT('User', FLOOR(RAND() * 100000000) + 1) AS name, FLOOR(RAND() * 100) + 1 AS age, CONCAT('Position', FLOOR(RAND() * 100000000) + 1) AS position FROM INFORMATION_SCHEMA.COLUMNS as a CROSS JOIN INFORMATION_SCHEMA.COLUMNS as b LIMIT 1000; --建索引 create index idx_nameagepos on User(name,age,position); #具体查询 EXPLAIN select id,name,age,position from User where name = 'User10052562' and age='38'; EXPLAIN select id,name,age,position from User where age='38' and position='Position57818398'; EXPLAIN select id,name,age,position from User where age='38';
2 相关分析,总是只看理论,记东西,时间真的会带走一切。
标签:name,age,索引,User,mysql,position,id From: https://www.cnblogs.com/Insist-Y/p/17681560.html