Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Foreign Key Constraints and Performace! Expand / Collapse
Author
Message
Posted Monday, July 5, 2010 4:46 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, August 28, 2014 11:00 PM
Points: 211, Visits: 1,113
Do Foreign key constraint implementation is fatal in terms of performance (keeping in view all CRUD Operations).

My design strategy for a medium level transactional DB (10 K - 500 K data records/Day) would be to not implement foreign key constraints?

How we can set any tradeoff between these two concerned factors.

Waiting Expertise !!!
Post #947462
Posted Monday, July 5, 2010 4:58 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, May 30, 2014 6:27 PM
Points: 2,808, Visits: 7,175
If you have a relational databae then you need to have FK constraints, without them you may as well look at column database.

The FK can impact perfromance, however they can also be used by the Query Optimizer for optimizing queries.

Post #947464
Posted Monday, July 5, 2010 5:12 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 9:44 AM
Points: 42,822, Visits: 35,953
Abrar Ahmad_ (7/5/2010)
My design strategy for a medium level transactional DB (10 K - 500 K data records/Day) would be to not implement foreign key constraints?


Half a million records a day is not a high-volume SQL database, not on appropriate hardware. There's no need to go to extreme measures (like dropping constraints) on a transactional volume that small.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #947468
Posted Monday, July 5, 2010 8:15 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,068, Visits: 4,639
Abrar Ahmad_ (7/5/2010)
Do Foreign key constraint implementation is fatal in terms of performance

FKs certainly add overhead but I would refrain myself of saying that FK implementation is fatal in terms of performance.

Having said that I have seen critical, high end systems - 60K+ executions per second - where each millisecond counted then no PK/FK was defined. In this case PKs got replaced by unique indexes and RI was enforced at the app side.

Abrar Ahmad_ (7/5/2010)
My design strategy for a medium level transactional DB (10 K - 500 K data records/Day) would be to not implement foreign key constraints?

There is a big difference in between 10K and 500K inserts nevertheless I agree with Gail this is not a large volume and provided hardware is appropriate I would enforce referential integritiy on the backend e.g. define PKs/FKs as business rules ask for.

Hope this helps.


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #947528
Posted Tuesday, July 6, 2010 3:00 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, August 28, 2014 11:00 PM
Points: 211, Visits: 1,113
PaulB-TheOneAndOnly (7/5/2010)

FKs certainly add overhead but I would refrain myself of saying that FK implementation is fatal in terms of performance.

Having said that I have seen critical, high end systems - 60K+ executions per second - where each millisecond counted then no PK/FK was defined. In this case PKs got replaced by unique indexes and RI was enforced at the app side.

Hope this helps.


Thanks Paul,


Do overhead of constraints is same for all CRUD Operations. Or there are some differences?




Post #947770
Posted Wednesday, July 7, 2010 2:48 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,068, Visits: 4,639
Abrar Ahmad_ (7/6/2010)
Do overhead of constraints is same for all CRUD Operations. Or there are some differences?


No doubt a select statement on a single table will show no overhead because of Referential Integrity

In regards of Insert, Update and Delete operations it all depends on the RI overall structure.

Inserting a row in a table where RI forces RDBMS engine to check the existance of - lets say 10 parent records in 10 different tables will have more impact than inserting a row in a table where rows have just one parent. The same applies to update and delete operations.


_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Post #948848
Posted Thursday, July 8, 2010 10:04 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, February 16, 2012 2:43 PM
Points: 7, Visits: 15
For well designed relational databases, foreign key (FK) constraints are not optional. They play a significant role in maintaining referential integrity. Having stated that principle, it is possible to place too many FK constraints on a given table and significantly degrade performance. However, this is most often a symptom of poor database design and not an indictment of FK constraints.

If you are concerned that specific FK constraints may degrade performance, then generate and examine the query execution plans for all related CRUD statements.

If the evidence points to FK constraints as being the root cause of the bottleneck, then refactor the physical database schema with the aim to reduce the number of FK constraint on a given table, but without sacrificing overall referencial integrity (enforced by the FKs).

Post #949416
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse