Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Oracle 10g2 LIKE operator and case-insensitive issues
Hi,
We're curerrently facing some performance issues related to the "LIKE" operator in Oracle 10g2. Here is what we encountered.
We have a Oracle 10g2 database which has the following characteristics.
NLS_CHARACTERSET => AL32UTF8 NLS_NCHAR_CHARACTERSET => AL16UTF16 NLS_RDBMS_VERSION => 10.2.0.1.0
We created a table like below.
-- creates test table
CREATE TABLE MYTEST
(id NUMBER(10, 0) NOT NULL,
str1 VARCHAR2(128) NOT NULL,
str2 NVARCHAR2(128) NOT NULL);
Then, we populated with some random data.
-- PL/SQL for creating random data
BEGIN
DBMS_RANDOM.SEED('thisisjustatest');
FOR i IN 1 .. 100000 LOOP
INSERT INTO MYTEST VALUES(i, DBMS_RANDOM.STRING('P', 64),
DBMS_RANDOM.STRING('P', 64));
END LOOP;
INSERT INTO MYTEST VALUES(100001, 'steve', 'chien');
INSERT INTO MYTEST VALUES(100002, 'STEVE', 'CHIEN');
END;
Afterwards, we created the indexes.
-- creates indexes
CREATE INDEX AK1_ID_MYTEST ON MYTEST(ID); CREATE INDEX AK2_STR1_MYTEST ON MYTEST(STR1); CREATE INDEX AK3_STR2_MYTEST ON MYTEST(STR2);
With the "autotrace" turned on , NLS_COMP set to BINARY, and NLS_SORT set to BINARY in SQLPlus, we did two experiments.
CASE I.
select * from mytest where str1 = 'steve'
Plan hash value: 587925449
Predicate Information (identified by operation id):
2 - access("STR1"='steve')
CASE II.
select * from mytest where str1 like 'steve%';
Plan hash value: 587925449
Predicate Information (identified by operation id):
2 - access("STR1" LIKE 'steve')
Here is what bothered us more... We actually wanted to do case-insensitive searches & sorts on columnes str1 & str2. We dropped the indexes and re-created them as blows.
CASE I.
select * from mytest where str1 = 'steve'
Plan hash value: 3883648009
Predicate Information (identified by operation id):
2 - access(NLSSORT("STR1",'nls_sort=''GENERIC_M_CI''')=HEXTORAW('
024F025501FE026101FE00000202020202') )
CASE II.
select * from mytest where str1 like 'steve%';
Plan hash value: 1692938441
Predicate Information (identified by operation id):
1 - filter("STR1" LIKE 'steve%')
Oracle was using the "TABLE ACCESS FULL" to handle the "LIKE" operator. It's extremely slow and we wondered why it couldn't use the "INDEX RANGE SCAN" anymore.
Thanks for any suggestion!
![]() |
![]() |