Order of fields in Primary key in where clause

Hello,
Does order of fields(complete primary key) in where condition matters with the performance or using of index ?
Here is an example -
BKPF has primary key - bukrs, gjahr, belnr.
1. select single awkey into lv_awkey
  from bkpf where bukrs = p_bukrs
              and gjahr = p_gjahr
              and belnr = p_belnr.
2. select single awkey into lv_awkey from bkpf
                              where bukrs = p_bukrs and
                                        belnr = p_belnr and
                                        gjahr = p_gjahr.
Does it make any difference in performance point of view with above two kinds ? Is that same applicable when accessing based on secondary index ?
Thanks,
Nagarjuna

Hi Nagarjuna,
the order of the fields does not influence the performance of the execution of the statements. This is true for primary key and secondary key accesses. In the statement cache (SAP and DB) two different statemens have to be maintained (parsing, space, ...) but their execution time is the same.
Kind regards,
Hermann

Similar Messages

  • How to Alter any table to make some fields Composite Primary Key

    I need to Alter Table to make some fields Composite Primary Key.
    Is it possible to do this ?
    Please give any example.
    Regards,
    AgrawalV

    Agrawal
    If you are looking for an example to create a composite primary key, here you are.
    sql> Alter Table myTable add constraint pk_myTable primary key(col1, col2, ...coln) ;
    where
    pk_myTable is the name of the primary key constraint,
    myTable is the name of the table that you want to create a constraint on and
    col1...coln are the column names in the table <myTable)

  • Adding 2 new fields as Primary Key field in a Z Table which is existing PRD

    Hi Friends,
    I have to add two new fields as primary key fields in a Z TABLE, which is existing in Quality and Production Systems with Data.
    If I incorporate these two new fields (Primary Key fields) in development and if the TR is moved to Quality and Production sytems, is there any possibility of loss in data will happen at Quality and Prd systems?
    At present, Table is having 20 fields with 2 primary key fields and i have to add 2 more primary key fields.
    I have checked in SCN and not find relevant threads.
    Please help me out.
    Regards,
    Suresh.

    NO . It wont be a problem .
    For ex :
    If you have VBELN  , POSNR are key fields now , you have an unique reord with that combination .
    If you add one other field in it  fo ex  VKBUR  then records will be like this
    VBELN     POSNR     VKBUR   MATERIAL   QTY
    10020      10                            abcxyz      1
    10020      10            1234        abcxyz     1
    So your previous records before adding new primary keys , will have new fields balnk , and the new records will have data filled up in all primary key fields .
    However , if you try to update the existing records that will be in existing PRIMARYKEY combination only .
    for example if you try update record 1 above with VKBUR value 85858 , it creates a new record , it wont be updated in existing record.
    Hope this helps , Pls let me know if u have any more doubts.

  • Using CMR field as Primary Key in Entity Bean

    Hi, all!
    Can somebody tell me, is it possible to use CMR field as Primary Key field in Entity Bean?
    Thanks

    WebLogic Server supports mapping a cmr field to the primary key.

  • Problem in primary key column where user does typo error.

    Hi all,
    I have a primary key in the table that some part of it was the current date. For example if today date is 3rd May then it will contain xxxxxx-0503 (where xxxxxx will be unique for this day). In order save time needed to enter the data, I achieve this by having another (non database) item in the datablock where the user type the xxxxxx part and use a pre-insert trigger to add the '-0503' part to the actual primary key item in the datablock.
    This works well if the user enter the xxxxxx part in the non database item correctly. But the problem show up when the users have typo error in the non database item that break the uniqueness of the primary key. Form as usual will tell us that it cannot insert the item but when I try to fix the error, it will report that records has been inserted before. The only solution is to clear form and retype the xxxxxx part.
    Anyone have any idea on what is the best method to implement this in form? Thanks in advance for your help.

    Marcel,
    I cannot reproduce this in version 10.1.2.2. We did not "fix" this, although changes in the runtime might have fixed this "silently". I suggest you upgrade to 10.1.2.2 and see whether you still get the error.
    Steven Davelaar,
    JHeadstart Team.

  • Utilizing auto-increment/identity fields for primary key with "application" identity

    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?

    To the best of my knowledge, you cannot use auto-increment. Due to the
    differences in the way that identities are generated at the datastore
    (upon insert) vs. JDO (upon makePersistent), this feature of SQLServer is
    not supported yet.
    However, we do provide a variety of other ways of generating identity
    which may provide a closer fit to what you want, and
    our users may have some experience in solving your problem.
    On Tue, 28 Jan 2003 09:56:08 +0000, Sean Ryan wrote:
    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?--
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • How add new field as primary key for existing table

    Hi,
    There is table with name REVIEWER_REUSE_EFFORT and the table has 8000 rows in it.
    Now the enhacement i must do on this table is there is no primary key on this table. so i must create a ID also add values to this table of ID
    Table structure is like this
    Create table REVIEWER_REUSE_EFFORT
    PRO_ID number,
    POBJ_ID number,
    TASK_ID number,
    POTENTIAL_EFFORT number,
    COMMENTS varchar2(1200),
    CREATED_BY varchar2(100),
    CREATION_DATE sysdate
    UPDATED_BY varchar2(1200),
    UPDATED_DATE sysdate
    Please suggest me how to add values in that 8000 rows
    Thanks
    Sudhir

    Hi,
    If you want to add a new column and update the new column with sequence of number
    alter table REVIEWER_REUSE_EFFORT add (ID number);
    update REVIEWER_REUSE_EFFORT  set ID=rownum;Regards,
    Prazy
    Edited by: Prazy on Jun 21, 2010 3:13 PM

  • Queryeditor using fields more than once in where clause not possible?

    I have to create a select query with a WHERE clause using a field multiple times.
    I can't get this to work. For example:
    SELECT ALL
      EMSDTALIB.EMSPPA.PAIDNR,
      EMSDTALIB.EMSPPA.PANAAM,
      EMSDTALIB.EMSPPA.PAVLTR,
      EMSDTALIB.EMSPPA.PATITL,
      EMSDTALIB.EMSPPA.PAADRS,
      EMSDTALIB.EMSPPA.PAHSNR,
      EMSDTALIB.EMSPPA.PAHSNT,
      EMSDTALIB.EMSPPA.PAPCA1
    FROM EMSDTALIB.EMSPPA
    WHERE EMSDTALIB.EMSPPA.PABEDR=1 AND EMSDTALIB.EMSPPA.PADTUD=0 AND
      (EMSDTALIB.EMSPPA.PADVBD='001' OR EMSDTALIB.EMSPPA.PADVBD='003' OR EMSDTALIB.EMSPPA.PADVBD='006')How do I get this to work?
    Regards,
    Roland

    Hi Roland, Luca, ICON_SS,
    I just tried similar queries using the latest release bits and it works fine.
    My Queries that worked fine are :
    SELECT ALL DASUSR1.PERSON.PERSONID, DASUSR1.PERSON.NAME, DASUSR1.PERSON.JOBTITLE, DASUSR1.PERSON.FREQUENTFLYER
    FROM DASUSR1.PERSON
    WHERE ( DASUSR1.PERSON.NAME='Able, Tony' OR NAME='Black, John' )
    SELECT ALL DASUSR1.PERSON.PERSONID, DASUSR1.PERSON.NAME, DASUSR1.PERSON.JOBTITLE, DASUSR1.PERSON.FREQUENTFLYER
    FROM DASUSR1.PERSON
    WHERE ( DASUSR1.PERSON.PERSONID=1 OR PERSONID=2 OR PERSONID=3)
    I would suggest you to Download & Install latest Creator bits released 9/27/2004, if not already done.
    Appreciate your valuable feedback,
    Sakthi

  • Partition Key in Where Clause

    I have a range partition on a date column (load_dt). if I have the partitioned key in my where clause and I DO NOt specify the partition name, will Oracle still know which partiion to get the row from? BTW, we are on Oracle 11.0.1.0.7

    ji**** wrote:
    I have a range partition on a date column (load_dt). if I have the partitioned key in my where clause and I DO NOt specify the partition name, will Oracle still know which partiion to get the row from? BTW, we are on Oracle 11.0.1.0.7Yes.
    Please read http://download.oracle.com/docs/cd/E11882_01/server.112/e16541/part_avail.htm#VLDBG00401

  • Order of Predicates and Joins in a where Clause

    I always specify the join conditions and then predicates in where clause . But when i placed the predicates first and then joins the response was quicker . I compared the execution plan and each has a different approach .
    Is it true in all cases or it doesn't matter ? Which one is better ? In the following examples I usually follow the first approach but when i tried the second one it was faster .
    Query 1
    select t1.something from
    table1 t1 , table2 t2
    where t1.id=t2.id
    and t1.year = 2009
    Query 2
    select t1.something from
    table1 t1 , table2 t2
    where t1.year = 2009and
    and t1.id=t2.id
    Edited by: user561066 on Sep 24, 2010 11:57 AM

    Welcome to the forum.
    As SomeoneElse already asked: mentioning your database version is crucial when it comes to these types of questions.
    So just be default always post the result of:
    SQL> select * from v$version;when asking a question.
    Find more information here, it explains clearly what information is needed from you to post:
    How to post a SQL statement tuning request HOW TO: Post a SQL statement tuning request - template posting
    Execution plans, database version, optimizer settings....

  • Primary key based on multiple fields which are of a custom class type

    Hello!
    I have the following two classes.
    public class Application
    protected String appName;
    protected Set moduleOptions = new HashSet(); //Set<ModuleOption>
    public class Option
    protected String name;
    protected Application application;
    Now, I need for Option to have a composite primary key based on both its
    fields. How do I do this?
    For starters, I just need a few hints on how this should be done in Kodo
    because I already have this thing working in JPOX and that solution does
    not map directly to Kodo. JPOX defines the OptionPK (primary key class)
    to contain field ApplicationPK, and not Application. But Kodo does not
    accept this because of a mismatch between fields in class and its primary
    key class. (Not implying that Kodo should accept the same kind of
    solution.)
    Btw, I'm evaluating version 3.2.3.
    Thanks in advance!

    Viktor,
    The typical Kodo pattern for doing this is to create a private field in
    Option for each primary key in Application, map those fields as
    primary-key (but not the field of type Application), and therefore put
    those fields in the OptionPK. These fields should then be mapped to the
    same columns as the Application reference. Then, set the primary key
    fields to the same value as they are in the related object.
    Kodo allows multiple fields to be mapped to the same column in the
    database, and throws an exception if your actions would set the column
    to different values. So, typically, this might look like:
    public class Application
    protected String appName; // I'm assuming that this is the PK
    protected Set moduleOptions = new HashSet ();
    public class Option
    protected String name; // pk
    protected Application application; // not pk
    private String applicationAppName; // pk
    public Option (String n, Application a)
    name = n;
    application = a;
    applicationAppName = a.appName;
    -Patrick
    Viktor Matic wrote:
    Hello!
    I have the following two classes.
    public class Application
    protected String appName;
    protected Set moduleOptions = new HashSet(); //Set<ModuleOption>
    public class Option
    protected String name;
    protected Application application;
    Now, I need for Option to have a composite primary key based on both its
    fields. How do I do this?
    For starters, I just need a few hints on how this should be done in Kodo
    because I already have this thing working in JPOX and that solution does
    not map directly to Kodo. JPOX defines the OptionPK (primary key class)
    to contain field ApplicationPK, and not Application. But Kodo does not
    accept this because of a mismatch between fields in class and its primary
    key class. (Not implying that Kodo should accept the same kind of
    solution.)
    Btw, I'm evaluating version 3.2.3.
    Thanks in advance!

  • How to specify multiple sequence for multiple fields in a primary key!

    Hi,
    i have a table which has about 15 fields, one of the field is primary key and i am able to specify the sequence for it using toplink and when the object is created through toplink the sequence get generated automatically, which is fine.
    Now i have to add another sequence generated field to the table this field is not nullable and
    i am looking for a way in toplink to specify the sequence for this field too, so that when we create objects through toplink the value for the field is automatically generated instead of us fetching the next value from sequence using a sql statement and then using the set method for the field.
    is there a way i can specify a sequence for another field through toplink, while keeping the sequence settings for the primary field untouched.
    thanks for your help!
    -

    TopLink only supports a single sequence field in its' mappings. There should be an API you can use to get another sequence number from an event, but I could not find an easy one (please log a bug for this on EclipseLink). The following code might work if you define the other sequence in TopLink, but you could also just execute the raw SQL as you are doing.
    i.e. something like,
    preInsert(DescriptorEvent event) {
    MyObject object = (MyObject) event.getObject();
    object.setOtherId(event.getSession().getDatasourcePlatform().getSequence("MY_OTHER_SEQ").getGeneratedValue(event.getSession().getAccessor(), event.getSession()));
    -- James : http://www.eclipselink.org

  • Tables-Primary Key-Sequential read

    Hi Folks,
    Out of the following which imporves performace?
    1.Using all the primary keys of a table in the where clause of a select statement?
    2.Using any one or two (not all) primary keys of a table in the where clause of a select statement?
    Let me the know the same in the case of using an Secondary index.
    3.If we follow the second one,then it will go for a sequential read,how this sequential read mars the performance?
    4.How creating an index will affect the database as BASIS guys are not in favour to creating an index.
    Thanks,
    K.Kiran.

    1.Using all the primary keys of a table in the where clause of a select statement?
    2.Using any one or two (not all) primary keys of a table in the where clause of a select statement?
    Out of the above 2 first one will give more performance. Coming to primary key or Secondary indexses, anything.. it gives better performance if you give the key fileds in the order of DB declaration.
    I mean you are specifying some fields of primary key.. but not in the order .. i mean u have specified key1, key3, key4. It will give less performance than specifying only key1 and key2.
    in secondary indexes if you are not specifying all key completely that will take the key up to the order matches. i mean in key1, key3, key4 case.. it will consider only Key1.
    In Key1, Key2 case it will consider both.
    3.If we follow the second one,then it will go for a sequential read,how this sequential read mars the performance?
    4.How creating an index will affect the database as BASIS guys are not in favour to creating an index.
    Creating an secondary index will save the table contents in the format of starting with index fields in the DB. So number of indexes on the same table will need to craete more views in database. So leads to poor DB performance. i mean more space unnecesarily for a single table. That's why they will create indexes only for very frequently used fields on tables.

  • Table Creation & Primary Keys

    Hi there
    I have a table with the 1st 3 fields as primary keys. I now need to change this to other fields.. But these fields are in the middle of the table. Apparently the primary keys must be the first fields in the table so I have to move the fields I need up. The problem is it will influence my XI/PI development cause Im using substrings to get the correct fields and If I change the order of the fields my interfaces will not work anymore.. I there a way to set the primary keys without changing the order of the fields?
    Thanks,
    Jan

    Hi Jan,
         I think there is no other way to do it. All the primary keys should be declared in continuation at the begining of the table. Try to change your XI/PI development according to these entries.
    Regards,
    Swapna.

  • Oh.. Primary key index is missing!

    Database: 10.2.0.4.0
    Platform : Linux
    SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME FROM DBA_CONSTRAINTS WHER
    E TABLE_NAME='ISSUE_COMMENTS';
    CONSTRAINT_NAME C STATUS VALIDATED
    SYS_C0031516 C ENABLED VALIDATED
    SYS_C0031517 C ENABLED VALIDATED
    SYS_C0031519 P ENABLED VALIDATED
    SQL> SELECT INDEX_NAME,TABLE_NAME FROM DBA_INDEXES WHERE TABLE_NAME='ISSUE_COMMENTS';
    INDEX_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS ISSUE_COMMENTS
    SQL> select distinct index_name,column_name,table_name from dba_ind_columns wher
    e table_name in ('ISSUE_COMMENTS');
    INDEX_NAME COLUMN_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS IDX ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS ISSUE_ID ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS PARENT_ID ISSUE_COMMENTS
    Where is the index for the primary key 'SYS_C0031519'?
    SQL>
    After droping and recreating the primary key also,just primary constrainy is created but there is no corresponding index.
    SQL> ALTER TABLE ISSUE_COMMENTS DROP CONSTRAINT SYS_C0031519;
    Table altered.
    SQL> ALTER TABLE ISSUE_COMMENTS ADD PRIMARY KEY (IDX)
    2 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    3 STORAGE(INITIAL 32768 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    4 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    5 TABLESPACE "TABLE_DATA" ENABLE;
    Table altered.
    SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,status,validated FROM DBA_CONSTRAINT
    S WHERE TABLE_NAME='ISSUE_COMMENTS';
    CONSTRAINT_NAME C STATUS VALIDATED
    SYS_C0031516 C ENABLED VALIDATED
    SYS_C0031517 C ENABLED VALIDATED
    SYS_C0034310 P ENABLED VALIDATED
    SQL> SELECT INDEX_NAME,TABLE_NAME FROM DBA_INDEXES WHERE TABLE_NAME='ISSUE_COMMENTS';
    INDEX_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS ISSUE_COMMENTS
    SQL> select distinct index_name,column_name,table_name from dba_ind_columns wher
    e table_name in ('ISSUE_COMMENTS');
    INDEX_NAME COLUMN_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS IDX ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS ISSUE_ID ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS PARENT_ID ISSUE_COMMENTS
    Here also, the primary key constraint SYS_C0034310 is available but there is no index for that primary key.
    Where the primary index has gone?

    MohanaKrishnan wrote:
    Database: 10.2.0.4.0
    Platform : Linux
    SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME FROM DBA_CONSTRAINTS WHER
    E TABLE_NAME='ISSUE_COMMENTS';
    CONSTRAINT_NAME C STATUS VALIDATED
    SYS_C0031516 C ENABLED VALIDATED
    SYS_C0031517 C ENABLED VALIDATED
    SYS_C0031519 P ENABLED VALIDATED
    Your first query is not consistent with the first set of results you have displayed.
    Your later query for index columns is also not very helpful as it won't list the column names in the right order.
    The probably answer to your question is that the index you have is non-unique and starts with the column you've used for the primary key, which means Oracle can use it to support the primary key constraint. Here's a quick cut-n-paste from a SQL*Plus session to demonstrate the point:
    SQL> create table t1 (n1 number, v1 varchar2(10));
    Table created.
    SQL> create index t1_n1 on t1(n1);
    Index created.
    SQL> alter table t1 add primary key(n1);
    Table altered.
    SQL> select index_name from user_indexes where table_name = 'T1';
    INDEX_NAME
    T1_N1
    1 row selected.
    SQL> select constraint_name, constraint_type, index_name from user_constraints
      2  where table_name = 'T1';
    CONSTRAINT_NAME      C INDEX_NAME
    SYS_C0033465         P T1_N1
    1 row selected.
    SQL> spool offNote how I've added a primary key with no name, and Oracle has decided to use the t1_n1 index to support it.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    "Science is more than a body of knowledge; it is a way of thinking" Carl Sagan
    Edited by: Jonathan Lewis on Dec 31, 2008 2:16 PM
    Apologies to Satish - I didn't see either prior post

Maybe you are looking for