I have a table with a text field of 100 characters in size, but about half a million rows (and counting). The text field contains people's names, and there is no empty field. An index is also present for this text field. Whenever I run a SELECT query that searches for a substring in this field, it usually returns about a few thousand rows, and it takes 1.5 to 2 seconds on my quad-core Windows 7 PC:
Obviously I want to minimize this time. Any ideas? Or does the high row count make it very difficult if not impossible? (For tables with only a few thousand rows, this kind of query finishes almost instantaneously on my PC.)Code:SELECT * FROM Table1 WHERE ContactName Like "*james*";
I tried using the InStr() function, but it actually took MORE time (about a fraction of a sec to a full sec) than using the Like operator:
I tried converting the text field to memo field (also with an index), but there was virtually no time difference.Code:SELECT * FROM Table1 WHERE InStr(1, ContactName, "james") <> 0;
Then I upsized the table to SQL Server Express 2008, also created an index for the text field, and ran the same query in passthrough mode (i.e. using SQL Server syntax for queries) and in Access query syntax. To my surprise, running a passthrough query on the upsized table did NOT result in faster processing time than running an Access query on the Access table. And in fact, running an Access query on the upsized table was actually about A SECOND SLOWER than running an Access query on the Access table.
Many years ago, I used SQL Server 6.5 and Access 2.0 (and later Access 97), and there was a MARKED increase in speed when running this kind of substring-finding queries on SQL Server compared to doing it in Access. But now, perhaps because later Access versions have greatly improved (I'm using 2007), SQL Server doesn't seem to offer a speed increase in this type of query.
If a table is small (a few thousand rows), Access can finish the query nearly instantaneously. When I run a query on an address table (2000+ rows) that finds a substring in all the address fields (street, city, state, postal code, country) and then UNION it to another query on another address table (8000+ rows) that also finds the same substring on all its fields, Access is able to produce near-instant result. This was not what I experienced with the older Access versions.
But for a table with half a million rows (and counting), is there any way to speed up such a query? Is it realistic to hope for near-instant result just like with tables that have only a few thousand rows? What concerns me is that my table is growing. Should I just use faster PCs? Or other database products? Are there other database products that perform better with this particular type of query?