I have a table CREATE TABLE passengers ( pid int(11) NOT NULL, pname varchar(50) DEFAULT…
- User
I have a table CREATE TABLE passengers ( pid int(11) NOT NULL, pname varchar(50) DEFAULT 'somebody', sex bit(1) DEFAULT NULL, age decimal(5,2) NOT NULL, PRIMARY KEY (pid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE sailors.passengers ADD COLUMN e_mail VARCHAR(45) NULL AFTER age;
And i had an index CREATE INDEX age_sex ON passengers(age, sex);
I performed EXPLAIN SELECT * FROM passengers WHERE age = 0 AND sex = 0;
And then I dropped previous index (age, sex) and created a new one, (sex, age). ALTER TABLE sailors.passengers DROP INDEX age_sex ; CREATE INDEX sex_age ON passengers(sex, age);
In EXPLAIN SELECT with the same select, I see that type and rows havent changed, but key_len decreased from 5 to 2. How does this value being calculated and what does it mean in context of optimization?
EXPLAIN SELECT * FROM passengers WHERE sex = 1 ORDER BY age;
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.