This article was previously published under Q224581
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 54366 (SQLBUG_70)
A query that contains a large number of predicates that are AND-ed together may cause a stack overflow exception. Several thousand conditions are typically required for this problem to occur, and you may reach a limit on the maximum batch size of your query tool before encountering this situation. Many query tools limit batches to 128 KB, whereas SQL Server 7.0 now accepts a batch size as large as (65536 * network packet size).
During optimization, memory for selectivity calculation was being allocated from the stack. This allocation depends on the number of nodes being AND-ed together and can result in a stack overflow.
To work around this problem, rewrite the query to reduce the number of AND conditions required. For example, you may be able to rewrite the query as a join.
Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 1 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
232570INF: How to Obtain Service Pack 1 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.
The SQL Server error log will contain an entry similar to the following when the exception occurs:
1999-04-01 16:22:13.78 spid7 04/01/99 16:22:13 Stack Overflow Dump not possible - Exception c00000fd E at 780348a41999-04-01 16:22:13.78 spid7 Address=780348a4 Exception Code = c00000fd1999-04-01 16:22:13.78 spid7 eax=00000008 ebx=000d6558 ecx=00000008 edx=7804093a1999-04-01 16:22:13.78 spid7 esi=00000001 edi=00000000 eip=780348a4 esp=02f82f381999-04-01 16:22:13.78 spid7 ebp=02f83208 efl=000102031999-04-01 16:22:13.78 spid7 cs=1b ss=23 ds=23 es=23 fs=3b gs=01999-04-01 16:22:13.78 spid7 Input Buffer 393228 bytes -...<query text>...1999-04-01 16:22:31.64 spid7 Error: 0, Severity: 19, State: 01999-04-01 16:22:31.64 spid7 language_exec: Process 7 generated an access violation. SQL Server is terminating this process.