Subject RES: [firebird-support] Re: Problem slow sorting/distinct in Firebird
Author Fabiano
Try this:



SELECT FIRST 30 SKIP 0 tr.NodePosition, tr.IdLink, tr.IdTargetLink,
tr.IdItem
FROM Tree3 tr
inner join article3_1 art on art.idarticle = Tr.iditem
WHERE
tr.NODELEVEL =5 and tr.LINKTYPE <> 5 and tr.ItemType = 2 AND tr.Market1 = 1
and
(lower(coalesce(art.Artikelnummer , '') || ';'
|| coalesce(art.Artikelnr_leverancier, '') || ';'
|| coalesce(art.Artikelnaam1, '') || ';'
|| coalesce(art.Artikelnaam2, '') || ';'
|| coalesce(art.MERK, '') || ';'
|| coalesce(art.EAN, '') || ';'
|| coalesce(art.ALTARTNR1, '') || ';'
|| coalesce(art.ALTARTNR2, '')

) like '%a4%')

AND (lower(coalesce(art.Artikelnummer , '') || ';'
|| coalesce(art.Artikelnr_leverancier, '') || ';'
|| coalesce(art.Artikelnaam1, '') || ';'
|| coalesce(art.Artikelnaam2, '') || ';'
|| coalesce(art.MERK, '') || ';'
|| coalesce(art.EAN, '') || ';'
|| coalesce(art.ALTARTNR1, '') || ';'
|| coalesce(art.ALTARTNR2, '')

) like '%papier%')

group by tr.NodePosition, tr.IdLink, tr.IdTargetLink, tr.IdItem



Finally create na índex on Tree3 table with the fields: NodePosition,
IdLink, IdTargetLink, IdItem



I think you do not need a forced “order by” clause because it is implicitly
formed as a group by.



Measure time, then drop this index and create another on fields: iditem,
NodePosition, IdLink, IdTargetLink, IdItem



One of these Will perform a better performance.



[Non-text portions of this message have been removed]