I would like tuning my query with full-text searching.
I have two tables:
1. artaolInventTable
a) IT_NAMEIDIDX (Unique, Non-clustered)
- itemId
- itemName
(include column
b) IT_IMPORTIDX (Non-unique, non-clustered)
- importIndex
c) IT_ITEMNAMEIDX (Unique, clustered)
- itemName
d) PK_ARTAOLINVENTTABLE (Unique, non-clustered)
- itemId
2. InventSumIntegration_ART
a) IS_AVAILIDX (Non-unique, Non-clustered)
- availphysical
b) IS_ITEMIDX(Unique, Clustered)
- itemId
- availphysical
Query 1 - first I have simple query:
SELECT it.ItemId, it.ItemName, it.ItemBrand, it.Amount, it.salesunit, it.importIndex FROM artaolInventTable IT WHERE (CONTAINS(it.ItemName, '("Papier*" OR FORMSOF(THESAURUS, Papier)) AND ("ksero*" OR FORMSOF(THESAURUS, ksero)) AND ("A4*" OR FORMSOF(THESAURUS, A4))') OR it.importIndex = 'IP000' OR it.ItemId = 'aaaa' ) order by it.ItemName
CPU time = 32 ms, elapsed time = 205 ms.
Execution plan looks good. To find every conditions in where clause sql use indexes.
Query 2 - I added second table and my execution time increased to 51 sec!. Why? Is there problem with my indexes? How I should build it?
INVENTSUMSHOPINTEGRATION has invent stock value.
SELECT IT.ITEMID, IT.ITEMNAME, IT.ITEMBRAND, IT.AMOUNT, IT.SALESUNIT, IT.ImportIndex, ISU.AVAILPHYSICAL FROM ARTAOLINVENTTABLE IT JOIN INVENTSUMSHOPINTEGRATION_ART ISU ON ISU.ITEMID = IT.ITEMID WHERE (CONTAINS(IT.ITEMNAME, '("Papier*" OR FORMSOF(THESAURUS, Papier)) AND ("ksero*" OR FORMSOF(THESAURUS, ksero)) AND ("A4*" OR FORMSOF(THESAURUS, A4))') OR IT.IMPORTINDEX = 'IP000' OR IT.ITEMID = 'aaaa' ) AND (ISU.AVAILPHYSICAL >= 0) order by it.ITEMNAME
CPU time = 51418 ms, elapsed time = 51756 ms.
save screenshots to disk to get good quality.
exection plan query 2
exection plan query 1
Best regards Jacek