explain query plan uses no unique index with where condition

Hi all

I use in the 10.2.0.5 oracle database Enterprise edition 64-bit on 64-bit windows server 2008.

I'm following this tutorial on my own table

Guide to understanding Oracle QUERY PLAN - 10 minutes

my questions are below

Analyze table LIB_CLASSIFICATIONS compute statistics;
explain plan for  SELECT class_id  FROM lib_classifications WHERE class_no = '538' ;
select * from table(dbms_xplan.display);

the result is less than

Hash value of plan: 3022072076

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

| ID | Operation | Name                | Lines | Bytes | Cost (% CPU). Time |

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

|   0 | SELECT STATEMENT |                     |     1.    10.     5 (0) | 00:00:01 |

|*  1 |  TABLE ACCESS FULL | LIB_CLASSIFICATIONS |     1.    10.     5 (0) | 00:00:01 |

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

Information of predicates (identified by the operation identity card):

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

1 - filter ("CLASS_NO" = '538')

DESC LIB_CLASSIFICATIONS

Name of Type Null

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

CLASS_ID NOT NULL NUMBER (10)

CLASS_DESC VARCHAR2 (50)

REMARKS VARCHAR2 (250)

CLASS_NO VARCHAR2 (20)

CLASS_TYPE VARCHAR2 (10)

CREATE_USER VARCHAR2 (10)

MODIFY_USER VARCHAR2 (10)

CREATE_DATE DATE

MODIFY_DATE DATE

CLASS_CATEGORY_ID VARCHAR2 (10)

class_id has a primary key.

now when I remove the condition where the query, the result is lower;

Analyze table LIB_CLASSIFICATIONS compute statistics;
explain plan for  SELECT class_id  FROM lib_classifications ;
select * from table(dbms_xplan.display);

the result is less than

Hash value of plan: 262704430

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

| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

|   0 | SELECT STATEMENT |             |  1558.  6232.     2 (0) | 00:00:01 |

|   1.  FULL RESTRICTED INDEX SCAN FAST | SYS_C005653 |  1558.  6232.     2 (0) | 00:00:01 |

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

now it's using indexes with INDEX FAST FULL SCAN.

I need the index using the WHERE condition as well.

How to do this?

Thank you.

you have indexes on the column class_id not on class_no column how u would expect index to use when there is no index on the column class_no

Tags: Database

Similar Questions

  • When we use a unique index for PK?

    I was reading this part of the manual oracle:

    http://docs.Oracle.com/CD/B28359_01/server.111/b28310/indexes003.htm#ADMIN11727

    I got confused because I was trying to research why sometimes, we want to create a primary key by using a unique index.

    CREATE A UNIQUE MYTABLE_PK ON MYTABLE INDEX

    (START_DT, ANNUAL)

    LOGGING

    TABLESPACE TBS_INDEX01

    NOPARALLEL;

    ALTER TABLE MYTABLE ADD)

    CONSTRAINT MYTABLE_PK

    KEY ELEMENTARY SCHOOL

    (START_DT, ANNUAL)

    WITH THE HELP OF INDEX MYTABLE_PK);

    And sometimes we simply create the primary key without using a unique index.

    ALTER TABLE MYTABLE ADD)

    CONSTRAINT PK_MYTABLE

    KEY ELEMENTARY SCHOOL

    (START_DT, ANNUAL)

    THE HELP INDEX);

    When we use a unique index for PK?

    James, you have returned to the question thread.

    I apologize: I'm sorry, user8875620, your son has been hijacked. A UK or PK constraint needs an index. You can create a (unique or non-unique) explicitly, or you can let Uncle Oracle create it implicitly when you define the constraint.

  • How to make a sum of text_field or column with where condition?

    Hi all

    In Oracle forms 6i, I created a form in which there are 5 text_Items (with 20 none of the displayed fields) namely ACCOUNT FD DO, AMOUNT, INTEREST RATE, STATUS and INTEREST_YEAR.

    FD ACCOUNT NO.

    AMOUNT

    INTEREST RATE

    STATUS

    INTEREST_YEAR

    47665

    50000

    1. 11.5

    E

    5750

    37463

    60000

    12

    D

    7200

    47651

    100000

    1. 12.5

    D

    12500

    34766

    70000

    11

    E

    7700

    I want to make the sum of the INTEREST_YEAR where status = 'E '.

    I created a TOTAL_INTEREST_YEAR name field in which I want to display the sum.

    How the sum with where condition?

    Thank you.

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    Oracle form Builder 6i.

    Michael,

    When you write the formula for a calculated item, it does not use PL/SQL expressions (to include built-in DECODING) in Forms 6i.  If there was no conditional control over your calculation, you can simply make your article a summary point and perform the summation over column interest_rate .  However, because your calculation depends on the value in the STATUS column, you will need to use a combination of a calculated item and a summary article because you can't use an IF, DECODE or any other PL/SQL statement in the formula for the calculated item.  Therefore, you need to create a function in the knot of program units and call the function in your formula.  I tested it using the following code and it worked correctly.

    First, create the following function in the node of the object browser program units.

    FUNCTION calc_interest RETURN NUMBER IS
         n_ret_val  NUMBER := 0;
     BEGIN
       IF ( :YOUR_BLOCK.STATUS = 'E' ) THEN
           n_ret_val := :YOUR_BLOCK.interest_rate;
       END IF;
       RETURN n_ret_val;
    END calc_interest;
    

    First, you must change the property to BLOCK request all archives = Yes

    Then, open the palette of your calculated item property, and set the following properties:

    1. calculation = Formula

    2 property Forumla = CALC_INTEREST

    3. point data base = No.

    Now create a second item in the table not based on in your block that will display the amount of the interests summarized.  Open the palette property for this element and set the following properties:

    1 Data Type = number

    2 calculation Mode = Summary

    3. function = sum

    4 summarizes point = "name of your element calculated.

    5 base of data point = No.

    6 canvas = "your canvas.

    When you query your block, you should see the sum of all records where STATUS = 'E '.

    It worked for me, in my example form that I created so this should work for you.

    Craig...

  • (ORA-00955) conflict of naming for index and constraint when you use a unique index (.. desc,.. CSA)

    Hello

    indexes and constraints are in different namespaces, so it should be possible to give them the same name.

    In the following case that apparently does not work:

    create unique index orders_year_show_uq
      on orders (year desc, show_orders asc);
     
     alter table orders
      add constraint orders_year_show_uq unique (year, show_order);
    

    When I run these statement, I get a "SQL Error: ORA-00955: name is already used by an existing object". ""

    If I clean and I execute the same instructions as above with the only difference on the 2 line, using "asc year" instead of "year desc":

    
      on orders (year asc, show_orders asc);
    

    then it success.

    I can't explain it, you have an idea?

    Thanks in advance.

    Kind regards

    Giovanni

    First of all, you have show_orders in index and show_order in the constraint. I'll assume that it's a typo. Second, when you create constraint without index enhance the specification Oracle seeks indexes existing on the same set of columns in ascending order. If this index does not exist (and it's your case, since one of your columns to index is in descending order), Oracle tries to create one with the same name as the constraint. That's why you get ORA-00955: name is already used by an existing object. In general, you can specify explicitly the index name to force the Oracle by using the existing index. But it will not help you. If you issue

    ALTER table orders add unique constraint (year, show_orders) orders_year_show_uq using index orders_year_show_uq;

    You will get the ORA-14196: specified index cannot be used to apply the constraint.

    In any case, Oracle does not support using index DESC for PK/UK.

    SY.

  • Unique index with TRIM

    I want to create a unique constraint with TRIM, I get the error message. Is there a way...
    ALTER TABLE core_business.cb_pensioner ADD CONSTRAINT unique_claim_no UNIQUE(TRIM (claim_no))   deferrable initially deferred NOVALIDATE;
    
    ORA-00904: : invalid identifier

    Pre 11g - unique index; 11g go - virtual columns.

    SQL> create table t1
      2  (col1 varchar2(10));
    
    Table created.
    
    SQL> alter table t1 add constraint uk_t1 unique (trim(col1));
    alter table t1 add constraint uk_t1 unique (trim(col1))
                                                *
    ERROR at line 1:
    ORA-00904: : invalid identifier
    
    SQL> create unique index i1 on t1 (trim(col1));
    
    Index created.
    
    ... virtual column method ...
    
    SQL> drop index i1;
    
    Index dropped.
    
    SQL> alter table t1 add col2 as (trim(col1));
    
    Table altered.
    
    SQL> alter table t1 add constraint uk_t1 unique (col2);
    
    Table altered.
    
    SQL> insert into t1 (col1) values ('1');
    
    1 row created.
    
    SQL>  insert into t1 (col1) values ('1  ');
     insert into t1 (col1) values ('1  ')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (RIMS.UK_T1) violated
    
    SQL> select * from t1;
    
    COL1       COL2
    ---------- ----------
    1          1
    
    SQL> 
    
  • What is the difference between primary key and unique indexes with forced not null?

    Primary key is = unique index + not null?

    The short answer is Yes.

    However, even if the primary key, applying both uniquness and not null, there is a notion of "special".

    You can only have one primary key in tables, but you can have multiple unique indexes and constraints not null.

    See: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8743855576462

  • Can we add a new column to a UNIQUE INDEX with out droping the same index?

    Can one please let me know how to add a new column to the UNIQUE INDEX existing on the same fall.
    DB: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
    Thank you.
    Mahi.

    TechMahi.com wrote:
    Can one please let me know how to add a new column to the UNIQUE INDEX existing on the same fall.
    DB: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
    Thank you.
    Mahi.

    I think that its doable and I don't think that it should be feasible to all too since that would disrupt the structure of index completely. I think, you must delete the existing one to add a new column that is do a composite index.

    Aman...

  • But UNIQUE constraint with a condition?

    Hello!

    Is it possible to define a unique constraint in a table that would apply only to a condition (according to the content of the line only)?

    For example:
    CREATE TABLE example
    (
      pk number,
      a number,
      b number,
      c VARCHAR2(10),
      x number
    );
     
    The constraint would be UNIQUIE (a, b), but only when x is > 10.
    So if x is not greater than 10, then the same values for a and b nd should be allowed.

    Maybe with a view?


    Like this?
    create view example_view  ( unique (a,b)) AS
    select a,b from example where x > 10
     with read only; -- ??? needed? 
    Kind regards
    David

    You can create an index based on a function. This takes advantage of the fact that Oracle does not store the NULL entries in an index b-tree

    CREATE UNIQUE INDEX idx_example
        ON example(
          (CASE WHEN x > 10 THEN a ELSE NULL END),
          (CASE WHEN x > 10 THEN b ELSE NULL END)
        );
    

    Justin

  • Publish with where condition

    SELECT product_id, ID_lieu FROM tablea where product_id product_id = '023V003961010000. '
    result of the query is
    product_id, location_id
    023V003961010000 058053278

    The two columns are explained as a varchar in the tables

    Now, if I use the same query, but want to filter those with location_id < '9000'

    SELECT product_id, ID_lieu FROM tablea where product_id product_id = '023V003961010000' and location_id < '9000'

    I was expecting this return zeros rank location_id 058053278 is not < 9000 but still me back
    product_id, location_id
    023V003961010000 058053278

    Thank you

    Hello

    You can use:

    SELECT product_id, location_id FROM tablea where product_id product_id = '023V003961010000' and to_number(ltrim(location_id ,'0')) < 9000
    
  • explain the plan using plan_hash_value and runtime

    Hello

    Please let me know the syntax to get the plan to explain using sql_id and plan_hash_value.

    Also let me know how to find out the same sql execution times in the previous months. I have the ID value of sql.

    Kind regards

    VN

    > Is it possible to check how long the sql finished in the previous months?

    Of AWR / StatsPack reports.

    Or use awrsqrpt.sql which can query the repository for a single SQL_ID AWR.

    However, you must have the AWR data kept for 4 months.  The default retention is 7 days.

    Hemant K Collette

  • Query not using Full Scan Index

    Hello world

    I'm on 11.2.0.3.0 AIX 6.1.

    There is a query such as:

    Select: sys_b_0 | Count (distinct (column_name)) table;

    that goes for the analysis full table. The column was values separate only 104 with not NULL values. To save memory buffer gets, I created an index on the table with the column used in the query (i.e. whose distinct values are recovered).

    The problem is that even after the creation of indexes and force the flag index that it does not use the full scan of the index. The provided indication is correct in syntax and was the only clue in the query, so there is no question of conflicts with others.

    Can anyone suggest me what I might be missing?

    Thank you

    It seems to me that if print_branch_code is defined as nullable in the table. If this is the case, the optimizer goes for a sweep of index, even if there is no real NULL values

  • How to use variables in conjunction with a conditional statement

    v_sql:=  'SELECT  /* * */ trans_id' || 
                'FROM            NDW_trans '||
                'WHERE           cable =TRIM(LEADING 0 FROM ' ||  i_Cab     || ')' || 
                                'AND ' ||  i_Pair  || 'BETWEEN low and highr' ||
                                'AND termsysid =' ||  i_termsysid ||
                                'AND provisionstatus= ' ||  3 /* find what the constant is for inservice*/ ;
                                
         IF     i_Bill IS NOT NULL THEN
                v_sql := v_sql || 'AND CO_Clli = i_Bill';
         END IF;                  
          BEGIN                  
               EXECUTE IMMEDIATE v_sql INTO o_trans_id_list; 
    How can I convert this to binding of variables that I also have a conditional statement which stretches from the place where clause

    Try this

    v_sql:=  'SELECT  /* * */ trans_id
                FROM            NDW_trans
                WHERE           cable =TRIM(LEADING 0 FROM :i_Cab
                                AND  :i_Pair BETWEEN low and highr
                                AND termsysid = :i_termsysid
                                AND provisionstatus=3 '  /* find what the constant is for inservice*/ ;
    
         IF     i_Bill IS NOT NULL THEN
                v_sql := v_sql || 'AND CO_Clli = :i_Bill';
         END IF;
          BEGIN
               EXECUTE IMMEDIATE v_sql INTO o_trans_id_list
               USING i_Cab, i_Pair, i_termsysid, i_Bill ;
    

    HTH
    SS

  • Explain the plan of a query?

    Hello
    How I watched the explain query plan?

    I tried...
     
       explain plan for select * from dual; 
       
       Explained 
       
      
    then then I tried
     
        select * from  from table(dbms_xplan.display); 
    
       plan_table_output 
       .... 
    
       
    Oracle version 11.1.0 information;

    Is what I have, it is true m do? or if not can you explain to me how I am looking for explain plan of the query...

    Thank you!!!

    Yes, that seems correct

    SQL> explain plan for
      2  select *
      3    from dual
      4  /
    
    Explained.
    
    SQL> select *
      2    from table (dbms_xplan.display())
      3  /
    
    PLAN_TABLE_OUTPUT
    ----------------------------------------------------------------------------------
    Plan hash value: 272002086
    
    --------------------------------------------------------------------------
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    --------------------------------------------------------------------------
    
    8 rows selected.
    
    SQL> 
    
  • CREATE INDEX with ON DUPLICATE

    Hello

    I use Oracle10g Express (v10.2.0). What is given the equivalent query in Oracle for SQL Server query below?

    CREATE UNIQUE INDEX uix_NumberUnique ON UserInfo(UserID, Number)
    WITH (IGNORE_DUP_KEY = ON)

    I appreciate your inputs.

    Thank you
    Jonathan

    Here is an example

    SQL> create table t (no integer primary key);
    
    Table created.
    
    SQL> exec dbms_errlog.create_error_log('T','T_ERR')
    
    PL/SQL procedure successfully completed.
    
    SQL> insert into t
    select no
      from (
              select 1 no from dual union all
              select 2 no from dual union all
              select 1 no from dual
           )
    log errors into t_err('Insert Error') reject limit unlimited;         2    3    4    5    6    7    8  
    
    2 rows created.
    
    SQL> select * from t
      2  /
    
            NO
    ----------
             1
             2
    
    SQL>  exec dev_util.print_table('select * from t_err')
    ----------------------------------------------------------------------------------------------------
    Field Name                      Field Value
    ----------------------------------------------------------------------------------------------------
    ORA_ERR_NUMBER$               : 1
    ORA_ERR_MESG$                 : ORA-00001: unique constraint (ARBORU.SYS_C00407493) violated
    ORA_ERR_ROWID$                :
    ORA_ERR_OPTYP$                : I
    ORA_ERR_TAG$                  : Insert Error
    NO                            : 1
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • 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

Maybe you are looking for

  • How to disable the backlight on the keypad for the Qosmio X 70-A-120

    Please, do you know how to disable the backlight on the keypad for the QOSMIO X 70-A-120? Concerning

  • Windows Firewall is not enabled...!

    Windows firewall in not enabled. I want to update my windows store application but a message that windows firewall is not enabled.when I guess the do, it dosent happen. a mistake is diplays i.e. 0 x 80070422 This is something serious because I want t

  • Satellite M40-236 Blue Screen of Death

    A few days ago, I bought a Toshiba Satellite M40-236. I hated the pre-installed Windows XP Home Edition and installed Windows XP Pro with SP2 integrated. Subsequently, I installed all the drivers provided and recommended by Toshiba of: http://eu.comp

  • How can I reset my laptop to DVD factory State?

    Hi, I recently bought a Levono Thinkpad W530 and recovery media creation/test gives me a world of hurt. I really wish they had just sent me a recovery DVD (s) with the laptop, as Fujitsu made when I bought my laptop from them years ago. in any case,

  • SP3 update: problems, can only start in safe mode

    Windows XP Home Edition: update to SP3, in the hope that it would, among other things, allow me to install the windows update service. Unfortunately, I can only boot in safe mode. If I try the normal startup, it goes into a boot loop. By that I mean