How many columns to index

Hi,
I have a table t1 which has nearly 20000 rows. It is accessed by a query which has 3 columns in its where clause lets say col1, col2 and col3. the table doesn't have any index so it does a full table scan. Now if I put an index on all the 3 columns it uses the index and avoids the FTS. Also if I index just 2 columns instead of three then also it uses index (something that I don't know why). my question is should I index the two coulmns or three columns? the third column which i left out has nearly 8000 distinct values.
the query is of the form:
select col5 from table1 where col1=value1 and col2=value2 and col3=value3 and rownum=1
the execution plan with index on three columns is:
Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
0 | SELECT STATEMENT | | 1 | 24 | 2 (0)| 00:00:01 |
* 1 | COUNT STOPKEY | | | | | |
* 2 | TABLE ACCESS BY INDEX ROWID| table1     | 1 | 24 | 2 (0)| 00:00:01 |
* 3 | INDEX RANGE SCAN | ind-3col | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("col1"=6003 AND "col2"=1532 AND
"col3"=267)
the execution plan with index on two columns is:
======
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 24 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
|* 2 | TABLE ACCESS BY INDEX ROWID| table1 | 1 |     24 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | ind-2col | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(ROWNUM=1)
2 - filter("col3"=267)
3 - access("col1"=6003 AND "col2"=1532)
I don't know if I should index on 2 columns or 3 columns...can someone suggest?
Thanks
Edited by: orausern on Feb 8, 2010 5:28 AM
Edited by: orausern on Feb 8, 2010 5:29 AM

Hi,
To index or not to index on columns would totally depends on type of query(update/delete/select) being run on that table.
So you need to check all/majority of the query that would be running on this table to decide which column should be indexed.
eg:
If i have just one query which you posted that would be running against this table then I would have index on all the three columns.
But only 10-20% of the query would be making use of all the three columns, and rest 70-80% of the queries are making use of same 2 out of these 3 columns then I would be indexing only 2 columns.
I suppose you would also like to understand that queries also determines which column would be leading column in index.
Index makes select queries to run faster in most of the case, but it also makes insert statements run slower and utilized space. So keeping all this factor in mind it should be decided on which columns and in which order should we index.
Regards
Anurag

Similar Messages

  • Determinng how many times an index was used

    DB Version:10gR2
    Is there a way i could determine how many times an index was used? i couldn't find any related columns in user_indexes.

    I don't think you can count how many times it's been used. However, you can check whether the index is used or not over a given period by looking at v$object_usage view.
    However, you do have to monitor the index usage by issuing
    alter index index_name monitoring usage;
    However, there is a problem with this view in that the username is always the user who set monitoring on the index.
    Solution from metalink is:
    select
    io.name, t.name,
    decode(bitand(i.flags, 65536), 0, 'NO', 'YES'),
    decode(bitand(ou.flags, 1), 0, 'NO', 'YES'),
    u.start_monitoring,
    ou.end_monitoring
    from
    sys.obj$ io,
    sys.obj$ t,
    sys.ind$ i,
    sys.object_usage ou
    where
    io.owner# = userenv('SCHEMAID')
    and
    i.obj# = ou.obj#
    and
    io.obj# = ou.obj#
    and
    t.obj# = i.bo#;

  • At max how many columns is advisable to create in a table/view

    Hi All,
    I have two transaction table from which i want to create a simple view or materialized view. But the number of columns is about 200. So i want to know at max how many columns is advisable from the performance point of view.
    Even though i will create 200 columns in a view , for a perticular client installation i may not use all the columns.
    one more thing i will never use 200 columns in the select statement . At a time i will use only 4/5 columns.
    It may happen from this four column one column will be the 1st and 2nd column will be the 200th one.
    I want to know how it affects the performance and in which scenario . Please help if any body knows or already faced this kind of scenario.
    I am using oracle 10g .

    Annapurna Nayak wrote:
    thanks for ur reply .
    We are going to use this view in a report , so if i will create it as simple view it will affect report performance. because the view script is too long ...so every time quring to a view will decrease the performance.
    Are you asking me if it will? I think it probably won't but of course you have the means to test it to be sure, right?
    As u said MV should be done with minimum possible column . what can be the maximum column in MV ..??It would be defined by the limits on:
    * The maximum number of columns that a table can contain
    * The size of the query needed to define the select statement
    * Limitations on queries needed to maintain the data
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/limits003.htm#i288032

  • How many columns a sql selects

    I need to find out how many columns are in a sql statement like below:
    sql = "select id, decode(description,'','No decription', description), comment from my_table";
    The sql string is build dynamically so I don't know it when I write the code. I need to know before I do
    call rs.next(), because I need to set up the table header so I need to know how many columns the sql is selecting.
    Thanks inadvance.
    Botao

    You can use the interface ResultSetMetaData,below are some methods of it.
    int getColumnCount()
    Returns the number of columns in this ResultSet object.
    String getColumnName(int column)
    Get the designated column's name.
    int getColumnType(int column)
    Retrieves the designated column's SQL type.
    for more infomation ,you can refer to JDBC Online Document.

  • How many columns can be used in the SELECT Statment

    Hi all,
    How many columns can be used in the SELECT statement?
    Ex: SELECT x1,x2,....xn FROM <table_name>;
    Thanks,
    GowriShankar.N

    Let me join ;-)
    SQL> select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    PL/SQL Release 9.2.0.6.0 - Production
    CORE    9.2.0.6.0       Production
    TNS for Linux: Version 9.2.0.6.0 - Production
    NLSRTL Version 9.2.0.6.0 - Production
    SQL> DECLARE
      2  l_sql varchar2(32000);
      3  begin
      4  l_sql := 'CREATE TABLE T(';
      5  for i in 1..999 loop
      6  l_sql := l_sql ||'C'||i||' NUMBER,
      7  ';
      8  end loop;
      9  l_sql := l_sql||'C1000 NUMBER)';
    10  EXECUTE IMMEDIATE l_sql;
    11  end;
    12  /
    PL/SQL procedure successfully completed.
    SQL> select count(*) from cols where table_name = 'T';
      COUNT(*)
          1000
    SQL> insert into t(c1) values(1);
    1 row created.
    SQL> select *
      2  from t t1,t t2;
            C1         C2         C3         C4         C5         C6         C7         C8         C9       
    ...   snipped
    C991        C992       C993       C994       C995       C996       C997       C998       C999         C1         C2         C3       C4         C5         C6         C7         C8         C9        C10       
    ...   snipped
    C990       C991       C992       C993    C994        C995       C996       C997       C998       C999
    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------          1
                                                                                                                                        1
    SQL>
    SQL> select count(*) from (
      2  select * from t t1,t t2)
      3  ;
    select * from t t1,t t2)
    ERROR at line 2:
    ORA-01792: maximum number of columns in a table or view is 1000Obviously, inline view is obliged the same restrictions as a view, but select list is not constrained.
    Best regards
    Maxim

  • How many column can I make in a table or view??

    What is the maximum column that I can create in a table or a view in Oracle9i??
    When I create a view of 500 columns, I encountered an error "too many sort key", can any one tell me what is the limit for Oracle9i on number of column

    I believe the limit was raised to 1000 columns in 8i; that's certainly what it is in 9i. At a guess I would suspect your problem is the number of columns in your GROUP BY or ORDER BY clause. It would be helpful if you posted the error number, the ORA-nnnnn bit.
    Cheers, APC

  • How to see how many times of  index split occured on an index?

    hi gurus
    The ASH reports shows a lot of enq: index contention wait event on an index.I suspect that it's index split that caused the waits. From wht dictionary can I see the times of index split once occured on that index?
    Thanks very much!

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/instance_tune.htm#i16341
    The name of the enqueue is included as part of the wait event name, in the form enq: enqueue_type -  related_details. In some cases, the same enqueue type can be held for different purposes, such as the following related TX types:
        *      enq: TX - allocate ITL entry
        *      enq: TX - contention
        *      enq: TX - index contention
        *      enq: TX - row lock contention
    The V$EVENT_NAME view provides a complete list of all the enq: wait events.
    You can check the following V$SESSION_WAIT parameter columns for additional information:
        *      P1 - Lock TYPE (or name) and MODE
        *      P2 - Resource identifier ID1 for the lock
        *      P3 - Resource identifier ID2 for the lockdoes following SQL return any rows for you?
    SELECT Decode(request, 0, 'Holder: ',
                           'Waiter: ')
           || sid sess,
           id1,
           id2,
           lmode,
           request,
           TYPE
    FROM   v$lock
    WHERE  ( id1, id2, TYPE ) IN (SELECT id1,
                                         id2,
                                         TYPE
                                  FROM   v$lock
                                  WHERE  request > 0)
    ORDER  BY id1,           request; 

  • How many columns can be display if use Class cl_gui_alv_grid?

    Hi,
        I have a fieldcat table which contains 200 items. But it only shows about 90 columns in my alv display.
    I use function: LVC_FIELDCATALOG_MERGE to build fieldcatory and I found there are 200 records in my fieldcatory internal table when I debug it.
        Can anyone give me some advise to show full culomns in my alv display?
        Thanks a lot~

    Hi,
    In Debug mode check check the NO_OUT field for each entry in the Field Catalog. If it has the value X for some fields then those fields will not be displayed.
    Or check is there any Layout Variant is passed to the IS_VARIANT parameter.

  • How to use script to show how many columns contain no data

    I have a requirement. There is a source which is excel file, from this excel file we need to load data in staging table. There are 5 mandatory columns those should not be null. We have used 'No Data Check' for this. The logic is if any of the above mentioned 5 columns  do not contain any record the record will be moved to without data. Up to this it is fine. Now the requirement is to show which column/columns does/do not contain data. We have used a script for this purpose as:
    res=' '
    res=input1[0]+'  :Failed due to null values in mandatory columns';
    input1[1]=res;
    output1=res;
    But this is showing message as 'Failed due to null values in mandatory columns', which is a generic message. We need to show which column/columns does/do not contain value as 'Failed due to null values in mandatory column columnA, columnB, columnC'. Can anyone help me in this regard. Any kind of help is appreciated.

    You could use the variable inputname1, which holds an array of the input attribute names to the script processor. For example:
    var result = "";
    var first = true;
    for (i = 1; i < input1.length; i++) {
      if (input1[i] == null || input1[i] == "") {
        if (first) {
          first = false;
        } else {
          result += ", ";
        result += inputname1[i];
    if (result.length > 0) {
      result = "Failed due to null values in the following mandatory columns: " + result;
    output1 = result;
    Regards,
    Nick

  • Is thr any way to know how many coloumn in  ResultSet object?

    hi madam,
    I want know how many column in result set when query like this
    "select * from table_name"
    is thr any way to know
    thank in advance

    ResultSetMetaData md = rs.getMetaData();[url http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getMetaData()]http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getMetaData()

  • At max how many logical columns can be created in RPD

    Hi All,
    At max how many logical columns can be created in RPD. I have a requirement of creating 200 columns. Will there be any problem .
    Is there any predefind number of columns for RPD creation??
    Please help ..

    Hi Annapurna,
    There's no limit that I'm aware of or which is mentioned anywhere. Just as an example: I have a logical fact table with around 750 logical columns (>500 original measures & 250 derived measures). No issue whatsoever. Opening the presentation table through answers takes about 2-3 seconds (the NQSQL command has a lot to retrieve), but that's about it.
    Cheers,
    C.

  • How to get the index of a h:column element?

    Hi!
    I'd like to know how to get the index of a <h:column> element.
    Here is the code of what I'm trying to do:
    <h:column>
         <a:commandLink
              value="#{familyAction.familyDocsByPrj}"
              action="#{homeAction.search(ROW_INDEX)}"
              reRender="rightAppPanel" />
    </h:column>When clicking a row, I'd like to make a "search" depending on the selected row.
    Does anybode know how to do that?
    Thanks a lot :)

    Thanks a lot for all your answers! :)
    I finally got to do something with my little knowledge =P
    I created a new class containing all the data needed for the dataTable (including a "String id").
    And that's what I get:
    <h:column>
         <a:commandLink
              value="#{familyAction.familyDocsByPrj.name}"
              action="#{homeAction.search(familyAction.familydocsByPrj.id)}"
              reRender="rightAppPanel" />
    </h:column>

  • Table has too many columns for one pg in InDesign document. How do I force a break?

    I have imported an Excel table into my InDesign document.  The table is 598 columns wide.  Obviously this isn't fitting on one page.  I want it to just keep flowing from page to page, keeping one same column at the beginning of each page (like "freeze panes" does in Excel) but it's not doing that.  Is this possible in my InDesign document or will I have to manually copy and paste 10 columns at a time, which is about how many are fitting on one page?  Any searches I do on this subject just talk about flowing rows but nothing about columns. 

    As far as I know there's probably no way ID is going to do what you want.
    You can place a table across a multiple page spread, but the odds of being able to do that and still keep the file printable are marginal, at best. You can't for example, leave blank space at the gutters unless you are able to add a blank column that spans the gutter, and the limt for multipage spreads is 10 pages wide, whcih doesn't sound like it's probably enough to hold almost 600 columns.
    Perhaps placing the table using named ranges of appropriate widths would work...

  • How to define the Index on the column which is define in view (9i)

    hi all,
    I have one view which is based on to tables say 'customers' and 'vendors'
    view definition is like:
    create or replace view customer_vendor as
    select customer_name, 'Customer' type from customers
    union all
    select vendor_name, 'Vendor' type form vendors;
    my problem is that how i can define index on 'type' column if i used in where clause when i query the view.
    Regards
    s

    An index is a pointer. A pointer to a data place.
    Data result of a view aren't stored.
    So, how an index may work against a view ?
    SQL> create index idx1 on v1(type);
    create index idx1 on v1(type)
    ERROR at line 1:
    ORA-01702: a view is not appropriate hereThink about mview instead of view, maybe that can help. Data result of mview are stored somewhere in database, so you are allowed to create an index against mview, like for table.
    Anyway, if you want 'Customer', why not request onto customers table ?
    Nicolas.

  • How to create a index on a column with type clob

    how to create a index on a column with type clob

    You should have a look to Oracle Text to check if Oracle Text indexing features can meet your needs:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/cncptdev.htm#CNCPT1537

Maybe you are looking for

  • Help for runtime change in list item

    hi i have created a tabuler form and have list_items on it i want when i select category monitor then in next list i get monitor's serial numbers in next record when i select printer then in next list i get printer's serial numbers i had tried it on

  • Encoding and compression in After Effects (Problems with some colors and some effects))

    Hello dear friends, I would like to export an openning title video for a movie, which is about 2,45 seconds long and 22 GB (Uncompressed) The footage is 1920X1080. There are a lot of effects, such as, alpha chanel clips of smoke, explossions and stuf

  • Changes done in the ValueChangeListener is not reflecting else where

    Abstract: There is an input File competent where the user can select a file to upload. The user will press a Savebutton to store file in the database. Work Flow: When the user select the file to upload the valueChangeListener will be called. In the v

  • Help converting two 16 bit hex words to signed integer

    I am currently attempting to use labVIEW 2010 to read temperature and mass flow information off of a modbus instrument. However the instrument returns all values in 2 16 bit hex words in "Intel Bytes" ordering. I am having trouble converting this inf

  • Previous Recipients will not delete - have tried everything

    I've removed from Previous Recipients list in the address line, in the drop down menu... I have removed the email addresses from the Address Book and still they keep coming back.  On several occasions I'll delete it repeatedly from all areas and it k