MYSQL Question: Which is better for performance, many tables or...

Discussion in 'MySQL' started by x0x, Sep 6, 2009.

  1. #1
    Which is better. To rather have many tables or have everything squeezed in a few tables? I'm talking about hundreds of tables... IMO it would be more professional to have separate tables, just worried about the performance.
     
    x0x, Sep 6, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Wrong forum, but we need more information on what you're trying to accomplish before giving you any advice.
     
    premiumscripts, Sep 6, 2009 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I'm coding a rpg game and I want to log everything, I just don't know if I should create a separate table for each page...

    Having more tables might utilize more server memory?
     
    x0x, Sep 6, 2009 IP
  4. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It depends on how much data you have and how it will be accessed. I had one 7 gig table that was very slow but any given query only wanted a small section of it. Breaking it into 68 tables made each of those queries MUCH faster. I have over 200 tables in all.

    If each of your pages only needs access to a small amount of the table, and it's always the same section, then breaking them into smaller tables will usually be faster.

    For example, if page1.php only ever accesses Big-Table where Column1 = 'page1' then making a page1 table makes sense. It keeps the server from having to look at thousands of 'page2' entries to find 'page1.'

    However, if page1.php sometimes checks where Column1='page2' then you should keep it together; joins are slow.

    Make sense?
     
    Goramba, Sep 17, 2009 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    This is a very debatable topic and I don't think there is a correct answer. Take a project like wordpress. They stuff data into tables in ways that would not be considered a good practice. But, it's a simple schema, and it works.

    As far as most best practices are concerned, table numbers shouldn't be a concern, provided that they are created in a logical and relational manner. Don't store data in non relational formats (ex: deliminated data in a field) which is something that wordpress does.

    If you're worried about performance, then I would actually lean towards more tables. Selecting from massive tables with many rows can destroy the usability of an app. What Goramba is describing is basically partitioning where you break a large data set into smaller ones to increase the database's speed, which can be a major concern for large tables and limited resources.
     
    jestep, Sep 17, 2009 IP