How MySQL builds the index

Source: Internet
Author: User

1. Select the data type of the index

MySQL supports many data types, and choosing the right data type to store data has a significant impact on performance. In general, you can follow some of the following guidelines:

(1) Smaller data types are generally better: smaller data types typically require less space in disk, memory, and CPU caches, and are processed faster.
(2) Simple data types are better: integer data is less expensive to handle than characters, because string comparisons are more complex. In MySQL, you should use a built-in date and time data type instead of a string to store the time, and an integer data type to store the IP address.
(3) Try to avoid null: The column should be specified as NOT NULL unless you want to store null. In MySQL, columns with null values are difficult to query optimization because they complicate indexing, index statistics, and comparison operations. You should use 0, a special value, or an empty string instead of a null value.


2 MySQL indexed commands


1.PRIMARY KEY(primary key index) MySQL>ALTER TABLE' table_name 'ADD PRIMARY KEY( `column` ) 2.UNIQUE(unique index) MySQL>ALTER TABLE' table_name 'ADD UNIQUE (`column` ) 3.INDEX(normal index) MySQL>ALTER TABLE' table_name 'ADD INDEXIndex_name ('column` )4. Fulltext (full-text index) MySQL>ALTER TABLE' table_name 'ADDFulltext ('column` )5. Multi-column index MySQL>ALTER TABLE' table_name 'ADD INDEXIndex_name (' Column1 ', ' column2 ', ' column3 ')

How MySQL builds the index

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.