SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Foreign Key Constraints and Performace!


Foreign Key Constraints and Performace!

Author
Message
Abrar Ahmad_
Abrar Ahmad_
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1488 Visits: 1312
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 !!!

steveb.
steveb.
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19318 Visits: 7195
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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (416K reputation)SSC Guru (416K reputation)SSC Guru (416K reputation)SSC Guru (416K reputation)SSC Guru (416K reputation)SSC Guru (416K reputation)SSC Guru (416K reputation)SSC Guru (416K reputation)

Group: General Forum Members
Points: 416092 Visits: 47141
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, MVP, M.Sc (Comp Sci)
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


PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26531 Visits: 4639
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.
Abrar Ahmad_
Abrar Ahmad_
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1488 Visits: 1312
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?





PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26531 Visits: 4639
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.
charlesbc
charlesbc
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 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).
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search