mysql - Storing view count into database -


I want to store a video view number in a database (MySQL)

I I want to store visitor IP address (and some other information)

So I have created a table with (VidoId, Ip, Date, UserAgent)

Now my problem is every time I want to show the view number to execute this query:

  Selection Count (*) from scenes where video id = xxx  

I know that M Can not store it in the column on your video that table and update it each insert. But this will create a fragmentation and break the data continuously and it will not be possible to make models even with the EER. I also know that I can cache it.

Thanks

Thank you.

I just want to know that there is no way to make it both efficiently and model worthy?

Thank you. -Text "itemprop =" text ">

A typical way to handle it is to create a separate table that connects the data of an organization. In your case, it will be a video_gridate table with the following columns: / P>

Video (Primary key), Number of views

Here are some of the big advantages I think is that another table:

1) reads very quickly, and only Adding a simple, if you want to video it You need to combine with A

2) Not every time locking / blocking on your video table on the views of a person, a video. In fact, both thoughts and videos are all updated (and probably may be) It can be asynchronous, it can tolerate a little latency. <3> The number of views is not a feature of the video - that unit does not show at all. This is a user activity It describes the methodology, but it is necessary for expert modeling and when you take care of this type in the relational database model, play well over time.

ps " View, "Call a more specific table like" Video View "


Comments