Microsoft KB Archive/232926

From BetaArchive Wiki
Knowledge Base


FIX: Complex Query Containing Redundant Logic May Cause Access Violation

Article ID: 232926

Article Last Modified on 3/14/2006



APPLIES TO

  • Microsoft SQL Server 7.0 Standard Edition



This article was previously published under Q232926

BUG #: 54578 (SQLBUG_70)

SYMPTOMS

A complex query that includes logically redundant code may cause a handled access violation (AV) when the Query Optimizer attempts to remove the unnecessary logic at compile time.

WORKAROUND

To work around this problem, avoid using logical redundancy in complex SQL queries.

STATUS

Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0


For more information, contact your primary support provider.

MORE INFORMATION

For example, the following query can be said to contain logically redundant code:

select stor_id, isnull(isnull(qty,0),0) quantity
   from pubs..sales
   where ord_num = 'P3087a'
                

The outer ISNULL() function is unnecessary because the nested ISNULL() will never return NULL. In fact, neither ISNULL() function is necessary because the qty column of the sales table does not permit NULL values.

The Query Optimizer in SQL Server 7.0 attempts to make queries more efficient by eliminating unnecessary logic like that shown above (a technique referred to as "Folding"). It is during this phase of optimization with a highly complex query that SQL Server may encounter the AV described in this article.

Keywords: kbbug kbfix KB232926