What is the best for index field, and space token on hard disk/RAM? Biginteger or Varchar(15) ? I can have for example such index number:
from 10000001 to 45281229703 and higher...
But what is better to choose? Also on non-indexing field what field type is better?
The number is used to display width. BIGINT takes 8 bytes i.e. 64 bits. The signed range is -9223372036854775808 to 9223372036854775807 and unsigned range takes positive value. The range of unsigned is 0 to 18446744073709551615.
Storage Size (INT VS BIGINT) If we talk about the storage size of INT and BI GINT, the storage size of INT is 4 bytes while the storage size of BIGINT is double of that i.e.: 8 bytes.
Bigint requires 8 Byte to store a number, while varchar(16) will require at minimum the double amount of Bytes. Depending on the character set used, even 4 times more. So type of bigint will save space on your disk but also reduce network traffic. A varchar(16) will not be able to represent all bigint numbers.
BIGINT is the MySQL data type that can be assigned to the columns of the table in which we want to store the whole numbers and we are aware that the range of the numbers that we will store in that column will be huge and not exceed the range of the BIGINT data type.
BIGINT
is always 8 bytes, VARCHAR(15)
is 1..16 bytes depending on value length, so BIGINT
needs less memory on large numbers, but more memory on small numbers (shorter than 7 digits). Also, BIGINT is faster.
We have run test in simulation environment.
Here is script to perform above steps:
Create table r5(mob bigint,m_mob varchar(30));
Create index i_d on r5(mob,m_mob);
do $$
begin
for i in 1..3000000 loop
insert into r5(mob,m_mob) values(i,i||’abc’);
end loop;
end; $$
select * from r5
where mob=2900000;
select * from r5
where m_mob=’2900000abc’;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With