Very slow ORDER BY
Posted on 2006-06-12
When I tried to ORDER BY anything in one of my tables, it takes a lot of time to do it even for not too many records (about a thousand).
I have two tables, say Contracts and Names table, the query is:
contractor_names.Name AS contractor_name,
client_names.Name AS client_name
Contracts as contracts
Names as contractor_names
on contracts.Contractor_Name_Key = contractor_names.Name_Key
Names as client_names
on contracts.Client_Name_Key = client_names.Name_Key
order by contracts.key
Everything works fine UNLESS I try to order this query by anything... In which case it does it, but extremely slow, like sorting 100 rows for a minute. I presume it's because of my double join, so can it be fixed somehow?
The query and all names have been changed as originally it's a bit bigger, so pay no attention to that.