Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Storing Hex values

Good morning,
I have a collection of HEX values, which are 36 characters long I need to store efficently in a database.

My problem is I dont know what to use. If I use VARCHAR(36) then it seems to waste a lot of space. If I store it as Blobs I cant index the values.

The table has 2 coloums, one being a bigint with autonumbering, and the other being the field with the Hex values in.

Any suggestions that I can use to optimise my table would be appriciated.

Thank you
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

If they are ALWAYS going to be 36-char, then BINARY(18) would be most efficient*.
Otherwise VARBINARY(18) for varying lengths up to hex(36).

*Storage-wise: Each BINARY byte will hold the equivalent data of 2 HEX values, but you need some processing to encode/decode between hex and binary.
Avatar of gremwell
gremwell

Note that to have an index BLOB and BINARY fields you need to specify a prefix length.

"Prefix lengths are given in characters for nonbinary string types and in bytes for binary string types. That is, index entries consist of the first length  characters of each column value for CHAR, VARCHAR, and TEXT columns, and the first length bytes of each column value for BINARY, VARBINARY, and BLOB columns"

See http://dev.mysql.com/doc/refman/5.0/en/create-index.html for more details.
Avatar of tonelm54

ASKER

Is there a way to insert Hex into a binary field, and return hex?

So-
Insert into myTable (`blobData`) VALUES (Hex2Bin(0x3451346342456));

And then:-
select 2hex(`blobData`) from `myTable`
ASKER CERTIFIED SOLUTION
Avatar of wolfgang_93
wolfgang_93
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial