Yohanes AI
Yohanes AI

Reputation: 3621

Storing data VS querying?

I have an application that want to provide any information about how many people share apps via Social Network. My question, which method is better(in term of speed, efficiency, security and maintainability)?

Method 1 : Provide one field(eg. apps_shared) in one table that contain the number of people who have shared this application, and every time user shared apps, i just updating existing value in field.

Method 2 : Saving one record(contain time when sharing happened, and others data) when people share apps and count it when requiring the number of people who have shared application.

Thanks for your help, any advice i appreciated it. Sorry for my bad English.

Upvotes: 0

Views: 49

Answers (1)

Andrew
Andrew

Reputation: 20081

Method 1 of course is faster, because you just update one value and can query one value, instead of getting the count of rows to find the number of shares.

But for scalability and usability, you might prefer the second method so that you can store extra data with each share and use it for other purposes in your application.

More likely you should have a table containing data on each share and a running count in another table as well, combining the best of both options.

Upvotes: 1

Related Questions