Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is it possible to speed this loop and/or SQL up?
Message
From
18/03/2005 13:39:02
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00997258
Message ID:
00997370
Views:
11
To have this fully optimized, you need a lot of index tags.

where PADR( RZStop.RTE_NO, 6) = lcRteNo ; && Tag on PADR(RTE_NO, 6)
and RZStop.RTE_LET = "A" ; && Tag on RTE_LET
and RZStop.DIRECTN = lcDirectn ; && Tag on DIRECTN
and STR( RZStop.SeqNo, 4) = lcSeqNo ; && Tag on STR(SeqNo,4)
and STR( RZStop.Number, 3) = lcNumber ; && Tag on STR(Number,3)
and PADR( RZStop.Stop, 8) = lcStopNo ; && Tag on PADR(Stop, 8)
and PADR( RZStop.County, 2) = lcCounty ; && Tag on PADR(County, 2)
and not EMPTY( RZStop.TIME) ; && Tag on TIME

But with only ANDs, you have an advantage. VFP will always start from the left, so it will first SELECT the records which match the first comparison, PADR(RZStop.RTE_NO,6) = lcRteNo. So it's important to have a tag on at least the first expression, and to have the first expression select as few records as possible. Then the records which are selcted/filtered out, will be compared against expression no. 2, and so on.

>Hilmar
>
>:-(
>
>Elation turns to deflation. I don't understand. Everything worked fine. I'd commented out the bad code and done the good, like I copied to you (see below). And it worked great. Then I went back and got rid of the old code and ran it again. It's now taking JUST AS LONG and is reporting EVERY record.
>
>Can you see anything wrong with the code below?
>
>Thanks
>
>Terry
>
>Select RZSTOP
>Set Order To RGDSNum   && RTE_NO + RTE_LET + DIRECTN + STR(SEQNO,4) + STR(NUMBER,3)
>Select * From RZStop ;
>	where RZStop.SeqNo = 1 ;
>	and	  EMPTY( RZStop.Time) ;
>	into CURSOR csrSubjRZStop ;
>	Order by Rte_No, Rte_Let, Directn, Number
>lnNoRecs		= _TALLY
>
>Select csrSubjRZStop
>lnInterval		= INT( lnNoRecs / 100)
>If lnInterval < 1
>	lnInterval	= 1
>EndIf
>lnDone			= 0
>Thisform.barProgressBar.Reset( lnNoRecs)
>Thisform.barProgressBar.Visible = .T.
>
>SCAN
>  lcRteNo 	= PADR( RTE_NO, 6)
>  lcDirectn	= DIRECTN
>  lcSeqNo  	= STR( SEQNO, 4)
>  lcNumber	= STR( NUMBER, 3)
>  lcStopNo	= PADR( STOP, 8)
>  lcCounty	= PADR( COUNTY, 2)
>
>  Select DISTINCT TIME from	RZStop ;
>    where 	PADR( RZStop.RTE_NO, 6)    = lcRteNo ;
> 	  and   RZStop.RTE_LET		= "A" ;
> 	  and 	RZStop.DIRECTN		= lcDirectn ;
> 	  and	STR( RZStop.SeqNo, 4)	= lcSeqNo ;
>	  and	STR( RZStop.Number, 3)	= lcNumber ;
>	  and	PADR( RZStop.Stop, 8)	= lcStopNo ;
>	  and	PADR( RZStop.County, 2)	= lcCounty ;
> 	  and	not EMPTY( RZStop.TIME) ;
>    to SCREEN NOCONSOLE	
>  If _TALLY = 0			&& no hits on this stop # - i.e. all Time values empty
>       ...
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform