Foreign Key Constraints and Performace!

  • [font="Verdana"]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 !!!

    [/font]

  • 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.

  • 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
  • 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.
  • 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.

    [font="Verdana"]

    Thanks Paul,

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

    [/font]

  • 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.
  • 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).

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply