I am using SQLite3
in C++ where I need to store text data. There are 7 columns in the table. I need to filter data by 7 columns. I need to check for equality of 6 columns to a specific value, and I need to search for a substring by the last column. I use a regular index for the first 6 columns and the search (SELECT query) works quite fast. However, for the 7th column, I use LIKE %value%
to search for a substring. However, LIKE
does not use indexes. How can I efficiently implement searching by this field? Note that WHERE
filtering by fields can contain all 7 columns, or just one (which uses LIKE).
UPDATE I found out that full text search works well in such cases, but full text search does not work with a regular table, as far as I know. What solution do you recommend?
My texts are not long (up to 100 characters) and there are no spaces. Example: ThisIsMyExampleString. In that case I'm not sure that full text search will work here
Select string where instr(sting, "whatImSearchingFor")>0
will return the entire string if "whatImSearchingFor" is contained within it. The point is that LIKE needs to be more complicated than Instr() to handle wildcards anywhere so instr() may perform better. You have no hope of using an index lookup on a substring search since all possible substrings would need to be indexed.