indexing - What should "length" be for this MySQL tinyblob key? -



indexing - What should "length" be for this MySQL tinyblob key? -

for table i'm creating include ip ranges, need store 2 128-bit (16-byte) int values in mysql record. since mysql supports 8-byte ints, i've found need utilize binary column (tinyblob), , good.

create table `ip_ranges` ( `ip_start` tinyblob not null, `ip_end` tinyblob not null, ... unique key `index_ip_ranges_on_ip_start_and_ip_end` (`ip_start`(16),`ip_end`(16)) );

i'm running problem unique index on these 2 columns. far understand, ipv6's integer representation 128 bits (16 bytes). such, set unique index ip_start , ip_end columns in unique key 16 bytes. unfortunately, end getting duplicate key errors when populating real ipv6 data:

> insert `ip_ranges` (`ip_end`, `ip_start`, ...) values ("42540649945883696925221210589465935872", "42540649945883696943667954663175487487", ...); duplicate entry '42540649945883696925221210589465935872-4254064994588369694366795' key 'index_ip_ranges_on_ip_start_and_ip_end'

the key value displayed on "duplicate entry" line above makes part of ip_end value beingness lopped off. it's missing lastly 13 digits: "4663175487487". makes me think i'm wrong "16" i'm providing unique key length representing bytes.

what's going on here, , how can prepare it?

no. no tinyblob. utilize varbinary. then, each digit store 1 byte, key need 39b long.

alternatively utilize decimal(39)

or wait until mysql 5.6 native ipv6 back upwards ;p

mysql indexing ipv6 unique-constraint

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -