MoinJ said:
I have a query like 'Select distinct class_id from product where col1
like '%...%''. Now, in this particular table i have around 400k
records and the class_id and col1 fields are indexed. This query
takes me around 4-5 mins to execute. Is there any other way to get me
all the distinct class_id's?
Are you using ANSI-compatible SQL, so that the '%' character matches
multiple characters? Normally, in an .mdb file and Jet SQL, the '*'
character is used for that. I only mention that in case you find you
don't get the results you expect.
The problem is with the leading wildcard character. That prevents the
database engine from using the index you have on col1. If the criterion
used just the trailing wildcard, then the index could be used.
If the query
SELECT DISTINCT class_id, col1 FROM PRODUCT
significantly reduces the number of records, then *maybe*
SELECT DISTINCT T.class_ID FROM
(SELECT DISTINCT class_id, col1 FROM PRODUCT) AS T
WHERE T.col1 LIKE '%[foo]%'
would help.
If that doesn't make things any better, then maybe the problem can be
refined somewhat. For example, if you are looking for a specific word
in a space-delimited or punctuated list of words, then maybe the field
can be parsed into words at the time the record is saved, and the
associated words can be saved, indexed, in a related table. In that
case you could write a query that searches the Keywords table and
returns only products that match the word you're looking for.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)