I need to do an autocomplete functionality and need to do something like this:
select field from huge_table where field like '%some string%';
The table is 2 million rows, and I need quick and several responses from it. We are using Postgres. And that kind of query will take forever.
Is there an efficient way for doing this with postgres? Or maybe should I be using some other thing than postgres?
Thanks!
You could add an index to the
fieldbeing searched.Also, if it's avoidable, don't use open ended wild cards like
%some string%they really hurt performance. If possible, dosome string%.