Optimize query
How can i optimize this query ?
# Query_time: 2 Lock_time: 0 Rows_sent: 1 Rows_examined: 613322
SELECT
SUM(IF(lastvisit >= 1263996911, 1, 0)) AS active,
COUNT(*) AS users,
MAX(userid) AS maxid
FROM user;
--------------- Added [DATE]1266652432[/DATE] at [TIME]1266652432[/TIME] ---------------
Also this query.
Its killing my server
# Query_time: 10 Lock_time: 0 Rows_sent: 30 Rows_examined: 1839053
SELECT user.*,usertextfield.*,userfield.*, user.userid, options,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
,avatar.avatarpath,NOT ISNULL(customavatar.userid) AS hascustomavatar,customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight
, IF((options & 512 AND user.userid <> 0), 0, lastactivity) AS lastvisittime
FROM user AS user
LEFT JOIN usertextfield AS usertextfield ON(usertextfield.userid=user.userid)
LEFT JOIN userfield AS userfield ON(userfield.userid=user.userid)
LEFT JOIN avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN customavatar AS customavatar ON(customavatar.userid = user.userid)
WHERE 1=1
AND (user.usergroupid IN (-1,6,30,34,5,7,29,2,32,3))
ORDER BY user.username asc
LIMIT 406590, 30;
|