Website Visits Database Projects

for counting website visits, which table schema do you prefer? enter image description here

For scheme a: make sure the IP logout is complete, we are incrementing the count by one step and not adding a new IP address.

For scheme b: we add a new IP address each time and we use GroupBY in our application for reporting.

+3


source to share


1 answer


1st is perfect.

Why?



  • See, for one visitor, you only store one record. There may be multiple entries for a visitor, for example you have, for example, one customer has multiple addresses. In this case, the address is multiple. But there will be only one client. The same case applies in your example.

  • You don't need to grow the database size by adding the same row multiple times for the same user / visitor.

  • For SELECT, you will need to extract multiple records, although most of the records are the same.

    So if you follow path 2, you will enter 1000 records for one visitor with the same ip. If you follow path 1, you have 1 record which is updated with countVisited. Now say fetch 1000 rows faster or fetch 1?

  • If you want to UPDATE a parameter, you need to find the visitor's record in 1000 records and then change it. You can tell yourself which path is best.

+2


source







All Articles