DP
2005-07-14 21:23:04 UTC
I do like to use SELECT-SQL statements yet I just found out that for doing
so I am paying a big price in performance. So what am I doing wrong?
Here is an example. Invoice master file has the master record and is openend
in the Dataenvironment with alias a_mast. the detail file is opened as
a_tran. the mast file is about 80 meg the tran file about 220 meg. I got to
get for a small range of invoices the box count so initialy, Both mast and
tran files have an invno index (and a few more indexes)
SELECT a.invno, a.custno, .........SUM(b.boxcnt) AS boxcnt ;
FROM a_mast a, a_tran b WHERE a.invno = b.invno and a.invno >= ln_beginv AND
a.invno <= ln_endinv AND b.arstat # "V" GROUP BY a.invno ;
INTO TABLE <restablename>
Takes about 9 seconds. (also tried BETWEEN(invno, ln_beginv, ln_endinv) with
no noticable time difference
Time was established through the file created by "SET COVERAGE ..."
Changeing above to
CREATE TABLE <restable> (invno C(8), .......etc etc)
USE restable ALIAS a_res
SELECT a_mast
SET ORDER TO tag invno
SET KEY TO RANGE ln_beginv, ln_endinv
SCAN FOR arstat # "V"
SCATTER MEMVAR
SELECT a_tran
SET KEY TO a_mast.invno
SUM boxcnt TO m.boxcnt
INSERT INTO a_res FROM memvar
SELECT a_mast
ENDSCAN
Took after adding up all the times produced by the COVERAGE FILE between 0.1
and 0.3 Seconds depending on the size of the result set (typically 10-50
invoices)
SO WHY is doing it the "old fashioned" way so much faster? (No noticable
time difference between VFP7.0 or 9.0 on that one)
TIA
so I am paying a big price in performance. So what am I doing wrong?
Here is an example. Invoice master file has the master record and is openend
in the Dataenvironment with alias a_mast. the detail file is opened as
a_tran. the mast file is about 80 meg the tran file about 220 meg. I got to
get for a small range of invoices the box count so initialy, Both mast and
tran files have an invno index (and a few more indexes)
SELECT a.invno, a.custno, .........SUM(b.boxcnt) AS boxcnt ;
FROM a_mast a, a_tran b WHERE a.invno = b.invno and a.invno >= ln_beginv AND
a.invno <= ln_endinv AND b.arstat # "V" GROUP BY a.invno ;
INTO TABLE <restablename>
Takes about 9 seconds. (also tried BETWEEN(invno, ln_beginv, ln_endinv) with
no noticable time difference
Time was established through the file created by "SET COVERAGE ..."
Changeing above to
CREATE TABLE <restable> (invno C(8), .......etc etc)
USE restable ALIAS a_res
SELECT a_mast
SET ORDER TO tag invno
SET KEY TO RANGE ln_beginv, ln_endinv
SCAN FOR arstat # "V"
SCATTER MEMVAR
SELECT a_tran
SET KEY TO a_mast.invno
SUM boxcnt TO m.boxcnt
INSERT INTO a_res FROM memvar
SELECT a_mast
ENDSCAN
Took after adding up all the times produced by the COVERAGE FILE between 0.1
and 0.3 Seconds depending on the size of the result set (typically 10-50
invoices)
SO WHY is doing it the "old fashioned" way so much faster? (No noticable
time difference between VFP7.0 or 9.0 on that one)
TIA