To force the index

Hello

My DB is 10.2.0.4

I have a HISTORY table that has 4 million documents.
I have a query which gives 15 lines out of it.
Index is exactly on the same columns as the where clause.
My = ALL_ROWS optimizer_mode

I had read "complete analyses are NOT ALWAYS evil, indexes are NOT ALWAYS good.
But is it possible to force the query to use the indexes here?
 
CREATE INDEX history_idx3
  ON history (
    ACCNR,
    ACCERGNR,
    CUSTNR
  )
  STORAGE (
    INITIAL  241664 K
  )
/


SQL> SELECT * FROM HISTORY
WHERE ACCNR = 1500003
AND ACCERGNR = 0
AND CUSTNR = 230530  2    3    4  ;

15 ROWS SELECTED.

ELAPSED: 00:03:41.00

EXECUTION PLAN
----------------------------------------------------------
PLAN HASH VALUE: 3565408272

------------------------------------------------------------------------------
| ID  | OPERATION         | NAME     | ROWS  | BYTES | COST (%CPU)| TIME     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |          |     1 |   200 | 93050   (2)| 00:18:37 |
|*  1 |  TABLE ACCESS FULL| HISTORY |     1 |   200 | 93050   (2)| 00:18:37 |
------------------------------------------------------------------------------

PREDICATE INFORMATION (IDENTIFIED BY OPERATION ID):
---------------------------------------------------

   1 - FILTER("CUSTNR"=230530 AND "ACCERGNR"=0 AND
              TO_NUMBER("ACCNR")=1500003)


STATISTICS
----------------------------------------------------------
          1  RECURSIVE CALLS
          0  DB BLOCK GETS
     420095  CONSISTENT GETS
     418614  PHYSICAL READS
          0  REDO SIZE
       6266  BYTES SENT VIA SQL*NET TO CLIENT
        492  BYTES RECEIVED VIA SQL*NET FROM CLIENT
          2  SQL*NET ROUNDTRIPS TO/FROM CLIENT
          0  SORTS (MEMORY)
          0  SORTS (DISK)
         15  ROWS PROCESSED

seems to be ACCNR in the table BACKGROUND is defined as VARCHAR?
If so, your index is ignored.

Try this:

SELECT * FROM HISTORY
WHERE ACCNR = '1500003'
AND ACCERGNR = 0
AND CUSTNR = 230530                                                                                                                                                                                                                                                                                                                                                                                                        

Tags: Database

Similar Questions

  • Force the use of the index without advice

    Dear all,

    I'm a newbie in the world of oracle.

    I HAD POSTED THIS SAME QUESTION IN SQL AND PLSQL CATEGORY, but thought that I had posted in a wrong category, so I post the same question again here.

    Recently my boss asked me a question about the use of the index.

    He wants to force the index to use if the optimizer chooses not to use it.

    But limitattion is this boat reach the query or the code because it is taken directly by an application that we can not change the code.

    So how is - a can force a query to use index without giving advice.

    It should be for a particular query, it should not apply for all indexes in the database.

    I know a parameter "OPTIMIZER_INDEX_COST_ADJ. If you set this parameter correctly, you can force the optimizer to use index. But it has its own limitations.

    So I want an alternative to this option which can only be applied to a particular query that is run without the use of indicators.

    Because this is my first thread, sorry if I made any mistake by posting the question

    Thank you all in advance

    Kind regards
    Navin Bandi

    Hello

    Have you tried the oracle outlines.

    Concerning
    Anurag

  • TIP, GOLD and the INDEX FUNCTION-ORIENTED

    RDBMS: 10.1.0.5.0

    I'm trying to force an index based on a function in a query with a condition OR .
    It seems that INDEX INDICATOR does not work if the query has an OR condition.

    I created a test case to describe the problem:
    create table tab1 (col1 VARCHAR2(300))
    
    ....load the table.......
    
     CREATE INDEX col1_IX ON tab1
       (
          my_FUNCTION(col1)
       )
       TABLESPACE USERS ;
    The plan of the explain for a simple query command is:
    select * from tab1 where my_FUNCTION(col1) = '+23452081'
    
    Plan hash value: 2179519467
     
    ---------------------------------------------------------------------------------------
    | Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |         |   871 |   512K|     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| TAB1    |   871 |   512K|     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | COL1_IX |   348 |       |     1   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------
     
    Predicate Information (identified by operation id):
    ---------------------------------------------------
     
       2 - access("my_FUNCTION"("COL1")='+23452081')
     
    Note
    -----
       - dynamic sampling used for this statement
    If the simple query has a CONDITION or:
    select * from tab1 where ( MY_FUNCTION(col1) = '+23452081' or col1       <> '')
    
    Plan hash value: 2211052296
     
    --------------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |  5183 |  3047K|    59  (31)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| TAB1 |  5183 |  3047K|    59  (31)| 00:00:01 |
    --------------------------------------------------------------------------
     
    Predicate Information (identified by operation id):
    ---------------------------------------------------
     
       1 - filter("COL1"<>'' OR "MY_FUNCTION"("COL1")='+23452081')
     
    Note
    -----
       - dynamic sampling used for this statement
    I tried to force the index using the trick without success:
    select /*+ index(tab1 col1_IX) */ * from tab1 where ( MY_FUNCTION(col1) = '+23452081' or col1       <> '')
    
    Plan hash value: 2211052296
     
    --------------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |  5183 |  3047K|    59  (31)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| TAB1 |  5183 |  3047K|    59  (31)| 00:00:01 |
    --------------------------------------------------------------------------
     
    Predicate Information (identified by operation id):
    ---------------------------------------------------
     
       1 - filter("COL1"<>'' OR "MY_FUNCTION"("COL1")='+23452081')
     
    Note
    -----
       - dynamic sampling used for this statement
    Can you help me?

    Published by: Dom Brooks on January 28, 2011 11:26

    Sorry too hasty.

    If you have an index on COL1 and your predicate can use this index, then you might get a BITMAP CONVERSION.

    If you do not have an index on COL1 or you cannot use it, then you will do a FTS.

    Useful relevant info:

    Based on an index function are not used in the expansion of GOLD in 10gR 1 (or beyond - restriction still documented in 11 GR 2)

    See here:
    http://download.Oracle.com/docs/CD/B14117_01/AppDev.101/b10795/adfns_in.htm#1006464

    Dion Cho spoke here:
    http://dioncho.WordPress.com/2009/07/31/function-based-index-and-or-expansion/

  • Query is not using the index. (Included execution plan. TKPROF output not available)

    Hi all

    Version of DB: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

    Here is the description of the problem:
    (The statistics are up to date for all tables).

    The query below does not use the index on ACCOUNTS_LIVE (ID). (Unique index)
    SQL> explain plan for
      2  select txn.account_number,to_number(txn.amount_lcy) txn_amt,to_date(booking_date,'YYYYMMDD') TXN_DATE,
      3        sal.latest_sal,sal.sal_date,customer_name,employer_name,
      4       decode(COMMUNICATION_TYPE_1,'MOBILE',COMMUNICATION_NO_1,
      5            decode(COMMUNICATION_TYPE_2,'MOBILE',COMMUNICATION_NO_2)) mob,
      6       txn.CURRENCY, CHEQUE_NUMBER,trans_dets,trans_reference,target,teller_id,acc.category,acc.inactive_marker,
      7            acc.posting_restrict,cus.sector,cus.industry
      8  from coreadmin.Gtxn_dtl_v1 txn,
      9                     (select account_number,round(to_number(nvl(amount_lcy,0)),2) latest_sal,TXN_DATE sal_date,rr
     10                      from
     11                        (select to_date(booking_date,'YYYYMMDD') TXN_DATE,batch_id,account_number,amount_lcy
     12                             ,row_number() over (partition by account_number
     13                                                     order by to_date(booking_date,'YYYYMMDD') desc NULLS LAST,
     14                                                     batch_id desc nulls last) rr,
     15                                     CURRENCY, CHEQUE_NUMBER,trans_dets,trans_reference
     16                             from coreadmin.Gtxn_dtl_v1
     17                             where transaction_code in ('204','938')
     18                  and to_number(amount_lcy) > 0)
     19                             where rr = 1
     20                       ) sal,accounts_live acc,customers_live cus
     21  where to_date(booking_date,'YYYYMMDD') between to_date('030109','DDMMRR') and to_date('020209','DDMMRR')
     22  and txn.account_number = sal.account_number
     23  and txn.account_number = acc.id
     24  and txn.CUSTOMER_ID = cus.CUSTOMER_number
     25  and target in ('30','31','32')
     26  /
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT                                                                                                                                     
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 920245766                                                                                                                            
                                                                                                                                                          
    -----------------------------------------------------------------------------------------------------------                                           
    | Id  | Operation                        | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                           
    -----------------------------------------------------------------------------------------------------------                                           
    |   0 | SELECT STATEMENT                 |                |   363M|   121G|       |   223K  (4)| 00:44:47 |                                           
    |*  1 |  HASH JOIN                       |                |   363M|   121G|  6232K|   223K  (4)| 00:44:47 |                                           
    |*  2 |   VIEW                           |                | 34453 |  5820K|       |   147K  (1)| 00:29:36 |                                           
    |*  3 |    WINDOW SORT PUSHED RANK       |                | 34453 |  1480K|  4072K|   147K  (1)| 00:29:36 |                                           
    |*  4 |     FILTER                       |                |       |       |       |            |          |                                           
    |   5 |      INLIST ITERATOR             |                |       |       |       |            |          |                                           
    |*  6 |       TABLE ACCESS BY INDEX ROWID| GTXN_DTL_V1    | 34453 |  1480K|       |   147K  (1)| 00:29:31 |                                           
    |*  7 |        INDEX RANGE SCAN          | IDX_TXN5       |   707K|       |       |  1815   (2)| 00:00:22 |                                           
    |*  8 |   HASH JOIN                      |                |   598K|   106M|    20M| 63724   (1)| 00:12:45 |                                           
    |*  9 |    MAT_VIEW ACCESS FULL          | CUSTOMERS_LIVE |   227K|    17M|       |  2239   (4)| 00:00:27 |                                           
    |* 10 |    HASH JOIN                     |                |   598K|    59M|  9504K| 57157   (1)| 00:11:26 |                                           
    |  11 |     MAT_VIEW ACCESS FULL         | ACCOUNTS_LIVE  |   249K|  6577K|       |  1832   (2)| 00:00:22 |                                           
    |* 12 |     TABLE ACCESS BY INDEX ROWID  | GTXN_DTL_V1    |   597K|    43M|       | 52319   (1)| 00:10:28 |                                           
    |* 13 |      INDEX RANGE SCAN            | IDX_TXN11_V1   |  1204K|       |       |  3931   (2)| 00:00:48 |                                           
    -----------------------------------------------------------------------------------------------------------                                           
                                                                                                                                                          
    Predicate Information (identified by operation id):                                                                                                   
    ---------------------------------------------------                                                                                                   
                                                                                                                                                          
       1 - access("TXN"."ACCOUNT_NUMBER"="ACCOUNT_NUMBER")                                                                                                
       2 - filter("RR"=1)                                                                                                                                 
       3 - filter(ROW_NUMBER() OVER ( PARTITION BY "ACCOUNT_NUMBER" ORDER BY                                                                              
                  TO_DATE("BOOKING_DATE",'YYYYMMDD') DESC  NULLS LAST,INTERNAL_FUNCTION("BATCH_ID") DESC  NULLS                                           
                  LAST)<=1)                                                                                                                               
       4 - filter(TO_DATE('030109','DDMMRR')<=TO_DATE('020209','DDMMRR'))                                                                                 
       6 - filter(TO_NUMBER("AMOUNT_LCY")>0)                                                                                                              
       7 - access("TRANSACTION_CODE"='204' OR "TRANSACTION_CODE"='938')                                                                                   
       8 - access("TXN"."CUSTOMER_ID"="CUS"."CUSTOMER_NUMBER")                                                                                            
       9 - filter("TARGET"='30' OR "TARGET"='31' OR "TARGET"='32')                                                                                        
      10 - access("TXN"."ACCOUNT_NUMBER"="ACC"."ID")                                                                                                      
      12 - filter("TXN"."CUSTOMER_ID" IS NOT NULL)                                                                                                        
      13 - access(TO_DATE("BOOKING_DATE",'YYYYMMDD')>=TO_DATE('030109','DDMMRR') AND                                                                      
                  TO_DATE("BOOKING_DATE",'YYYYMMDD')<=TO_DATE('020209','DDMMRR'))                                                                         
    
    38 rows selected.
    
    SQL> select index_name
      2  from dba_ind_columns
      3  where table_name = 'ACCOUNTS_LIVE'
      4  and column_name = 'ID';
    
    INDEX_NAME                                                                                                                                            
    ------------------------------                                                                                                                        
    IDX_ACCLIVE                                                                                                                                           
    Line 23 of the query uses accounts_live.id.

    11 the order ID explain plan shows that the index does not use.

    Please suggest.

    Thanks in advance,
    Jac

    What happens when you force the index by using hint and use the hash between txn and acc join?

    See you soon
    Sarma.

  • I know how to force the Spotlight for re - index a drive or a folder. But how then do I mail?

    I know how to force the Spotlight for re - index a drive or a folder.

    But how then do I mail? I drag this file to the window?

    Thank you.

    Try re-indexing of mailboxes mailbox. This can take some time if you have a lot of mail.

    Reindex messages           For El Capitan, try looking in V3.

    Reindex messages (2)        See post by Linc Davis

  • How we force a query to use transparently a hint, even if the index is not given in the query as a query rewriting.

    How we force a query to use transparently a hint, even if the index is not given in the query as a query rewriting.

    For example:

    If the user runs a query select deptno, avg (sal) from emp group by deptno;

    We want the optimizer to use a hint of result_cache with this request, and it should be transparent to the user.

    Query should be rewritten to seamlessly

    Select / * + result_cache * / deptno, avg (sal)

    WCP

    Group of deptno;

    How can this feature we make? Please advice.

    I checked the possibility of SPM and contours, but it is not clear if this rewrite is possible here.

    Thank you and best regards,

    Vikas Krishna

    Surely dbms_advanced_rewrite is designed for this situation?

  • What is the right time to use the index with force?

    I have an EMPLOYEE table.  I join with the ROLE, and it has only about 200 distinct values on column EMPLOYEE. EMPLOYEE_TYPE_ID.

    Select / * + INDEX (an i_employee_type_id) * / b.SID as EMP_NAME, b.role_cd in the ROLE

    Of

    EMPLOYEE,

    B ROLE

    where

    a.EMPLOYEE_TYPE_ID = b.EMPLOYEE_TYPE_ID

    AND a.EFFECTIVE_END_TS > = systimestamp;

    Is it a good idea to use the index?  .. Or let the full table scan.

    SQL > select distinct EMPLOYEE_TYPE_ID of the EMPLOYEE;

    238 selected lines.

    If you don't know it will help not to use.

    Personally, I found several SQLs with index finger tips (written by programmers thinking index access is ALWAYS GOOD) end up harming performance. Oracle made a reading diluvium full table scan, single index reads as follows, according to the % of the returned array it is actually faster to do a full table scan. The optimizer did a great job to determine this.

    If you think there are cardinality estimation problems, and the optimizer expects a large number of lines when there are actually few being returned, in THIS case a suspicion was justified. Even so, in this case, I prefer that oracle manages the flag itself.

    You can do this by running the SQL tuning advisor. In fact, it will trigger the optimizer checks that the estimates are turned off and it will create a profile for you. (A profile is actually a stored set of advice that set the execution plan for you). If at the point where the underlying data changes significantly and profile ends up hurting performance, you do not need to touch the code like you would with manually added notes, you can just disable or delete the profile and let the optimizer re - analyze the statement.

    Concerning

    EDIT: In case of small tables, it is preferable to just cache the whole table in the POOL to KEEP and let oracle scan if necessary.

    Edit2: With the notable exception of index fast full scans, which are diluvium index readings. But they are only relevant when the request is quite satisfied by the index and has no need to visit the table.

  • How to force the opening of the PDF with plugin even for download links?

    I would like to know if there is a way to force Firefox to ALWAYS open PDF links in the browser, rather than leaving the Web site to force the download. This isn't something related to the plugin PDF.js viewer or Adobe Reader or any other.

    Sometimes makes a link to a PDF file be opened in a plugin container in tab, e.g.: http://www.empreende.org.br/pdf/Programas%20e%20Pol%C3%ADticas%20Sociais/Governan%C3%A7a, %20accountability%20e%20responsividade.pdf

    But sometimes, it forces the PDF to download, like this: http://ojs.uwindsor.ca/ojs/leddy/index.php/informal_logic/article/download/510/473

    Can I avoid this to happen, that is, I can tell Firefox never download a PDF file, always open in a tab, as usual, regardless of the command "Download"?

    Hello alainsr, you can use the InlineDisposition addon to fix this: https://addons.mozilla.org/firefox/addon/inlinedisposition/

  • How to stop the indexing of media files in Windows Media Center Xbox 360 extender?

    I have successfully set up the Xbox 360 Windows Media Center and attaches it to a machine Windows 7 Ultimate 32 bit on the same LAN segment.  It works fine, except that he rebuilt his index from scratch, apparently file whenever it is launched on the Xbox.  Specifically, if the Xbox is turned off and then turned back on, and WMC on that is launched, the files in the folder of the Windows 7 machine media library are indexed again).  This makes WMC on Xbox almost unusable, because it forces you to wait a long time for the UI to become sensitive, whenever it is launched after turning on the Xbox.

    This doesn't seem to be a network problem, as I've reconfigured it all the senses (wired and wireless), network setting tool reports always excellent results, and once the index file is rebuilt files media play very well.

    I tried to reduce the number of files in the files of 'library' of the media on the Windows 7 machine and were reduced to a single folder in which the files do not change (that is, the files are added, deleted or changed between Xbox WMC launches).

    This behavior is normal?  Is it possible to change it?  I can't find the settings on the Xbox that control it.

    The local network segment is on the Internet, and the Windows 7 machine had all updates applied from the time of this post.  The Xbox is the new Xbox 360 4 gig, with more than 2 GB of free space on the internal memory and another 8 GB of free space on MU.

    ---------------

  • How can I exclude specific folders of the indexing of Windows Media Player stream?

    Windows Media Player 12 has removed the possibility of excluding some files being indexed.  This feature was available in Windows Media Player 11.  I need to be able to exclude some records indexed because I have collections of photos that are too big for the WMP player to manage.

    Excluding these folders in the library WMP is not an option because MediaCenter uses the settings of the library to determine where to find pictures (even if it does not use the library to view photos or videos - just the WMP settings) so if they are not included in the library WMP, I can't see them in MediaCenter, but if they are in the WMP library he freezes everything for 30 minutes whenever I turn on an Extender that forces a re-analysis of the WMP library.

    I tried to edit wmpfolders.wmdb to exclude certain files, but the changes that I last only for a few hours to a day or two.

    any ideas?

    Thank you
    Dan

    Hi Khaled, thank you very much for your answer.  My question was related to the media library in Windows Media Player, but your response was to Windows 7 libraries.  Unfortunately, your answer does not apply to my question.

    What I need to be able to do, is to exclude a folder from indexing of Windows Media Player streams although it is included in the list of folders to the index.  It's because the Media Center uses the settings of the library Windows Media Player to determine where to find pictures.  However, it does not use the Windows Media Library to view the photos.  It is, therefore, no need to have Windows Media Player, indexing of thousands of photos when Media Center does not even use the library to display.

    The problem is that when I let Windows Media Player scan my pics, it causes all to slow down for 30 minutes or more each time I light a MediaCenter extender because it is re-scanner all my photos.  However, if I let Windows Media Player not scan my photos, so they are not visible in the MediaCenter.  There is a catch 22.

  • After a clean install of windows 7 Home premium 64-bit, dvd will play not [scrambled] and computer is crashes sometimes and I have to force the reboot.

    I have windows 7 Home premium 64-bit, which has totally collapsed.  By mistake, I installed my operating system 32-bit vista on it.  I bought a new windows 7 Home premium operating system and installed.  I did a clean install after formatting the hard drive [the did twice].  Now dvd will play not [scrambled] and computer is crashes sometimes and I have to force the reboot.  I saw the reference to System 32 on restart options.  Help?

    Original title: operating system 32 and 64 bit

    Have you installed Windows 7 device drivers for your make and model. If this is not the case, then go to the support web site factory and download Windows 7 drivers to a folder on your PC and then first install the drivers for the card mother/chipset, followed by USB, SATA, LAN, Audio and all other pilots.

    Find the website of your computer manufacturer support.
    http://Windows.Microsoft.com/en-us/Windows/help/contact-support/computer-manufacturers

    How do you know if you have a 32 bit or bit 6 vrsion of Windows installed:

    http://support.Microsoft.com/kb/827218

    BIOS updates: you should check to see if there was one, or sometimes several updates BIOS for the motherboard. Read (if provided) which solves the update. Sometimes a newer BIOS update will fix the problem. Read the instructions on how to your BIOS update/flash very carefully and be more you understand the process. There is a risk of a bad flash/update occurs which can make your system unbootable.

    Also check the download site of the manufacture of the graphics card for the latest Windows 7 drivers for your card.
    ATI: http://support.amd.com/us/gpudownload/Pages/index.aspx
    NVIDIA: http://www.nvidia.com/Download/index5.aspx?lang=en-us

    J W Stuart: http://www.pagestart.com

  • How to force the Explorer search to show ONLY the files that match the search target?

    I frequently need to search for files with brackets in the name of the file.    However, a bug in the Search Explorer means that search results will fill up with a lot of waste that does not match my search target.

    Example:

    At a command prompt "dir/s * (abc) *.» ' * ' usually works: the name of each file found will contain "(abc)".   (The only time that a search for the command line fails is when the version 8.3 of the name of the file matches the search target, but the name of the actual file does not work.)

    However, in Solution Explorer, look for "* (abc) *.» "*" returns all files with 'abc' in the name, and provides no way to filter the results so that I only see files with '(abc)' in the name of the file.

    This search bug means that you want "* (de) *.» ' * ' at the command prompt returns 72 hits, while searching with Explorer returns 7381 hits!

    Cancellation: Another inconvenience of Windows is when I work at a command prompt I get often unexpected results because the wildcard matching is done against both the full name of the file or folder and the name of 8.3.   Is there a way to force cmd.exe to restrict the wildcard matches only the complete names of the files and folders?  That is to say, is there a way to force cmd.exe to never, ever, use the 8.3 names?

    Hi Rob,

    In order to quickly provide a solution, please answer this question:

    Did you do changes on the computer before the show?

    Follow the steps below to solve the problem:

    Method 1: If you have problems of location of the files, folders, or other items on your computer, try using the search and indexing of troubleshooting to solve the problem. It ensures that the Windows Search service is running and checks if you have the correct permissions to search all the directories on your computer.

    See the article below for additional information and steps.

    Open the troubleshooter for search and indexing

    http://Windows.Microsoft.com/en-us/Windows7/open-the-search-and-indexing-Troubleshooter

     

    Method 2: I also suggest you to re - index files, then check. Follow the article below for the procedure.

    Change advanced indexing options

     http://Windows.Microsoft.com/en-us/Windows7/change-advanced-indexing-options

    See also:

    Improve Windows searches using the index: frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows7/improve-Windows-searches-using-the-index-frequently-asked-questions

    Hope this information helps. Pleave get back if you need help, will be happy to help you.

  • Invalidation of the index based on a function because the recompilation

    Hello

    one of our customers has two indices according to the functions that fall under the State "off" in some situations. After looking more closely at the situation, there are some things that my opinion are different from what I expected of a function-based index. Because I am unable to find anything about either on metalink (or I'm not asking the right question) I would appreciate a second opinion of you.

    To keep things simple, I gave an example to illustrate the behavior. I use Oracle 12.1.0.2, although it can also be reproduced on versions 10.2 and 11.2.

    It's my environment and three parameters that I find relevant to the discussion:

    SQL> select banner from v$version;
    
    BANNER
    ----------------------------------------------------------------------------
    
    Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
    PL/SQL Release 12.1.0.2.0 - Production
    CORE    12.1.0.2.0      Production
    TNS for Linux: Version 12.1.0.2.0 - Production
    NLSRTL Version 12.1.0.2.0 - Production
    
    SQL> show parameter remote_dependencies
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ----------
    remote_dependencies_mode             string      TIMESTAMP
    
    SQL> show parameter query_rewrite
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- -------------
    query_rewrite_enabled                string      TRUE
    query_rewrite_integrity              string      enforced
    

    Test case:

    SQL> CREATE OR REPLACE FUNCTION f1 (p_string IN VARCHAR2)
      2  RETURN VARCHAR2
      3  DETERMINISTIC
      4  IS
      5  BEGIN
      6    RETURN lower(p_string);
      7  END f1;
      8  /
    
    Function created.
    
    SQL> CREATE TABLE tmp_t1 (a_string VARCHAR2(10));
    
    Table created.
    
    SQL> INSERT INTO tmp_t1 VALUES ('a');
    
    1 row created.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL> CREATE INDEX x1_tmp_t1 ON tmp_t1(f1(a_string));
    
    Index created.
    
    SQL> set linesize 80;
    SQL> column index_name format a10;
    SQL> SELECT index_name, index_type, status, funcidx_status
      2    FROM user_indexes;
    
    INDEX_NAME INDEX_TYPE                  STATUS   FUNCIDX_
    ---------- --------------------------- -------- --------
    X1_TMP_T1  FUNCTION-BASED NORMAL       VALID    ENABLED
    

    We have our table and our based on an index function which basically converts the values to lowercase. From here on things, download a little weird. What happens with the index based on a function if the underlying function is recompiled? I always thought (and which is also stated in the Concepts and the use of function index (Doc ID 66277.1)) that the index would change its status to "disabled". Here is an excerpt of the said Doc ID:

    The index depends on the State of the PL/SQL function. The index can be

    struck down or rendered useless by changes to the function. The index is marked

    People with DISABILITIES, if he is brought to the function or function is re-created.

    The timestamp of the function is used to validate the index.

    To allow the index after it is created, the function if the signature of the

    the function is identical to the front:

    ALTER INDEX ENABLE;

    If the signature of functions is changed, to make the changes effective

    in the index, the index must be renewed to make it valid.

    ALTER INDEX REBUILD.

    It seems that this is not the case, as the index remains valid and activate.

    SQL> alter function f1 compile;
    
    Function altered.
    
    SQL> SELECT index_name, index_type, status, funcidx_status
      2    FROM user_indexes;
    
    INDEX_NAME INDEX_TYPE                  STATUS   FUNCIDX_
    ---------- --------------------------- -------- --------
    X1_TMP_T1  FUNCTION-BASED NORMAL       VALID    ENABLED
    

    OK, explicitly recompiling function F1 single timestamp changed. What if we replace the function completely and we change the output of the function - for example we will switch from a LOWER function to SUPERIOR function in the body of the F1. Again, it is change that I thought would be not only to disable the index based on a function, but also force its reconstruction. At least that is my understanding of the explanation in Doc ID).

    SQL> CREATE OR REPLACE FUNCTION f1 (p_string IN VARCHAR2)
      2  RETURN VARCHAR2
      3  DETERMINISTIC
      4  IS
      5  BEGIN
      6    RETURN UPPER(p_string);
      7  END f1;
      8  /
    
    Function created.
    
    SQL> SELECT index_name, index_type, status, funcidx_status
      2    FROM user_indexes;
    
    INDEX_NAME INDEX_TYPE                  STATUS   FUNCIDX_
    ---------- --------------------------- -------- --------
    X1_TMP_T1  FUNCTION-BASED NORMAL       VALID    ENABLED
    
    

    Should not be. Because of the function "create or replace" F1 never go through a "invalid" phase which may be necessary for index becomes unusable? What about queries on the TMP_T1 table? Does optimizer always uses access index or not? What about the results?

    SQL> EXPLAIN PLAN SET statement_id='s1' FOR
      2  SELECT a_string, f1(a_string) as f1_a_string, f1('a') as f1_literal
      3    FROM tmp_t1
      4   WHERE f1(a_string) = 'a';
    
    Explained.
    
    SQL> SELECT * from table(dbms_xplan.display(statement_id=>'s1'));
    
    PLAN_TABLE_OUTPUT                                                                                                   
    ------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 3133804460                                                                                         
                                                                                                                        
    -------------------------------------------------------------------------------------------------                   
    | Id  | Operation                           | Name      | Rows  | Bytes | Cost (%CPU)| Time     |                   
    -------------------------------------------------------------------------------------------------                   
    |   0 | SELECT STATEMENT                    |           |     1 |  2024 |     2   (0)| 00:00:01 |                   
    |   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TMP_T1    |     1 |  2024 |     2   (0)| 00:00:01 |                   
    |*  2 |   INDEX RANGE SCAN                  | X1_TMP_T1 |     1 |       |     1   (0)| 00:00:01 |                   
    -------------------------------------------------------------------------------------------------
    

    The index is used by the optimizer, see the results.

    SQL> column f1_a_string format a15;
    SQL> column f1_literal format a15;
    SQL> SELECT a_string, f1(a_string) as f1_a_string, f1('a') as f1_literal
      2    FROM tmp_t1
      3   WHERE f1(a_string) = 'a';
    
    A_STRING   F1_A_STRING     F1_LITERAL
    ---------- --------------- ---------------
    a          a               A
    

    A_STRING = value in the table

    F1_A_STRING = value of f1 (a_string) but the value is not evaluated because it comes from an index, so tiny value (remember, at the time index created the function returned small values)

    F1_LITERAL = value of the function f1 newly evaluated, using literal instead of the value in the table.

    Predicate f1 (a_string) = 'a' should return no rows because no character uppercase is equivalent to "a". Query with f1 (a_string) = 'A' should return a line, but it doesn't.

    SQL> SELECT a_string, f1(a_string) as f1_a_string, f1('a') as f1_literal
      2    FROM tmp_t1
      3   WHERE f1(a_string) = 'A';
    
    no rows selected
    

    Anyone know if this is an expected behavior? And, is it possible to disable the index based on a function whenever the underlying function signature is changed? The parameter query_rewrite_integrity = applied from

    DOC-ID 66277.1 does not seem to do the trick:

    (c) session variables

    ~~~~~~~~~~~~~~~~~~~~

    QUERY_REWRITE_ENABLED (true, false),

    QUERY_REWRITE_INTEGRITY (confidence, forced, stale_tolerated)

    determines the optimizer to use index based on a function with

    expressions using SQL, user defined functions functions.

    TRUST: Oracle allows rewrites using relationships that have

    was declared.

    APPLIED: Oracle ensures and guarantees consistency and integrity.

    STALE_TOLERATED: Oracle allows rewrites using vessels of the relationship not applied.

    Used in the case of materialized views.

    Set session variable cost function optimizer to choose the

    a function-based index

    Kind regards

    SAMO

    From the Manual 11.2 ( https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_indexes.htm#ADFNS254 )

    "If you change the semantics of a DETERMINISTIC run and recompile, then you must manually rebuild all addicts depending on index and materialized views." Otherwise, they report results for the previous version of the function. »

    This note is not that I made my initial comment well - which was based on an incorrect memory the relationship between function-oriented and autonomous pl/sql functions, so I won't try to explain it. In fact, I went back to Oracle 8i practice to see if something had changed between yesterday and today and found that I had described exactly the behavior that the OP has been seeing. It's the way it is supposed to be.

    Concerning

    Jonathan Lewis

  • Bad alphabetically in the index

    Dear community,

    I use ID CS6.

    I have discovered a reproducible error, given the order of the names in the index sheets.

    When I put marks index to names

    • Anton huh
    • Martin huh
    • Johannes Heindl

    in this way they will be sorted:

    1. Huh, Anton
    2. Heindl, Johannes
    3. Huh, Martin

    which is obviously incorrect. The order should rather be 1,3,2.

    I think the problem is that the spaces between the first and last name are ignored:

    The names "Smith, John" is treated as "Smithjohn".

    Corsica, I can force ID to sort correctly by using the "sort by"-field. But why is that need?

    Names are generally classified by NAME and if they are the same, you look on the first NAME. Word by word instead of the letter by letter.

    Are there really no feature that provides "the word of the order of the words" without interfering manually?

    Thank you in advance!

    I have the honour, of course, you put these scripts to use, but they serve a particular purpose and they mess around with the document considerably. Because everything what needs index of martin is setting/updating the fields from the sort order, it is easier to target the index panel immediately: it is faster and safer.

    You are partially right that remove the space after that a comma sorts the sorting problem, but using the sign $ is delicate because you might want to do things later, and symbols that have a special meaning in regular expressions are to be avoided if possible, just to make life easier. So, I use the number 5 instead. The advantage is that I can use different numbers to refine the sort order. Here's the script:

    (function () {
      if (app.documents[0].indexes.length > 0) {
        var order;
        var topics = app.documents[0].indexes[0].allTopics;
        for (var i = topics.length-1; i >= 0; i--) {
          order = topics[i].sortOrder;
          // If the topic already has a sort order defined, change it
          if (order !== '' && order.indexOf(', ') > -1) {
            topics[i].sortOrder = order.replace (', ', ',5');
          // Otherwise use the topic's name
          } else if (topics[i].name.indexOf(', ') > -1) {
            topics[i].sortOrder = topics[i].name.replace (', ', ',5');
          }
        }
      }
    }());
    

    Peter

  • does not use the INDEX

    I have problem with a query as follows. It does not index when I keep a function on the left side of the comparison in which the condition.

    But when I remove the function is using the index.

    With BLC AS 
    Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                        NOT NULL NUMBER
     MASTER_VALUE               NOT NULL NUMBER(8)
     DESC_TEXT_ID                                    NUMBER
     GVM                                                     VARCHAR2(50)
     MASTER_LOOKUP_ID    NOT NULL  NUMBER
     WORK_SECTION_ID                          NUMBER
     AUDIT_TRAIL_NO                              NUMBER
     
    
    SQL> SELECT COUNT(*) FROM BLC;
      COUNT(*)
    ----------
          7769
    
    SQL> SELECT COUNT(DISTINCT(GVM)) "distinct" FROM BLC;
      distinct
    ----------
          1350
    
    SQL> SELECT COUNT(*) "nulls" FROM BLC WHERE GVM IS NULL;
    
         nulls
    ----------
          6419
    
    SQL> SELECT COLUMN_NAME,INDEX_NAME FROM DBA_IND_COLUMNS WHERE TABLE_NAME='BLC';
    
    COLUMN_NAME                              INDEX_NAME
    ---------------------------------------- ------------------------------
    MASTER_LOOKUP_ID      LKPCDE_MSTLKP_FK_I
    WORK_SECTION_ID        LKPCDE_WRKSEC_FK_I
    GVM                                   LKPCDE_UK
    MASTER_VALUE              LKPCDE_MASTERID_VALUE_UK
    MASTER_LOOKUP_ID     LKPCDE_MASTERID_VALUE_UK
    ID                                       LKPCDE_PK
    
    SQL> EXPLAIN PLAN FOR SELECT ID FROM BLC WHERE UPPER ( GVM) = 'MAIN_ORG';
    Explained.
    SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 3196655606
    --------------------------------------------------------------------------------------
    | Id  | Operation         | Name             | Rows  | Bytes | Cost (%CPU)| Time|
    --------------------------------------------------------------------------------------
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |                  |    78 |   624 |    18   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| BLC |    78 |   624 |    18   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------------------
       1 - filter(UPPER("GVM")='MAIN_ORG')
    13 rows selected.
    
    
    SQL> EXPLAIN PLAN FOR SELECT ID FROM BLC WHERE GVM
      = 'MAIN_ORG';
    Explained.
    SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 1620245961
    --------------------------------------------------------------------------------
    ----------------
    | Id  | Operation                   | Name             | Rows  | Bytes | Cost (%
    CPU)| Time     |
    --------------------------------------------------------------------------------
    ----------------
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |                  |     1 |     8 |     2
     (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| BLC |     1 |     8 |     2
     (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN         | LKPCDE_UK        |     1 |       |     1
     (0)| 00:00:01 |
    --------------------------------------------------------------------------------
    ----------------
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       2 - access("GVM"='MAIN_ORG')
    14 rows selected.
    
    SQL> EXPLAIN PLAN FOR SELECT /* INDEX(LKPCDE_UK) */ ID FROM BLC WHE
    RE UPPER ( GVM ) = 'MAIN_ORG';
    Explained.
    SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 3196655606
    --------------------------------------------------------------------------------
    ------
    | Id  | Operation         | Name             | Rows  | Bytes | Cost (%CPU)| Time
         |
    --------------------------------------------------------------------------------
    ------
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |                  |    78 |   624 |    18   (0)| 00:0
    0:01 |
    |*  1 |  TABLE ACCESS FULL| BLC |    78 |   624 |    18   (0)| 00:0
    0:01 |
    --------------------------------------------------------------------------------
    ------
    
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    ---------------------------------------------------
       1 - filter(UPPER("GVM")='MAIN_ORG')
    13 rows selected.
    

    Please let me know how I can force it to use an index as it is causing the CPU usage.

    I can't change the query in the application it is used in several places.

    Thank you

    And/or read: ORACLE-BASE - Oracle function index

Maybe you are looking for