Subject Question about optimizer
Author Christian Kaufmann
I have the following query

select * from SWIMRESULT SR
join MEET M on M.MEETID = SR.MEETID
join ATHLETE A on A.ATHLETEID = SR.ATHLETEID
join SWIMEVENT SE on SE.SWIMEVENTID = SR.SWIMEVENTID
where SR.COURSE = 2 SR.STYLEID = 1 and and SR.STATUS in (0,1,101,102)
and A.GENDER = 1
order by SR.COURSE, SR.STYLEID, SR.SWIMTIME

since I have an index on SWIMRESULT with (COURSE,STYLEID,SWIMTIME) the
following plan is used:

PLAN JOIN (SR ORDER IX_SWIMRESULT_STYLE,SE INDEX (PK_SWIMEVENT),A INDEX
(PK_ATHLETE),M INDEX (PK_MEET))

This works fine and fast, especially because I'm only interested in the
first several hundred records. The full query would give over 100'000
records as result.

Now I would like to extend the order part of the SQL like this:

order by SR.COURSE, SR.STYLEID, SR.SWIMTIME, M.STARTDATE

unfortunately the plan changes to this:

PLAN SORT (JOIN (SR INDEX (IX_SWIMRESULT_STYLE),SE INDEX
(PK_SWIMEVENT),A INDEX (PK_ATHLETE),M INDEX (PK_MEET)))

and now the server retrieves all records before he starts to give back
the first records of the result set.

Are there any tricks to force the optimzer to use the first plan? Or do
I have to do the sort on M.STARTDATE in my application?

cu Christian