Subject RE: [ib-support] query plan
Author Svein Erling Tysvaer
At 08:42 30.04.2003 -0300, you wrote:
>(NS NATURAL,...,NT INDEX (RDB$PRIMARY48,RDB$FOREIGN50)

For some reason, IB/Fb believe that using no index for NS and two indexes
for NT is the best it can do. Beats me why it believes so... Try specifying
the plan explicitly writing something like

select
cu.id_cuenta
from cuenta cu
join notificacion nt on nt.id_cuenta = cu.id_cuenta
join noti_recipiente nr on nr.id_notificacion = nt.id_notificacion
join recipiente re on re.id_recipiente = nr.id_recipiente
join noti_servicio ns on ns.id_noti_servicio = re.id_noti_servicio
left join noti_reglas ng on ng.id_noti_reglas = nt.id_noti_reglas and
ng.activo = 1
where
nt.id_cuenta = 696 and
nt.id_evento = 123
PLAN JOIN (JOIN (NT INDEX
(<IndexFor_ID_EVENTO>,<IndexFor_ID_CUENTA>),CU(INDEX(<IndexFor_CU.ID_CUENTA>),NR
INDEX(IndexFor_NR.ID_NOTIFICACION),RE INDEX (IndexFor_RE.ID_RECIPIENTE),NS
INDEX(<IndexFor_NS.ID_ID_NOTI_SERVICIO>)),NG INDEX (PK_NOTI_REGLAS))

This may or may not be faster than your original plan, trial and error is
the easiest way to find the answer.

HTH,
Set

PS! Only you know your data, and if some of these fields belong to big
tables which contain lots of duplicates, then this may be a very slow plan.
Likewise, if ID_EVENTO and ID_CUENTA are very unevenly distributed with one
of the fields occuring plenty of times whereas the other is almost unique,
then you may want to remove the index for the duplicating field.