SQL Statement Performance Tuning

Source: Internet
Author: User
Tags create index range what sql

I. Problems with indexing (index)

1. Indexes (index), using or not? It's a problem.

Whether a full table scan or an index range scan mainly considers the SQL query speed problem. The main concern here is the number of records to read. According to Donald K. Burleson, the principle of using index range scanning is:

For tables with the original sort of data, queries that read less than 40% of the number of table records should use an index range scan. Queries that read 40% more than the number of records should be scanned all over the table.

For unordered tables, queries that read less than 7% of the number of table records should use an index range scan, whereas queries that read more than 7% of the table records should be scanned all over the table.

Note: In different books, the percentage value of the read record that uses the index is not consistent, which is basically an experience value, but the lower the percentage of the read record, the more efficient the use of the index.

2. What SQL queries are useful indexes (index) If there is an index on the column? What SQL query is not indexed (index)?

An index is not used for SQL that has the following condition:

There is a data type for stealth conversions, such as:

SELECT * from Staff_member where staff_id= ' 123 ';

Having mathematical operations on a column, such as:

SELECT * FROM Staff_member where salary*2<10000;

Using a not equal to (<>) operation, such as:

SELECT * FROM Staff_member where dept_no<>2001;

Using a substr string function, such as:

SELECT * from Staff_member where substr (last_name,1,4) = ' FRED ';

'% ' wildcard characters in the first character, such as:

SELECT * from Staff_member where first_name like '%don ';

string concatenation (| |) , such as:

SELECT * from Staff_member where first_name| | ' = ' DONALD '

3. Index of functions

Date types are also easy to use, and the To_char function is used in SQL statements to query for specific range dates. For example: SELECT * from Staff_member where To_char (Birth_day, ' YYYY ') = ' 2003 '; We can establish a function based index such as: Create INDEX Ind_emp_birth on Staff_member (To_char (birth_day, ' YYYY '));

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.