Analysis of 48 causes of slow SQL query _ MySQL

Source: Internet
Author: User
Analyze the 48 causes of slow SQL query:

1. no index or no index is used (this is the most common problem of slow query and is a defect in programming)

2. low I/O throughput, resulting in a bottleneck effect.

3. the query is not optimized because no computing column is created.

4. insufficient memory

5. slow network speed

6. the queried data volume is too large (you can use multiple queries to reduce the data volume in other ways)

7. lock or deadlock (this is also the most common problem of slow query and is a defect in programming)

8. sp_lock and sp_who are active users. The reason is that they read and write competing resources.

9. unnecessary rows and columns are returned.

10. the query statement is not good and is not optimized. ● you can optimize the query using the following methods:

1. place data, logs, and indexes on different I/O devices to increase the reading speed. in the past, Tempdb can be placed on RAID0, which is not supported by SQL2000. The larger the data size (size), the more important it is to increase I/O.

2. vertically and horizontally split the table to reduce the table size (sp_spaceuse)

3. upgrade hardware

4. create an index based on the query conditions, optimize the index, optimize the access mode, and limit the data volume of the result set. Note that the fill factor should be appropriate (preferably the default value 0 ). The index should be as small as possible. Use a column with a small number of bytes to create an index (refer to the index creation). do not create a single index for fields with a limited number of values, such as gender fields.

5. improve network speed;

6. expand the server memory. Windows 2000 and SQL server 2000 support 4-8 GB memory. Configure virtual memory: the virtual memory size should be configured based on services running concurrently on the computer. Run Microsoft SQL Server? 2000, you can consider setting the virtual memory size to 1.5 times the physical memory installed on your computer. If you have installed the full-text search feature and intend to run the Microsoft search service for full-text indexing and query, consider: set the virtual memory size to at least three times the physical memory installed on the computer. Configure the SQL Server max server memory Server configuration option to 1.5 times the physical memory (half the virtual memory size ).

7. increase the number of server CPUs. However, you must understand that resources such as memory are more required for concurrent processing of serial processing. Whether to use parallelism or serial travel is automatically evaluated and selected by MsSQL. A single task is divided into multiple tasks and can be run on the processor. For example, if the sort, connection, scan, and group by statements of delayed queries are executed simultaneously, SQL SERVER determines the optimal parallel level based on the system load, complex queries that consume a large amount of CPU are most suitable for parallel processing. However, UPDATE, INSERT, and DELETE operations cannot be processed in parallel.

8. if you use like for query, you cannot simply use index, but the full-text index consumes space. Like 'A % 'when the index like' % A' is used and like '% a %' is not used for the query, the query time is proportional to the total length of the field value, so the CHAR type cannot be used, but VARCHAR. Create a full-text index for a long field value.

9. separate DB Server and APPLication Server; separate OLTP and OLAP

10. distributed partition view can be used to implement database server consortium. A consortium is a group of separately managed servers, but they collaborate to share the processing load of the system. This mechanism of forming database server consortium through partition data can expand a group of servers to support the processing needs of large multi-layer Web sites. For more information, see designing a database federation server. (Refer to the SQL help file 'Partition view ')

A. Before implementing the partition view, a horizontal partition table must be created.

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.