KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q117408: Query Speed Is Slower with ORDER BY Clause

Article: Q117408
Product(s): Microsoft FoxPro
Version(s): MACINTOSH:2.5x,2.6; MS-DOS:2.5x,2.6x; WINDOWS:2.5x,2.6x,3.0
Operating System(s): 
Keyword(s): 
Last Modified: 10-FEB-2000

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft FoxPro for Macintosh, versions 2.5x, 2.6 
- Microsoft Visual FoxPro for Windows, version 3.0 
- Microsoft FoxPro for Windows, versions 2.5x, 2.6x 
- Microsoft FoxPro for MS-DOS, versions 2.5x, 2.6x 
-------------------------------------------------------------------------------

SUMMARY
=======

A query with an ORDER BY clause will be considerably slower than the same query
without the ORDER BY clause.

MORE INFORMATION
================

The query times will vary based on the size of the database queried and the
hardware involved. However, the times illustrated below show a considerable
difference between querying with and without an ORDER BY clause.

When an ORDER BY clause is used, a new database is being generated by the query.
Display status will show "table in use" as a table with a .TMP extension.
Without the ORDER BY clause, the original database is used to generate the
cursor query. Display status will show "table in use as the original table."

Steps to Reproduce Behavior
---------------------------

1. Open a database with 10,000 records or more and open an RQBE window.

2. Make sure an index exists for the field on which the query will be based, and
  then query without an ORDER BY clause. (In our test with a 10,000-record
  database, the query time shown in the status bar was 0.10 seconds.)

3. Query with an ORDER BY clause based on a different field. (In our test on the
  same database, the query time shown in the status bar was 17.68 seconds.)

Additional query words: VFoxWin FoxMac FoxDos FoxWin 2.50 2.50a 2.50b 2.50c 2.60 2.60a relational query by example

======================================================================
Keywords          :  
Technology        : kbHWMAC kbOSMAC kbVFPsearch kbAudDeveloper kbFoxproSearch kbZNotKeyword3 kbVFP300
Version           : MACINTOSH:2.5x,2.6; MS-DOS:2.5x,2.6x; WINDOWS:2.5x,2.6x,3.0

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.