Subject | Plan Syntax |
---|---|
Author | Mitch Peek |
Post date | 2008-03-12T21:47:48Z |
Query
Select D.ID, Cast(D.CreateDate as Date) as OrigDate, Cast(D.Editdate as
Date) as Lastedited,
D.EditUser, D.StockName, D.Status, D.Buyer, D.Bidamt ,
Cast(c.Createdate as Date) as LastComment, C.Author,
D.StockNumber, D.SR
from Deal D
left join Discussion C on C.Deal_Id=D.Id
and C.Id=(Select Max(C2.ID) from discussion C2
where C2.deal_id=d.id)
Where
D.editDate >= '3/1/2008'
OR
(Exists ( select 1
from discussion DS
where DS.Deal_ID=D.ID
AND DS.CreateDate >= '3/1/2008' ))
OR
(Exists ( Select 1
from Attachment A
where A.Deal_ID=D.ID
AND A.CreateDate >= '3/1/2008' ))
IbExpert shows the following
Plan
PLAN (C2 INDEX (FK_DISCUSSION_1))
PLAN (DS INDEX (FK_DISCUSSION_1,IDX_DISCUSSION_2))
PLAN (A INDEX (FK_ATTACHMENT_2,IDX_ATTACHMENT_1))
PLAN JOIN (D NATURAL,C INDEX (PK_DISCUSSION))
Adapted Plan
PLAN (C2 INDEX (FK_DISCUSSION_1)) PLAN (DS INDEX
(FK_DISCUSSION_1,IDX_DISCUSSION_2)) PLAN (A INDEX
(FK_ATTACHMENT_2,IDX_ATTACHMENT_1)) PLAN JOIN (D NATURAL,C INDEX
(PK_DISCUSSION))
If I change [D Natural] to [D INDEX (IDX_DEAL_1)] the performance would
increase dramatically. However, I can't get the syntax correct.
Can anyone help please?
TIA
MP
Select D.ID, Cast(D.CreateDate as Date) as OrigDate, Cast(D.Editdate as
Date) as Lastedited,
D.EditUser, D.StockName, D.Status, D.Buyer, D.Bidamt ,
Cast(c.Createdate as Date) as LastComment, C.Author,
D.StockNumber, D.SR
from Deal D
left join Discussion C on C.Deal_Id=D.Id
and C.Id=(Select Max(C2.ID) from discussion C2
where C2.deal_id=d.id)
Where
D.editDate >= '3/1/2008'
OR
(Exists ( select 1
from discussion DS
where DS.Deal_ID=D.ID
AND DS.CreateDate >= '3/1/2008' ))
OR
(Exists ( Select 1
from Attachment A
where A.Deal_ID=D.ID
AND A.CreateDate >= '3/1/2008' ))
IbExpert shows the following
Plan
PLAN (C2 INDEX (FK_DISCUSSION_1))
PLAN (DS INDEX (FK_DISCUSSION_1,IDX_DISCUSSION_2))
PLAN (A INDEX (FK_ATTACHMENT_2,IDX_ATTACHMENT_1))
PLAN JOIN (D NATURAL,C INDEX (PK_DISCUSSION))
Adapted Plan
PLAN (C2 INDEX (FK_DISCUSSION_1)) PLAN (DS INDEX
(FK_DISCUSSION_1,IDX_DISCUSSION_2)) PLAN (A INDEX
(FK_ATTACHMENT_2,IDX_ATTACHMENT_1)) PLAN JOIN (D NATURAL,C INDEX
(PK_DISCUSSION))
If I change [D Natural] to [D INDEX (IDX_DEAL_1)] the performance would
increase dramatically. However, I can't get the syntax correct.
Can anyone help please?
TIA
MP