Subject RE: [firebird-support] Need help in order to make this sql run efficiently...
Author Tasos Kyriakos
Many sorry as i didn't described previously correctly my query.
My only excuse is that tried to translate the names to be more
understandable
but the (local) time was 3 in the morning, so...


Trying to use model with exists, i run the query 2. This finished with
151058 reads from T_CASES (has totally 75529 records) and returns the
(correct) 3 records of V_CASES_GRID.
This is EXACTLY the same performence and result with mine (Query 1)

i used to believe that only 6 reads from T_CASES should be enough giving
that records with id 19,20 and 21 exist and that yp_id is (primary) indexed.
Maybe I am wrong but where?

Just for giving a better idea i enclose (as query 3) a more expanded form
of the query, believing that this time I haven't misspelled something.

/*---------------- QUERY 1 ----------------*/
select * from V_CASES_GRID vc
where vc.YP_ID in
(
select distinct(ty.YP_ID) from T_CASES ty
where
ty.yp_id between 19 and 21
)
order by vc.yp_id
/*-----------------------*/

/*---------------- QUERY 2 ----------------*/
select VC.* from V_CASES_GRID VC
where
exists
(
select 1 from T_CASES yp
where vc.yp_id=yp.yp_id
and
yp.yp_id between 19 and 21
order by yp.yp_id
)
order by vc.yp_id
/*-----------------------*/

/*---------------- QUERY 3 ----------------*/
select * from V_CASES_GRID vc
where vc.YP_ID in
(
select distinct(ty.YP_ID) from T_CASES ty
join T_SYNALL on sy_id=ty.yp_anti /* opponents */
join t_crossyp on cry_yp =ty.yp_id /* users */
where
SY_ID=9655 /* opponent's id */
and CRY_Person = 24 /* user's id */
and ty.yp_id between 1 and 1000
and ty.yp_descr like '%KEYWORD%'
)
order by vc.yp_id
/*-----------------------*/

[>>]
Thanks in advance

Regards

Tasos Kyriakos
Athens, Greece
tkyr@...