I've tried to make the sequence below self explanatory. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 108 Server version: 5.1.41-3ubuntu12.9 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> describe ipblock; +-------------+---------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------+------+-----+---------------------+----------------+ | address | decimal(40,0) | NO | MUL | NULL | | | description | varchar(128) | YES | | NULL | | | first_seen | timestamp | NO | MUL | 1970-01-02 00:00:01 | | | id | bigint(20) | NO | PRI | NULL | auto_increment | | info | blob | YES | | NULL | | | interface | bigint(20) | YES | MUL | NULL | | | last_seen | timestamp | NO | MUL | 1970-01-02 00:00:01 | | | owner | bigint(20) | YES | MUL | NULL | | | parent | bigint(20) | YES | MUL | NULL | | | prefix | int(11) | NO | | NULL | | | status | bigint(20) | YES | MUL | NULL | | | used_by | bigint(20) | YES | MUL | NULL | | | version | int(11) | NO | MUL | NULL | | | vlan | bigint(20) | YES | MUL | NULL | | +-------------+---------------+------+-----+---------------------+----------------+ 14 rows in set (0.00 sec) mysql> show indexes from ipblock; +---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ | ipblock | 0 | PRIMARY | 1 | id | A | 52 | NULL | NULL | | BTREE | | | ipblock | 0 | ipblock1 | 1 | address | A | 52 | NULL | NULL | | BTREE | | | ipblock | 0 | ipblock1 | 2 | prefix | A | 52 | NULL | NULL | | BTREE | | | ipblock | 1 | Ipblock2 | 1 | parent | A | 52 | NULL | NULL | YES | BTREE | | | ipblock | 1 | Ipblock3 | 1 | status | A | 6 | NULL | NULL | YES | BTREE | | | ipblock | 1 | Ipblock4 | 1 | first_seen | A | 52 | NULL | NULL | | BTREE | | | ipblock | 1 | Ipblock5 | 1 | last_seen | A | 26 | NULL | NULL | | BTREE | | | ipblock | 1 | Ipblock6 | 1 | interface | A | 52 | NULL | NULL | YES | BTREE | | | ipblock | 1 | Ipblock7 | 1 | vlan | A | 2 | NULL | NULL | YES | BTREE | | | ipblock | 1 | Ipblock8 | 1 | version | A | 4 | NULL | NULL | | BTREE | | | ipblock | 1 | owner | 1 | owner | A | 8 | NULL | NULL | YES | BTREE | | | ipblock | 1 | used_by | 1 | used_by | A | 4 | NULL | NULL | YES | BTREE | | +---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 12 rows in set (0.00 sec) mysql> select id,address,prefix from ipblock where address='42540577535367678161542323472695296000'; +----+----------------------------------------+--------+ | id | address | prefix | +----+----------------------------------------+--------+ | 54 | 42540577535367678161542323472695296000 | 64 | +----+----------------------------------------+--------+ 1 row in set (0.00 sec) mysql> select id,address,prefix from ipblock where address='42540577535367678161542323472695296000' and prefix=64; Empty set (0.00 sec) mysql> explain select id,address,prefix from ipblock where address='42540577535367678161542323472695296000'; +----+-------------+---------+------+---------------+----------+---------+-------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+------+---------------+----------+---------+-------+------+-------------+ | 1 | SIMPLE | ipblock | ref | ipblock1 | ipblock1 | 18 | const | 1 | Using index | +----+-------------+---------+------+---------------+----------+---------+-------+------+-------------+ 1 row in set (0.00 sec) mysql> explain select id,address,prefix from ipblock where address='42540577535367678161542323472695296000' and prefix=64; +----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ | 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables | +----+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+ 1 row in set (0.00 sec) mysql> ALTER TABLE ipblock DROP INDEX ipblock1; Query OK, 52 rows affected (0.05 sec) Records: 52 Duplicates: 0 Warnings: 0 mysql> select id,address,prefix from ipblock where address='42540577535367678161542323472695296000'; +----+----------------------------------------+--------+ | id | address | prefix | +----+----------------------------------------+--------+ | 37 | 42540577535367673549856305045307392000 | 64 | | 43 | 42540577535367672959560494686601740288 | 64 | | 60 | 42540577535367672904220262465473085440 | 48 | | 67 | 42540577535367672941113750612892188672 | 64 | | 78 | 42540577535367673549856305045307392001 | 128 | | 80 | 42540577535367672959560494686601740292 | 128 | +----+----------------------------------------+--------+ 6 rows in set (0.00 sec) mysql> ALTER TABLE ipblock ADD UNIQUE INDEX ipblock1 (address, prefix); Query OK, 52 rows affected (0.06 sec) Records: 52 Duplicates: 0 Warnings: 0 mysql> select id,address,prefix from ipblock where address=42540577535367678161542323472695296000 and prefix=64; +----+----------------------------------------+--------+ | id | address | prefix | +----+----------------------------------------+--------+ | 54 | 42540577535367678161542323472695296000 | 64 | +----+----------------------------------------+--------+ 1 row in set (0.00 sec) mysql> select id,address,prefix from ipblock where address=42540577535367678161542323472695296000 and prefix=64; +----+----------------------------------------+--------+ | id | address | prefix | +----+----------------------------------------+--------+ | 54 | 42540577535367678161542323472695296000 | 64 | +----+----------------------------------------+--------+ 1 row in set (0.00 sec) mysql> select address from ipblock where address=CONVERT('42540577535367678161542323472695296000', DECIMAL(40,0)) and prefix=64; +----------------------------------------+ | address | +----------------------------------------+ | 42540577535367678161542323472695296000 | +----------------------------------------+ 1 row in set (0.00 sec)