Vish
Vish

Reputation: 4492

float vs smallint vs decimal in mysql

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.

Upvotes: 0

Views: 1849

Answers (2)

Dave
Dave

Reputation: 29121

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.

Upvotes: 1

Rasika
Rasika

Reputation: 1998

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

Upvotes: 0

Related Questions