Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing very large integers in MySQL

I need to store a very large number (tens of millions) of 512-bit SHA-2 hashes in a MySQL table. To save space, I'd like to store them in binary form, rather than a string a hex digits. I'm using an ORM (DBix::Class) so the specific details of the storage will be abstracted from the code, which can inflate them to any object or structure that I choose.

MySQL's BIGINT type is 64 bits. So I could theoretically split the hash up amongst eight BIGINT columns. That seems pretty ridiculous though. My other thought was just using a single BLOB column, but I have heard that they can be slow to access due to MySQL's treating them as variable-length fields.

If anyone could offer some widsom that will save me a couple hours of benchmarking various methods, I'd appreciate it.

Note: Automatic -1 to anyone who says "just use postgres!" :)

like image 915
friedo Avatar asked Jul 31 '09 08:07

friedo


People also ask

How do you store large numbers in SQL?

You can add it as a field to an Access table. You can also link to or import from databases with a corresponding data type, such as the SQL Server bigint data type. To add the Large Number data type, you need Access 2016 (16.0. 7812 or later).

Which is the largest integer range in MySQL?

Standard integer value. Signed values range from -2147483648 to 2147483647. Unsigned values range from 0 to 4294967295. This is a synonym for the INT datatype.

How big can an int be MySQL?

INT − A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits.

Can MySQL store large data?

In modern MySQL using InnoDB, you can handle databases that are as big as you'd likely ever want. Our individual hosts have up to about six terabytes each, but in previous companies, we had hosts with up to 12 terabytes and 20 billion rows in individual instances.


2 Answers

Have you considered 'binary(64)' ? See MySQL binary type.

like image 87
jeje Avatar answered Oct 07 '22 08:10

jeje


Use the type BINARY(64) ?

like image 31
nos Avatar answered Oct 07 '22 09:10

nos