Storage Engine
definition:
Technical data is stored in the database, the engine can be likened to an engine, various engine properties vary
classification*****
The two most common storage engine is innodb and myisam, differences are as follows:
1、innodb
- 1, (default version is 5.5 and above)
--2, support services
--3, does not support full-text indexing
--4, indexing and data structures in the same file, .ibd
Structure of the table is in the .frm file
2、myisam
- 1, (default version 5.5 or less, most people with major 5.3)
--2, does not support transactions
--3, support for full-text indexing
--4, .frm: Table Structure
.MYD: table data
.MYI: Table Index
3, memory (not used)
ps: innodb does not support full-text indexing
Domestic widespread use of full-text indexing sphinx (Sphinx)
index
analogy
Equivalent directory Xinhua dictionary, the index can be understood as a special file,
If it does not, the query is to find data from front to back,
If you have this file, you will find data in accordance with a special data structure (binary tree)
effect
Accelerate data query
classification
1, the primary key index: speed up queries can not be repeated + + can not be null primary key
2, a unique index: + speed up queries can not be repeated unique (column name)
United unique index: + speed up queries can not be repeated unique (1 column name, column name 2, ..)
3, the general index: speed up queries index (column name)
Create and delete
create
1, created when construction of the table
Table T1 Create ( # create the primary key id int auto_increment primary key, name varchar(32) not null default '', age int not null default 0, int NUM not null default 0, # co-create a unique index UNIQUE uni_name_num (name, Age), # ordinary index create index ix_age (age) ).engine=innodb charset=utf8;
2, there is created after the table
# Primary key index to create the ALTER the Table T1 Change the above mentioned id AUTO_INCREMENT the above mentioned id int Primary Key # create a unique index create unique index ix_name on t1 (name ) create unique index ix_name_age on t1(name,age) # Ordinary index create create index ix_age on t1 (age)
delete
# If the primary key is auto-incremented, you can not delete, cancel the first increase since then delete # delete unique index and the general index as drop index ix_name on t1;
The advantages and disadvantages of index
advantage:
Query data faster
Disadvantages:
Version 5.3 of the following:
Delete and modify the data speed will become very slow, the index will be reconstructed
Version 5.5:
Delete and modify the data speed is not particularly slow
Use of the index
explain Tools
Sql statement to see whether the lingua franca of the index, or view sql efficiency tools
Sql statement to execute a report, this report is determined by the sql statement
The efficiency and effectiveness (not necessarily the result by up)
Rules SQL statements
1 is not recommended to use like search
2, a composite index of the most left-prefix
If the index is a combination of: (name, email)
where name and email - to use an index
where name - the use of the index
where email - NA index