Dual index for setscope.()

Dual index for setscope.()

Postby TimStone » Thu Mar 29, 2018 10:58 pm

I have a report that is taking a very long time to create. The reason is that it uses a filter on one field, and an index on another.

The first field is by NAME, and we want to do the report grouping all records by name, and breaking when the name changes.
The second field for selection is by date, and I use a filter to look only at records within a range of dates.

There might be 500,000 records in the .dbf. If I use a filter, it must go through each record to see if it has a date in the range specified. This is painfully slow

It would be great to use seascape...( ) to limit the records to just those in the date range, but then the break is with each date, not with each name. I tried the index as DTOS( itemdate ) plus item name

Using setscopetop( beginningdate ) and setscopebottom( endingdate ) selects the correct records, but breaks with every day change plus every name change.

Any ideas on how to accomplish this ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Dual index for setscope.()

Postby Jack » Fri Mar 30, 2018 7:49 am

Hi,
In this situation , i make a temorary index with the for clause :
index on NAME to TEST FOR DATE > ... .and. DATE < ....

Good luck
Philippe
Jack
 
Posts: 288
Joined: Wed Jul 11, 2007 11:06 am

Re: Dual index for setscope.()

Postby nageswaragunupudi » Fri Mar 30, 2018 11:10 am

DBFCDX optimizes filters if we have indexes on the fields used in the filter expression. In the above case, we need two index tags

Code: Select all  Expand view  RUN

field NAME,ITEMDATE

INDEX ON UPPER(NAME) TAG NAME   // do not use FIELD-> or ANY ALIAS->
INDEX ON ITEMDATE TAG ITEMDATE  // do not use DTOS()
INDEX ON DELETED() TAG DELETED
 


On a 500,000 record DBF creation of these 3 index tags may take betwen 2 to 3 seconds. In any case this is one time job and these 3 tags would be included in the compound index.
Note: Do not use expressions like DTOS(), FIELD->, etc.

Now, set up the DBF like this:
Code: Select all  Expand view  RUN

field ITEMDATE
local ...


USE YOURDBF NEW SHARED VIA "DBFCDX"
SET ORDER TO TAG NAME
SET FILTER TO ITEMDATE >= {^ 2018/01/01} .AND. ITEMDATE < {^ 2018/03/01} .AND. !DELETED()
GO TOP // this may take between 2 and 3 seconds

// do not forget this next line
TPreview():lListViewHide := .t.  // List view takes hell of a time on large previews

// now create the report

 

You use the dates you want.

RDD sees that the field name used in the filter expression is ITEMDATE. It also checks to see if there is an index on the same name, i.e., ITEMDAE and uses the index to construct a bitmap record list for the optimized filter.

Now the report will run faster
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Dual index for setscope.()

Postby TimStone » Fri Mar 30, 2018 3:52 pm

Thank you for the input. I will work with those today,.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2945
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 50 guests