I'm a newbie when it comes to mysql things and queries in general, just wanted to point that out.
I'll keep this as short as I can.
I have a table where I track the IPs of users that enter the front-page of a site. Any other page is not logged.
I have a unique ID for that table set as the IP of the client.
Every time a new user hits the front-page I have to look-up his IP in the table to make sure his IP is not there, if it's not it gets inserted, if it is, nothing happens.
So far this is working great, but then again, there aren't many IPs in there.
Since I'm using Laravel's Eloquent, I can't give you the precise query, in PHP it looks like this:
Tracker::where('ip', $client_ip)->first();
Although I'm not sure, I suspect that the raw query looks something like this:
SELECT ip FROM table_name WHERE column_client_ip = '127.0.0.1' LIMIT 1
The IP itself is saved as a varchar
. I know about INET_ATON
but I'm not exactly sure if I can use it with ipv6
.
My questions are as follows:
- I know that searching and comparing varchar type fields isn't the fastest thing in the world, do I have any other options to save IP? Keep in mind that they can also tunnel their IP which, in case I'm not wrong, it adds to the total length of the string I get as the IP - I could be way off here, my sysadmin skills are basically non-existent.
- Currently the search is really fast, mostly because there aren't a lot of records and I also keep an index on the
ip
column. Realistically speaking, at what point should I start being concerned that the search/compare will slow down significantly?
If you guys have any other suggestions or want to warn be about possible issues I may have in the future with the current setup, I'm all ears.
unique
index. You could also don't bother checking first and useINSERT ... ON DUPLICATE KEY UPDATE ...
syntax instead. But that may not be appropriate for your case (if you need to check the IPs often.)ip
column is set tounique
.ip
orcolumn_client_ip
?ip
I just named itcolumn_client_ip
to make sure people knew what I was talking about in the post.