Harry
2010-02-21 09:44:23 UTC
As people visit the page, the IP is either recorded as new or updated.
I can think of two ways to do it so far (the following queries are abbreviated):
1.) SELECT ip. If rows are round, run an UPDATE and increment num_visits where ip = ip. If no rows are round, run INSERT.
2.) just run INSERT from the start, assuming it's a new IP. If it fails because it already exists, then I know to do an UPDATE instead.
My database is expected to get large (30,000 entries or more), so I wonder if #1 or #2 is faster or more efficient.
I assume that an update or insert involving a unique field automatically performs some sort of select query to make sure the new insert is actually unique.