Subject | Slow query when using ORDER BY |
---|---|
Author | markd_mms |
Post date | 2006-02-06T04:21:32Z |
I'm having trouble with the following query. When I run the following
it returns 14016 record in just over 4 seconds:
SELECT ITEM.TITLE AS "Title", ITEM.TITLE2 AS "Title2",
ITEMINFORMAT.CATALOGUENO AS "Catalogue Number",
ITEMINFORMAT.BARCODE AS "Barcode", FORMATS.DESCRIPTION AS "Format",
DISTRIBUTORS.DESCRIPTION AS "Distributor", GENRES.DESCRIPTION AS "Genre",
ITEM.DISTRIBUTOR_RELEASE_DATE AS "Release Date", ITEM.ITEMID
FROM ITEM
LEFT JOIN ITEMINFORMAT ON ITEMINFORMAT.ITEMID = ITEM.ITEMID
LEFT JOIN ACTORITEM ON ITEM.ITEMID = ACTORITEM.ITEMID
LEFT JOIN ACTORS ON ACTORITEM.ACTORID = ACTORS.ACTORID
LEFT JOIN FORMATS ON ITEMINFORMAT.FORMATID = FORMATS.FORMATID
LEFT JOIN DISTRIBUTORS ON ITEM.DISTRIBUTORID = DISTRIBUTORS.DISTRIBUTORID
LEFT JOIN GENRES ON ITEM.GENREID = GENRES.GENREID
but as soon as I add
ORDER BY ITEM.TITLE ASC
the query takes over 4 minutes to run. There is an ascending index on
ITEM.TITLE that I tried removing but it doesn't make a difference.
Does anyone know why it could be making such a big difference?
TIA
Mark
it returns 14016 record in just over 4 seconds:
SELECT ITEM.TITLE AS "Title", ITEM.TITLE2 AS "Title2",
ITEMINFORMAT.CATALOGUENO AS "Catalogue Number",
ITEMINFORMAT.BARCODE AS "Barcode", FORMATS.DESCRIPTION AS "Format",
DISTRIBUTORS.DESCRIPTION AS "Distributor", GENRES.DESCRIPTION AS "Genre",
ITEM.DISTRIBUTOR_RELEASE_DATE AS "Release Date", ITEM.ITEMID
FROM ITEM
LEFT JOIN ITEMINFORMAT ON ITEMINFORMAT.ITEMID = ITEM.ITEMID
LEFT JOIN ACTORITEM ON ITEM.ITEMID = ACTORITEM.ITEMID
LEFT JOIN ACTORS ON ACTORITEM.ACTORID = ACTORS.ACTORID
LEFT JOIN FORMATS ON ITEMINFORMAT.FORMATID = FORMATS.FORMATID
LEFT JOIN DISTRIBUTORS ON ITEM.DISTRIBUTORID = DISTRIBUTORS.DISTRIBUTORID
LEFT JOIN GENRES ON ITEM.GENREID = GENRES.GENREID
but as soon as I add
ORDER BY ITEM.TITLE ASC
the query takes over 4 minutes to run. There is an ascending index on
ITEM.TITLE that I tried removing but it doesn't make a difference.
Does anyone know why it could be making such a big difference?
TIA
Mark