Subject | Slow query help |
---|---|
Author | markd_mms |
Post date | 2005-12-01T03:49:41Z |
Running this query takes 3 seconds:
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'
but if I add
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:
PLAN JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (ITEM NATURAL,ARTISTITEM INDEX
(IDX_ARTISTITEM_ITEMID)),ARTISTS INDEX (PK_ARTISTS)),ITEMINFORMAT
INDEX (PK_ITEMINFORMAT)),FORMAT INDEX (PK_FORMAT)),DISTRIBUTOR INDEX
(PK_DISTRIBUTOR)),GENRE INDEX (PK_GENRE)):
PLAN JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (ITEM NATURAL,ARTISTITEM INDEX
(IDX_ARTISTITEM_ITEMID)),ARTISTS INDEX (PK_ARTISTS)),ITEMINFORMAT
INDEX (PK_ITEMINFORMAT)),FORMAT INDEX (PK_FORMAT)),DISTRIBUTOR INDEX
(PK_DISTRIBUTOR)),GENRE INDEX (PK_GENRE))
Adapted plan:
PLAN JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (ITEM NATURAL,ARTISTITEM INDEX
(IDX_ARTISTITEM_ITEMID)),ARTISTS INDEX (PK_ARTISTS)),ITEMINFORMAT
INDEX (PK_ITEMINFORMAT)),FORMAT INDEX (PK_FORMAT)),DISTRIBUTOR INDEX
(PK_DISTRIBUTOR)),GENRE INDEX (PK_GENRE))
Is there any way of speeding this up?
TIA
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'
but if I add
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:
PLAN JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (ITEM NATURAL,ARTISTITEM INDEX
(IDX_ARTISTITEM_ITEMID)),ARTISTS INDEX (PK_ARTISTS)),ITEMINFORMAT
INDEX (PK_ITEMINFORMAT)),FORMAT INDEX (PK_FORMAT)),DISTRIBUTOR INDEX
(PK_DISTRIBUTOR)),GENRE INDEX (PK_GENRE)):
PLAN JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (ITEM NATURAL,ARTISTITEM INDEX
(IDX_ARTISTITEM_ITEMID)),ARTISTS INDEX (PK_ARTISTS)),ITEMINFORMAT
INDEX (PK_ITEMINFORMAT)),FORMAT INDEX (PK_FORMAT)),DISTRIBUTOR INDEX
(PK_DISTRIBUTOR)),GENRE INDEX (PK_GENRE))
Adapted plan:
PLAN JOIN (JOIN (JOIN (JOIN (JOIN (JOIN (ITEM NATURAL,ARTISTITEM INDEX
(IDX_ARTISTITEM_ITEMID)),ARTISTS INDEX (PK_ARTISTS)),ITEMINFORMAT
INDEX (PK_ITEMINFORMAT)),FORMAT INDEX (PK_FORMAT)),DISTRIBUTOR INDEX
(PK_DISTRIBUTOR)),GENRE INDEX (PK_GENRE))
Is there any way of speeding this up?
TIA