# Optimizing Query

**URL:** <https://forums.percona.com/t/optimizing-query/991>\
**Category:** Other MySQL® Questions\
**Created:** [November 7, 2008, 7:48am UTC](https://forums.percona.com/t/optimizing-query/991 "2008-11-07T07:48:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![USAF\_Pride](https://avatars.discourse-cdn.com/v4/letter/u/a8b319/32.png) [@USAF\_Pride](https://forums.percona.com/u/USAF_Pride)\
**Post date:** [November 7, 2008, 7:48am UTC](https://forums.percona.com/t/optimizing-query/991/1 "2008-11-07T07:48:22Z")

</div>

I have a database with 9 tables of unique data and 1 table that links it all together. I know the speed issue is all the JOINS and I am way outside of my league in attempting to fix it. The one table that links everything together only stores the primary ID from the other 9 tables. Here is the sql

SELECT DISTINCT guid, name as unique\_name, ip as unique\_IP, Violation, vdate, vtimeFROM tbl\_player\_kick LEFT JOIN tbl\_guid ON tbl\_player\_kick.guid\_id = tbl\_guid.guid\_id LEFT JOIN tbl\_kick ON tbl\_player\_kick.kick\_id = tbl\_kick.kick\_id LEFT JOIN tbl\_name ON tbl\_player\_kick.name\_id = tbl\_name.name\_id LEFT JOIN tbl\_ip ON tbl\_player\_kick.ip\_id = tbl\_ip.ip\_id LEFT JOIN tbl\_violation ON tbl\_player\_kick.viol\_type = tbl\_violation.violation\_idLEFT JOIN tbl\_date ON tbl\_player\_kick.date\_id = tbl\_date.date\_idLEFT JOIN tbl\_time ON tbl\_player\_kick.time\_id = tbl\_time.time\_idWHERE tbl\_player\_kick.banned = 1

and the explain that goes with it

id select\_type table type possible\_keys key key\_len ref rows Extra  
1 SIMPLE tbl\_player\_kick ref banned banned 2 const 262650 Using where; Using temporary  
1 SIMPLE tbl\_guid eq\_ref PRIMARY PRIMARY 4 aaser2\_bansdbase.tbl\_player\_kick.guid\_id 1  
1 SIMPLE tbl\_kick eq\_ref PRIMARY PRIMARY 8 aaser2\_bansdbase.tbl\_player\_kick.kick\_id 1 Using index  
1 SIMPLE tbl\_name eq\_ref PRIMARY PRIMARY 4 aaser2\_bansdbase.tbl\_player\_kick.name\_id 1  
1 SIMPLE tbl\_ip eq\_ref PRIMARY PRIMARY 4 aaser2\_bansdbase.tbl\_player\_kick.ip\_id 1  
1 SIMPLE tbl\_violation eq\_ref PRIMARY PRIMARY 8 aaser2\_bansdbase.tbl\_player\_kick.viol\_type 1  
1 SIMPLE tbl\_date eq\_ref PRIMARY PRIMARY 4 aaser2\_bansdbase.tbl\_player\_kick.date\_id 1  
1 SIMPLE tbl\_time eq\_ref PRIMARY PRIMARY 8 aaser2\_bansdbase.tbl\_player\_kick.time\_id 1

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![xaprb](https://avatars.discourse-cdn.com/v4/letter/x/49beb7/32.png) [@xaprb](https://forums.percona.com/u/xaprb)\
**Post date:** [December 25, 2009, 10:30am UTC](https://forums.percona.com/t/optimizing-query/991/2 "2009-12-25T10:30:26Z")

</div>

I don’t see evidence that the joins are the problem. You have all eq\_ref which should be fine. I would guess that the problem is “using temporary” which is caused by DISTINCT.
