I don't know which to choose.. BIGINT OR DECIMAL. Help needed.

Discussion in 'Databases' started by x0x, Dec 19, 2009.

  1. #1
    I have about 50 tables of which each have about 10 fields whose values will likely be 100,000,000,000-100,000,000,000,000. No negative values.

    I know that having that many big fields will eat my servers memory. Since bigint can hold up 18,446,744,073,709,551,615 it seems such a waste to use it. Should I use decimal instead for better performance?

    I'm trying to utilize my script because the on script on my old server, mysql was utilizing 100% of the servers memory at least a few times a day. That server had 4GB of ram and a pretty powerful processor. No more than 100 users browsing my site.

    It's a game site by the way, that's why I need so many big fields.
     
    x0x, Dec 19, 2009 IP
  2. jedi.knight

    jedi.knight Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you have indexed the database properly, the variable size won't be a big problem. Your problem with bigint is performance, not space, right?

    Can you give an example of a query? May be we can figure out the proper indexes.
     
    jedi.knight, Dec 20, 2009 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Decimal would not be better performing. An unsigned bigint (20) would be the best way to go.

    Out of curiosity, what are you doing that requires numbers this large?
     
    jestep, Dec 23, 2009 IP
  4. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Also, are all those digits significant? That is, do you ever actually use the ones, tens, hundreds, etc. spot? Or are they always zeros? If that's the case you can store the number to accomodate the least signficant digit and then just multiple it out when you retrieve it.

    So if the last 3 digits are always zeros, you would save 987,456,000 as 987,456 in the database and always multiply it by 1,000 when retrieving it.
     
    plog, Dec 23, 2009 IP
  5. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #5
    They are almost never zeros....


    To jedi.knight: To be honest I have never heard about indexing. The most common queries are while loops that pull data from the db. Like messages. I don't know if that's what you wanted to hear.
     
    x0x, Dec 24, 2009 IP
  6. ceemage

    ceemage Well-Known Member

    Messages:
    297
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #6
    If you are doing any kind of arithmetic with these fields, and the data is always whole numbers, keep them as integers rather than decimals. Avoids rounding errors.
     
    ceemage, Dec 26, 2009 IP