CREATE TABLE people ( peopleid SMALLINT NOT NULL, name CHAR(50) NOT NULL ); |
CREATE TABLE people ( peopleid SMALLINT NOT NULL AUTO_INCREMENT, firstname CHAR(50) NOT NULL, lastname CHAR(50) NOT NULL, age SMALLINT NOT NULL, townid SMALLINT NOT NULL, PRIMARY KEY (peopleid) ); |
firstname,lastname,agefirstname,lastnamefirstname |
SELECT peopleid FROM people WHERE firstname='Mike' AND lastname='Sullivan' AND age='17'; SELECT peopleid FROM people WHERE firstname='Mike' AND lastname='Sullivan'; SELECT peopleid FROM people WHERE firstname='Mike'; The following queries cannot use the index at all: SELECT peopleid FROM people WHERE lastname='Sullivan'; SELECT peopleid FROM people WHERE age='17'; SELECT peopleid FROM people WHERE lastname='Sullivan' AND age='17'; |
SELECT age ## 不使用索引 FROM people WHERE firstname='Mike' ## 考虑使用索引 AND lastname='Sullivan' ## 考虑使用索引 |
SELECT people.age, ##不使用索引 town.name ##不使用索引 FROM people LEFT JOIN town ONpeople.townid=town.townid ##考虑使用索引 WHERE firstname='Mike' ##考虑使用索引 AND lastname='Sullivan' ##考虑使用索引 |
欢迎光临 MariaDB社区 (http://123.56.88.72/) | Powered by Discuz! X3.2 |