Sorting over multiple JOINS
Posted by: Günther Schmidt
Date: January 20, 2015 07:04AM

Hi people,
I have a performanceproblem with sorting over more than one table.
This are my example tables:

main
ID | thingID | info1 | info2

Index: PRIMARY (ID), INDEX (thingID , info1)
All columns are unsigned INT
thingID is foreign key to table

thing:
ID | thing1 | thing2 | thing3

Index: PRIMARY (ID)
All columns are unsigned INT

Now I do a JOIN:

SELECT main.info2, thing.thing1, thing.thing2, thing.thing3
FROM main
INNER JOIN thing ON main.thingID=thing.ID
WHERE main.info1 = 12

This works like a charm on our MySLQ 5.5 InnoDB tables. Resultset is about 500.000 rows with a duration of <1s.
But if I add some sorting...

ORDER BY thing.thing1, main.info2, thing.thing2

then a filesort is done because there is no index usable. It takes around 250s to get the results.
How can I change my indexes or the query to prevent the filesort? I did quite some research on that but all examples I found do not mix columns from more than one table for sorting.
What do you think?

Regards
Günther

Options: ReplyQuote


Subject
Written By
Posted
Sorting over multiple JOINS
January 20, 2015 07:04AM
January 21, 2015 02:14PM
January 24, 2015 12:36AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.