SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Zurev's Avatar
    Join Date
    Feb 2009
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    More efficient, which?

    Just wondering, the easiest way I can think of to give an example is this:

    Scenario A:
    Need to figure out post count on a forum
    Everytime someone posts their row updates a post_count field by 1, and then that number gets displayed.

    Scenario B:
    You use count();(If I remember correctly) to tally all the posts that are started by that user and display that number.

    Since most major forum systems use a post_count field in their tables I'm going to assume scenario A is more efficient, but does it really matter?

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but does it really matter?
    On really large tables, it can.

    Mysql with myIsam tables use the counter trick to lighten the server work.
    I encountered situations where having multi million rows to be counted, with a where clause led to several seconds of work for the db (postgresql, back in 1999. They got better since..)

    So yes, it can make a difference.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    how many times does a person post, versus how many times is his post count retrieved for display?

    that'll guide your decision

    r937.com | rudy.ca | 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
  •