SQL statement Optimization (iii)

Source: Internet
Author: User

4.1 Optimizing the types of tables

In MySQL, you can use the function Procedureanalyse () to analyze the currently applied table, and modify the function to make recommendations on the data types of the columns in the data table, and the user can consider whether or not to implement them according to the actual situation of the application.

Mysql> SELECT * from Duck_cust procedure analyse () \g
1. Row ***************************
Field_name:sakila.duch_cust.cust_num
Min_value:1
Max_value:6
Min_length:1
Max_length:1
empties_or_zeros:0
nulls:0
avg_value_or_avg_length:3.5000
std:1.7078
Optimal_fieldtype:enum (' 1 ', ' 2 ', ' 3 ', ' 4 ') notnull
2. Row ***************************
... ...

4.2 Large Storage Solution

1. Sub-database sub-table

2. Partitioning

Main Purpose:

1. Reduce the number of records in a table

2. Reduce the burden on the operating system

MyISAM Read lock

1.lock table T1 Read

2. Open another MySQL connection terminal, then try:

SELECT * FROM t1

3. Insert, update, and delete T1 This table, you will find that all the data is stuck on the terminal and there is no real operation.

4. Read locking is useful when we are backing up large amounts of data.

mysqldump-uroot-p123 Test >test.sql

MyISAM Write lock

1.lock Table T1 Write

2. Open another MySQL terminal, try to select, INSERT, UPDATE and delete this table T1, you will find that all can not operate, will stay on the terminal, only wait for the first terminal operation, the second terminal can be really executed.

3. The write lock on the visible table is more restrictive than the read lock

4. In general, we seldom go explicitly to read and write locks on the table, MyISAM will automatically lock.

Slow query log

1. About Slow queries

Open an account and set a slow query time:

Vi/etc/my.cnf

Log_slow_queries=slow.log

Long_query_time=5

SQL statement Optimization (iii)

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.