Criteria for choosing to create index on column?

Hello,
This maybe is a trivial question. I have been reading on performance tuning of SQL queries. What criteria is used to determine which column needs to have an index?
If a query is as follows:
Select * from table where column1=<value> and column2=<value> and column3=<value>;What is the criteria for choosing a particular column to be indexed?. Is it the column containing the higher number of unique rows so that index selectivity is high?
Thanks

For that particular query, an index on all three columns would be best. However, that's probably not the only query on that table, and you have to take them into account as well.
What's the main use of your table? What functionality is used most or is most important? Design your index scheme to assist those queries if possible.
If you have a book, would you use the index? If it's a technical reference book, or an encyclopedia, yes. If it's a novel you read from start to finish, probably not. And if you are reading the Oracle Concepts Manual and you want to search for the paragraphs containing the word "database", would you use an index? And if you search for the logwriter process (LGWR)? It's just about common sense in general: you'll want an index to be selective.
Another side of the story is that indexes slow down inserts, deletes and updates, so you'll have to make a trade-off: is this penalty worth the speedup of a few queries?
Regards,
Rob.

Similar Messages

  • ABAP Routine for Deleting and creating index for ODS in Process chains

    Any pointers for the ABAP Routine code for deleting and creating index for ODS in Process chains.

    Hi Sachin,
    find the following ABAP code to delete ODS ondex.
    data : v_ods type RSDODSOBJECT.
    move 'ODSname' to v_ods .
    CALL FUNCTION 'RSSM_PROCESS_ODS_DROP_INDEXES'
      EXPORTING
        I_ODS = v_ods.
    To create index:
    data : v_ods type RSDODSOBJECT.
    move 'ODSname' to v_ods .
    CALL FUNCTION 'RSSM_PROCESS_ODS_CREA_INDEXES'
      EXPORTING
        I_ODS = v_ods.
    hope it helps....
    regards,
    Raju

  • Do I need to create indexes on column name?

    Following queries have been shown as bad sql :          
    select * from t1 where name = 'FUNCTION'
    Count=     7     Avg Time=13     Min Time=0     Max Time=47
    select * from t2 where name = 'USER_TYPE'      
    Count=2     Avg Time=85     Min Time=0     Max Time=156
    select * from t3 where name = 'TEMPLATE'
    Count=7     Avg Time=19     Min Time=0     Max Time=32
    All these tables have less than 20 records and static tables.                    
    Do I need to create indexes on column name?

    A FTS even on very small tables can require more latches than accessing via an index. Also, a table access requires the segment header and data block to be accessed (2) whereas an index on a small index only requires access to the index root block and table block (2).
    True, it's unlikely to make much of a difference in most environments but if the table is really heavily accessed, indexing even very small tables can help to reduce the related latch overheads.
    Most of these small tables have PKs and are accessed via the PK so associated indexes usually exist anyways.
    Cheers
    Richard Foote
    http://richardfoote.wordpress.com/

  • Tuning report by creating index.

    Hi...all,
    I try to tuning discoverer reports for getting better performance by creating index on columns that used to join
    between tables, but when I set join type to one to one relationship and outer join on detail in Discoverer Admin.,I found that index I created was not used in query (explain plan show full scan table).
    Anyone know how to solve this problem?
    Thank you,
    Vilas

    Hi,
    According to the documentation you will get this error when:
    Cause: The select clause referenced UID, USER, ROWNUM, SYSDATE, CURRENT_TIMESTAMP, MAXVALUE, a sequence number, a bind variable, correlation variable, a set result,a trigger return variable, a parallel table queue column, collection iterator, etc.
    Action: Remove the offending expression or disable the REWRITE option on the materialized view.
    You will probably find you have one of these expressions in your custom business area/folder.
    Rod West

  • R12 Time Card - Is it possible to add criteria for Choice list?

    Hi,
    Is it possible to add criteria for choice list created using HXC_CUI_CUSTOMn_V?
    If it is possible could you share which attribute to use and if could share sample code that will be great.
    Thanks
    Prasad

    You actually have a choice of both Norsk Nynorsk and Norsk Bokmål.
    First select your text then:
    +Inspector > Text (T tab) > More > Language > Norsk Nynorsk / Norsk Bokmål+
    The method is to label the language you want to spell check with its native dictionary. So having done the above, when you spell check it will now use the Norwegian dictionaries.
    see p 115 +Working with Spelling Suggestions+ in the Pages09_UserGuide.pdf downloadable from under the Help menu.
    If you don't see the Norwegian options it is because you haven't added them in the International preferences in your System preferences:
    +Menu > Finder > System Preferences… > International > Language > Edit List… > Norsk Nynorsk and Norsk Bokmål > OK+
    If you drag them to the top of your language list they become the System language. If you leave them lower down they are available in other menus such as Pages Inspector palette.
    Peter

  • How to create  index for a column of a view

    Hi,
    I have created view for a table and then i am trying to create index for a column of that view. i am using the query "CREATE INDEX index_name ON view_name (col)". but Mysql is showing error like "view_name is not a base table".
    How can i do that......

    As mentioned this is a java forum not a mysql forum, but as I know the answer - you can't create an index directly on a view in mysql.

  • Create index for the NVARCHAR Datatype columns.

    We have facing problem with NVARCHAR datatype columns during the select with WHERE condition . The Index is not getting used even though index is available. Oracle takes FULL table Scan only .
    For Eg:
    Table created with ITEM_NO as NVARCHAR2(100). and we have create normal index on ITEM_NO
    When I capture the run time sql from the v$session and checked SQL plan it show FULL Table scan.Sql is as below
    SELECT col1, col2, col3 from table x
    WHERE ITEM_NO=N'123'
    If ithe abvove sql is changed as below .It takes the Index
    SELECT col1, col2, col3 from table x
    WHERE ITEM_NO='123'
    Can any one advise why this behaviour is happing
    Regards
    Chandrasekar

    the second statement is transformed to <convert to varchar2>(item_no)='123'.
    This means Oracle can't take the index as there is a function on the indexed column.
    This is likely version-dependent, reason why you always, really always need to specify your four digit version
    Solution: always use N'<hardcoded literal'.
    Sybrand Bakker
    Senior Oracle DBA

  • What index is suitable for a table with no unique columns and no primary key

    alpha
    beta 
    gamma
    col1
    col2
    col3
    100
    1
    -1
    a
    b
    c
    100
    1
    -2
    d
    e
    f
    101
    1
    -2
    t
    t
    y
    102
    2
    1
    j
    k
    l
    Sample data above  and below is the dataype for each one of them
    alpha datatype- string 
    beta datatype-integer
    gamma datatype-integer
    col1,col2,col3 are all string datatypes. 
    Note:columns are not unique and we would be using alpha,beta,gamma to uniquely identify a record .Now as you see my sample data this is in a table which doesnt have index .I would like to have a index created covering these columns (alpha,beta,gamma) .I
    beleive that creating clustered index having covering columns will be better.
    What would you recommend the index type should be here in this case.Say data volume is 1 milion records and we always use the alpha,beta,gamma columns when we filiter or query records 
    what index is suitable for a table with no unique columns and primary key?
    col1
    col2
    col3
    Mudassar

    Many thanks for your explanation .
    When I tried querying using the below query on my heap table the sql server suggested to create NON CLUSTERED INDEX INCLUDING columns    ,[beta],[gamma] ,[col1] 
     ,[col2]     ,[col3]
    SELECT [alpha]
          ,[beta]
          ,[gamma]
          ,[col1]
          ,[col2]
          ,[col3]
      FROM [TEST].[dbo].[Test]
    where   [alpha]='10100'
    My question is why it didn't suggest Clustered INDEX and chose NON clustered index ?
    Mudassar

  • How to create index on a xmltype column stored as CLOB

    actually i have two problems.
    i uploaded this schemaA.xsd file into xmldb repository without problems. registration also went ok.
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    schemaURL => 'http://xmlns.example.com/xdb/documentation/schemaA.xsd'
    ,schemaDoc => sys.UriFactory.getUri('/home/dev/schemaA.xsd')
    ,local => TRUE
    ,genBean => false
    ,genTypes => TRUE
    ,genTables => false
    ,enableHierarchy => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
    END;
    then i run this:
    create table pf_table_a(
         id VARCHAR2(100) primary key,
         xsd VARCHAR2(3000),
    xml_document XMLType
    ) XMLTYPE COLUMN xml_document
    STORE AS CLOB
    XMLSCHEMA "http://xmlns.example.com/xdb/documentation/schemaA.xsd"
    ELEMENT "order";
    and got this error:
    SQL> @d:\usr\dev\perftest\create_tables.sql
    Table created.
    create table pf_table_a(
    ERROR at line 1:
    ORA-00955: name is already used by an existing object
    anyway the table was created. so i went on to create indexes.
    SQL> create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@or
    derNo'));
    create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@orderNo
    ERROR at line 1:
    ORA-04063: table "BAUSER1.PF_TABLE_A" has errors
    this of course is wrong. because the command is for creating index of a XMLTYPE table. no a column. but what is the correct command? thanks.
    jack.

    actually i have two problems.
    i uploaded this schemaA.xsd file into xmldb repository without problems. registration also went ok.
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    schemaURL => 'http://xmlns.example.com/xdb/documentation/schemaA.xsd'
    ,schemaDoc => sys.UriFactory.getUri('/home/dev/schemaA.xsd')
    ,local => TRUE
    ,genBean => false
    ,genTypes => TRUE
    ,genTables => false
    ,enableHierarchy => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
    END;
    then i run this:
    create table pf_table_a(
         id VARCHAR2(100) primary key,
         xsd VARCHAR2(3000),
    xml_document XMLType
    ) XMLTYPE COLUMN xml_document
    STORE AS CLOB
    XMLSCHEMA "http://xmlns.example.com/xdb/documentation/schemaA.xsd"
    ELEMENT "order";
    and got this error:
    SQL> @d:\usr\dev\perftest\create_tables.sql
    Table created.
    create table pf_table_a(
    ERROR at line 1:
    ORA-00955: name is already used by an existing object
    anyway the table was created. so i went on to create indexes.
    SQL> create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@or
    derNo'));
    create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@orderNo
    ERROR at line 1:
    ORA-04063: table "BAUSER1.PF_TABLE_A" has errors
    this of course is wrong. because the command is for creating index of a XMLTYPE table. no a column. but what is the correct command? thanks.
    jack.

  • How can I create index(uniqie index) for a existed table?

    Hi guys,
    I want to create a index for a existed table, it should be unique index. I did it using se11, "indexes," and select the radio button "unqiue index", of course the fields as well. But when I activate it, I get a waring and therefore can not create this index. But if I select radio button "non-uniqe index", it works.
    However I have to reate a unqiue index.
    How can I do it?
    Thanks in advance
    Regards,
    Liying

    HI Wang
    You can create your index via SE11, enter the table name, click change, choose Go To, Indexes. Here create your index with the key fields that you want. To use the index, your select statement WHERE clause, you must have the key fields of the index in the order that they appear in the index. The "optimizer" will choose the index depending on your fields of the WHERE clause.
    One thing to remember is that when you create indexes for tables, the update or insert of these tables may have a slower response then before, I for one have never seen a big problem as of yet.
    this Document may help u on primary and secondary indexes :
    http://jdc.joy.com/helpdata/EN/cf/21eb20446011d189700000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eb47446011d189700000e8322d00/content.htm
    If it helps Reward the points
    Regards,
    Rk
    Message was edited by:
            Rk Pasupuleti

  • CREATE INDEX WITH DUPLICATE COLUMN NAME

    Hi,
    i need to interface our application with an Orale Bridge to CREATE INDEX with duplcate column Name.
    For Example
    CREATE index NLOT_FOURNLOT_idx ON NLOT(FOURNISSEUR ,NOLOT ,FOURNISSEUR ,NOBLFOUNISSEUR,NOLIGNEBL ,NOLOT ,QTECOLISRECUES ,CODENONQUALITE ,QTECOLISACCEPTE);
    CREATE table NLOT(
    FOURNISSEUR VARCHAR2(09)
    ,NOBLFOURNISSEUR VARCHAR2(13)
    ,NOLIGNEBL VARCHAR2(03)
    ,NOLOT VARCHAR2(20)
    ,QTECOLISRECUES VARCHAR2(10)
    ,CODENONQUALITE VARCHAR2(02)
    ,QTECOLISACCEPTE VARCHAR2(10)
    ,NOMBREDECOLISRE VARCHAR2(10)
    ,NOMBREDECOLISAC VARCHAR2(10)
    ,FILLER VARCHAR2(1)
    ,FILLE1 VARCHAR2(1)
    ,TYPEREFERENCE VARCHAR2(01)
    ,REFERENC1 VARCHAR2(15)
    ,CONTROLERECEPTI VARCHAR2(01)
    ,DATEDEPEREMPTIO VARCHAR2(8)
    ,CONTROLEPROCHAI VARCHAR2(1)
    Thanks
    Philippe

    Well, you can't do it. ORA-957 is one of those irrevocable errors for which the solution is to remove the duplicate name from the SQL statement.
    But, anyway, why do you want to do this? I would guess there's no performance benefit from having the same column indexed twice (of course it's impossible to test this, so it's just my opinion).
    Cheers, APC

  • How to create index on xmtype column

    Hi,
    I have a table as follows
    CREATE TABLE T_TEST_XML (PROCESS_ID NUMBER, TXT_XML XMLTYPE);
    I query the above table very frequently with the query
    SELECT * FROM T_TEST_XML TXS WHERE EXISTSNODE(TXS.TXT_XML, '/order[status="PEN"]') = 1
    How to create function based index on the TXT_XML column for the xpath expression /order[status="PEN"]' to improve the query performance?
    Thank you

    Actually if you are limited to using older software
    1. Consider defining an XML Schema and storing the XML using object relational storage.
    or
    2. If you must store the XML as CLOB create the index on extractValue(), rather than existsNode() and supply the predicate value at the SQL level rather than the XPATH level.
    SQL> DROP TABLE T_TEST_XML
      2  /
    Table dropped.
    SQL> CREATE TABLE T_TEST_XML (PROCESS_ID NUMBER, TXT_XML XMLTYPE)
      2  /
    Table created.
    SQL> create INDEX T_TEXT_XML_IDX on T_TEST_XML( extractValue(TXT_XML,'/order/status'))
      2  /
    Index created.
    SQL> set autotrace on explain
    SQL> --
    SQL> SELECT *
      2    FROM T_TEST_XML TXS
      3   WHERE ExistsNode(TXT_XML,'/order[status="PEN"]') = 1
      4  /
    no rows selected
    Execution Plan
    Plan hash value: 3001212210
    | Id  | Operation          | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |            |     1 |  2017 |    31   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS SEMI |            |     1 |  2017 |    31   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| T_TEST_XML |     1 |  2015 |     2   (0)| 00:00:01 |
    |*  3 |   XPATH EVALUATION |            |       |       |            |          |
    Predicate Information (identified by operation id):
       3 - filter("P"."C_01$"='PEN')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL> SELECT *
      2    FROM T_TEST_XML TXS
      3   WHERE extractValue(TXT_XML,'/order/status') = 'PEN'
      4  /
    no rows selected
    Execution Plan
    Plan hash value: 1430727070
    | Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                |     1 |  2015 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_TEST_XML     |     1 |  2015 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | T_TEXT_XML_IDX |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access(EXTRACTVALUE(SYS_MAKEXML(0,"SYS_NC00003$"),'/order/status',null,0,0,5242
                  93,133120)='PEN')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL>
    SQL>
    SQL>
    SQL>
    SQL>
    SQL>This allows the index to support querying on any value of status, rather than just PEN

  • Creating index for standard SAP tables

    Hi!
    What are the advantages and disadvantages of creating addtional indexes for tables with massive amount of data (BSEG, BKPF, COEP, etc...).
    If I create a new index it supposed to make the table access faster, for the cost of hard disk space.
    Am I right?
    Thank you
    Tamá

    Hi,
    Primary and secondary indexes
    Index: Technical key of a database table.
    Primary index: The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The primary index is created automatically when the table is created in the database.
    Secondary index: Additional indexes could be created considering the most frequently accessed dimensions of the table.
    Structure of an Index
    An index can be used to speed up the selection of data records from a table.
    An index can be considered to be a copy of a database table reduced to certain fields. The data is stored in sorted form in this copy. This sorting permits fast access to the records of the table (for example using a binary search). Not all of the fields of the table are contained in the index. The index also contains a pointer from the index entry to the corresponding table entry to permit all the field contents to be read.
    When creating indexes, please note that:
    An index can only be used up to the last specified field in the selection! The fields which are specified in the WHERE clause for a large number of selections should be in the first position.
    Only those fields whose values significantly restrict the amount of data are meaningful in an index.
    When you change a data record of a table, you must adjust the index sorting. Tables whose contents are frequently changed therefore should not have too many indexes.
    Make sure that the indexes on a table are as disjunctive as possible.
    (That is they should contain as few fields in common as possible. If two indexes on a table have a large number of common fields, this could make it more difficult for the optimizer to choose the most selective index.)
    Accessing tables using Indexes
    The database optimizer decides which index on the table should be used by the database to access data records.
    You must distinguish between the primary index and secondary indexes of a table. The primary index contains the key fields of the table. The primary index is automatically created in the database when the table is activated. If a large table is frequently accessed such that it is not possible to apply primary index sorting, you should create secondary indexes for the table.
    The indexes on a table have a three-character index ID. '0' is reserved for the primary index. Customers can create their own indexes on SAP tables; their IDs must begin with Y or Z.
    If the index fields have key function, i.e. they already uniquely identify each record of the table, an index can be called a unique index. This ensures that there are no duplicate index fields in the database.
    When you define a secondary index in the ABAP Dictionary, you can specify whether it should be created on the database when it is activated. Some indexes only result in a gain in performance for certain database systems. You can therefore specify a list of database systems when you define an index. The index is then only created on the specified database systems when activated
    Thanks and Regards
    Arun Joseph

  • Creating Index for PDF documents

    Hello,
    I am trying to index a column in one of my tables that contains a BLOB object that is a PDF for each record. I want to create an index on that column so I can search through the contents of these PDFs.
    I have tried several times to create the index using this sql command:
    create index rep_index on report(report_binary)
    indextype is ctxsys.context;
    I have also tried it with severa other variations using the parameter list, but I believe that this way is sufficient because all the default options, as I understand them, are good enough for a search through PDFs.
    The command did succeed in creating the index (or so it claims), but when I query using the contains method no pdfs are ever returned. Here is an example query after the index is created:
    select score(1), report_id from report where contains(report_binary, 'the', 1) > 0 order by score(1) desc;
    That and other similar queries never return anything!!
    Is there some piece of the index creation specific to BLOBs that I am missing?
    thanks for the help!
    -- Joseph
    Edited by: user12036946 on Oct 9, 2009 10:40 AM

    "the" is a stopword for English-language default installations, so that particular search won't find anything.
    Try
    select token_text from dr$rep_index$i to see if you have any indexed words. If you do, try searching for one of those.
    If you don't have any indexed words, check the view ctx_user_index_errors to see if there are any row-level index creation errors.
    What version and platform are you running on? The filters which provide the processing of PDF files are not available on all platforms - for example prior to 11g we didn't support Solaris X86-64.

  • A query related to creating Indexes for a table

    Hi ,
    I am in a J2EE Banking Project using Oracle 10g as our Database .
    We have created Indexes on some tables .
    But this this is not called by any of our Java class .
    Could anybody please let me know how these Indexes will actually improve the Performance .
    Waiting for your replies .
    Thanks in advance .

    But in our safety database (huge & ofcourse Oracle), we use indexes just because to avoid duplicates, improve data retrieval and so on.As you pointed out indexes can do 2 things for you: enforce uniqueness and (hopefully) improve data retrieval. Enforcing uniqueness is pretty basic, but indexes don't always improve performance. Under the wrong condtions indexes can hurt performance. The ideas below refer to B-TREE indexes; other kinds of indexes have other considerations
    Indexes add overhead to insert, delete, and (hopefully not - updating index columns is a Bad Idea), enough so that if you're inserting a lot of rows into a large table it is sometimes helpful to drop the indexes, load the data, and recreate the indexes when done to help performance. The more indexes a table has the more overhead DML statements need to maintain them.
    Indexes help query performance under a couple of conditions. When using them as join keys to retrieve a small percentage of rows in a table (< 20% maybe; there is no firm number) indexes can help. When a query can read its columns from an index only (such as counts against a primary key index) index access can be faster than table access.
    Indexes can hurt performance by adding overhead for maintenance if the index is never actually used or if used to read most of the rows in a table when a full table scan would be more efficient (why go through the extra effort to read the index and then table when you'll have to read most of the rows in the table anyway?).

Maybe you are looking for

  • Do I need to use a semaphore when reading/writing a functional global from reentrant VIs?

    I have a program that spawns multiple reentrant VIs running simultaneously.  These VIs write their status to a functional global.  The VI that monitors them periodically polls this global to check out how they're doing and takes action based on their

  • Acrobat Reader DC Save Folder

    I have just upgraded to Acrobat Reader DC. The problem is that I had a shortcut to a commonly used drive in the default location. However, now this does not help me as it does not show the shortcut. I am also unable to create a shortcut since it does

  • My pdf attachments to emails suddenly will no open.

    I have had no problem opening pdf attachments to emails. I have done this repeatedly. Over the last day, I have suddenly had problems opening pdf attachments to emails. If I reboot the computer, I may get one or two pdf attachments to open and then t

  • Transfer ENTIRE iTunes library via Wifi?

    Hi, I ordered my first mac today and i cant wait for it but i was wondering how could i transfer my entire itunes library from my PC (TV, Movies, podcasts, Music, Playlists)to my new mac via the Wifi setup in my house.

  • COMBINED TEXT & GRAPHICS QUALITY

    I'm looking at buying a high-end colour laser like the Xerox 7750 or Ricoh 7200. I've got a few questions about colour lasers in general (see my other recent posts). Feel free to offer any comments about: COMBINED TEXT & GRAPHICS QUALITY My HP scanne