How It Works: XEvent String Comparison Performance Tip

Moved from:


I​​ ran across​​ a​​ check in the​​ XEvent​​ string comparison logic​​ which​​ can​​ be used to improve performance of the​​ ‘like’ comparison.

At first glance the string comparison seems straightforward. ​​ However, the logic​​ may require complex comparison​​ (SQL Server collations and/or​​ surrogate​​ characters​​ involved in UNICODE, UTF_16, etc.)

When performing comparison,​​ simple checks are attempted first. ​​ For example:

If the compare value is ‘Bob%’ the logic​​ may​​ compare the first 3 characters and can avoid a more involved check.

If the compare value is ‘%Bob’ the logic may compare the last 3 characters and avoid a more involved check

However, a compare value of ‘%Bob%’ may require more work than