I have a query that pulls data from a table based on the last date/time a user viewed a page, in order to see which of your 'friends' are online. I currently have about 3000 members, the user_friends table that is being queried has 46,000 records total. This is what my hosting company has told me, which makes no sense to me how they came up with such a HUGE number of rows being examined... any ideas?
From Host : 'We have disabled your database to return the server to normal usage. To re-enable your database, you will need to correct the following query:
-SELECT user_id2 AS online_id, user_last_call_date2 AS user_last_call_date, friend_top1 AS friend_top
FROM user_friends
WHERE user_id1 = 2286
AND user_last_call_date2 >= '{ts \'2010-12-13 07:22:37\'}'
UNION
SELECT user_id1 AS online_id, user_last_call_date1 AS user_last_call_date, friend_top2 AS friend_top
FROM user_friends
WHERE user_id2 = 2286
AND user_last_call_date1 >= '{ts \'2010-12-13 07:22:37\'}'
ORDER BY friend_top DESC, user_last_call_date DESC
EXPLAIN:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY user_friends ALL 46240 Using where
2 UNION user_friends ALL 46240 Using where
UNION RESULT ALL Using filesort
This query examines 2138137600 rows, which is unacceptable in shared hosting.'
From Host : 'We have disabled your database to return the server to normal usage. To re-enable your database, you will need to correct the following query:
-SELECT user_id2 AS online_id, user_last_call_date2 AS user_last_call_date, friend_top1 AS friend_top
FROM user_friends
WHERE user_id1 = 2286
AND user_last_call_date2 >= '{ts \'2010-12-13 07:22:37\'}'
UNION
SELECT user_id1 AS online_id, user_last_call_date1 AS user_last_call_date, friend_top2 AS friend_top
FROM user_friends
WHERE user_id2 = 2286
AND user_last_call_date1 >= '{ts \'2010-12-13 07:22:37\'}'
ORDER BY friend_top DESC, user_last_call_date DESC
EXPLAIN:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY user_friends ALL 46240 Using where
2 UNION user_friends ALL 46240 Using where
UNION RESULT ALL Using filesort
This query examines 2138137600 rows, which is unacceptable in shared hosting.'