Why CBO don't use function-base index when I use like and bind variable

Hello
I have litle problem with function-base index and like with bind variable.
When I use like with bind variable, the CBO don't use my function-base index.
For example when I create table and index:
ALTER SESSION SET NLS_SORT='BINARY_CI';
ALTER SESSION SET NLS_COMP='LINGUISTIC';
alter session set nls_language='ENGLISH';
-- DROP TABLE TEST1;
CREATE TABLE TEST1 (K1 VARCHAR2(32));
create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI'));
INSERT INTO TEST1
SELECT OBJECT_NAME FROM ALL_OBJECTS;
COMMIT;
When I run:
ALTER SESSION SET NLS_SORT='BINARY_CI';
ALTER SESSION SET NLS_COMP='LINGUISTIC';
SELECT * FROM TEST1 WHERE K1 = 'abcd';
or
SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%';
CBO use index.
PLAN_TABLE_OUTPUT
SQL_ID 4vrmp7cshbvqy, child number 1
SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%'
Plan hash value: 1885706448
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 2 | 98 | 1 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | TEST1_IDX | 2 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TEST1"."SYS_NC00002$">=HEXTORAW('6162636400') AND
"TEST1"."SYS_NC00002$"<HEXTORAW('6162636500') )
but when I run
SELECT * FROM TEST1 WHERE K1 LIKE :1;
CBO don't use index
PLAN_TABLE_OUTPUT
SQL_ID 9t461s1669gru, child number 0
SELECT * FROM TEST1 WHERE K1 LIKE :1
Plan hash value: 4122059633
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 89 (100)| |
|* 1 | TABLE ACCESS FULL| TEST1 | 2 | 48 | 89 (3)| 00:00:02 |
Predicate Information (identified by operation id):
1 - filter("K1" LIKE :1)
What should I change to force CBO to use index.
I don't wont use index hint in query.
My oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE     11.2.0.1.0     Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

OK. But why if I create normal index (create index test1_idx on test1(K1)) and return to default nls settings this same query use index.
PLAN_TABLE_OUTPUT
SQL_ID 9t461s1669gru, child number 0
SELECT * FROM TEST1 WHERE K1 LIKE :1
Plan hash value: 598212486
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 1 (100)| |
|* 1 | INDEX RANGE SCAN| TEST1_IDX | 1 | 18 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("K1" LIKE :1)
filter("K1" LIKE :1)
Note
- dynamic sampling used for this statement (level=2)
when index is function-base (create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI')))
PLAN_TABLE_OUTPUT
SQL_ID 9t461s1669gru, child number 1
SELECT * FROM TEST1 WHERE K1 LIKE :1
Plan hash value: 4122059633
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 89 (100)| |
|* 1 | TABLE ACCESS FULL| TEST1 | 3 | 54 | 89 (3)| 00:00:02 |
Predicate Information (identified by operation id):
1 - filter("K1" LIKE :1)
Note
- dynamic sampling used for this statement (level=2)
when I create index with upper function "index test1_idx on test1(upper(K1))" the query use index
SELECT * FROM TEST1 WHERE upper(K1) LIKE :1
Plan hash value: 1885706448
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 4481 | 157K| 1 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | TEST1_IDX | 806 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TEST1"."SYS_NC00002$" LIKE :1)
filter("TEST1"."SYS_NC00002$" LIKE :1)
Note
- dynamic sampling used for this statement (level=2)

Similar Messages

  • Why is my touch screen function not working when using facetime

    Why is my touch screen function not working when using facetime

    Hello megascones,
    After reviewing your post, it sounds like the screen is not responding to touch in one app. I would recommend that you read this article, it may be able to help the issue.
    If the screen on your iPhone, iPad, or iPod touch doesn't respond to touch - Apple Support
    Restart your device. If you can't restart, reset your device.
    Thanks for using Apple Support Communities.
    Have a nice day,
    Mario

  • Why my iphone 4 connect to wifi, but when i open safari and search something it say i not connect.. but in the same house my sister using iphone4 too but she can online with the same router

    why my iphone 4 connect to wifi, but when i open safari and search something it say i not connect.. but in the same house my sister using iphone4 too but she can online with the same router. i go and check over the detail of the network i connected, over the ip address and subnet mask have the numbers, but over the DNS and router don't have any number...isit the problem???? i can online at any other place but just my home cant...y????

    Hey confuddled_chica!
    Try the steps in the article below to troubleshoot this issue:
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/ts1398
    Thanks for being a part of the Apple Support Communities!
    Regards,
    Braden

  • I've seen all the posts for fixing the wifi on the 4s, none of them work!  So, who can tell me why my iPhone 4S cannot find any wifi when it used to easily, and when it does it can never connect?

    I've seen all the posts for fixing the wifi on the 4s, none of them work!  So, who can tell me why my iPhone 4S cannot find any wifi when it used to find wifi, and when it does find a wifi network it can never connect?  You think apple would have a clue how to fix it!  Because turning the wifi on and off doesn't work, resorting network settings doesn't work, even restoring phone to factory default doesn't work...

    Did not work. I've selected iMessage to ON and left it. After a few hours I recieved a message "activation unsuccessful. Turn on iMessage to try again". This has been going on for the past 3 days.

  • Why is my adobe photoshop trying to crash when i use the puppet warp tool?

    Every time i go to use the puppet warp tool i need to finish my assignment, photoshop says it is trying to fix the problem and then says it cant fix it and shuts the whole program down. And would like to know why is my adobe photoshop trying to crash when i use the puppet warp tool?

    You'll need to give us more information. What OS, what Photoshop version, how much RAM, what is your video card, and what are your performance preferences, etc., etc. -- ??

  • Just got a used airport base station. Set it up and getting wif signal. when I try to hook up on a computer it asks for a security key. where can I locate key?

    just got a used airport base station. Set it up and getting wif signal. when I try to hook up on a computer it asks for a security key. where can I locate key?

    If you mean the hexidecimal equivalent of the alphanumeric password, then you can find this via the AirPort Utility, as follows:
    AirPort Utility > Select the AirPort > Manual Setup
    On the AirPort Utility's menubar select Base Station > Equivalent Network Password

  • Why apple don't open online apple store for saudi arabia ? and can apple open online store for saudi arabia please

    why apple don't open online apple store for saudi arabia ? and can apple open online store for saudi arabia please

    PLEASE CAN APPLE OPEN ONLINE STORE FOR SAUDI ARABIA

  • I cannot use data back up when I use iphone4s in iphone5 ,please help me?

    I cannot use data back up when I use iphone4s in iphone5 ,please help me?now a day I use iphone5 and ipad4 I love apple

    I back up in iCloud when I used iPhone 4S,but now I want use data iCloud in iphone5 but I cannot do it,please help me?what should Ido ?

  • Query don't use the right index when using bind variables

    Hi people !
    I need some help because I have an issue with a query that don t use the right Indexes as it should
    First of all, I have mainly three tables :
    ORDER : Table that contains description for each Order (approximately 1 000 000 Records)
    ORDER_MVTS : Table that contains the tasks made (called movements) to set up each Orders
    with quantity of packages prepared for each product (approximately 10 000 000 Records)
    PRODUCT : Tables that contains the products (approximately 50 000 Records)
    When I launch the query with hard coded values, it brings back response very fast
    because it uses the right index (ORDER_DHR_VALID) which represent the date and hour of the order
    (with format 'DD/MM/YYYY HH24:MI:SS'). The selectivity for this index is good.
    NB 1: I have to use the trick " >= Trunc(date) and < trunc(date) +1 " to filter on a simple date because
    the index contains hour and minutes (I know it wasn't probably a bright idea at conception time).
    NB 2: The index on ORDER_MVTS.PRODUCT_CODE is'nt discriminating enough because there is'nt enough different products.
    It's the same for index on CUSTOMER_CODE and on MVT_TYPE so only the index on ORDER.DHR_VALID is good.
    Here is the correct explain plan when I execute the query with hard coded values :
    SELECT SUM(ORDER_MVTS.NB_PACKAGE)
    FROM ORDER_MVTS, PRODUCT, ORDER
    WHERE ORDER.DHR_VALID >= TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS'))
    AND ORDER.DHR_VALID < TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS')) + 1
    AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
    AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
    AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
    AND ORDER.CUSTOMER_CODE = 'ADIDAS'
    AND PRODUCT.CODE = 1234
    Rows Row Source Operation
    1 SORT AGGREGATE
    2 NESTED LOOPS
    4 NESTED LOOPS
    2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
    4 TABLE ACCESS BY INDEX ROWID ORDER
    777 INDEX RANGE SCAN (object id 378119) --> ORDER_DHR_VALID
    2 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
    30 INDEX RANGE SCAN (object id 377784) --> ORDER_MVTS_ORDER_FK
    Now the problem is when the query is used in a Cursor with bind variables.
    It seems like Oracle don't use index on ORDER.DHR_VALID because he can't figure out that he have
    to actually filter on a short period of time (only one day).
    So Oracle uses the index on ORDER_MVTS.PRODUCT_CODE which is'nt a bright idea (it takes 10 secondes instead of just one)
    Here is the bad explain plan :
    Rows Row Source Operation
    1 SORT AGGREGATE
    2 NESTED LOOPS
    722 NESTED LOOPS
    2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
    722 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
    1790 INDEX RANGE SCAN (object id 377777) --> ORDER_MVTS_PRODUCT_FK
    2 TABLE ACCESS BY INDEX ROWID ORDER
    1442 INDEX UNIQUE SCAN (object id 378439) --> ORDER_PK
    Now I have found two solutions to this problem :
    1) using a Hint to force the use of index on ORDER.DHR_VALID (with /*+ INDEX(ORDER ORDER_DHR_VALID) */ )
    2) Using Dynamic SQL and keeping the date hard coded (but not the other values except mvt_type)
    For example :
    QUERY :=
    'SELECT SUM(ORDER_MVTS.NB_PACKAGE)
    FROM ORDER_MVTS, PRODUCT, ORDER
    WHERE ORDER.DHR_VALID >= TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) '||
    AND ORDER.DHR_VALID < TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) + 1 '||
    AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
    AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
    AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
    AND ORDER.CUSTOMER_CODE = :CUSTOMER
    AND PRODUCT.CODE = :CODE ';
    These two solutions work but Number 1 is bad in theory because it uses a Hint
    and Number 2 may be difficult to code.
    So my question is : Does someone knows another solution to force the use of index ORDER_DHR_VALID that can be simple and reliable.
    Thank you very much for support
    Edited by: remaï on Apr 1, 2009 4:08 PM

    What version of oracle you have? CBO work is different in 9i and 10g.
    Usually cost based optimizer do not want to use index for >< condition with binding variables because optimizer can not use statistic to determine selectivity, and by default selectivity of <> operators is low.
    (As I remember '>' selectivity by default is 5%, you have two conditions > and <, therefore resulting selectivity will be 0.05*0.05=0.0025 as two independent events, but selectivity of other conditions
    ORDER_MVTS.MVT_TYPE = 'DELIVERY' or ORDER.CUSTOMER_CODE = 'ADIDAS' looks much better for CBO)
    The best solution I see is do not use binding variables. Actually your query looks as searching query, which executes not so often, therefore you will not have perfomance win along of skipping execution plan creation.
    Edited by: JustasVred on Apr 1, 2009 10:10 AM

  • Using function based index causing connection to abort

    My problem is as below
    I m using oracle 8i data base
    I have a table Dummy with column col1 .
    I have created a function based index on col1
    Now i try to update the table dummy using this function based index (i.e)
    i run the following query
    update dummy set col2='new value' where col1=ltrim(col2,'0')
    now when i execute this statement it causes the connection to abort. It gives the error
    ERROR at line 1:
    ORA-03113: end-of-file on communication channel
    But if i run select query (i.e) select col2 from dummy where col1=ltrim(col2,'0')
    it executes sucessfully.
    Also if i wrap the ltrim over some other function it works (i.e.)
    update dummy set col2='new value' where col1=upper(ltrim(col2,'0'))
    Any thoughts or ideas on what can be the reason...
    plese let me know for any questions,clarifications..
    Thanks in advance...
    Balaji

    Balaji, what is the exact error message returned? Remember to always include all the error details so that the problem can be identified and diagnosed.
    If you mean you are getting an ORA-03113: end-of-file on communication channel, this means that the Oracle Server Process that serviced your client session, crashed.
    In that case you need to refer to the alert log file on the database instance to see the server-side error message that resulted (often an ORA-0600 internal error) and the name of the trace file that was created at a result.
    You also failed to specify the exact Oracle 8i version you are using. Make sure you're on the very last patch set released for 8i - that should be 8.1.7.4 as far as I recall.

  • Why Apple don't fix half year serious problem with HD3000, Lion and Adobe products? Doesn't Apple really care about advanced users?

    Why Apple don't fix half year serious problem with HD3000 drivers, Lion and Adobe products? Doesn't Apple really care about advanced users?
    I have Mac mini and Macbook Pro 13". Bouth with HD3000. And I can't work at all. With Snow Lepard I had no problems. It's tiny problem in code. And such pain for lots of users!

    If you have a problem with Adobe products, voice your issues with them.
    It is the software developers responsibility to maintain compatability
    with any operating system, beit OSX or Windows.

  • Is there a problem using popup LOVs in a portal form with a bind variable?

    I have a portal form with 2 LOVs. The second LOV is a dependent LOV whose bind variable can be NULL. I have read Note 263923.1, "How To Create Dependent Lovs In Forms", and my form works as long as I use combo boxes to display the LOVs. I need to use popups so the user can search the LOVs as they are quite lengthy. Plus I want to be able to pick a value from my second LOV without selecting a value from the first LOV -- hence, my bind variable can be null and that is where my problem lies. As long as I select a value from the first LOV, the second LOV popup will work. If I click on the icon to display the second LOV without pre-selected a value from the first LOV, I get the following error:
    POPUP LOV ERROR:
    LOV: "9A17692880B6B8509F514F5B9CA9EC808DD403218B3CF19A33C04CD1FAB0ADE17ADC33E6B67998A933357CE5264D204E"
    Parse Message: Parse as pre-set global: "TORE".
    Find Message: LOV is of type DYNAMIC (LOV based on SQL query).
    Query: "SELECT ...."
    wwv_bind.prepare_bind: ORA-01403: no data found
    My form is based on a table with a custom layout. The sql for the second LOV is similar to: SELECT ENAME, EMPNO FROM SCOTT.EMP WHERE (DEPTNO = :DEPT AND :DEPT IS NOT NULL) OR :DEPT IS NULL.
    Thanks in advance for any help,
    Carol

    Don't use EPS any more! It does not support transparency nor color management.
    If you save vector files from Illustrator, use AI with PDF compatiblity.
    If you save image files from Photoshop, use PSD.
    If you save image files combined with vector forms and/or text from Photoshop, use PDP which is a Photoshop PDF.
    For vectors from Illustrator use CMYK files.
    For images use RGB, conversion to CMYK should never done before PDF export, better, if the printer allows it, is to export a PDF with live transparency as it is PDF/X-4
    If the printer requires a PDF with CMYK only export a PDF/X-1a.

  • My i mac isnt finding my sd card when i use the slot, or when i use a card reader via the useb ports, however it works on other i macs, can anyone help?

    my i mac isnt finding my sd card, when i use the slot or even when I use usb port via card rader. I have tried on anothe r machine and it works fine. can you help?
    thanks

    First thing to check if go to Finder Menu/Preferences/General
    Make sure External disks is checked

  • Help setting Parameters using JDBC and Bind Variables for Oracle List

    I fully understand the concept of using Bind Variables when using JDBC to avoid hard parses everytime my SQL statement is executed when only a certain value changes. For example, perhaps I have the following statement:
    PreparedStatement ps = con.prepareStatement("select salary from employees where employee_id = ?");
    I would then set the value of the question mark (the first and in this case only parameter) using:
    ps.getStmt().setString(1,empId1);
    That is assuming I have the variable empId1 populated with what I want. Anyway, my question has to do with Oracle lists. In other words, if I am just executing the statement against the db, it might look like:
    select salary from employees where employee_id in ('123','456','789');
    I still want to use bind variables and I can do it in JDBC with something like:
    select salary from employees where employee_id in ('123','456','789');
    ps.getStmt().setString(1,empId1);
    ps.getStmt().setString(2,empId2);
    ps.getStmt().setString(3,empId3);
    BUT, what if I just want to construct my list of ids upfront as a string and do something like:
    select salary from employees where employee_id in (?)
    ps.getStmt().setString(1,listOfEmpIds);where listOfEmpIds would look something like '123','456','789'.
    That's what I want to do but it doesn't work. It would be treating the list as a single parameter as opposed to lots of individual parameters. Can someone please tell me the syntax for this if it is possible? I have tried where XX in (?) and where XX in ? (and the string I substitute has the parenthesis in it), but neither work.
    Thank you for your help.

    I always build the list myself.
    You could, however, pass the list as a varchar to a stored proc and then have the stored proc parse (or dynamically execute) using it.
    The second method might even be faster although I would suspect that is only going to be the case if the list is very large. Or it might not.

  • Is neccesary to use commit()...when you use stmt.executeUpdate(sentence);?

    Is neccesary to use commit()..... when you use
    stmt.executeUpdate(sentence);
    and the sentence is by example:
    sentence = "delete from table_X where ELEMENT1 = 'hi'"; ????
    This is because...i did a servlet in which i send a sentence (the sentence could be insert or delete).....and apparently it is working very well....i can see that the rows are added or removed in the DB table...but i am a little confused...because in a paper says "modifications in tuples are temporarily stored in the db system. They become permanent only after the statement commit has been issued"
    and i am not calling commit in my servlet.....
    Thanks in advance,
    Mary

    AFAIK, by default, Connection objects have their auto-commit feature enabled.
    So, assuming your database supports transactions, every operation will be commited automatically by the JDBC driver's code.
    To turn it off, you must call:
    connection.setAutoCommit( false );
    By doing so, you will need to call commit() in your code if you want to make those changes permanent.
    HTH

Maybe you are looking for

  • Can not access to OCA User Pages

    Hello, I am following the OBE for External Authentication Pluggin Configuration, and The guide said i should go url: https://host.domain:4400/oca/user I changed according the host and domain for the infrastructure server, but when I try the resul is

  • B1DE (AddOn Installer) for 64 bit server

    Hi All, I have a problem. One of my client has a 64 bit server. AddOn installation created with B1DE for SAP 2007 doesn't work on that server. After running SAP AddOn is trying to install, and then there is an error. Is there any way to create AddOn

  • Where do I find my playing lists that were next to the library?

    Where will I find all my playing lists that were next to my libray?

  • Displaying messages without h:message or h:messages tag

    How can you display messages without h:message or h:messages tag. Is it possible to disply messages in another component. I have only a small piece of page reserved for displaying errors and it would be nice to show these errors in component with scr

  • Opteron errata 131 - machine freezes regularly

    Hello, i got a new Dual-DC-Opteron (270) machine using a Tyan Thunder K8SR (S2881) with 4 GB RAM, a scsi boot disk and 4 SATA disks running as a Raid 10 under Solaris VolumeManager. The machine freezes sometimes when i start to copy files to it via N