Primary Key in DW and indexes - composite key of all dimensional FKs?

Hi guys,
I have a DW and indexing question. Our metadata DW and physical DW are the same (star schema, no snowflakes). Should all dimensional FKs (such as TIME_KEY, ORG_KEY) be included as a part of a fact table's PK (a composite key becomes a combination of the TIME_KEY, ORG_KEY, etc.) in the database. Second question is, should we create just 1 composite index per fact table (resembling fact table's PK) or should we build several indexes (1 per dimension) ? Also, does it pay to build indexes on dimension tables?
I'm mostly worried about fact table with a few hundred million records that has 7 dimensional-FK columns(only numeric codes), 1 value column, and several ETL-related date columns. I wonder what's the best course scenario be for that one.
Thank you.

You can use bitmap indexes on foreign keys to enable star transformations to be carried out. There are full details in the Datawarehouse documentation. Unfortunately I can't access it at the moment to show you where!
As with anything you can check your performance using oracle trace events (10046) to ensure its performing as you want.
http://www.dwoptimize.com/2007/06/101010-answer-to-life-universe-and.html
Edited by: Matt T on Oct 22, 2008 4:50 PM

Similar Messages

  • Help with primary key problem

    Oracle 9.2.0 on Red Hat Linux advanced server 2.1
    (There are a number of large tables that this applies to)
    I have a partitioned table where during the creation of the table a Primary key was declared and was placed 'using index tablespace primary_key'. So the table is created, and the primary key is set to use the 'primary_key' tablespace.
    Since our loads are quite large, we disable constraints during the load process, then enable them after the load has completed. Here's the problem, when the constraints are enabled, the tablespace for constraints change to the default tablespace of the schema owner.
    We have a specific tablespace created to hold the primary keys of the various tables, called 'primary_key'. The schema owner has his own default tablespace called 'POWER1'. When the schema owner runs the enable script to enable the primary keys, they all start being placed in 'POWER1' which is not nearly as large as 'primary_key' and as a result the first couple primary keys are created in 'POWER1' and then 'unable to extend segment in tablespace POWER1' pops up and the rest of the primary keys fail to enable.
    The workaround for this is to set the default tablespace for the schema owner to to be 'primary_key' but that is not what we really want.
    any feedback on this is appreciated, thanks

    In the old days, when we disabled a primary constraint, Oracle dropped the index. When we re-enabled the constraint the index was built again. But, if we didn't specify the index tablspace when we re-enabled the constraint the index was built in the default tablespace. Which is what is happening to you now.
    In 9i Oracle added the KEEP INDEX clause, which allowed us to retain the index even though the primary key was no longer enforced. However, as your aim is to increase the speed of data take on, you in fact want the index dropped. So, what you need to do is:
    ALTER TABLE whatever DISABLE PRIMARY KEY
    DROP INDEX;
    ALTER TABLE whatever ENABLE PRIMARY KEY
    USING INDEX TABLESPACE indx;Cheers, APC

  • Primary key in Fact table

    Hi ,
    I have a question usually fact table consists of all primary keys from different dimensional tables but i have a requirement like this:
    Fact table consists of non-dimensional columns and one primary key Amount_ID(PK) aand this amount_ID is a FK in another table which records day to day transactions. My question is can a fact table have a PK ?
    Thanks,
    ch

    Yes Fact Table can have a Primary key
    But in your case it looks like the Other Table which is storing Day to Day transaction should be made FACT , and the one you are calling FACT should be made Dimension..
    Well depends again, how you are analysing data and against which attributes
    Thanks
    Ashish

  • Physical Model - Primary Key changed

    I have a report called 'Service Report' running fine. This report uses multiple tables like Service,Specification etc...
    Now that the primary key of service table has changed from 'jdoid' to 'entityId' (The primary key of all the other tables also have changed).
    Wondering what is the best way to rewrite this report?
    Do I have to import 'Service' table (and all other tables) and redefine physical model,business model and presentation model from scratch?
    Is there any other strategy that anybody could think of?
    Appreciate your help.
    Thanks
    Kavi

    No you don't need to re-import. You can edit manually in the Admin tool - start with the physical layer, then the BMM layer.
    Depending on the columns and how the report is built you might not need to edit the report at all.

  • Manually Entering Primary Key.

    Hi,
    I am in the very early stages of looking at creating Apex Forms/Reports to replace our existing systems on Oracle Forms.
    In the existing database, there are huge numbers of tables that use manually enterable primary keys when creating the record.
    These primary keys can be very simple, such as just a 6 character code field or 20 character reference field (made up of several different user enterable fields concatenated together) to multiple composiite primary keys, where there could be several levels of master/detail records.
    I have looked in the forums for information on this but am struggling to find a way of being able to create records where the primary key can be typed in manually when inserting records and then getting the reports/forms to work. I do not need to update the primary key, just allow it to be entered.
    It would just not be practical to create new sequences as primary keys for all our tables, just to get Apex to work how it wants - wouldn't this mean dropping the existig PK and creating a new one, then populating all records with the new sequence?
    I need to be able to use tabular forms for multi row record inserts where the user can enter (but not modify) the PK - using a report/form to do this seems too long winded. I will also need to be able to do this in a form only, for inserting singular records.
    Any help would be appreciated.
    Regards,
    Carl

    you should set in your entity object the attribute as DBSequence and then create a before insert trigger in the db table to get the pk from a sequence or so, something like:
    CREATE OR REPLACE TRIGGER trigger_name
    BEFORE INSERT
    ON table_name
    FOR EACH ROW
    begin
    select seq_name.nextval into :new.pk_id from dual;
    end;

  • Need to create form on a table with report with a table has NO primary key

    Hi, I tried to created some insert/update/delete form+report in an application, it works fine only if the table has primary key. Does anyone know how to create the same functionality with a table with no primary key? I saw an application is built on older version of htmldb that is using tables with no primary keys at all.
    Here are the specific issues that I am facing:
    - I am building some Form on a table with Report, it requires the table with primary key for form to update. Is there a workaround that I can use tables that has no primary keys at all?
    - Say if primary key is necessary in the previous report+form, but the maximum number of columns that I can use to composed a primary is only 2 for that Form-Report, I cannot find anything handling > 2 primary key. Do you know if there are some ways to composite a primary key from many columns together?
    Your help is really appreciated.
    Thanks,
    Angela

    Sorry to ask response so late. I had no time to get back to that issue before.
    Regarding the triggers, I can make it work for the update, but not the insert.
    Here is my trigger:
    create or replace trigger STATUS_T1
    instead of insert on STATUS
    begin
    insert into STATUS ("LABEL", "AREA", "OWNER", "TEST_NAME", "STATUS", "REMARKS", "BUGS", "DEV_MGR", "TEST_BY_DATE")
    values(:new.LABEL, :new.AREA, :new.OWNER, :new.TEST_NAME, :new.STATUS, :new.REMARKS, :new.BUGS, :new.DEV_MGR, :new.TEST_BY_DATE);
    end;
    by any chance, you can notify what is wrong?
    I already skip the ROWID when inserting to the view STATUS, but I cannot figure out what is wrong when inserting a new record to that view.
    It gave me the following errors:
    ORA-06550: line 1, column 38: PL/SQL: ORA-00904: "ID": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
    Error Unable to process row of table STATUS
    Then, I turned to debug mode, I am thinking that maybe because I use a HIDDEN item to hold the value of ROW_ID as I use the rowid (called ID in the view) to retrieve the record as a column link from previous page. What do you think?
    Thanks again,
    Angela

  • Let me know the standary primary key tables in standard table??

    let me know the standary primary key tables in standard table??

    Hi,
    You can go and check the primary keys of a table in SE11 by entering the table name and pressing display.
    You will get to see that there will be some fields with a tick mark in the primary key column.The fields which have such tick marks are the primary keys of that table.
    As far as I know there is nothing called primary key tables.All tables have some fields as primary keys based upon which a record is uniquely defined in that table.
    Hope it was useful.
    Thanks,
    Sandeep.

  • Mapping tables with no primary key defined

    Hi!
    I was just wondering if it's possible to map a table with no primary key? The reason why is that I have a logging table that I want to access, which is built very simple and the only useful filtering criteria that I'll be using there is a date column.
    Regards,
    Bjorn Boe

    TopLink requires that an object have a primary key to determine identity, perform caching, and database updates and deletes. It is best to define a primary key in all your objects; a sequence number can be used if the object has no natural primary key. The primary key does not have to be defined on the database, as long as a set of fields in the table are unique you can define them to be the primary key in your TopLink descriptor.
    If your table truly has no primary key, nor unique set of fields, it is still possible to map the table with some restrictions. If you disable caching, and mark the object as read-only, and never update or delete the object, you can map it for read-only purposes.
    You will need to do the following:
    - Set any field as the primary key to avoid the validation warning.
    - Set the cache type to NoIdentityMap.
    - Set the descriptor to be read-only.

  • Can I modify primary key or I need to drop it to create another overhide?

    I am getting this issue when I try to create another primary key in my table. The example bellow express the situation.
    TABLE AAA
    (ID
    NAME
    REGISTER)
    PK: ID
    I cannot drop the primary key, cause the table have some FK, so, I was thinking about to try "modify" this key (to put too other field), but I have not found one way to do it, I think just I can drop out the FKs, drop PK after, and create another new primary key after all, but this issue can be bring on a big trouble with other tables, there is another way to fix it, modifyng or just overhide the key?
    Thanks all and apologize about my bad english!

    Disable the refrencing FKs, then drop and recreate the PK. You will also have to modify the FKs. You can, alternatively, create a unique constraint on the new column combination.

  • Access path difference between Primary Key and Unique Index

    Hi All,
    Is there any specific way the oracle optimizer treats Primary key and Unique index differently?
    Oracle Version
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> Sample test data for Normal Index
    SQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12));
    Table created.
    SQL> create sequence seq_t_test_tab start with 1 increment by 1 ;
    Sequence created.
    SQL>  insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    99999 rows created.
    SQL> commit;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1565504962
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6915  consistent gets
            259  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> create index idx_t_test_tab on t_test_tab(col1);
    Index created.
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1565504962
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> Sample test data when using Primary Key
    SQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12));
    Table created.
    SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ;
    Sequence created.
    SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    99999 rows created.
    SQL> commit;
    Commit complete.
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab1;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1727568366
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |             | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB1 | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1);
    Table altered.
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
    PL/SQL procedure successfully completed.
    SQL> select col1 from t_test_tab1;
    99999 rows selected.
    Execution Plan
    Plan hash value: 2995826579
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    59   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 |   488K|    59   (2)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6867  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL> If you see here the even though statistics were gathered,
         * In the 1st table T_TEST_TAB, the table is still using FULL table access after creation of index.
         * And in the 2nd table T_TEST_TAB1, table is using PRIMARY KEY as expected.
    Any comments ??
    Regards,
    BPat

    Thanks.
    Yes, ignored the NOT NULL part.Did a test and now it is working as expected
    SQL>  create table t_test_tab(col1 number not null, col2 number, col3 varchar2(12));
    Table created.
    SQL>
    create sequence seq_t_test_tab start with 1 increment by 1 ;SQL>
    Sequence created.
    SQL> insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    99999 rows created.
    SQL> commit;
    Commit complete.
    SQL>  exec dbms_stats.gather_table_stats('GREP_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL>  set autotrace traceonly
    SQL>  select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 1565504962
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6912  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL>  create index idx_t_test_tab on t_test_tab(col1);
    Index created.
    SQL>  exec dbms_stats.gather_table_stats('GREP_OWNER','T_TEST_TAB',cascade => true);
    PL/SQL procedure successfully completed.
    SQL>  select col1 from t_test_tab;
    99999 rows selected.
    Execution Plan
    Plan hash value: 4115006285
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    63   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| IDX_T_TEST_TAB | 99999 |   488K|    63   (2)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
           6881  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    SQL>

  • Difference between primary key and primary index

    Dear All,
             Hi... .Could you pls tell me the difference between primary key and primary index.
    Thanks...

    Hi,
    Primary Key : It is one which makes an entry of the field unique.No two distinct rows in a table can have the same value (or combination of values) in those columns.
    Eg: first entry is 111, if you again enter value 111 , it doesnot allow 111 again. similarly for the strings or characters or numc etc. Remember that for char or numc or string 'NAME' is not equal to 'name'.
    Primary Index: this is related to the performance .A database index is a data structure that improves the speed of operations in a table. Indices can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records. The disk space required to store the index is typically less than the storage of the table (since indices usually contain only the key-fields according to which the table is to be arranged, and excludes all the other details in the table), yielding the possibility to store indices into memory from tables that would not fit into it. In a relational database an index is a copy of part of a table. Some databases extend the power of indexing by allowing indices to be created on functions or expressions. For example, an index could be created on upper(last_name), which would only store the uppercase versions of the last_name field in the index.
    In a database , we may have a large number of records. At the time of retrieving data from the database based on a condition , it is a burden to the db server. so whenever we create a primary key , a primary index is automatically created by the system.
    If you want to maintain indices on other fields which are frequently used in where condition then you can create secondary indices.
    Reward points if helpful.
    Thanks,
    Sirisha..

  • Primary keys and index

    Hi,
       I got these question in interview Plz answer them
       1. Maximum number of primary keys u can use for a table?
       2. Maximum number of indexes u can create?
       3. Maximum number of secondary indexes?
       4. Maximum number fields in a table?
       5. Maximum length of primary key field?
    Plz answer these questions
    regards,
    kumar

    >>1. Maximum number of primary keys u can use for a table?
    16
    >>2. Maximum number of indexes u can create?
    >>3. Maximum number of secondary indexes?
    Only 16 Primary Index and n number of secondary indexes.
    >>4. Maximum number fields in a table?
    249
    >>5. Maximum length of primary key field?
    255
    Cheers,
    Hakim
    Mark all useful answers..Close the thread once your question has been answered.

  • Null in Composite Primary Key and "Primary keys must not contain null"

    Hello all.
    I'm a newbie concerning to JPA/EJB3, but I was wondering if toplinks doesn't support composite primary keys with null in some field (something perfectly right in any RDBMS).
    I used JDeveloper (I'm using Oracle 10g database and JDeveloper 10.1.3.2.) wizards to generate JPA classes and I checked out generated files (with annotations), so they should be right (by the way, other O-R mappings for my model are working right, but this one).
    I'm getting the next error:
    Exception Description: The primary key read from the row [DatabaseRecord(
         TSUBGRUPOSLDI.CD_GRUP => 01
         TSUBGRUPOSLDI.CD_SUBGRUP => null
         TSUBGRUPOSLDI.CG_POBL => 058
         TSUBGRUPOSLDI.CG_PROV => 28
         TSUBGRUPOSLDI.DSCR => Sanidad)] during the execution of the query was detected to be null. Primary keys must not contain null.
    Compound primary key is (CD_GRUP, CD_SUBGRUP). No foreign keys, no joins (only a NamedQuery: "select o from ..."). It's the simplest case!
    I checked out that everything runs ok if there's no "null" value in CD_SUBGRUP.
    After some research (this and other forums) I'm beginning to believe that it's not supported, but not sure.
    Am I doing sth wrong? If not, what is the reason to not support this? Will it be supported in the future?
    Thanks in advance.

    Null is a special value and in many databases is not comparable to another null value (hence the isNull operator) and may pose problems when used to uniquely identify an Entity. TopLink does not support null values within a composite PK. As the nullable column is most likely not designated as a PK within your database table (many databases do not allow this) I recommend updating the Entity PKs to match that of the database.
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Recreate indexes,triggers and primary keys.

    Hi All,
    We have done an import of few table from MS SQL Server to oracle. But we couldnt see the indexes, triggers, primary key, foreign key of those tables.
    Could you please let us know how to recreate the primary key, foreign key, indexes, triggers etc of those tables.
    Pl suggest.
    Thanks in advance!
    Regards,
    Vidhya

    >
    We have done an import of few table from MS SQL Server to oracle
    >
    What does that mean exactly? How did you do an import from sql server to Oracle?
    Post your 4 digit Oracle version (result of SELECT * FROM V$VERSION) and the exact steps you took to 'import'.

  • UNIQUE INDEX and PRIMARY KEYS

    Hi Friends,
    I am confused about primary keys.
    What is the purpose of this key again? I know it is used for unique constraints.
    Supposing I have a table with two (2) columns which are each indexed as unique.
    Then they can me both candidate at primary key right?
    So why do I need a primary key again? when I have 2 columns which are uniquely index?
    Thanks a lot

    A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. This constraint does not apply to NULL values except for the BDB storage engine. For other engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL
    The differences between the two are:
    1. Column(s) that make the Primary Key of a table cannot be NULL since by definition; the Primary Key cannot be NULL since it helps uniquely identify the record in the table. The column(s) that make up the unique index can be nullable. A note worth mentioning over here is that different RDBMS treat this differently –> while SQL Server and DB2 do not allow more than one NULL value in a unique index column, Oracle allows multiple NULL values. That is one of the things to look out for when designing/developing/porting applications across RDBMS.
    2. There can be only one Primary Key defined on the table where as you can have many unique indexes defined on the table (if needed).
    3. Also, in the case of SQL Server, if you go with the default options then a Primary Key is created as a clustered index while the unique index (constraint) is created as a non-clustered index. This is just the default behavior though and can be changed at creation time, if needed.
    So, if the unique index is defined on not null column(s), then it is essentially the same as the Primary Key and can be treated as an alternate key meaning it can also serve the purpose of identifying a record uniquely in the table.

Maybe you are looking for