September 20, 2011 at 8:56 am
Can this Query be optimized and if so, how?
DROP TABLE DBO.AS_TMP_FLAT_WORDS1_LESS_THOU
SELECT DISTINCT A.EMAILGUID, A.[MESSAGE]
INTO DBO.AS_TMP_FLAT_WORDS1_LESS_THOU
FROM DBO.AS_TMP_FLAT_LESS_THOU A,
DBO.AS_FLAT_WORDLIST1_LESS_THOU B
WHERE A.[MESSAGE] LIKE '%'+SPACE(1)+B.WORD+SPACE(1)+'%'
OR A.[MESSAGE] LIKE '%[0-9] FOR $%'
OR A.[MESSAGE] LIKE '%[0-9]% OFF'
OR A.[MESSAGE] LIKE '%[$][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9] PER UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] PER UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] PER UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] PER UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] PER UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] PER UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9] /UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] /UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] /UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] /UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] /UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] /UNIT%'
OR A.[MESSAGE] LIKE '%[$][0-9] PER ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] PER ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] PER ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] PER ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] PER ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] PER ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9] /ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] /ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] /ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] /ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] /ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] /ITEM%'
OR A.[MESSAGE] LIKE '%[$][0-9] PER PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] PER PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] PER PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] PER PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] PER PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] PER PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9] /PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] /PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] /PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] /PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] /PIECE%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] /PIECE%'
GO
September 20, 2011 at 9:07 am
Very unlikely.
You can always post the actual execution plan, but I don't see this ever running fast.
You'll always scan the whole table and worst, make multiple pattern matches on the same, possibly long, string.
September 20, 2011 at 2:10 pm
I think you can remove this block:
OR A.[MESSAGE] LIKE '%[$][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9].[0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9].[0-9][0-9] OFF%'
OR A.[MESSAGE] LIKE '%[$][0-9][0-9][0-9].[0-9][0-9] OFF%'
since all of those conditions are covered by
OR A.[MESSAGE] LIKE '%[0-9]% OFF'
September 21, 2011 at 7:07 am
I think you are wrong. because if in the data there is :
20% OFF
Then it will select that and I don't want that.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply