Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, bilyaminu.

Asked: July 18, 2017 - 1:06 am UTC

Last updated: July 19, 2017 - 6:04 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Good day
Please I need serious help, I have a table with 4 million records. Here is my query select * from table where custname like rownum <40 and ( '%WE%' or custnumber like '%WE%')
These are both var2 even thou I say custnumber.
This runs well in the morning hours before 11am, but from then to about 4pm the system takes time to fetch. Looking at the server the CPU has not reach 20% likewise d ram.

and we said...

In your query:
SELECT * 
FROM Customer 
WHERE Custname like ‘%WE%’;

You are searching for some characters in the middle of a string. In such cases, Oracle is unable to use an index and therefore the resulting execution plan will be a full table scan.

Given the performance characteristics you described, you are most like contending for IO bandwidth with other queries on your system in the afternoon.

Assuming your search criteria is actually selective (will return a small subset of the 4 million records in your table), and an index exists on the CUSTNAME column, it is possible to force an index access, which could be beneficial.

SELECT /*+ index (CUSTOMER CUSTNAME_IDX) */ * 
FROM Customer 
WHERE Custname like ‘%WE%’;


An example of where this was useful can be seen in an early askTOM question:
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1434815000346190059

An alternative option would be to create a context index, which will allow you to do a more IO friendly full text searches of large amounts of data.

First you would need to create the context index. For example:
CREATE INDEX search_idx 
on Customers(custname) 
INDEXTYPE is CTXSYS.CONTEXT
/ 

To utilize the context index you would need to change your query to be something like:
SELECT * 
FROM Customer 
WHERE contains(Custname ‘WE’) > 0 
/ 


To read more about it, see
https://docs.oracle.com/cd/B28359_01/text.111/b28303/ind.htm - g1020588

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, July 21, 2017 - 1:17 am UTC


BILYAMINU, July 27, 2017 - 8:18 pm UTC

THANK YOU SO MUCH

More to Explore

Hints

Need more information on hints? Check out the complete hint descriptions