Quote:
Originally Posted by Konstantinos
I've been reading a lot of articles and documentation for optimization and I've discovered INET_ATON and INET_NTOA few days ago. Saving IPs as an integer (UNSIGNED) saves a lot of space but I was wondering which one is better
pawn Код:
SELECT COUNT(ip) FROM some_table WHERE ip BETWEEN INET_ATON('45.166.0.0') AND INET_ATON('45.166.255.255');
pawn Код:
SELECT COUNT(ip) FROM some_table WHERE INET_NTOA(ip) LIKE '45.166.%';
The second is what I came up with as I was using LIKE when I had them stored as VARCHAR as well, the first is from an article.
|
Personally, I use the first one. But it must be noted that I select it from a humongous table which contains all CIDR ranges around the world, so the query usually looks something like:
PHP код:
SELECT country FROM iptable WHERE INET_ATON('x.x.x.x') BETWEEN range_start and range_end
There is no other way to do it because CIDR ranges could go from something like 25.47.0.0 to 25.48.255.255.