DOCUMENT:Q191172 27-JUL-2001 [foxpro] TITLE :FIX: Performance Degradation with Repeated SQL SELECTs PRODUCT :Microsoft FoxPro PROD/VER:WINDOWS:5.0,5.0a,6.0 OPER/SYS: KEYWORDS:kbDatabase kbSQL kbvfp500 kbvfp500aBUG kbvfp500bug kbvfp600 kbvfp600bug kbVS600sp3fix k ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a, 6.0 ------------------------------------------------------------------------------- SYMPTOMS ======== There is a slow degradation of Visual FoxPro's performance with repeated execution of SQL SELECT statements. The results returned by SYS(1016) and the time required to process SQL Select statements gradually increase with repeated execution of SQL Select statements. CAUSE ===== This is caused by repeated execution of an SQL SELECT statement containing WHERE and OR clauses, as in the following example: SELECT * ; FROM ; WHERE .T. ; OR .T. ; INTO CURSOR TEST RESOLUTION ========== Here are three ways to workaround this problem: - Use the HAVING clause in the SQL Select statement rather than the WHERE clause. For example: SELECT DISTINCT * ; FROM
; HAVING ; OR ; OR ; ORDER BY ; INTO CURSOR - Use the INLIST() function in the SQL Select statement, in place of the OR. For example: SELECT DISTINCT * ; FROM
; WHERE INLIST(eExpression,, ; , ; , ; ORDER BY ; INTO CURSOR ; - Use a UNION for each OR condition. For example: SELECT DISTINCT * ; FROM
; WHERE ; UNION SELECT DISTINCT * ; FROM
; WHERE ; UNION SELECT DISTINCT * ; FROM
; WHERE ; INTO CURSOR STATUS ====== Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual Studio 6.0 Service Pack 3. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base: Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed MORE INFORMATION ================ The amount by which the result returned by SYS(1016) increases is dependent on the version of Visual FoxPro and the number of ORs contained in the SQL Select statement. With Visual FoxPro 5.0, the amount of increase in the result returned by SYS(1016) is 16 times the number of ORs contained in the SQL Select statement. In Visual FoxPro 6.0, the amount of increase in the result returned by SYS(1016) is 24 times the number of ORs contained in the SQL Select statement. This behavior does not occur with Visual FoxPro 3.0. Steps to Reproduce Behavior --------------------------- 1. Create a program named Test.prg using the following code: CLOSE ALL CLEAR ALL OPEN DATABASE "c:\program files\devstudio\vfp\samples\data\testdata" startval=VAL(SYS(1016)) FOR i=1 TO 10 SELECT * FROM customer WHERE .T. OR .T. INTO CURSOR test endval=VAL(SYS(1016)) ? ALLTRIM(STR(endval)) + ; " - " + ALLTRIM(STR(startval)) + ; " = " + ALLTRIM(STR(endval-startval)) startval=endval NEXT 2. From the Command prompt, type the following: DO TEST 3. Observe that the startval and endval increase and that the difference between endval and startval is 16 in Visual FoxPro 5.0 and 24 in Visual FoxPro 6.0. (c) Microsoft Corporation 1999, All Rights Reserved. Contributions by John Desch, Microsoft Corporation Additional query words: ====================================================================== Keywords : kbDatabase kbSQL kbvfp500 kbvfp500aBUG kbvfp500bug kbvfp600 kbvfp600bug kbVS600sp3fix kbGrpDSFox kbSQLProg Technology : kbVFPsearch kbAudDeveloper kbVFP500 kbVFP600 kbVFP500a Version : WINDOWS:5.0,5.0a,6.0 Issue type : kbbug Solution Type : kbfix ============================================================================= 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 2001.