Subject | Re: [firebird-support] Slow query help |
---|---|
Author | Alexandre Benson Smith |
Post date | 2005-12-01T04:05:28Z |
markd_mms wrote:
clause and is not a null comparision is just as if it is an inner join.
table Item (probably using an index), without this criteria and with all
left joins all rows in the Item Table should be scanned.
SELECT ITEM.TITLE AS "Title", ITEM.TITLE2 AS "Title2",
ITEMINFORMAT.CATALOGUENO AS "Catalogue Number",
ITEMINFORMAT.BARCODE AS "Barcode", FORMAT.DESCRIPTION AS "Format",
DISTRIBUTOR.DESCRIPTION AS "Distributor", GENRE.DESCRIPTION AS "Genre",
ITEM.DISTRIBUTOR_RELEASE_DATE AS "Release Date", ITEM.ITEMID
FROM ITEM
JOIN ITEMINFORMAT ON ITEM.ITEMID = ITEMINFORMAT.ITEMID
LEFT JOIN ARTISTITEM ON ITEM.ITEMID = ARTISTITEM.ITEMID
LEFT JOIN ARTISTS ON ARTISTITEM.ARTISTID = ARTISTS.ARTISTID
LEFT JOIN FORMAT ON ITEMINFORMAT.FORMATID = FORMAT.FORMATID
LEFT JOIN DISTRIBUTOR ON ITEM.DISTRIBUTORID = DISTRIBUTOR.DISTRIBUTORID
LEFT JOIN GENRE ON ITEM.GENREID = GENRE.GENREID
WHERE
ITEMINFORMAT.CATALOGUENO = '8236709'
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
>Running this query takes 3 seconds:When when use a "right" table field used in a left join in the where
>
>SELECT ITEM.TITLE AS "Title", ITEM.TITLE2 AS "Title2",
>ITEMINFORMAT.CATALOGUENO AS "Catalogue Number",
>ITEMINFORMAT.BARCODE AS "Barcode", FORMAT.DESCRIPTION AS "Format",
>DISTRIBUTOR.DESCRIPTION AS "Distributor", GENRE.DESCRIPTION AS "Genre",
>ITEM.DISTRIBUTOR_RELEASE_DATE AS "Release Date", ITEM.ITEMID
>FROM ITEM
>LEFT JOIN ARTISTITEM ON ITEM.ITEMID = ARTISTITEM.ITEMID
>LEFT JOIN ARTISTS ON ARTISTITEM.ARTISTID = ARTISTS.ARTISTID
>LEFT JOIN ITEMINFORMAT ON ITEM.ITEMID = ITEMINFORMAT.ITEMID
>LEFT JOIN FORMAT ON ITEMINFORMAT.FORMATID = FORMAT.FORMATID
>LEFT JOIN DISTRIBUTOR ON ITEM.DISTRIBUTORID = DISTRIBUTOR.DISTRIBUTORID
>LEFT JOIN GENRE ON ITEM.GENREID = GENRE.GENREID
>WHERE
>ITEMINFORMAT.CATALOGUENO = '8236709'
>
>
clause and is not a null comparision is just as if it is an inner join.
>but if I addwith this criteria in the where clause the optimizer could filter on
>
>AND
>ITEM.TITLE CONTAINING 'knight'
>
>
>then it only takes ~700ms. Looking at the plan analyser shows 14010
>unindexed reads on the ITEM table, which is the number of records in
>the table. Every selected field in the query is indexd. The plan is as
>follows:
>
>
table Item (probably using an index), without this criteria and with all
left joins all rows in the Item Table should be scanned.
>Is there any way of speeding this up?try this one:
>
>
SELECT ITEM.TITLE AS "Title", ITEM.TITLE2 AS "Title2",
ITEMINFORMAT.CATALOGUENO AS "Catalogue Number",
ITEMINFORMAT.BARCODE AS "Barcode", FORMAT.DESCRIPTION AS "Format",
DISTRIBUTOR.DESCRIPTION AS "Distributor", GENRE.DESCRIPTION AS "Genre",
ITEM.DISTRIBUTOR_RELEASE_DATE AS "Release Date", ITEM.ITEMID
FROM ITEM
JOIN ITEMINFORMAT ON ITEM.ITEMID = ITEMINFORMAT.ITEMID
LEFT JOIN ARTISTITEM ON ITEM.ITEMID = ARTISTITEM.ITEMID
LEFT JOIN ARTISTS ON ARTISTITEM.ARTISTID = ARTISTS.ARTISTID
LEFT JOIN FORMAT ON ITEMINFORMAT.FORMATID = FORMAT.FORMATID
LEFT JOIN DISTRIBUTOR ON ITEM.DISTRIBUTORID = DISTRIBUTOR.DISTRIBUTORID
LEFT JOIN GENRE ON ITEM.GENREID = GENRE.GENREID
WHERE
ITEMINFORMAT.CATALOGUENO = '8236709'
>TIAsee you !
>
>
>
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br