Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimize this query, can it be done?
Message
De
20/07/2009 17:16:08
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Optimize this query, can it be done?
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01413457
Message ID:
01413457
Vues:
143
On systems with hundreds of thousands of records, these two queries take 17 seconds. Can anyone see a way to optimize them without changing the results? It's a strange query which was modified in the past to add the >0 section because sqlserver was returning errors without out it.
lcParent_Id = ALLTRIM(NVL(parent_id,''))  && 
lcChild_Id = ALLTRIM(NVL(child_id,''))

TEXT TO lcSQL NOSHOW PRETEXT 15 TEXTMERGE

      SELECT tw.* FROM tow AS tw

       INNER JOIN

            (SELECT inhistory.child_id FROM inhistory

             WHERE  inhistory.child_id = '<<lcchild_id>>'

             OR inhistory.parent_id = '<<lcchild_id>>'

             OR (LEN(inhistory.child_id)>0 AND inhistory.child_id = '<<lcParent_Id>>')

             OR (LEN(inhistory.parent_id)>0 AND inhistory.parent_id = '<<lcParent_Id>>')) qry1

      ON tw.child_id = qry1.child_id WHERE tw.towid > 0 AND tw.vehi_id > 0 AND canccode='    '

ENDTEXT

IF SQLProc("SP",m.lcSQL,,,"cTowCT") > 0 && Return any Tow records

      TEXT TO lcSQL2 NOSHOW PRETEXT 15 TEXTMERGE

            SELECT qry2.towid, vh.* FROM vhtable as vh 

      INNER JOIN

            (<<m.lcSQL>>) qry2

            ON vh.vehi_id = qry2.vehi_id ORDER BY vh.vehi_id

      ENDTEXT

      IF SQLProc("SP",m.lcSQL2,,,"cvhtableIn") > 0 && Return the vhtable Records

            SELECT cvhtableIn

      ENDIF

ENDIF
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform