SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    photo tags: one row all tags or each tag new row?

    Considering a site with 100.000+ photos and growing. All photo tags are separated with comma.

    Is better to put all photo tags into 1 row or separate?
    photoId | tag
    -------------
    1 | sea
    1 | beach
    1 | night
    33 | cars

    SELECT photoId FROM photos WHERE tag='tagname'

    OR

    photoId | tags
    1 | sea, beach, night
    2 | cars

    SELECT photoId FROM photos WHERE tag IN ('tagname')

    Which one is better, or is any other better way?

    Thank you

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    new tag each row is significantly better, see NORMALIZATION for clarity.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    what guelphdad said

    besides, you can't use WHERE tag IN ('tagname'), you have to use FIND_IN_SET, and of course this requires a table scan which gets slower and slower the more rows you have...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •