Optimize this Query

  • 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

  • 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.

  • 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'



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • 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