review
1. What is the database
2.SQL installation
3. User Authorization
4. The various operations of the database
1. Library
2. Table
-type of data
- foreign key
Many
Many to many
One to One
- increment
3. Line
Sort by: order by
Packet
condition
Even table
Temporary tables
Tsuhaifu
Paging
combination
4. View
5. Trigger
6. Functions
7. Stored Procedures
cursor
Affairs
Dynamic SQL execution
8.pymysql
1. The stored procedure is called
2.conmmit
3.SQL injection, SQL annotated as -
Learning Content
1. Index
1. Role
1. Constraints
2. Find accelerate
2. Type
1. Ordinary Index: Accelerated Find
2. The primary key index: Acceleration is not empty Find + + can not be repeated
3. unique index: + can not be repeated accelerate Find
4. The joint operations :( primer combination index)
- UNITED unique index
- the primary key index
- Joint general index
3. Find accelerate
None Index: front to back once to find
index:
According to the index column, create a file corresponding increase in search speed
Index Category:
hash index
Single-valued fast
Find a range of slow
btree index
Binary Tree
4. Indexing
1. Additional special data structure file is saved
2. Query fast, slow insert delete update
3. Hit Index
select * from xx where oo=‘aa’ 命中
select * from xx where oo like 'aa_' no hit
4.SQL statement
General index
-create index xx on the table name (column)
-drop index xx on the table name (column)
The only index
-create unique index xx on the table name (column)
-drop unique index xx on the table name (column)
Composite index
1. The most left-prefix match
create index ix_name_email on userinfo3 (name,email)
Hit
select * from userinfo3 where name='alex'
select * from userinfo3 where name='alex' and email'sss'
You can not hit
select * from userinfo3 where email'sss'
2. Combination Index efficiency> Index Merge
5. noun
Covering index
- Get data directly in the index file
-select name from userinfo3 where name='alex' (name索引)
Index Merge
- The combined use of multiple separate index
select * from userinfo3 where name = 'alex' and id = 11 (name, id have created the index)
6. Frequent create an index lookup column
1. Create Index
2. Hit Index
The situation can not hit lists some common index
Table id, In Email as an index, wherein the primary key id, name no index
1.like
select * from xx where email like 'c%'
2. Functions
select * from xx where reverse(email) = 'cc'
3.or
select * from xx where id = 1 or name = 'cc'
or contains non-indexed columns, failure
4. is inconsistent
select * from xx where email = 11;
If the primary key, you should still be able to hit
5.!=
select * from xx where email = 'c'
If the primary key or index can go
6.>
select * from xx where email > 'c%'
If the primary key or index of type integer, the index can go
7.order by
select name from xx order by email desc
If the index sort, select the index is not mapped, not take the index
According to the primary key sort, or you can take the index
8. The composite index of the most left-prefix
7. Optimization
1. Notes
1. Avoid using select *
2.count (1) or the count (column) Alternatively count (*)
3. Try to use alternative char varchar (sacrifice storage space for performance)
4. The hash value index (repeating less) is not suitable for indexing, for example: Gender
The order of the fields of fixed length table field preference
(Often used when a plurality of query conditions) 6. The composition index in place of a plurality of single-column index
7. make use of short index
Table 8. Note that even the same type of conditions
2. Implementation Plan
mysql pre-estimated execution operation
According to the estimated type
all<index<range<index_merge<ref_or_null<ref<eq_ref<system/const
See details
https://www.cnblogs.com/wupeiqi/articles/5716963.html
http://www.cnblogs.com/xiaoboluo768/p/5400990.html
http://dev.mysql.com/doc/refman/5.7/en/explain-output.html#jointype_system
3. Slow Log
1. Conditions
1. Perform time record
2. misses index
3. Log File Path
2. Configure
1. Direct memory configuration items to be
-show variables like '%query%'
-set global variable name = value
2. Profiles
1. file my-default.ini for the configuration file, change the internal data, restart mysql
2. Start mysqld, remarks profile location
mysqld --defaults-file='E...\my-default.ini'
3. Modify the content with almost the same memory
8. Paging
1. The actual site will disable user access part of the data
2. Solution
1.select * from xx where id in (select id from xx limit 200000,10) hit by the index, but the effect is not obvious
2. The current record was the maximum and minimum page ID (actually is to do so)
Next Page
select * from xx where id>200000 limit 10;
Previous
select * from xx where id <200000 order by id desc limit 10; (order by the primary key is not very slow)
Jump a page: Previous ... 12 [98] 99 100 ... Next
select * from xx where id in (
select id from
(select id from xx where id > max_id limit 20) as T
order by T.id desc limit 10
)
3. and can not be achieved through between, because id is not necessarily in a row