Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use select... where EXISTS ... ?
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00793069
Message ID:
00793131
Vues:
61
Sergey,

>It's actualy opposite. IN subquery runs once and than result is used by the main query. The EXISTS uses correlated subquery so it has to run for every record in the main query.

This test code would seem to say that IN is doing a lot more work than EXISTS.
create cursor x1 ( i1 i, c1 c(10) )
for i = 1 to 10000
   insert into x1 values ( i, transform( i ) )
endfor
index on i1 tag i1

create cursor x2 ( i1 i, c1 c(10) )
for i = 1 to 10000 step 2
   insert into x2 values ( i, transform( i ) )
endfor
index on i1 tag i1

n1 = 0
n2 = 0

select *, f1() ;
   from x1 where exists ( select i1, f2() from x2 where x2.i1 = x1.i1 ) ;
   into cursor x3

? n1, n2

n1 = 0
n2 = 0

select *, f1() ;
   from x1 where i1 in ( select f3(i1) from x2 ) ;
   into cursor x3

? n1, n2

function f1()
n1 = n1 + 1
return

function f2()
n2 = n2 + 1
return
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform