Hello, I have the following two tables:
userrelation: (around 60 GB InnoDB)
user1id int(4) unsigned
user2id int(4) unsigned
This table specifies which pairs of users have some kind of friendship. Such relationship is also assumed to be directed: user1id -> user2id
usergroup: (around 4 GB InnoDB)
userid int(4) unsigned
groupid int(4) unsigned
This table specifies which group each user belongs to.
Now I want to know for each pair of groups, how many directed user pairs exist. The very straighforward statement would be:
Code:
SELECT t1.groupid, t2.groupid FROM usergroup AS t1, usergroup AS t2, userrelation AS t3 WHERE t1.userid=t3.user1id AND t2.userid=t3.user2id ORDER BY t1.groupid, t2.groupid;
Anyone knows if this statement could be further optimized? Does anyone have some similar experiences and could give a rough estimation of the execution time? Any guru could explain in some details how MySQL would process such a statement?