An optimized query __c language for large scale data scales

Source: Internet
Author: User
1: Index, our first thought is to create an index, create an index can multiply the efficiency of the query, save time. But if the amount of data is too large, this time simply to create an index is useless, we know if especially in large data statistics query, take 1000W data, if you use the Count function, at least 50-100 seconds or more, of course, if your server configuration is high enough, It can be handled fast enough, maybe a lot less, but it will be more than 10 seconds.
Simply indexing is useless. We can add a property to the index when we create the index, compress, which allows the index to be created in a good collation, so that the query can be raised 5-10 times faster or higher. But the only disadvantage is that the compressed index can only be created manually, for those keys can not be compressed, because the key (primary key) is automatically created by the index, compress required properties, generally default is not created. So when you create a compressed index, you can find other key fields for compression, such as the flow of the work sheet
2: Use as little as possible those functions, such as is null;is not null,in; Matching functions such as not in, which can be manipulated using a symbol program
3: As little as possible to use the subquery, if you write a class, which mimics the effect of subqueries, you will find, simply in the death, we can use the joint query, or external connection query, so the speed will be much faster than the subquery.
4: When using the index, note the following:
In the WHERE clause there is ". = "Will invalidate the index
Select account_name from test where amount!= 0 (not used)
Select account_name from test where amount > 0 (use)

Adding a handler function to a field in a where condition will not use the index of the column
SELECT * from emp where TO_CHAR (hire_date, ' yyyymmdd ') = ' 20080411 ' (not used)
SELECT * from emp where hire_date = To_char (' 20080411 ', ' YYYYMMDD ') (used)

Avoid using is null and is not NULL on indexed columns
SELECT * from emp where dept_code isn't null (not used)
SELECT * from emp where Dept_code > 0 (use)

Use of wildcard characters%
SELECT * from emp where name like '%A ' (not using index)
SELECT * from emp where name like ' a% ' (use index)

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.