Subject Indexes and Joins
Author GreatDayDan
Good Morning!

I have a query that looks like this:

SELECT SO.SERVICEORDERID, SO.STATUS,SO.CLIENTBILLTOID,
BT.ATTN,BT.ADDRESS1, BT.ADDRESS2, BT.ADDRESS3,
BT.CITY, BT.ST, BT.ZIP,
CL.NAME,
CL.ACCOUNTNUMBER,SO.VERBALPO,SO.BLANKETPOID,
SUM((PD.QTY*PD.SALEPRICE)+PD.SALESTAX) AS
PARTTOTAL
FROM SERVICEORDER SO
JOIN CLIENTBILLTO BT ON SO.CLIENTBILLTOID =
BT.CLIENTBILLTOID
JOIN CLIENT CL ON BT.CLIENTID = CL.CLIENTID
LEFT OUTER JOIN PARTDETAIL PD ON SO.SERVICEORDERID =
PD.SERVICEORDERID
WHERE SO.STATUS = 10
AND SO.DATECOMPLETED < '04/03/2002'
AND SO.INVOICENUMBER IS NULL
GROUP BY SO.SERVICEORDERID,
SO.STATUS,SO.CLIENTBILLTOID,
BT.ATTN,BT.ADDRESS1, BT.ADDRESS2, BT.ADDRESS3,
BT.CITY, BT.ST, BT.ZIP,
CL.NAME,
CL.ACCOUNTNUMBER,SO.VERBALPO,SO.BLANKETPOID


This is the plan that IB comes up with:

PLAN
SORT
(JOIN
(JOIN
(BT Natral,

CL INDEX (RDB$PRIMARY13),
SO INDEX (SERVICEORDER_COMPLETEDATE,
SERVICEORDER_CLIENTBILLTOID,
SERVICEORDER_STATUS
)
),
PD INDEX (PARTDETAIL_SO)
)
)

This makes for a rather slow result set.
If I try to use **BT INDEX (RDB$PRIMARY14)**, IB
complains that that index cannot be used. That is the
primary key for that table.

Any ideas why it cannot be used?

Thanks...Dan'l



=====
____________________________________
Every day is a Great day, but
some days are GREATER than others!

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/