Home » Performance » MySQL » Degree of Separation Calculation
Degree of Separation Calculation [message #480] Tue, 19 December 2006 11:11 Go to previous message
Skeptical
Messages: 4
Registered: December 2006
Junior Member
I'm looking to do permission calculation based on degrees of separation. This would include things like granting permissions based on if the viewing user is your friend, your friend's friend, or your friend's friend's friend.

A friend would be 1 degree away.
A friend's friend would be 2 degrees away.
A friend's friend's friend would be 3 degrees away.

In order to calculate the degree of separation user B is away from user A, the most basic logic would mean the traversal of all of A's friends, and their friends, and so on, until the shortest link is found that connects A and B.

However, this is very database consuming, as each degree of separation can result in an exponential increase in the amount of queries.

A shorter way would be to store on a cache table all second-degree level friendships for all users. Then another table for all third-degree friendships. However, this will obviously lead to a HUGE database, and I'm not sure if this is the best way to go about it. Every time a friendship is added/editted/removed, it could mean the updating of thousands+ of records in the cache table.

Is there a better way to go about doing this?

[Updated on: Tue, 19 December 2006 11:14]

Read Message
Read Message
Read Message
Read Message
Previous Topic:Self-made index: faster or slower?
Next Topic:mysql going to sleep/sbwait while executing slow query
Goto Forum:

  


Current Time: Thu Jul 9 20:14:27 EDT 2009

Total time taken to generate the page: 0.02275 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.