Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Fast select becomes slow in form
Message
From
30/10/2003 08:45:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
29/10/2003 19:18:00
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00843940
Message ID:
00844474
Views:
20
>>>I have two tables, PERSON (21000 records, index on Person_Id), PERSON_SOURCE (22500 records, index on Person_id, Source_id), on which I do the following SELECT:
>>>
>>>SELECT DISTINCT Person.*;
>>> FROM cavr!person_source INNER JOIN cavr!person ;
>>> ON Person_source.person_id = Person.person_id;
>>> WHERE Person_source.source_id = '00031' INTO CURSOR XXXX

>>>
>>>I run this SELECT in the command window and it takes about 0.3 seconds.
>>>
>>>When I run this in the INIT of a form:
>>>
>>>lnStartTime = SECONDS()*1000
>>>
>>>SELECT DISTINCT Person.*;
>>> FROM cavr!person_source INNER JOIN cavr!person ;
>>> ON Person_source.person_id = Person.person_id;
>>> WHERE Person_source.source_id = '00031' INTO CURSOR XXXX
>>>
>>>WAIT WINDOW 'done loading all people' +STR(SECONDS()*1000-lnStartTime)

>>>
>>>
>>>it takes almost 5 seconds. Any reason why this could happen?
>>>
>>>TIA,
>>>
>>>Ken
>>
>>As Larry said it might be exclusivity.
>>Another reason might be you're not using the same database and tables from IDE and form.
>>ie: In IDE you have a set path to local data folder but in form you've a DE or from load you use a network data folder.
>>
>>PS: What's the person_source's contribution to this query other than checking if exists there too ?
>>If you don't need it really do not use distinct as it slows down the query.
>>Cetin
>
>Cetin,
>
>Checked the exclusivity and they are the same in both IDE and form.
>
>I also doubled checked and the tables are both running from the same local folder.
>
>I do need to get a distinct list (Person-Person_Source 1:M). I removed the distinct and replaced with a Group By Person_id and it now runs fine and fast. (so problem solved at one level)
>
>Still I am baffled why the same query in the command window and form have such drastic time differences under (apparently) the same enviornment conditions just because of the Distinct.
>
>Ken

If the environment and tables are really same then I'm afraid I've no idea why one might be slower.

In my first reply I see that I mistakenly saw all as ID (missed last one was source_id).
I don't suggest group by to make it faster. Saying (Person-Person_Source 1:M) you mean in person table there is only one record for a given id ? If so why bother with a join or group by/distinct ?
Wouldn't this work the same way and be faster - group by trick would have problems when same code goes to VFP8 :
lnStartTime = SECONDS()*1000

SELECT * ;
 From cavr!person ;
 where Person.person_id in ;
 ( select person_id ;
 FROM cavr!person_source ;
 WHERE Person_source.source_id = '00031') ;
 INTO CURSOR XXXX

WAIT WINDOW 'done loading all people' +STR(SECONDS()*1000-lnStartTime)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform