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.
|
I would think that the first one would be faster since inet_aton returns a integer. But something i just found out is you can add "explain" to the beginning of your query and it returns some helpful info.
pawn Код:
explain SELECT COUNT(ip) FROM some_table WHERE ip BETWEEN INET_ATON('45.166.0.0') AND INET_ATON('45.166.255.255');
//and
explain SELECT COUNT(ip) FROM some_table WHERE INET_NTOA(ip) LIKE '45.166.%';
It will show how many rows were checked and it seems that the first one checked less rows so it should(might) be faster possibly. I could be wrong, its something i just found out lastnight.