Intersystems Cache Indexing Shocker - How to Fix Sluggish Queries
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7MOooM8M2tyl8AIVZ-q9gIlXzacdynmtBBMv6MmTF0owjOBbLjdQRzErSUZmeKXAVnAHgZNHmZCECCi70Zzd_LayFCa12-U9mIXYGBDd_Ls-zido0tl8CsyJrfGgSk6PtBIquBc6WbdI/s1600/14201997467_e5c2c16ea7_b.jpg)
Photo: Markus Spiske / www.temporausch.com / CC-BY When going through a performance review of a grid on the website, I was struggling to see why the query was taking so long. It was a single table query with a single where clause which was on an indexed field. This indexed field could only contain 5 different values and the query was return fewer than 100 entries but was taking over 1 second. On other lower powered servers the query was taking less than a third of a second and often returning more data albeit on a smaller total data set. Checking the query plan revealed something interesting, the query was not using the index but was instead performing a whole table scan. Further testing revealed that only "=" queries use indexes. "!=" ignore indexes as do any queries with "OR" or "IN". After further investigation I found that if you only return the ID then NOT, OR , IN queries do use indexes, however, if you return any other field inc...