Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ORDER BY is slow
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00631051
Message ID:
00631054
Views:
26
>Hi everyone,
>
>I need to do a SELECT DISTINCT from a table with about 100,000 records to populate the top level nodes of a treeview control, with the user able to select different fields to populate the treeview with.
>
>I have index tags on the fields that the user can specify and UPPER() of the same fields.
>
>The following query takes about 36 seconds:
>
>
SELECT DISTINCT &lcField FROM DocsMast ;
>   ORDER BY &lcField ;
>   INTO CURSOR TreeInit
>
>The following code runs in less than 1 second:
>
>
SELECT DISTINCT &lcField FROM DocsMast ;
>  INTO CURSOR TreeInit
>
>INDEX ON UPPER(&l_cField) TAG Sorted
>
>Why? Is there a way to get the result ordered without having to do a manual INDEX or wait for 30+ seconds? I gather that VFP is applying the ORDER BY to the entire table before applying the DISTINCT clause.

How about select &lcField group by &lcField instead of select distinct?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform