Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need index suggestions to optimize the speed

Status
Not open for further replies.

fredgmain

IS-IT--Management
Oct 30, 2009
22
MY
Hi all,

I have the following partial criteria for the SELECT statement. It involves the following fields ("senderemailaddress","cc","to"). The query definitely not very effective because it is very slow when I created 100,000 test records. But I must use AT() or $ to match the string within the fields.

Please give me suggestions on the indexing or alter the following partial query to improve the performance.

cond = cond + "((AT('@abc.com',senderemailaddress) > 0 AND cc = 'abcoutbox@nrsint.com' AND to = 'abcinbox@nrsint.com') ;
OR ;
(AT('@abc.com',senderemailaddress) = 0 AND AT('@abc.com',to) = 0)) and " ;

Thanks in advance.
Fred
 
If that string would be from the beginning of the query, then you could have used LIKE clause which is Rushmore optimizable, e.g.

SenderMailAddress LIKE '@abs.com%' and ...

Unfortunately, it seems like you need to search at the end of the field.

Perhaps you can create an index on last 8 characters of e-mail address and search for the last 8 chars = the string to search. This would be quick then.
 
Fred,

If you goal is to run a query on the domain part of an email address (that is, the part after the "@"), one possibility would be to split the address into two separate fields: the part before the "@ and the part after. You could then create an index on the second of those, and the query would be fully optimised.

The disadvantage is that, whenever you want to reference an email address elsewhere in your app, you would have to deal with two fields rather than one.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mark & Mike,

Thanks for you suggestions. I will first try to index the last 8 characters and check the performance. If that is still slow, I have to split the field or create additional fields for performance.

Thanks and Regards,
Fred

 
hybrid to Mike's suggestion
retain the senderemailaddress as is and add a fromdomain field for indexing


Steve Bowman
Independent Technology, Inc.
CA, USA
 
You could make that index more intelligent: Instead of indexing RGHT(field,8), index on this:

Code:
INDEX ON PADR(substr(senderemailaddress,at('@',senderemailaddress)+1),Len(senderemailaddress)) TAG senderdom
INDEX ON PADR(substr(to,at('@',to)+1),Len(to)) TAG todomain

Then you can do

Code:
SELECT ... WHERE ((PADR(substr(senderemailaddress,at('@',senderemailaddress)+1),Len(senderemailaddress)) = 'abc.com') AND cc = 'abcoutbox@nrsint.com' AND to = 'abcinbox@nrsint.com') OR (NOT (PADR(substr(senderemailaddress,at('@',senderemailaddress)+1),Len(senderemailaddress)) = 'abc.com') AND NOT (PADR(substr(to,at('@',to)+1),Len(to)) = 'abc.com'))

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top