W
W
warchant2015-11-08 14:44:54
MySQL
warchant, 2015-11-08 14:44:54

How does MySQL search sorted data within a db file?

There is a table with 1 million records:

CREATE TABLE `affiliation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(512) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=291323 DEFAULT CHARSET=latin1;

After uploading the dump, I noticed that the data is sorted by name instead of being sorted by id. Logically, everything is correct, because name is unique and you need to check before inserting whether there is such a name. To do this, you need to find such a name.
With a search by id, everything is clear, a b+-tree (or b-tree) is built there, in which the keys are sorted and the search is logarithmic from the height of the tree. BUT, how is the sorted names searched? Really one more index is under construction?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2015-11-08
@warchant

Well, you yourself created a unique index for this field, why be surprised?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question