Subject | Re: [firebird-support] How to optimize this query |
---|---|
Author | Alexandre Benson Smith |
Post date | 2004-05-25T16:21:24Z |
Christian Kaufmann wrote:
Have you tried this kind of query ?
select
R.T_RESULTID, R.SWIMTIME,
A.LASTNAME, A.FIRSTNAME, A.BIRTHDATE,
S.STARTDATE, M.CITY, M.NATION,
C.CODE
from T_RESULT R
join T_ATHLETE A on A.T_ATHLETEID = R.T_ATHLETEID
join T_AGEGROUP AG on AG.T_AGEGROUPID = R.T_AGEGROUPID
join T_EVENT E on E.T_EVENTID = AG.T_EVENTID
join T_SESSION S on S.T_SESSIONID = E.T_SESSIONID
join T_MEET M on M.T_MEETID = S.T_MEETID
join T_ATHLETEMEET MM on MM.T_MEETID = M.T_MEETID and MM.T_ATHLETEID =
A.T_ATHLETEID
join T_CLUB C on C.T_CLUBID = MM.T_CLUBID
where
E.T_STYLEID = 1 and
A.GENDER = 0
/* and C.T_CLUBID = 56 */
and R.SWINTIME = (select min(SWINTIME) from t_RESULT where T_ATHLETID = A.T_ATHLETID)
order by
R.SWIMTIME
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
>Hi,Christian,
>
>I have a query, that runs to slow and I'm looking for hints how to
>optimize it. You find at the end of the message:
>- the query
>- the plan
>- the DDL
>
>cu Christian
>
>-----------------------------
>
>select
> R.T_RESULTID, R.SWIMTIME,
> A.LASTNAME, A.FIRSTNAME, A.BIRTHDATE,
> S.STARTDATE, M.CITY, M.NATION,
> C.CODE
>from T_RESULT R
>join T_ATHLETE A on A.T_ATHLETEID = R.T_ATHLETEID
>join T_AGEGROUP AG on AG.T_AGEGROUPID = R.T_AGEGROUPID
>join T_EVENT E on E.T_EVENTID = AG.T_EVENTID
>join T_SESSION S on S.T_SESSIONID = E.T_SESSIONID
>join T_MEET M on M.T_MEETID = S.T_MEETID
>join T_ATHLETEMEET MM on MM.T_MEETID = M.T_MEETID and MM.T_ATHLETEID =
>A.T_ATHLETEID
>join T_CLUB C on C.T_CLUBID = MM.T_CLUBID
>
>where
> E.T_STYLEID = 1 and
> A.GENDER = 0
> /* and C.T_CLUBID = 56 */
>order by
> R.SWIMTIME
>
>
>
>
Have you tried this kind of query ?
select
R.T_RESULTID, R.SWIMTIME,
A.LASTNAME, A.FIRSTNAME, A.BIRTHDATE,
S.STARTDATE, M.CITY, M.NATION,
C.CODE
from T_RESULT R
join T_ATHLETE A on A.T_ATHLETEID = R.T_ATHLETEID
join T_AGEGROUP AG on AG.T_AGEGROUPID = R.T_AGEGROUPID
join T_EVENT E on E.T_EVENTID = AG.T_EVENTID
join T_SESSION S on S.T_SESSIONID = E.T_SESSIONID
join T_MEET M on M.T_MEETID = S.T_MEETID
join T_ATHLETEMEET MM on MM.T_MEETID = M.T_MEETID and MM.T_ATHLETEID =
A.T_ATHLETEID
join T_CLUB C on C.T_CLUBID = MM.T_CLUBID
where
E.T_STYLEID = 1 and
A.GENDER = 0
/* and C.T_CLUBID = 56 */
and R.SWINTIME = (select min(SWINTIME) from t_RESULT where T_ATHLETID = A.T_ATHLETID)
order by
R.SWIMTIME
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br