简体   繁体   中英

Best way to store and retrieve (user's actions) in php/MYSQL?

I'll be storing things like a users; search history, post viewing history, saved posts etc... you get the idea.

For instance, for the user's saved post, a user will have approx 500-2,000 throughout their lifespan, and with thousands of users you can see how this will add up very quickly.. So when a user want's to see their saved post history what's the best way to go about showing it?

Surley quering the table for all saved posts matching the userid (around 2,000) would be crazy (if i store it in the conventional way (user,postid))!

I had the idea of keeping all the users saved post ids in a large array, so there would be 1 row per user instead of 2,000 (stored in one cell). Is there any reason I shouldn't be doing this? What's the most efficient way you know off? oh and if you agree what datatype should this be, BLOB?

Side question - what solution do most people move onto when the database reaches a size of over 10-100Million rows? (hardware aside)

Add indexes as suggested. A possible solution to 100 million rows is a technique called database sharding where you effectively silo the same table across multiple database instances (servers) according to, say, ID range. A given user's posts will then live on one of many "shards"

http://en.wikipedia.org/wiki/Shard_(database_architecture )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM