Looking for a little support, if you don't mind. Our forum has been cripplingly slow for the last few days and it turns out that this query is tying up the user table in our database for at least 20 seconds each time:
PHP Code:
SELECT user.username, user.userid, user.vbookie_cash AS vcash, userban.liftdate, if( customavatar.dateline IS NULL , NULL , 1 ) AS hasAvatar, (
SELECT bet_id
FROM vbookie_bets_placed
WHERE userid = user.userid
AND bet_private = 'N'
AND bet_settled = 'Y'
AND bet_amount_won >0
ORDER BY bet_placed DESC
LIMIT 1
) AS lastwinid
FROM user
LEFT JOIN userban ON user.userid = userban.userid
LEFT JOIN customavatar ON customavatar.userid = user.userid
WHERE user.vbookie_cash >450
AND userban.liftdate IS NULL /* REMOVE THIS FOR REAL DATA */
AND (
SELECT bet_amount_won
FROM vbookie_bets_placed
WHERE userid = user.userid
AND bet_private = 'N'
AND bet_settled = 'Y'
ORDER BY bet_placed DESC
LIMIT 1
) >0/* ^^^^ REMOVE THIS FOR REAL DATA */
ORDER BY user.vbookie_cash DESC
LIMIT 7
Trouble is--or one of the troubles--is that I can't find where this is being executed, so I can't remove/rewrite it. Any idea?