# Slow query - Using where; Using temporary; Using filesort

**URL:** <https://forums.percona.com/t/slow-query-using-where-using-temporary-using-filesort/672>\
**Category:** Other MySQL® Questions\
**Created:** [March 13, 2008, 3:00pm UTC](https://forums.percona.com/t/slow-query-using-where-using-temporary-using-filesort/672 "2008-03-13T15:00:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PowerBlade](https://avatars.discourse-cdn.com/v4/letter/p/d9b06d/32.png) [@PowerBlade](https://forums.percona.com/u/PowerBlade)\
**Post date:** [March 13, 2008, 3:00pm UTC](https://forums.percona.com/t/slow-query-using-where-using-temporary-using-filesort/672/1 "2008-03-13T15:00:25Z")

</div>

Hey!

I have some queries taking ~3-5 seconds to execute. With lots of queries being run all the time, it can take down the database.

The query in question is

SELECT partid, rtp.tableid, chainCount, type, charset, minLetters, maxLetters, `index`, chainLength, rtp.tableid, salt, CONVERT\_TZ(DATE\_ADD(NOW(), INTERVAL +2 DAY), &#64;&#64;global.time\_zone, ‘+0:00’) AS expiration  
FROM rainbowcrack\_parts rtp  
INNER JOIN rainbowcrack\_tables rtt ON rtp.tableid = rtt.tableid AND rtp.status = 0  
INNER JOIN rainbowcrack\_tablesets rts ON rtt.tablesetid = rts.tablesetid  
WHERE type != ‘lm’  
ORDER BY rts.priority DESC, rtp.partid ASC LIMIT 1;

The table structure is the following:  
CREATE TABLE `rainbowcrack_parts` (  
`partid` int(11) NOT NULL auto\_increment,  
`tableid` int(11) NOT NULL,  
`userid` int(11) default NULL,  
`chainStart` int(11) NOT NULL,  
`chainCount` int(11) NOT NULL,  
`ip` varchar(255) default NULL,  
`status` int(11) default NULL,  
`starttime` datetime default ‘0000-00-00 00:00:00’,  
`finishedtime` datetime default ‘0000-00-00 00:00:00’,  
`clientid` int(10) unsigned NOT NULL default ‘0’,  
`creditvalue` float unsigned NOT NULL default ‘0’,  
PRIMARY KEY (`partid`),  
KEY `tableid` (`tableid`),  
KEY `userid` (`userid`),  
KEY `creditvalue` (`creditvalue`),  
KEY `finishedtime` (`finishedtime`),  
KEY `status` (`status`)  
)

and result of EXPLAIN is:

1 SIMPLE rtp ref tableid,status status 5 const 41886 Using where; Using temporary; Using filesort  
1 SIMPLE rtt eq\_ref PRIMARY,tablesetid,type PRIMARY 4 rainbowtables-distrrtgen.rtp.tableid 1 Using where  
1 SIMPLE rts eq\_ref PRIMARY PRIMARY 4 rainbowtables-distrrtgen.rtt.tablesetid 1

The table contains 668.000 rows

I have added indexes, but still gets “using temporary; Using filesort”… Any ideas?
