You are stuck with looking at all rows.
LIKE '%...'
cannot use an index because of the leading wildcard
REGEXP
can do all the testing in one try, versus multiple LIKEs
, so it might be faster
AND NOT (...)
does not help
OR
does not help
FULLTEXT
can't be very helpful because of the 'negative' testing.
- etc.
I recommend this:
AND j.Note IS NOT NULL
AND j.Note REGEXP 'audit|discrepancy|returns|shipment error|inventory adjustment'
If Note
has lots of NULLs
, then INDEX(Note)
may help by avoiding the NULLs
.
Here's another approach: As you insert rows, categorize them as "audit" or ... Then have another column (perhaps a SET
) that flags which categories each Note belongs to.
If each Note belongs to only one category, then use ENUM and index it. If not, testing the SET would be a little faster than LIKEs or REGEXP.