BUG: Index Not Used on Temp Table Created Inside Procedure

Last reviewed: April 28, 1997
Article ID: Q98860

The information in this article applies to:
  • Microsoft SQL Server version 4.2 for OS/2
  • Microsoft SQL Server, version 4.2
BUG# OS/2: 1679 (4.2)
       NT:  232 (4.2)

SYMPTOMS

Output from SET SHOWPLAN ON reveals that an index (clustered or non-clustered) on a temporary table created inside a stored procedure is not used if the temporary table is queried from a nested procedure (even using a search clause with a very high selectivity). For example:

   procedure P1
      Creates a temporary table including a unique id column
      Populates it with data
      Builds an index on the unique id column
      exec procedure P2
         which SELECT's a single row from the temporary table
         using the unique id in the search clause

Note that this only happens if the outer stored procedure P1 is executed right after the two procedures are created. If the server is shut down and restarted and P1 is executed again, the index will be used from that point onward until the procedures are dropped and recreated.

WORKAROUND

Shut down and restart SQL Server if you run into the above situation. This means that those sites that shut down the server frequently will probably not see this problem. Another workaround is to replace the temporary table with a permanent table.

STATUS

Microsoft has confirmed this to be a problem in SQL Server version 4.2 for OS/2 and Microsoft SQL Server version 4.2. We are researching this problem and will post more information here in the Microsoft Knowledge Base as it becomes available.


Additional query words: Windows NT
Keywords : kbbug4.20 kbprg SSrvServer SSrvWinNT
Version : 4.2 | 4.2 4.2a
Platform : OS/2 WINDOWS


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.

Last reviewed: April 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.