Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Counting Child Records
Message
From
08/05/2002 06:47:02
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00653805
Message ID:
00653896
Views:
24
I do seem to recall that a SET RELATION is indeed very fast. Looks like the test results do indeed prove your point.

>>I'd be interested in your test results. Now that I think about it a bit more, the FOR condition should be Rushmore optimizable so there may not be a big difference.
>
>TestSpeed.prg
>local lnMax, lnMin, lnI, lnK, lnParent
>if not file('Parents.dbf')
>	create table parents (ParentID I)
>	index on ParentID tag ParentID
>	create table Children (ParentID I, ChildID I)
>	index on ParentID tag ParentID
>	rand(-1)
>
>	lnMax=1
>	lnMin = 10000
>** Create test tables
>	for ln=1 to 500
>		lnParent = int((m.lnMax - m.lnMin + 1) * rand( ) + m.lnMin)
>		if not indexseek(m.lnParent,.f.,'Parents','ParentID')
>			insert into parents ;
>				values (m.lnParent)
>			for lnK=1 to 1000
>				insert into Children ;
>					values (m.lnParent,m.lnK)
>			next
>		endif
>	next
>endif
>local lnSec, lnRecno, lnChildren
>select Children
>set order to ParentID
>select parents
>set relation to ParentID into Children
>lnSec=seconds()
>scan && Parent
>	lnParent = ParentID
>	select Children
>	lnRecno=recno()
>	count for ParentID = m.lnParent to lnChildren
>	goto m.lnRecno && Restore record pointer
>endscan
>?seconds()- m.lnSec
>go top && in parents
>lnSec=seconds()
>scan && Parent
>	lnParent = ParentID
>	select Children
>	lnRecno=recno()
>	seek m.lnParent
>	count while ParentID = m.lnParent to lnChildren
>	goto m.lnRecno && Restore record pointer
>endscan
>?seconds()- m.lnSec
>
>Results:
>First run: 1.106 - 1.854
>Second run: 0.448 - 1.868
>Third run: 0.490 - 1.846
>
>E.g. count while seems to be much slower.
>
>May be it's not a really good test, what do you think?
Previous
Reply
Map
View

Click here to load this message in the networking platform