Function index in Oracle

Hi gurus,

Just trying to get some info in the function-based index.

Can we have index created in the user-defined function?

Lets say we have a table and I need a counter of a column. Could we have indexes on County?

Select count (name) of employee

WHERE name = "Hary";

Thank you

Tina

The functions used in the function-based index must be DETERMINISTIC.

Example you is not deterministic, that is given the input, the output can vary, because there might be 10 Harys today and 5 tomorrow.

Deterministic functions always return the same value for the same entry.

See: http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/function.htm#LNPLS1580

Tags: Database

Similar Questions

  • query not given function function index in oracle 11g

    I have a query that uses function based indexes when run in oracle 9i, but when I run the same query
    without any change, it does not consider the index. This is the query:

    SELECT distinct patient_role.domain_key, patient_role.patient_role_key,
    patient_role.emergency_contact_name,
    patient_role.emergency_contact_phone, patient_role.emergency_contact_note,
    patient_role.emergency_contact_relation_id,
    patient_role.financial_class_desc_id, no_known_allergies, patient_role. CREATED_BY,
    patient_role. CREATED_TIMESTAMP,
    patient_role. CREATED_TIMESTAMP_TZ, patient_role. UPDATED_BY, patient_role. UPDATED_TIMESTAMP,
    patient_role. UPDATED_TIMESTAMP_TZ,
    patient_role.discontinued_date
    MEETING, patient_role
    WHERE patient_role.patient_role_key = encounter.patient_role_key
    AND SUPERIOR (TRIM (main: encounter.account_number SYS_B_0)) = UPPER (TRIM (main: SYS_B_1 of))
    ((: SYS_B_2))
    AND patient_role.discontinued_date IS null
    AND encounter.discontinued_date IS null;

    Definition of the index:

    CREATE INDEX "user1". "' IX_TRIM_ACCOUNT_NUMBER ' ON 'user1 '. MEETING"(AT THE TOP (TRIM (LEADING))
    ('0' TO 'ACCOUNT_NUMBER')), 'PATIENT_ROLE_KEY', 'DOMAIN_KEY', 'DISCONTINUED_DATE')
    PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    DEFAULT USER_TABLES)
    TABLESPACE "user1".

    Database: Oracle 11g (11.2.0.3)
    O / s: 64-bit Linux (the query does not consider the index even on the windows operating system)

    Any suggestions?

    -Onkar

    Published by: onkar.nath on July 2, 2012 15:32

    Onkar,

    I don't appreciate posting you this issue in several forums at the same time.
    If I know you also posted this on Asktom, I wouldn't even bother.
    As for your "problem":
    First of all: some kind cursor_sharing MUST have been implemented. Oracle is a predictable system, not a fruitmachine.
    Anyway, your statement that '0' is replaced by a variable binding is simply false. If you really believe this isn't fake, SUBMIT an SR.

    But your real problem isn't Oracle: it is your 'application', which is a mess anyway. Allowing for alphanumeric numbers is a very bad idea.
    Now, you already put workaround on workaround on workaround on workaround.
    Question is this: it is terminal, and you must either to kill him or to replace it.

    -------------
    Sybrand Bakker
    Senior Oracle DBA

  • Function Index

    I'm reviewing an existing table in a database Oracle 11g and I do not understand a function based index that was created. The syntax is less than

    CREATE INDEX abc. Orders_Date on abc. ORDERS

    (CASE WHERE "ORDER_DATE" IS NOT NULL THEN "ORDER_DATE" ELSE NULL END)

    LOGGING;

    This table has about 90 000 lines with 32 000 values distinct order_date, 3000 lines have order_dates null. When you run a query on this table using the order_date column it makes a full table scan.

    What does this function index based? because I do not see how it adds all the required features

    Thank you

    As others have said, this index is actually right on order_date, however, is a core function so it cannot be used in queries that use CASES WHEN "ORDER_DATE" IS NOT NULL THEN END NO OTHER "ORDER_DATE."

    It is assumed that it might be possible that there is an index on (order_date) but it was found that it was used in the sql queries, which would have preferred to use other indexes. Some queries benefits so maybe that option based function was created as the sql must refer to the phrase exactly, requests that have received have been rewritten and others were left so that they could avoid the new index of the index.

    Of course, if this were the case then maybe you can take a look at your stats.

  • Function Index problem.

    Hello

    I have a problem regarding a function function index.

    example:

    TableName: Test

    Column: A, B, C, D

    I create the index on the table, column, a test using a user-defined function.

    If I do a select on the column, he'll be fine. In other words, I'll get the results you want.

    However, if I insert in the table and validation, and I do a query using the 'A' column in the where clause. I don't have any query hits. Its really weird.

    Have you ever experienced this problem? and is there an index of function according to back and donts w.r.t.?

    Thank you.

    MichaelR

    If you use a deterministic function really, it works:

    create or replace function test_fn (p_number number) return number deterministic
    is
      vreturn number := 0;
    begin
      if p_number = 1 then vreturn := 55; end if;
      if p_number = 2 then vreturn := 89; end if;
      return vreturn;
    end;
    

    Or, if you reverse the order of your second inserts (insert the folder before the recording of test1 test2) - it works fine.

    The reason why you get no results is when you insert the file test1 with a = 2, Oracle executes the function and gets no data, so it assumes that the result is NULL and puts in the index. You said Oracle function is deterministic, so he starts from the principle that any time test_fn (2) is called, it retrieves a null response.

  • CBO bug or not, or else develop do not consider the function index

    SQL> create table test_fun_or as select object_id+sysdate id,object_name from        
    
      2  dba_objects;
    
    Table created.
    
    SQL> create index i_test_fun_or on test_fun_or(id,'a') nologging;   
    
    //I don't know why oracle consider it as function index
    
    Index created.
    
    SQL> create index i_test_fun_or_1 on test_fun_or(object_name) nologging;
    
    Index created.
    
    SQL> set autot trace exp
    
    SQL> exec dbms_stats.gather_table_stats(user,'TEST_FUN_OR',estimate_percent=>null,method_opt=>'for all columns size 1');
    
     
    
    PL/SQL procedure successfully completed.
    
     
    
    SQL> select * from test_fun_or where id=sysdate or object_name='aa';
    
     
    
    Execution Plan
    
    ----------------------------------------------------------
    
    Plan hash value: 3247456674
    
     
    
    ---------------------------------------------------------------------------------
    
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    
    ---------------------------------------------------------------------------------
    
    |   0 | SELECT STATEMENT  |             |     3 |    87 |   219   (3)| 00:00:03 |
    
    |*  1 |  TABLE ACCESS FULL| TEST_FUN_OR |     3 |    87 |   219   (3)| 00:00:03 |
    
    ---------------------------------------------------------------------------------
    
     
    
    Predicate Information (identified by operation id):
    
    ---------------------------------------------------
    
     
    
       1 - filter("OBJECT_NAME"='aa' OR "ID"=SYSDATE@!)
    
     
    
    SQL> select /*+ use_concat */ * from test_fun_or where id=sysdate or object_name='aa'; 
    
    //or expand don't use index i_test_fun_or
    
     
    
    Execution Plan
    
    ----------------------------------------------------------
    
    Plan hash value: 3161566054
    
     
    
    ------------------------------------------------------------------------------------------------
    
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    
    ------------------------------------------------------------------------------------------------
    
    |   0 | SELECT STATEMENT             |                 |     3 |    87 |   224   (3)| 00:00:03 |
    
    |   1 |  CONCATENATION               |                 |       |       |            |          |
    
    |*  2 |   TABLE ACCESS FULL          | TEST_FUN_OR     |     1 |    29 |   219   (3)| 00:00:03 |
    
    |*  3 |   TABLE ACCESS BY INDEX ROWID| TEST_FUN_OR     |     2 |    58 |     5   (0)| 00:00:01 |
    
    |*  4 |    INDEX RANGE SCAN          | I_TEST_FUN_OR_1 |     2 |       |     3   (0)| 00:00:01 |
    
    ------------------------------------------------------------------------------------------------
    
     
    
    Predicate Information (identified by operation id):
    
    ---------------------------------------------------
    
     
    
       2 - filter("ID"=SYSDATE@!)
    
       3 - filter(LNNVL("ID"=SYSDATE@!))
    
       4 - access("OBJECT_NAME"='aa')
    
     
    
    SQL> drop index i_test_fun_or;
    
     
    
    Index dropped.
    
     
    
    SQL> create index i_test_fun_or on test_fun_or(id,object_name) nologging;
    
     
    
    Index created.
    
     
    
    SQL> alter table test_fun_or modify object_name not null;
    
     
    
    Table altered.
    
     
    
    SQL> select /*+ use_concat */ * from test_fun_or where id=sysdate or object_name='aa';
    
     
    
    Execution Plan
    
    ----------------------------------------------------------
    
    Plan hash value: 1705821130
    
     
    
    ------------------------------------------------------------------------------------------------
    
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    
    ------------------------------------------------------------------------------------------------
    
    |   0 | SELECT STATEMENT             |                 |     3 |    87 |     8   (0)| 00:00:01 |
    
    |   1 |  CONCATENATION               |                 |       |       |            |          |
    
    |*  2 |   INDEX RANGE SCAN           | I_TEST_FUN_OR   |     1 |    29 |     3   (0)| 00:00:01 |
    
    |*  3 |   TABLE ACCESS BY INDEX ROWID| TEST_FUN_OR     |     2 |    58 |     5   (0)| 00:00:01 |
    
    |*  4 |    INDEX RANGE SCAN          | I_TEST_FUN_OR_1 |     2 |       |     3   (0)| 00:00:01 |
    
    ------------------------------------------------------------------------------------------------
    
     
    
    Predicate Information (identified by operation id):
    
    ---------------------------------------------------
    
        2 - access("ID"=SYSDATE@!)
    
       3 - filter(LNNVL("ID"=SYSDATE@!))
    
       4 - access("OBJECT_NAME"='aa')

    Jinyu wrote:
    Thanks Jonathan, I don't have 11.2.0.2 on-site, I'll test it later, I just test it on 11.2.0.1

    If you see the notes of fixed a bug fixes for 11.2.0.2 Group (Doc ID:1179583.1) it's bug 8352378 "allow index GOLD-Expansion functions.

    Concerning
    Jonathan Lewis

  • Function table in oracle

    Hi all

    I am using Oracle 11g

    I want to know in order to learn

    What is the CURSOR in the function table.

    What is its usefulness

    Can someone explain to me.

    SELECT x.*

    (TABLE (package1.function1)

    CURSOR (SELECT

    t.*

    OF test1 t))) x

    Thank you

    What is the CURSOR in the function table.

    What is its usefulness

    Can someone explain to me.

    SELECT x.*

    (TABLE (package1.function1)

    CURSOR (SELECT

    t.*

    OF test1 t))) x

    This slider is NOT 'in the function table. It is in the call to YOUR function named "packagae1.function1" and the function returns a collection. If it is the result of the collection of YOUR function call which is 'in the function table.

    Your probable function takes a REF CURSOR as a parameter, so the code above uses the CURSOR operator to create a cursor from a subquery.

    Your function then returns a collection and SCOREBOARD operator is used to make this collection available in SQL.

    See FUNCTIONS TABLE in the Oracle documentation. A simple search for 'oracle 11g table function' returns the Oracle doc as the FIRST result listed:

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28425/pipe_paral_tbl.htm

    This chapter describes the functions of table

    . . .

    Overview of the functions of table

    Table functions are producing a set of lines (a nested table or a varray) that can be queried as a physical database table. You use a function table as the name of a database table, in the FROM clause of a query.

    A table function can take a set of input lines. A parameter of the input collection can be of a collection type or a REF CURSOR .

    . . .

    Look at the examples 5-13 and 13-6, because they show the code for your EXACT example:

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28425/pipe_paral_tbl.htm#CIHEGADE

    . . .

    Example 13-6 How to use a function Table in pipeline with REF CURSOR Arguments

    SELECT * FROM TABLE(StockPivot(CURSOR(SELECT * FROM StockTable)));
    

    In the previous query, the function table in pipeline StockPivot retrieves the lines of the CURSOR subquery SELECT * FROM StockTable , performs the transformation and channels the results to the user in the form of table. The function produces two lines of output for each input line (items in the collection).

    Note that when a CURSOR subquery went from SQL for a REF CURSOR argument of function as in the previous example, the referenced cursor is already open when the function begins to run.

    As the doc example, as in your example, a subquery of CURSOR to create a cursor to be used as a function parameter. Example 13 - 5 has the actual code for the function.

    The documentation is your FRY - don't be afraid to use it.

    If you try to learn something a good question to ask on the forums is: where can I get more information about the functions of the table (or other topic).

    Then, we can direct you to the Oracle documentation that covers this topic.

  • Based on a function index

    Hi all

    Based on a function index are recommended to sql queries slow poor acceleration?


    Thank you

    Kinz

    The only thing that a function index based (FBI) is intended is so you don't lose the use of an index when you call a function in your WHERE (predicate) clause.

    Not sure, I would say it was "the only thing"...

    How about you, the ability to provide access to a very small percentage of rows that match a certain condition (using DECODE or CASE) effective index?

  • Operation of indexing in Oracle UCM 11g

    Hi all

    I'm using Oracle UCM 11 g on Windows platform.

    I wanted to know also how indexing in Oracle UCM Funtions? Here are some questions more related to this.

    1. If characters from multiple languages are added in the document and the document is indexed, then
    How data (tokens) will be stored in the database?
    2. How will the research work

    Hello

    1. If characters from multiple languages are added in the document and the document is indexed, then

    a. how data (tokens) will be stored in the database?

    It is stored in the DB IdcColl1 or IdcColl2 tables (if engine DB FullText Search indexer) and the table would be IdcText1 or IdcText2 (if an indexer OracleTextSearch is used). It is these tables that store the data of all content and are referred to as / interrogated when a FT research is called of the Complutense University of MADRID.

    b. how the indexing will be done?

    Indexer would have extracted the content in the case of mechanism of indexer FT all data and store them in the above mentioned tables in DB. It is stored in columns of type BLOB in the extraction process would make an insert for each piece of content that is being processed when Collection rebuild Cycle / program of automatic update is turned on.

    2. What are the settings to make in Oracle and search engine for this?

    For DB relevant AAU scripts must be run while the correct role are created and packages.

    3. what will be the additional settings must be made in the case if the operating system changes, for example, Linux.

    Relevant libraries must be checked to ensure that the indexer can access because there are a lot of dependent libraries for the process of indexer that is invoked by the TextExport process and these libraries vary for different OS. As part of the indexer process work very well everything what needs to be done is to install/activate specific versions of the OS to the ContentAccess on UCM component.

    Hope this gives an understanding on the part of the indexing of the Complutense University of MADRID.

    Thank you
    Srinath

  • What functions PKCS #11 Oracle Database 11 g made use of?

    I am currently come with a library PKCS #11 with a minimum set of features such as my legacy HSM supports transparent encryption of Oracle database 11 g (TDE) data. I don't want to come up with the full PKCS #11 library with all the functions for all that I need is to support the Oracle database. In addition, all functions of encoding will take too long a development effort and it would be an overdose in doing so.

    Does anyone have ideas on what are the PKCS #11 functions that makes "Oracle Database 11 g Release 2 (11.2)" use to support TDE with HSM?

    Hello

    I checked the code 11.2 and you need implement these functions for use with TDE:

    C_Initialize
    C_GetFunctionList
    C_GetInfo
    C_GetSlotList
    C_OpenSession
    Http://localhost
    C_CloseSession
    C_Finalize
    C_GenerateKey
    C_FindObjectsInit
    C_FindObjects
    C_FindObjectsFinal
    C_EncryptInit
    C_Encrypt
    C_DecryptInit
    C_Decrypt
    C_CloseSession

    It is also recommended to implement of the C_GenerateKeyPair so it can be used by Portfolio Manager to create a certificate request.

    Greetings,

    Damage

    Published by: hnapel on 14 Sep, 2010 06:58

  • Another key or a function Index Question

    Hello

    I have the following sample tables:
    CREATE THE TABLE1 TABLE:
    (
    NUMBER OF RESOURCE_KEY
    CONSTRAINT TABLE_PK
    KEY ELEMENTARY SCHOOL
    (RESOURCE_KEY)
    )
    /
    CREATE THE TABLE2 TABLE
    (
    RESOURCE2_KEY INTEGER NOT NULL,
    RESOURCE1_KEY INTEGER NOT NULL,
    CONSTRAINT TABLE2_PK
    UNIQUE (RESOURCE2_KEY, RESOURCE1_KEY)
    USING INDEX
    TABLESPACE TRACERT_DATA,
    CONSTRAINT TABLE1_FK1
    FOREIGN KEY (RESOURCE1_KEY)
    REFERENCES TABLE1 (RESOURCE_KEY)
    ON DELETE CASCADE,
    CONSTRAINT TABLE1_FK2
    FOREIGN KEY (RESOURCE2_KEY)
    REFERENCES TABLE1 (RESOURCE_KEY)
    ON DELETE CASCADE
    )
    /
    Insert into TABLE1
    (RESOURCE_KEY)
    Values
    (1) ;
    Insert into TABLE1
    (RESOURCE_KEY)
    Values
    (2) ;
    COMMIT;


    Now comes the tricky part. I want only one of the following inserts to work:
    Insert into TABLE2
    (RESOURCE2_KEY, RESOURCE1_KEY)
    Values
    (1, 2);
    Insert into TABLE2
    (RESOURCE2_KEY, RESOURCE1_KEY)
    Values
    (2: 1);
    COMMIT;


    Any suggestions?

    You can use a single function index based.

    SQL> create table t (x number, y number);
    
    Table created.
    
    SQL> create unique index t_idx on t (greatest(x, y), least(x,y));
    
    Index created.
    
    SQL> insert into t values (2, 1);
    
    1 row created.
    
    SQL> insert into t values (1, 2);
    insert into t values (1, 2)
    *
    ERROR at line 1:
    ORA-00001: unique constraint (TEST.T_IDX) violated
    
    SQL> rollback;
    
    Rollback complete.
    
    SQL> insert into t values (1, 2);
    
    1 row created.
    
    SQL> insert into t values (2, 1);
    insert into t values (2, 1)
    *
    ERROR at line 1:
    ORA-00001: unique constraint (TEST.T_IDX) violated
    
  • Function index and virtual columns

    I just read the documentation of Oracle on the FBI. In the context of optimization with a function-based index, it is said that "a virtual column is useful for speed of access to data from expressions.". Here is the link Index-Organized Tables and indexes.

    My question is, does Oracle already not create a virtual column when we create a function-based index?

    Concerning

    Charlie

    Hi Charlie
    Yes, the database engine creates a virtual column. But this column is hidden. Reproduced in 11.2.0.3 example:
    SQL> CREATE TABLE t (n NUMBER);SQL> CREATE INDEX i ON t (round(n,0));
    SQL> SELECT column_name, hidden_column, virtual_column  2  FROM user_tab_cols
      3  WHERE table_name = 'T';
    
    COLUMN_NAME                    HIDDEN VIR
    ------------------------------ ------ ---
    N                              NO    NO
    SYS_NC00002$                  YES    YES
    

    HTH

    Chris Antognini

    Troubleshooting performance Oracle, Apress 2008/2014

  • Function index and user_tab_cols

    Why an entry is created in user_tab_cols when we create a function based on a column in a table?

    create table t1(a varchar2(100), b number); 

    select * from user_tab_cols where table_name = 'T1'; -- Two rows coming 

    create index idx1 on t1(upper(a));

    select * from user_tab_cols where table_name = 'T1'; -- Three rows coming

    What is the reason to put an entry in user_tab_cols?

    Martin Preiss wrote:

    If I remember correctly there is also a VIRTUAL_COLUMN attribute in % _TAB_COLS (at least since 11.1).

    Yes, there is, but how it would be useful to determine if the column is the index of based function related? All not stored in the disk column is a virtual column:

    SQL > create table (tbl)
    Number 2,
    3 the number n
    4                  )
    5.

    Table created.

    SQL > create index tbl_idx1 on tbl (abs (n));

    The index is created.

    SQL > alter table tbl
    2. Add n_ceil number generated always as (ceil (n));

    Modified table.

    SQL > alter table tbl change invisible n_ceil;

    Modified table.

    SQL > create index tbl_idx2 on tbl (n_ceil);

    The index is created.

    SQL > select column_id,.
    2 column_name
    virtual_column 3,.
    4 hidden_column
    5 to user_tab_cols
    6 where table_name = "TBL";

    COLUMN_ID COLUMN_NAME HIDDEN VIR
    ---------- ------------------------------ --- ---
    1 ID                             NO  NO
    2 N                              NO  NO
    SYS_NC00003$ YES YES
    N_CEIL YES YES

    SQL >

    As you can see, the two SYS_NC00003$ and N_CEIL are hidden, virtual columns. This part is the same regardless of the version. And in 12 c with the invisible support of solumn, you can't count on the id of null column. That's why (or at least one of the reasons) Oracle introduced another column in the view _TAB_COLS in 12 c - USER_GENERATED:

    SQL > select column_id,.
    2 column_name
    virtual_column 3,.
    hidden_column 4,.
    5 user_generated
    user_tab_cols 6
    7 where table_name = "TBL";

    COLUMN_ID COLUMN_NAME VIR HID USE
    ---------- ------------------------------ --- --- ---
    1 NOT ONLY ID YES
    2 N NO NO YES
    SYS_NC00003$ YES YES NO
    N_CEIL YES YES YES

    SQL >

    Now, we can say column SYS_NC00003$ is related FBI.

    SY.

  • where to find info on the function index according to

    Hello

    With the help of Oracle 11.2, can someone tell me where I can find information about existing indexes to function in my database?

    I want to shrink the unused space on a table, but there is an index FB I have to drop in order to shrink the space.
    Then I need to recreate it after that I have shrink space.
    But how do I know what the index is created to be used for functions?

    I've looked dba_indexes and dba_ind_expressions with no luck.
    I see the index, but I don't see what functions are which are applied for the FB index.


    Thanks in advance.

    958713 wrote:

    select OWNER, INDEX_NAME, INDEX_TYPE, TABLE_OWNER, TABLE_NAME
    from dba_indexes where index_name = 'TQR1_C3';
    
    OWNER      INDEX_NAME INDEX_TYPE                  TABLE_OWNER  TABLE_NAME
    ---------- ---------- --------------------------- ------------ ----------
    TQ         TQR1_C3    FUNCTION-BASED NORMAL       TQ           TQR1
    

    Now, let's view the selection of dba_ind_expressions...

    INDEX_OWNER  INDEX_NAME TABLE_OWNER  TABLE_NAME COLUMN_EXPRESSI COLUMN_POSITION
    ------------ ---------- ------------ ---------- --------------- ---------------
    TQ           TQR1_C3    TQ           TQR1       "C3"                          1
    

    If you have a top-down column in an index the index is reported "based on a normal function", but the expression simply contains the name of the column without mentioning the bit downward. So one possibility is that your index finger is (descendant of c3).

    Concerning
    Jonathan Lewis

  • Function Index and Query Rewrite

    Hi members,


    I just stumbled on something that I've never thought of before.

    It has to do with the function according to index and (possibly re - write query)

    Here is my configuration:
    SQL> create table tab1 (
      2    x   varchar2 (1)   default 'N' not null check (x in ('Y', 'N')),
      3    y   varchar2 (100) not null
      4  );
    
    Table created.
    
    SQL> create index tab1ix on tab1 (NULLIF(x,'N'));
    
    Index created.
    
    SQL> insert into tab1 (y)
      2    (select rpad (level,100,'x') from dual connect by level <= 1000);
    
    1000 rows created.
    
    SQL> insert into tab1 (x,y) values ('Y', 'Hello there');
    
    1 row created.
    
    SQL> commit
      2  /
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats(user, 'tab1', cascade => true)
    
    PL/SQL procedure successfully completed.
    So, I created a small table with a FBI.

    Now, let's use it.
    The first is a query that obviously do not use it.
    Second, one is a query that corresponds to the FBI.
    SQL> explain plan
      2     set statement_id = 'st1'
      3     into plan_table
      4  for
      5  select * from tab1 where x = 'Y';
    
    Explained.
    
    SQL> 
    SQL> select plan_table_output
      2    from table(dbms_xplan.display('PLAN_TABLE', 'st1','TYPICAL'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    ----------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost  |
    ----------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |   501 | 51603 |     5 |
    |   1 |  TABLE ACCESS FULL| TAB1 |   501 | 51603 |     5 |
    ----------------------------------------------------------
    
    
    SQL> explain plan
      2     set statement_id = 'st2'
      3     into plan_table
      4  for
      5  select * from tab1 where NULLIF(x,'N') = 'Y';
    
    Explained.
    
    SQL> 
    SQL> select plan_table_output
      2    from table(dbms_xplan.display('PLAN_TABLE', 'st2','TYPICAL'));
    
    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    
    ----------------------------------------------------------------------
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost  |
    ----------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |        |     1 |   103 |     1 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| TAB1   |     1 |   103 |     1 |
    |   2 |   INDEX RANGE SCAN          | TAB1IX |     1 |       |     1 |
    ----------------------------------------------------------------------
    
    SQL> 
    No worries, right?
    Everything works as expected, when my predicate corresponds to the FBI, the index is used.


    But here's what surprises me. It seems that the index expression is rewritten then it is created:
    SQL> select column_expression from user_ind_expressions
      2  where index_name = 'TAB1IX';
    
    COLUMN_EXPRESSION
    --------------------------------------------------------------------------------
    CASE "X" WHEN 'N' THEN NULL ELSE "X" END
    
    SQL>
    Questions are now, is this safe? -Does still work?

    Can I trust the optimizer always did a rewrite such as performed when the index was created?


    This index might live throughout the years and many versions of the optimizer. But the expression stays (I guess)

    This is going into production this weekend, so I wanted to hear,
    ideas / comments?


    Best regards
    Peter
    SQL> select *from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Linux: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    PS: NULLIF is nothing else than a syntactic sugar for the CASE expression equivalent?
    docs say:
    The NULLIF function is logically equivalent to the following CASE expression:

    CASE WHEN expr1 = END expr1 expr2 THEN NULL ELSE
    edited by: Peter on February 9, 2012 05:32

    Hi Peter

    In the docs for NULLIF, he said

    The NULLIF function is logically equivalent to the following CASE expression:

    CASE WHEN expr1 = expr THEN ELSE NULL expr1 END 2

    http://docs.Oracle.com/CD/B10501_01/server.920/a96540/functions85a.htm
    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/functions102.htm
    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions116.htm

    Which would explain the behavior you saw. As you pointed out, it is possible that the transformation of NULLIF expression BOX equivalent is likely to change? It seems unlikely - indeed, it seems to be an alias or a macro for the instruction box unless there is some way technically superior to implement this logic, it seems to be here to stay. Certainly, it has remained unchanged since the 9i.

    Not sure how that helps.

    David

  • SQL tuning advisor recommnds to create the function SYS_OP_C2C function index

    I have a large table and an index on it. I use a tool to fill data, this simple tool submits the sql for Oracle DB and it does NOT index to use for requests. When I run the sql tuning advisor, he recommends to create additional indexes and use the SYS_OP_C2C function, which I don't want.

    When I run the query through sql plus picks it up in the index.
    Someone of you came, why its recommend that additional nonsense?

    create index abc.xxxx on this_table (SYS_OP_C2C ("this_column"));

    Thank you

    The internal Oracle SYS_OP_C2C function perform the conversion of a set of characters to another set of characters - C (haracterSet) 2 c (haracterSet). There are situations where you will see this conversion without explicit, as in this case command that should be a sign that the data types are not the same and the implicit conversion takes place and this could also be a problem from the point of view performance because it can disable the use of the index.

    Make sure you the characterset and nls set of all of the database and the tool are the same.
    Make sure that the data type of the column in the index is the same as the database.
    Confirm the ETL vendor for your database support and fixes, etc..

    Optimizer will only advise to use this function when the data type or the character set does not match.

    Thank you
    Kerry

Maybe you are looking for

  • Upgrade of RAM in my Satellite Pro A100 (PSAA3E) was not recognized.

    I have a Pro A100 (PSAA3E) with only 512 MB of RAM. I added another identical stick but only 1 has been recognized.Each stick is recognised individually in each slot, but never as a 1 GB together. Thus, the two sticks are ok and two slots are okay! H

  • formula node

    I send it a zone indicator shows full decimal form but receive and whole. I changed the data types of the double room on long extended float etc, with no result. Y at - it something I am doing wrong?

  • PCI-6509 in DAQmx configuration

    Hello We plan to use a PCI-6509 for state change detection. Our system will receive a signal on a line from a source and then relay to another system. We intend to do in Linux using the ANSI C DAQmx drivers. The manual indicates that the card is conf

  • Impossible to switch from windows vista

    Hello!When I have vista windows upgrade vile com a failcode 800700CB masage

  • Acrobat Pro 2013 Word XI component software plug-in has stopped working

    I used Acrobat yesterday no problem... Today, in addition to the Pro Acrobat XI in Word 2013 (Office 365 version of click-to-run) just stopped working.I tried to uninstall Office and acrobat, reboot, reinstall office and acrobat... download all updat