0

Now I have a table with impressions, clicks and ctr.

I was wondering if I should use tinyint(1) and store ctr which has a range from 1-250

or should I store it as a float which has more precision. or maybe decimal.

For statistics I would be calculating the ctr using clicks/impressions, so getting a precise value is not a problem.

But for performance what would be the best way to store it.

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Vish
  • 4,508
  • 10
  • 42
  • 74

2 Answers2

1

If you're using php to calculate the CTR based on your mysql data, then there's no reason to use float or decimal - just use tinyint.

But if you want to have the CTR stored in the database, then use float - it's like a small version of decimal.

Dave
  • 28,833
  • 23
  • 113
  • 183
  • I am going to be using ctr quite often, do you think that precision is worth the performance. – Vish Mar 30 '11 at 23:06
  • Honestly, I can't imagine the volume you'd have to use to make much of a difference. I would use the "correct" one (float) until/unless you actually notice a performance issue. Even if your table is upwards of a few million records, I doubt you'll see any performance issues assuming your php is written well. – Dave Mar 30 '11 at 23:11
  • i have about 500 million records – Vish Mar 30 '11 at 23:13
  • btw i am getting a better insight from your answers, so giving you some rep mate. – Vish Mar 30 '11 at 23:13
  • wow - I guess now I can imagine a number that would make you worried about performance - 500 million! :) thanks for the rep. Even w/ 500 mil, imo I would still try float unless/until there's a noticeable performance hit. – Dave Mar 30 '11 at 23:19
0

If you are not worried about decimals, tinyint will be definitely more efficient than float.

Rasika
  • 1,980
  • 13
  • 19