Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What's the differences between nested and sub join query
Message
From
07/05/2004 07:50:22
 
 
To
07/05/2004 04:31:51
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00901574
Message ID:
00901878
Views:
17

In fact, Visual FoxPro SQL engine executes query #1 and query #2 as if they both were written using form #3. It ignores the nesting and applies special logic to determine which two tables should be joined first to achieve the best performance.
....


This logic is not very good.

A simple example:
- Table1 with index
- Table2 without index

VFP choice Table1 and build a temp index for Table2 when:
RECCOUNT('Table1')*(~2)<=RECCOUNT('Table2')
otherwise it use the Table2 index for do the join operation.

but:
- build a temp index for Table2 require more time ( >2x ) that scan Table2

A exampling code:
CLEAR
SET DELETED ON

CURSORSETPROP("Buffering",1,0)
CREATE CURSOR c1 ( f1 I DEFAULT RECCOUNT())

n=2000000
FOR i=m.n-99 TO m.n
INSERT INTO c1 VALUES (m.i)
NEXT
INDEX ON f1 TAG tagf11

CREATE CURSOR c2 ( f1 I DEFAULT RECCOUNT())
FOR k=0 TO m.n
	APPEND BLANK
NEXT

DELETE ALL WHILE _TALLY*2<RECCOUNT() && first 50% are old deleted records

SYS(3054,11)
tm1=SECONDS()
SELECT * FROM c2 JOIN c1 ON c2.f1 = c1.f1 INTO CURSOR TTTT
* SCANLOOP(c1)*SEEKLOOP(tempindex(c2))
? "VFP",SECONDS()-tm1,_TALLY

tm1=SECONDS()
SELECT * FROM FORCE c2 JOIN c1 ON c2.f1 = c1.f1 INTO CURSOR TTTT
* SCANLOOP(c2)*SEEKLOOP(tagf11(c1))
? "FORCE",SECONDS()-tm1,_TALLY

? '**************'
? 'with a filter condition on c1'
? '**************'
? ' condition is a 1% filtered condition'
? '**************'
tm1=SECONDS()
SELECT * FROM c2 JOIN c1 ON c2.f1 = c1.f1 AND c1.f1=m.n INTO CURSOR TTTT
* SCANLOOP(c1)*SEEKLOOP(tempindex(c2))
? "VFP",SECONDS()-tm1,_TALLY

tm1=SECONDS()
SELECT * FROM FORCE c2 JOIN c1 ON c2.f1 = c1.f1 AND c1.f1=m.n INTO CURSOR TTTT
* SCANLOOP(c2)*SEEKLOOP(tagf11(c1))
? "FORCE",SECONDS()-tm1,_TALLY

? '**************'
? ' condition is a 0% filtered condition, and not start the join operation'
? '**************'
tm1=SECONDS()
SELECT * FROM c1 c11 JOIN c2 ON c11.f1 = c2.f1 AND c11.f1=0 INTO CURSOR TTTT
* SCANLOOP(c1)*SEEKLOOP(tempindex(c2))
? "VFP",SECONDS()-tm1,_TALLY

tm1=SECONDS()
SELECT * FROM FORCE c2 JOIN c1 c11 ON c11.f1 = c2.f1 AND c11.f1=0 INTO CURSOR TTTT
* SCANLOOP(c2)*SEEKLOOP(tagf11(c1))
? "FORCE",SECONDS()-tm1,_TALLY
This choice is not clear for me.

For me the best choice is to minimize the number of temp index
( this reduce the temp space required and the cache swapping ),
and like seconds condition to compare the RECCOUNT() of the join members.

You can found a example where :
RECCOUNT() comparison logic is best of minimizing the temp index builded ?

Thanks

Fabio
Previous
Reply
Map
View

Click here to load this message in the networking platform