Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Slow SQL Statement
Message
 
 
To
01/12/2005 22:51:43
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01074021
Message ID:
01074619
Views:
21
This message has been marked as the solution to the initial question of the thread.
>That works a lot better. What makes the difference?

There're 3 ways you can write your select: IN, EXISTS and JOIN. The SYS(3054) doesn't show any difference in optimization between IN and EXISTS but obviously it's processed differently by VFP SQL Engine. It's always a good idea to try all 3 to see wich one is faster in your particular case.
CLEAR
CLOSE DATABASES 
SYS(3054,11) 

CREATE CURSOR t1 ( Field11 C(3), Field12 C(10))
INDEX ON Field11 TAG Field11
CREATE CURSOR t2 ( Field21 C(3), Field22 C(10))
INDEX ON Field21 TAG Field21

?
? "IN"
SELECT t1.* ;
	FROM t1 ;
	WHERE Field11 NOT IN ( SELECT Field21 FROM t2) ;
	INTO CURSOR crs1

?
? "EXISTS"
SELECT t1.* ;
	FROM t1 ;
	WHERE NOT EXISTS ( SELECT * FROM t2 WHERE t1.Field11 = t2.Field21) ;
	INTO CURSOR crs2

?
? "JOIN"
SELECT t1.* ;
	FROM t1 ;
	JOIN t2 ON t1.Field11 = t2.Field21 ;
	WHERE t2.Field21 IS NULL ;
	INTO CURSOR crs3

SYS(3054,0) 
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform