# Simple query still it needs Using temporary; Using filesort ??

**URL:** <https://forums.percona.com/t/simple-query-still-it-needs-using-temporary-using-filesort/696>\
**Category:** Other MySQL® Questions\
**Created:** [March 31, 2008, 4:07pm UTC](https://forums.percona.com/t/simple-query-still-it-needs-using-temporary-using-filesort/696 "2008-03-31T16:07:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stacionari](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/stacionari/32/773_2.png) [@stacionari](https://forums.percona.com/u/stacionari)\
**Post date:** [March 31, 2008, 4:07pm UTC](https://forums.percona.com/t/simple-query-still-it-needs-using-temporary-using-filesort/696/1 "2008-03-31T16:07:43Z")

</div>

HI,

My query is like this:

SELECT tag.\* FROM tag LEFT JOIN book\_item ON tag.Tag\_ID = book\_item.BookItem\_ID WHERE tag.Tag = “tags” GROUP BY tag.tag\_ID

Indexes:

Table ‘tag’:Keyname Type Cardinality FieldPRIMARY PRIMARY 203 Tag\_IDTag INDEX 203 TagItem\_ID INDEX 29 Item\_IDTable ‘book\_item’:Keyname Type Cardinality FieldPRIMARY PRIMARY 40 BookItem\_ID

Explain:

id select\_type table type possible\_keys key key\_len ref rows Extra1 SIMPLE tag ref Tag Tag 92 const 6 Using where; Using temporary; Using filesort1 SIMPLE book\_item eq\_ref PRIMARY PRIMARY 4 makeliterature.tag.Tag\_ID 1 Using index

My question is: how can I optimize this query to get rid of Using temporary; Using filesort ?

Even having in mind small size of dataset, what for on earth MySql and InnoDB need a temporary table to process this query ?

Thank you.

---

<div class="post-metadata">

**Author:** ![Hubert\_Roksor](https://avatars.discourse-cdn.com/v4/letter/h/8baadc/32.png) [@Hubert\_Roksor](https://forums.percona.com/u/Hubert_Roksor)\
**Post date:** [April 2, 2008, 6:57pm UTC](https://forums.percona.com/t/simple-query-still-it-needs-using-temporary-using-filesort/696/2 "2008-04-02T18:57:09Z")

</div>

| [B]stacionari wrote on Mon, 31 March 2008 23:37[/B] |
| My query is like this |

The query you posted has a LEFT JOIN on a table that isn't referenced anywhere else, so I guess your actual query is different from the one you published. Any optimization would only apply to the query you published and would therefore be useless to you.

You should post an actual query if you want to receive useful help.
