Foreign key referential integrity in the fact tables
+3
hang
ngalemmo
Ashish Mishra
7 posters
Page 1 of 1
Foreign key referential integrity in the fact tables
Hi experts,
While implementing the physical model for a star schema
is it advisable to keep the foreign key of the dimensions on fact table at the database level or should it be maintained only through the ETL instead of enforcing by DBMS
what are pro and cons
I am looking from the perspective of the load and extraction performance
Databases that I have to implement this model is
DB2
oracle
Teradata
SAS
should my choice also be based on these factor.
Regards and thanks
While implementing the physical model for a star schema
is it advisable to keep the foreign key of the dimensions on fact table at the database level or should it be maintained only through the ETL instead of enforcing by DBMS
what are pro and cons
I am looking from the perspective of the load and extraction performance
Databases that I have to implement this model is
DB2
oracle
Teradata
SAS
should my choice also be based on these factor.
Regards and thanks
Ashish Mishra- Posts : 11
Join date : 2011-02-22
Re: Foreign key referential integrity in the fact tables
In general, the process of assigning surrogate keys in the ETL process is more than sufficient to ensure FK RI. Enforcing constraints in the database is redundant and not necessary. Doing so slows down the load process.
However, some BI tools make use of FK declarations to ease defining relationships between tables. Therefore it is common practice to delcare FKs, but not implement contraints to enforce them.
However, some BI tools make use of FK declarations to ease defining relationships between tables. Therefore it is common practice to delcare FKs, but not implement contraints to enforce them.
Re: Foreign key referential integrity in the fact tables
Since ETL is a tightly controlled process, any database level RI requirements in data warehouse should be superseded by ETL. In OLTP system, RI constraints are targeted at data entry on record level and hence can protect data integrity. In data warehouse, data are loaded in batches by ETL and RI validation is just a bear minimum part of the whole complex process. RI constraints has performance implication to ETL, and some ETL also has its own peg order about loading the data which could require undoing the RI constraints.
In my experience, the only value having database RI is to automatically draw the connection lines between tables by some modelling tools. So part from superficial usefulness in data warehouse, database RI could be only useful, If you want your data bypass the ETL. Do you really want to do that?
In my experience, the only value having database RI is to automatically draw the connection lines between tables by some modelling tools. So part from superficial usefulness in data warehouse, database RI could be only useful, If you want your data bypass the ETL. Do you really want to do that?
hang- Posts : 528
Join date : 2010-05-07
Location : Brisbane, Australia
Re: Foreign key referential integrity in the fact tables
I don't know about other databases, but in SQL Server the foreign key constraints allow for Star Query Optimizations. You should check if this is the same for your databases.
Re: Foreign key referential integrity in the fact tables
thanks for the valuable inputs
Ashish Mishra- Posts : 11
Join date : 2011-02-22
Re: Foreign key referential integrity in the fact tables
John Simon wrote:I don't know about other databases, but in SQL Server the foreign key constraints allow for Star Query Optimizations. You should check if this is the same for your databases.
Oracle doesn't require it (but there are other things you need to do, not related to constraints or declarations), last I saw of DB2 (2 yrs ago) they did not support star joins, and for Teradata... forgedda bout it.
Does SQL Server require a constraint or a simple declaration?
Re: Foreign key referential integrity in the fact tables
Just the declaration.
Btw, I'm now working as a solution lead on a large Teradata implementation. I was reading the Teradata documentation today and Teradata does have Star Query optimizations.
Btw, I'm now working as a solution lead on a large Teradata implementation. I was reading the Teradata documentation today and Teradata does have Star Query optimizations.
Re: Foreign key referential integrity in the fact tables
I am not sure what the 'declaration' means. In my understanding, it is declarative foreign key constraint by DDL. However I have done some googling, and dug up this site, http://msdn.microsoft.com/en-us/library/bb522541.aspx. To summarrise, in SQL Server 2008 R2, the optimization can be achieved automatically through Bitmap Filtering that has the following requirements:
- Fact tables are expected to have at least 100 pages. The optimizer considers smaller tables to be dimension tables.
- Only inner joins between a fact table and a dimension table are considered.
- The join predicate between the fact table and dimension table must be a single column join, but does not need to be a primary-key-to-foreign-key relationship. An integer-based column is preferred.
- Joins with dimensions are only considered when the dimension input cardinalities are smaller than the input cardinality from the fact table.
- Fact tables are expected to have at least 100 pages. The optimizer considers smaller tables to be dimension tables.
- Only inner joins between a fact table and a dimension table are considered.
- The join predicate between the fact table and dimension table must be a single column join, but does not need to be a primary-key-to-foreign-key relationship. An integer-based column is preferred.
- Joins with dimensions are only considered when the dimension input cardinalities are smaller than the input cardinality from the fact table.
hang- Posts : 528
Join date : 2010-05-07
Location : Brisbane, Australia
Re: Foreign key referential integrity in the fact tables
You can include 'NOCHECK' on the foreign key statement which will create the constraint but not enforce it. The real value for me has always been that I get boxes and lines when I reverse engineer a dimensional model. Normally, I just get boxes.
BoxesAndLines- Posts : 1212
Join date : 2009-02-03
Location : USA
Re: Foreign key referential integrity in the fact tables
John Simon wrote:Just the declaration.
Btw, I'm now working as a solution lead on a large Teradata implementation. I was reading the Teradata documentation today and Teradata does have Star Query optimizations.
Is that by creating a join index or have they come up with something different?
Re: Foreign key referential integrity in the fact tables
It's nice to know 'NOCHECK'. So if that is all, I would be happy to add constraint declaration without enforcing it, just to please Boxes and Lines.BoxesAndLines wrote:You can include 'NOCHECK' on the foreign key statement which will create the constraint but not enforce it.
I have been waiting for some new form of database system that is squarly targeted at data warehousing. In the new system, I would like to see at least a couple of RDBMS features should disappear. For instance, Transaction Log is another feature that is an overkill for ETL process.
hang- Posts : 528
Join date : 2010-05-07
Location : Brisbane, Australia
Re: Foreign key referential integrity in the fact tables
I always had foreign keys with NOCHECK. It also helps if you are using Report Builder or creating a DSV in SSAS.
Neil, I'm not sure. I'll have to check and get back to you.
Neil, I'm not sure. I'll have to check and get back to you.
Re: Foreign key referential integrity in the fact tables
hang wrote:It's nice to know 'NOCHECK'. So if that is all, I would be happy to add constraint declaration without enforcing it, just to please Boxes and Lines.BoxesAndLines wrote:You can include 'NOCHECK' on the foreign key statement which will create the constraint but not enforce it.
I have been waiting for some new form of database system that is squarly targeted at data warehousing. In the new system, I would like to see at least a couple of RDBMS features should disappear. For instance, Transaction Log is another feature that is an overkill for ETL process.
Thanks Hang, after all, it's all about me.
BoxesAndLines- Posts : 1212
Join date : 2009-02-03
Location : USA
Re: Foreign key referential integrity in the fact tables
hang wrote:
I have been waiting for some new form of database system that is squarly targeted at data warehousing. In the new system, I would like to see at least a couple of RDBMS features should disappear. For instance, Transaction Log is another feature that is an overkill for ETL process.
Netezza is such a system, so you don't need to wait. It got rid of a lot of normal OLTP oriented features to suit data warehousing.
It does not enforce constraints.
It does not maintain transaction logs. It uses serialization to enforce transaction states (simple and effective).
It does not provide row level locking (not possible using serialization).
It does not have indexing (in the traditional sense).
It is really fast.
Re: Foreign key referential integrity in the fact tables
Thanks ngalemmo, it's good to know. Is Netezza the only such a system on the market at the moment? I guess it would set the direction for next generation of data system.
hang- Posts : 528
Join date : 2010-05-07
Location : Brisbane, Australia
Re: Foreign key referential integrity in the fact tables
John Simon wrote:I always had foreign keys with NOCHECK. It also helps if you are using Report Builder or creating a DSV in SSAS.
And also for automatic join statement suggestions for software like Redgate's SQL Prompt - making code writing much, much faster.
Dave Jermy- Posts : 33
Join date : 2011-03-24
Location : London, UK
Re: Foreign key referential integrity in the fact tables
hang wrote:Thanks ngalemmo, it's good to know. Is Netezza the only such a system on the market at the moment? I guess it would set the direction for next generation of data system.
Yes, it is unique in its implementation. Other MPP type appliances have not significantly altered the underlying DBMS (usually Postgres).
Re: Foreign key referential integrity in the fact tables
How do we declare FKs without implementing constraints? Does Oracle allow that?ngalemmo wrote:
However, some BI tools make use of FK declarations to ease defining relationships between tables. Therefore it is common practice to delcare FKs, but /not implement contraints to enforce them.
I tried looking in oralce books for the syntax but could not find any.
Moreover, in the book - Oracle data warehouse tuning for 10g: By Gavin Powell, he mentions on page 51 that
Is he refering to FK declaration or FK constraints?.....Star transaformation queries require foreign key constraints and foreign key indexes.....Star queries require fact table foreign key constraint indexes to be created as bitmap indexes.
bidw_kk- Posts : 5
Join date : 2011-07-16
Re: Foreign key referential integrity in the fact tables
My experience with Oracle (up through 10G) was not to define any constraints at all. Just have bitmap indexes on the fact table FK columns.
There is a way to define a constraint but not enforce it. But, I'm out of town and don't have an Oracle SQL reference handy...
I'm also not sure what Mr. Powell refers to when he talks about a 'FK constraint index'. The only index needed to check a FK constraint is an index on the PK of the referenced table, which would never be a bitmap index. I would assume he means a bitmap index on the FK column... which has nothing to do with constraints.
There is a way to define a constraint but not enforce it. But, I'm out of town and don't have an Oracle SQL reference handy...
I'm also not sure what Mr. Powell refers to when he talks about a 'FK constraint index'. The only index needed to check a FK constraint is an index on the PK of the referenced table, which would never be a bitmap index. I would assume he means a bitmap index on the FK column... which has nothing to do with constraints.
Re: Foreign key referential integrity in the fact tables
A quick experiment has shown that Oracle indeed needs only the bitmap indexes on the joining columns (FKs in this case) and not the foreign key constraints.
ngalemmo, can you please tell how to define a constraint but not enforce it whenver your you get time.
ngalemmo, can you please tell how to define a constraint but not enforce it whenver your you get time.
bidw_kk- Posts : 5
Join date : 2011-07-16
Re: Foreign key referential integrity in the fact tables
I am now on a very large EDW project and it has become a nightmare because of lack of hard Referential Integrity. I always though use Soft RI (i.e. not constrained), but I've changed my position.
Here is my new recommendation: Use Primary and Foreign Key contraints, then take them off after 6 months. This will show up any issues with the source system or ETL jobs. Especially if you are outsourcing your ETL offshore!
Here is my new recommendation: Use Primary and Foreign Key contraints, then take them off after 6 months. This will show up any issues with the source system or ETL jobs. Especially if you are outsourcing your ETL offshore!
Re: Foreign key referential integrity in the fact tables
http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general005.htm
BoxesAndLines- Posts : 1212
Join date : 2009-02-03
Location : USA
Similar topics
» Foreign key referential integrity in the fact tables (Oracle 11g)
» Factless fact table with null foreign keys
» Modelling question - Multiple fact tables with one to many relationships and querying from many fact tables
» Fact surrogate key as foreign key in another fact table
» Fact Table Foreign Key reference question
» Factless fact table with null foreign keys
» Modelling question - Multiple fact tables with one to many relationships and querying from many fact tables
» Fact surrogate key as foreign key in another fact table
» Fact Table Foreign Key reference question
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum