Question

I would like to find all rows that would match the predicate MyColumn LIKE '%FooBar' but by by using an index seek rather than a scan.

One approach is essentially to create a reversed version of MyColumn and search for the reversed pattern (ooF%) on that column with a conventional index on the reversed column.

I do not like manually creating this reversed column, however. Oracle has the concept of reversed key indexes that can automatically index on REVERSE(MyColumn) without the need for manually materializing reversed versions of the column (either in form of a physical column on the table or by creating an indexed view).

Are there any other ways to perform suffix substring searches in SQL Server efficiently?

Was it helpful?

Solution

Just use a calculated field with an index, or an indexed view with the reversed field.

Yes, this will materialise the reversed field. But how do you think Oracle's reversed indexes work?

For the search to be efficient, there must be a materialised data structure to search.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top