Oracle like Optimization

Source: Internet
Author: User

Query records of % XX %

1. Use instr
Select count (*) from table t where instr (T. column, 'xx')> 0
This query is very effective and fast

 

Query records of % xx

Select count (C. c_ply_no) as Count

From policy_data_all C, item_data_all I

Where C. c_ply_no = I. c_ply_no

And I. c_lcn_no like '% 100'

During execution, the execution plan is displayed, the consumption value,IoValue,CPUThe value is not always large, becauseLikeFuzzy search causes index failure and full table Scan

 

 

Solution: This is only prefix fuzzySQLThe following code can be modified:

Select count (C. c_ply_no) as Count

From policy_data_all C, item_data_all I

Where C. c_ply_no = I. c_ply_no

AndReverse (I. c_lcn_no)LikeReverse ('% 8080')

 

Item_data_allTableC_lcn_noYou can perform fuzzy match before a field. For example:

Select *

From (select C. c_ply_no as c67_0 _,

C. c_insrnt_cnm as c68_1432_0 _,

I. c_lcn_no as c83_1432_0 _,

To_char (C. t_insrnc_bgn_tm, 'yyyy-mm-dd') as t84_1432_0 _,

C. c_edr_type as c85_1432_0 _,

C. c_prod_no as c86_1432_0 _,

C. c_inter_cde as cintercde1432_0 _

From policy_data_all C, item_data_all I

Where C. c_ply_no = I. c_ply_no

AndReverse (I. c_lcn_no)LikeReverse ('% 8080')

Order by C. c_ply_no DESC)

UseFlip Function+ LikePrefix fuzzy search+Create a flipped Function Index=The index of the flipped function does not go through full scanning. Effectively reduce the consumption value,IoValue,CPUValue, especiallyIoValue.

 

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.