Inheritance & Polymorphism In Relational Databases

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Inheritance & Polymorphism In Relational Databases - Presentation Transcript

    1. Inheritance & Polymorphism In Relational Databases solving some common problems in web development
    2. The Problem
      • Books & Televisions
      • Both
        • SKU
        • Title
        • Description
        • Manufacturer
      • Books
        • ISBN
        • Author
      • Televisions:
        • Screen Size
        • Resolution
    3. Own Tables
      • Duplication of shared fields
        • Gets worse with more products
      • Lose indexing of shared fields
        • i.e. SKU unique across products
      SELECT * FROM books WHERE id = 7 SELECT id, title, ‘book’ AS type FROM books UNION SELECT id, title, ‘television’ AS type FROM televisions
    4. Single table inheritance (STI)
      • No duplication
      • Wasted fields
        • Gets worse with more products
      • Rails built in inheritance
      SELECT * FROM products WHERE id = 7 SELECT id, title, type FROM products
    5. Class Table Inheritance (CTI)
      • No duplication
      • No wasted fields
      • Index shared fields
      • Referential integrity
      • Difficult to enforce books or televisions
      • Creating and reading becomes more complex
      SELECT books.*, products.* FROM books JOIN products ON(products.id = books.product_id) WHERE books.id = 7 SELECT products.id, products.title, books.id, televisions.id FROM products LEFT JOIN books ON(books.product_id = products.id) LEFT JOIN televisions ON(televisions.product_id = products.id)
    6. Another Problem
      • Tags for Books and Televisions
      • Reference Products from Tags
      • What about tagging other things besides Products as well?...
    7. Multiple Tables
      • Duplication of Tag structure
      • Need new table for each thing
      • Can’t index across all tags
    8. Multiple Relationships
      • Single Tag structure
      • Can index all Tags
      • Need similar tables for anything we want to tag
      • Need some app logic
        • Deleting Product deletes relationship, not Tags themselves
    9. Class Table Inheritance
      • Generalize Products and Images
      • Avoids duplication
      • Alter existing structures
      • Increasing complexity
        • Books span 3 tables
      • Tightly coupled
        • Adding Comments: “TaggableCommentables”?
    10. Polymorphism
      • Simple
        • Just one Tags table to Tag anything
      • No changes to existing entities
      • Can handle tagging of any future entities
      • Loses referential integrity
        • Need to enforce in application logic
      • Comments could be added similarly
      • Rails has it built in

    + adorepumpadorepump, 2 years ago

    custom

    476 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 476
      • 476 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 11
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories