int, smallint, bigint etc

Discussion in 'PHP' started by x0x, Oct 9, 2009.

  1. #1
    I know that the length is the difference, but what's the difference? Wouldn't just choosing the biggest one be the best choice? I usually use decimal(60) for everything numeric...
     
    x0x, Oct 9, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    obviously the size means that you will create larger and smaller databases dependant on the field size for the data. Decimal would be pointless for any field with an auto increment such as an ID field (since it's positive integers only), so would be a waste of system resources
     
    JAY6390, Oct 9, 2009 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I have mediumint, unsigned for the ID fields. And decimal, unsigned for most of the big numeric fields where the numbers reach trillions, never negative.

    Let's say I have a field that will never have a greater value than xxx, should I choose tinyint(3), unsigned or it doesn't matter if I choose something larger? My current game site is not very well built. MySql ultilizes sometimes 100% of my server's 4GB ram.
     
    x0x, Oct 10, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    WHAT!? Sounds like you need to do some major overhauls on your SQL queries and code structure! Yes if you know how big a field will ever be, then use the smallest possible data length for it. Why bother wasting resources if you don't need to?
     
    JAY6390, Oct 10, 2009 IP
  5. kingsoflegend

    kingsoflegend Well-Known Member

    Messages:
    202
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #5
    If the data structures are bigger, then it will take more time for the DB server to process queries and also more data will be sent to the web server.

    If your site uses so much RAM then the problem probably lies elsewhere. Optimizing data structures would help, but I suggest you optimize your queries first. Read up on the "explain" command in MySQL so you can understand what's happening on the server when you do a query.
     
    kingsoflegend, Oct 10, 2009 IP
  6. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Oh, I didn't know that.

    What should I choose for text fields like for usernames? I usually use varchar 255. Also, for big numeric fields, what's the best option? I usually use decimal 60. Which is better decimal or bigint? Only positive values.

    Also, what's the point of the length option? Tinyint(1) and tinyint(3) both max value is 255...

    Oh and also what's the best option for text fields for usernames and larger text fields like description? I usually use TEXT for description (more text) and varchar(255) for usernames etc. Can anyone explain what's the point of the length behind the type?

    EDIT: The Length option only seems to make a difference for decimal fields. Decimal(3) max = 999, decimal (4) max = 9999 etc. So wouldn't decimal be the best choice for all numeric fields since I can get closer to the max amounts I need by using the length option? What's best for performance?
     
    Last edited: Oct 10, 2009
    x0x, Oct 10, 2009 IP
  7. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #7
    bump.......................
     
    x0x, Oct 11, 2009 IP