I don't have any experience with large amount of data and I'm trying to figure out the best way to save the mouse clicks (navigation) of web visitors into a MySQL database. The DB will be used by multiple websites at the same time with a lot of visitors. Currently I have two options..
Alt 1:
-----------------------------
| visit_id | timestamp | ip |
-----------------------------
| 1 | 2016 | 00 |
-----------------------------
------------------------------------
| visit_id | timestamp | x | y |
------------------------------------
| 1 | 14:01:00 | 165 | 365 |
------------------------------------
| 1 | 14:01:01 | 166 | 367 |
------------------------------------
Alt 1 is best but it will be huge amount of rows and I don't know if MySQL will be able to handle all this.
Alt 2:
----------------------------------------------------------------------------
| visit_id | timestamp | ip | cordinates |
----------------------------------------------------------------------------
| 1 | 2016 | 00 | [14:01:00, 165, 365], [14:01:01, 166, 366] |
---------------------------------------------------------------------------
Then use PHP to split the column cordinates into an array.
Anybody have any tips on how to do save mouse clicks in the best way with MySQL?
Best Answer
Go for the normalized structure. In your case, that's Alt 1.
Have your tables defined more or less like these:
You'll end up having data like these:
With this structure, you will be able to perform queries like the following one, which might be very difficult with an unnormalized structure:
You will find that, except for very specific questions, this structure will let you query virtually anything you can think of, in an easier fashion than with the unnormalized design. And you can do so within the database, without having to move information in and out of it, which makes the process much faster.
When in doubt: normalize. You'll be able later to aggregate or denormalize if you need to. Some very specific scenarios work better with denormalized data. I don't think that's your case
Check the setup at dbfiddle here