Subject Re: New Index causes unsuspecting queries to hang
Author starasoris
Sorry about the Chrystal Ball. I come from a long line of Gypsies.

The version of the database is FireBird 1.5

The index is on integer Gen_tabl_RequisitionItem.n_orderedunits
it is caled GEN_TABL_REQUISITION_IDX5

Here is the Query

select s.s_finedept, sum(I.D_Price * I.n_unitsordered) totalval
from gen_tabl_requisitionitem I
inner join gen_tabl_stockitem S on S.PKS_STOCKITEMID =
I.FKS_STOCKITEMID
where FKN_PICKSLIPID = 260874
or (fkn_requisitionid = 222824and n_unitsordered > 0
and d_datepicked is null and fkn_parentid = 0)
group by s.s_finedept order by s.s_finedept, pkn_requisitionitemid


Query Plan with index disabled

Plan
PLAN SORT (SORT (JOIN (S NATURAL,I INDEX
(GEN_TABL_REQUISITIONITEM_IDX3,GEN_TABL_REQUISITIONITEM_IDX2,RDB$PRIMA
RY90))))
Adapted Plan
PLAN SORT (SORT (JOIN (S NATURAL,I INDEX
(GEN_TABL_REQUISITIONITEM_IDX3,GEN_TABL_REQUISITIONITEM_IDX2,INTEG_297
))))

Query Plan with index enabled

Plan
PLAN SORT (SORT (JOIN (S NATURAL,I INDEX
(GEN_TABL_REQUISITIONITEM_IDX3,GEN_TABL_REQUISITIONITEM_IDX2,RDB$PRIMA
RY90,GEN_TABL_REQUISITIONITEM_IDX5))))
Adapted Plan
PLAN SORT (SORT (JOIN (S NATURAL,I INDEX
(GEN_TABL_REQUISITIONITEM_IDX3,GEN_TABL_REQUISITIONITEM_IDX2,INTEG_297
,GEN_TABL_REQUISITIONITEM_IDX5))))


If I take out the first part of the "or" out it runs fine

select s.s_finedept, sum(I.D_Price * I.n_unitsordered) totalval
from gen_tabl_requisitionitem I
inner join gen_tabl_stockitem S on S.PKS_STOCKITEMID =
I.FKS_STOCKITEMID
where (fkn_requisitionid = 222824 and n_unitsordered > 0
and d_datepicked is null and fkn_parentid = 0)
group by s.s_finedept order by s.s_finedept, pkn_requisitionitemid

Plan
PLAN SORT (SORT (JOIN (I INDEX
(RDB$PRIMARY90,GEN_TABL_REQUISITIONITEM_IDX5),S INDEX
(GEN_TABL_STOCKITEM_IDX2))))
Adapted Plan
PLAN SORT (SORT (JOIN (I INDEX
(INTEG_297,GEN_TABL_REQUISITIONITEM_IDX5),S INDEX
(GEN_TABL_STOCKITEM_IDX2))))

I hope that this is the info you seek

Thanks.