I am having some issues with a query that uses a GROUP BY
method. The query seems to take quite a while to execute and sometimes chewing up all of the memory on the server. I checked the tmp directory and it has plenty of space, so I am unsure of where to look next.
Here is the query:
SELECT count(p.id) AS total, p.user_id, u.username
FROM posts p
INNER JOIN users u
ON (p.user_id = u.id)
WHERE p.timeposted >= :time
AND p.user_id <> '2246'
GROUP BY p.user_id
ORDER BY total DESC
LIMIT 5
Here is a look at my posts
table:
CREATE TABLE `posts` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`post_id` int(11) NOT NULL,
`timeposted` int(11) NOT NULL COMMENT '11',
`brand` varchar(150) NOT NULL,
`postcontent` text NOT NULL,
`category` int(11) NOT NULL,
`album` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Indexes for table `posts`
--
ALTER TABLE `posts`
ADD PRIMARY KEY (`id`),
ADD KEY `user_id` (`user_id`),
ADD KEY `category` (`category`),
ADD KEY `post_id` (`post_id`),
ADD KEY `album` (`album`)
Any thoughts on what may be causing this query to get choked up?