A
A
apptimeru2016-12-23 00:48:11
MySQL
apptimeru, 2016-12-23 00:48:11

A lot of rows in the table per day, should the ID field be int or varchar?

Good afternoon friends, a question about optimization, is there a fundamental difference, what type to use for a table index? For example, about 1000-5000 rows are added to the table per day, int has a limit of 11 characters, varchar has much more, I understand that such a number will not be hammered soon, but still someday it will happen, is it possible to use varchar instead of int and how much it is will it affect performance?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Stalker_RED, 2016-12-23
@Stalker_RED

At five thousand a day, you will reach 10 million records in about six years. And 214748364 - in 120 years.

L
lega, 2016-12-23
@lega

int - not 11 characters, but 4 bytes, weighs less, works faster, but you won't notice the difference.

A
apptimeru, 2016-12-23
@apptimeru

And one more related question, if you will, the int type takes 4 bytes, and bigint 8, as I understand it, that the same number, for example: 999 will take in int (4+4+4 = 12 bytes) and in bigint (8+8+ 8 = 24 bytes)? Is my thought process correct or not?

T
ThunderCat, 2016-12-23
@ThunderCat

5000 *1000 = 5 million records in about 3 years, for a normally indexed table, this is not the burden of the word "at all".

A
Andrey Sitnikov, 2017-01-16
@Andrey001

If the data is only numeric, then store it always only in numeric form (for integer values ​​int, bigint, etc.). This will save space (in most situations), simplify and speed up indexing, speed up logical (<,>, range entry, etc.) and arithmetic (+,-,*,/,...) operations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question