Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inefficient query
Message
De
25/01/2007 09:45:05
 
 
À
24/01/2007 16:31:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01188966
Message ID:
01189139
Vues:
12
>
>		Select a.wcode, Min(d.st+d.cnty+d.unit) As collector, b.display_loan, d.acct, b.borrowername, a.branch, Min(b.Id) As loan_id, Min(a.Id) As property_id ;
>			from mtgproperty a , ;
>			mtgloan b, ;
>			mtgacctnum d;
>			INTO Cursor temp ;
>			where (a.client_id == users.client_id);
>			AND (b.Id == a.loan_id );
>			and (a.Id == d.property_id ) ;
>			AND Iif(!Empty(lcFromAccount),(Padl(Alltrim(b.loan),20,[0]) >= Padl(Alltrim(lcFromAccount),20,[0])),.T.);
>			AND Iif(!Empty(lcToAccount),(Padl(Alltrim(b.loan),20,[0]) <= Padl(Alltrim(lcToAccount),20,[0])),.T.);
>			AND Iif(!Empty(lcContract),(Alltrim(b.contract) == Alltrim(lcContract)),.T.);
>			AND Iif(!Empty(lcAddress),(Alltrim(a.situs_addr1) == Alltrim(lcAddress)),.T.);
>			AND Iif(!Empty(lcName),(Alltrim(b.borrowername) == Alltrim(lcName)),.T.);
>			AND Iif(!Empty(lcParcel),(Alltrim(d.acct) == Alltrim(lcParcel)),.T.);
>			AND Iif(!Empty(lcCounty),(Alltrim(a.county) == Alltrim(lcCounty)),.T.);
>			AND Iif(!Empty(lcBranch),(Alltrim(a.branch) == Alltrim(lcBranch)),.T.);
>			AND Iif(!Empty(lcSt),(Alltrim(a.st) == Alltrim(lcSt)),.T.);
>			AND Iif(!Empty(lcCollector),(d.st+d.cnty+d.unit == lcCollector),.T.);
>			GROUP By  1, 3, 4, 5, 6
>
>
A few suggestions:

1) SYS(3054) will tell you how VFP is optimizing the query (or not).

2) Move the join conditions into the FROM clause to distinguish them from the filter conditions.

3) Don't use single letter aliases in queries. While the bugs around this have been fixed, it's just tempting fate.

4) If this is a recent version, use EVL() instead of the IIF()'s. That should be a little faster.

5) Unless the id fields are character, you don't gain anything by using == instead of =.

Tamar
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform