MySQL joins on IP addresses

If you are doing this:

  1. using MySQL
  2. storing IPv4 addresses as varchar
  3. attempting to join two tables on IPv4 varchar columns

You need to stop and go learn about INET_ATON. It converts those IP addresses to BIGINTS and speeds up your queries like you wouldn’t believe. I had an existing project that did not require any joins against my IPs, so I never bothered to do the conversion. I’m currently neck-deep in some new code that requires me to join against those same IPs, and INET_ATON took my queries from 120 seconds to under half a second to complete.

Those are results you can believe in.