Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Anders Altberg
  Where is Anders Altberg?
 Uppsala
 Sweden
 Anders Altberg
 To: Binod Binani
  Where is Binod Binani?
 Kolkata
 India
 Binod Binani
Subject: RE: SQL-Speed issue
Thread ID: 179931 Message ID: 179941 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Tuesday, June 24, 2008 1:38:49 PM         
   



> Hello Every Experts,
>
> This time for me "SPEED DOES MATTER". I have folldowing Qry which works fine
> at development time considering apprx 2000 transaction. Taking less then 3 secenods.
>
> While at Client site with apprx 80000 transaction it consumes about 30 minutes.
>
> what could be done to more optimize.
>
>
** sreg.prg: For Sales Register
> ** Data base : \DATA9\AC_BILLS.DBC
> ** Cbj_srl: Doc_Date,Doc_no
> ** Cbj    : Amt,Ac_code,Vat_code
> ** Items  : item_code,Qnty,Rates,Adjst_amt
> 
> ** Memory Variables **
> store Date() to F_DATE,t_date
> 
> F_date=ctod('01.04.2008')
> t_date=date()
> 
> *CLOSE ALL
> **OPEN DATABASE \retail\data9\ac_bills.dbc
> 
> STORE TIME() TO start_time
> 
> SELECT cbj_srl.doc_Date,;
> 	   cbj_srl.doc_no,;
> 	   cbj_srl.vch_type,;
> 	   cbj_srl.link2cbj,;
> 	   cbj.ac_code,;
> 	   items.item_code,;
> 	   items.Qnty,;
> 	   items.pty_code,;
> 	   items.rates,;
> 	   items.adjst_amt,;
> 	   allt(item_mst.item_name)+"~~"+Item_mst.Makes as Iname,;
> 	   allt(led_mst.led_name) as pty_name;
> 	   FROM cbj_srl, Items, item_mst, led_mst ,cbj ;
> 	   WHERE Cbj_srl.vch_type ='SALES' AND ;
> 	         cbj_srl.link2cbj = items.link2cbj AND ;
> 	         cbj_srl.link2cbj = cbj.link2cbj AND ;
> 	         items.item_code = item_mst.item_codes AND ;
> 	         items.pty_code = led_mst.led_code AND ;
> 	         BETWEEN(cbj_srl.doc_date, m.f_date, m.t_date);
> 	         Order by cbj_srl.doc_date, cbj_srl.doc_no ;
> 	         INTO TABLE Sreg
> 	         
> STORE TIME() TO End_time
> 
> SELECT Sreg
> messagebox(RECCOUNT())
> ** eof() PRG  

>
>
> Thanx in Advance
>
>
>
>
> *Exchange of $1 Create only $1, But Exchage of one Ideas Makes different two Ideas*

Hi Binod,

You must have indexes on the columns in the WHERE clase for VFP to be able to optimize query performance. See SYS(3054) in VFP's Help.
SELECT Cbj_srl
INDEX ON vch_type TAG vch_type
SELECT cbj_srl
INDEX ON doc_date TAG doc_date

All keyfields used for joining table should be indexed.
SET DELETED ON/OFF can make a difference.

VFP decides in what order to open and join the tables as it builds the intermediate sets of data,
but it can be worthwhile to arrange the joins so that you get small dataset quickly.
Suppose the join between cbj and cbj_slr cuts the final output down by 70 procent, then it would likely be advantageous to perform that join very early. Place it at the top.

You could modernize your code.
If you created that query in the Query Designer of VFP9 you would have code like this:

SELECT cbj_srl.doc_Date,;
	   cbj_srl.doc_no,;
	   cbj_srl.vch_type,;
	   cbj_srl.link2cbj,;
	   cbj.ac_code,;
	   items.item_code,;
	   items.Qnty,;
	   items.pty_code,;
	   items.rates,;
	   items.adjst_amt,;
	   allt(item_mst.item_name)+"~~"+Item_mst.Makes as Iname,;
	   allt(led_mst.led_name) as pty_name;
	   FROM cbj_srl ;
	JOIN Items ON cbj_srl.link2cbj = items.link2cbj 
	JOIN item_mst ON items.item_code = item_mst.item_codes 
	JOIN led_mst ON items.pty_code = led_mst.led_code 
	JOIN cbj ON cbj_srl.link2cbj = cbj.link2cbj 
	   WHERE Cbj_srl.vch_type ='SALES' 
	   AND cbj_srl.doc_date BETWEEN m.f_date AND m.t_date;
	   Order by cbj_srl.doc_date, cbj_srl.doc_no ;
	         INTO TABLE Sreg


ENTIRE THREAD

SQL-Speed issue Posted by Binod Binani @ 6/24/2008 1:03:56 PM
RE: SQL-Speed issue Posted by Stefan Wuebbe @ 6/24/2008 1:34:48 PM
RE: SQL-Speed issue Posted by Anders Altberg @ 6/24/2008 1:38:49 PM
RE: SQL-Speed issue Posted by Josip Zohil @ 6/24/2008 2:52:41 PM
RE: SQL-Speed issue Posted by Frank Cazabon @ 6/24/2008 3:03:40 PM
RE: SQL-Speed issue Posted by tushar @ 6/24/2008 5:42:29 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/26/2008 8:13:13 AM
RE: SQL-Speed issue Posted by tushar @ 6/26/2008 8:39:29 AM
RE: SQL-Speed issue Posted by Anders Altberg @ 6/26/2008 11:14:54 AM
RE: SQL-Speed issue Posted by Binod Binani @ 6/26/2008 2:30:20 PM
RE: SQL-Speed issue Posted by tushar @ 6/26/2008 2:59:00 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/26/2008 5:36:31 PM
RE: SQL-Speed issue Posted by tushar @ 6/26/2008 6:42:11 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/27/2008 8:34:27 AM
RE: SQL-Speed issue Posted by Josip Zohil @ 6/27/2008 12:18:10 PM
RE: SQL-Speed issue Posted by tushar @ 6/27/2008 7:14:26 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/27/2008 7:14:43 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/28/2008 8:46:20 AM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/28/2008 1:42:07 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/28/2008 2:00:18 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/28/2008 2:48:58 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/28/2008 3:25:35 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/28/2008 9:31:53 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/26/2008 10:34:57 PM
RE: SQL-Speed issue Posted by tushar @ 6/27/2008 1:15:43 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/27/2008 7:04:34 PM
RE: SQL-Speed issue Posted by tushar @ 6/27/2008 7:11:21 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/27/2008 8:56:43 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/27/2008 7:17:28 PM
RE: SQL-Speed issue Posted by tushar @ 6/27/2008 7:21:34 PM
RE: SQL-Speed issue Posted by Josip Zohil @ 6/26/2008 6:08:04 PM
RE: SQL-Speed issue Posted by Anders Altberg @ 6/26/2008 6:22:44 PM
RE: SQL-Speed issue Posted by Josip Zohil @ 6/27/2008 12:53:40 PM
RE: SQL-Speed issue Posted by Pete Sass @ 6/28/2008 1:33:14 AM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/28/2008 1:43:25 PM
RE: SQL-Speed issue Posted by Binod Binani @ 6/28/2008 2:11:48 PM
RE: SQL-Speed issue Posted by Josip Zohil @ 6/29/2008 7:30:28 AM
RE: SQL-Speed issue Posted by Binod Binani @ 6/29/2008 8:51:50 AM
RE: SQL-Speed issue Posted by Anders Altberg @ 6/28/2008 11:54:15 AM
RE: SQL-Speed issue Posted by Patrick McGreevy @ 6/29/2008 12:18:34 AM
RE: SQL-Speed issue Posted by Binod Binani @ 6/29/2008 8:43:24 AM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/29/2008 4:17:56 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/29/2008 4:17:10 PM
RE: SQL-Speed issue Posted by Patrick McGreevy @ 6/29/2008 8:32:03 PM
RE: SQL-Speed issue Posted by Mike Yearwood @ 6/30/2008 2:11:45 AM