MySQL Classic case study

Source: Internet
Author: User

Problem:

CREATE TABLE A (
ID varchar (primary) key,
ver int,
...
)
There are federated indexes on the Id,ver, 10,000 data
Why is the select ID from the A order by ID particularly slow?
and select ID from A ORDER by id,ver very fast
My watch has several very long fields varbinary (3000)

Inference: 1. 2 SQL all use the index overlay, if the MyISAM engine 2 sentence SQL should be very fast, inference is using InnoDB engine 2. The order by ID, InnoDB engine cluster stores the value of each column, because there are a few very long fields, 1 blocks can not save many rows of data, resulting in more blocks, using the ID primary key, to cross a lot of small file blocks, resulting in low efficiency. 3. Order by Id,ver. Using a two-level index, the InnoDB engine two-level index is the address of the stored clustered index to the clustered index, so without data, the index file is smaller and lighter, and can be used in memory, so it's faster.
CREATE TABLE T7 (
ID char (primary key),
var int not null default 0,
STR1 varchar (+) is not NULL,
STR2 varchar (+) is not NULL,
STR3 varchar (+) is not NULL,
STR4 varchar (+) NOT NULL
Key ' Idvar ' (Id,var)
) Engine=myisam Charset=utf8;

CREATE TABLE T8 (
ID char (primary key),
var int not null default 0,
STR1 varchar (+) is not NULL,
STR2 varchar (+) is not NULL,
STR3 varchar (+) is not NULL,
STR4 varchar (+) NOT NULL
) Engine=innodb Charset=utf8;
ALTER TABLE T7 Add index Idver (id,var)

Conclusion: InnoDB large segment (char) primary key caused a lot of division, just play is the disadvantage of InnoDB
If there is not such a long column, the gap will not be very large
ALTER TABLE T8 drop column St1;alter table T8 drop column St2;alter table T8 drop column ST3;

MySQL Classic case study

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.