Subject | RE: [firebird-support] Plan Syntax |
---|---|
Author | Leyne, Sean |
Post date | 2008-03-14T04:32:41Z |
Mitch,
1 - you move the "and C.Id=(Select Max(C2.ID) from discussion C2 where
C2.deal_id=d.id)" criteria from the JOIN to the WHERE.
2 (or) - change the "and C.Id=(Select Max(C2.ID) from discussion C2
where C2.deal_id=d.id)" criteria to "and C.Id=(Select Max(C2.ID) from
discussion C2 where C2.deal_id=d.id+0)" criteria
I found that the v1.x optimizer had a number of issues with choosing the
best index.
These 'tricks' might get the Deal EditDate index to come into play, and
thus reduce the number of tests which the other criteria would invoke.
It think you would be very surprised, this particular index (the
DESCENDING index) would reduce the number of fetches per deal to 1 --
since the first indexed read for each Deal would yield the highest ID
value.
the PLAN and performance numbers, rather then doing all the changes in
one step.
It would give a better sense of the impact of each change.
Sean
> > 1 - Do you have an index on Deal EditDate? (This could helps getrid of
> > the NATURAL scan)What PLAN is generated if:
> >
> >
> I do. It was this index that I wanted to use.
1 - you move the "and C.Id=(Select Max(C2.ID) from discussion C2 where
C2.deal_id=d.id)" criteria from the JOIN to the WHERE.
2 (or) - change the "and C.Id=(Select Max(C2.ID) from discussion C2
where C2.deal_id=d.id)" criteria to "and C.Id=(Select Max(C2.ID) from
discussion C2 where C2.deal_id=d.id+0)" criteria
I found that the v1.x optimizer had a number of issues with choosing the
best index.
These 'tricks' might get the Deal EditDate index to come into play, and
thus reduce the number of tests which the other criteria would invoke.
> > 2 - You should create a DESCENDING compound index in Discussion,try.
> > combining Deal_ID + ID). The optimizer should choose this index to
> > resolve the MAX() criteria.
>
> I thought of that. However, there should be few rows per "Deal", so,
> not sure that would be a tremendous help, but is certainly worth a
It think you would be very surprised, this particular index (the
DESCENDING index) would reduce the number of fetches per deal to 1 --
since the first indexed read for each Deal would yield the highest ID
value.
> > 3 - You should create compound indexes on Attachments andDiscussions
> > (combining DealID + CreateDate). The optimizer should choose theseI would be beneficial if you could make one change at a time and post
> > indexes over the current approach of trying to create a bit map by
> > combining the separate indexes (FK_DISCUSSION_1/IDX_DISCUSSION_2 and
> > FK_ATTACHMENT_2/IDX_ATTACHMENT_1).
>
> another goo suggestion. Thanks, I'll try it.
the PLAN and performance numbers, rather then doing all the changes in
one step.
It would give a better sense of the impact of each change.
Sean