x
login about faq Site discussion (meta-askssc)

Query optimization - Please help

While executing a stored procedure, I am getting this error message,

Msg 8621, Level 17, State 2, Line 1 The query processor ran out of stack space during query optimization. Please simplify the query.

more ▼

asked Jan 27 '12 at 10:40 PM in Default

Bins gravatar image

Bins
68 3 3 7

Could you post the query?

Jan 28 '12 at 01:21 AM sp_lock
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

This is a rare internal error (the optimizer contains logic to avoid stack problems in the most common cases). Related errors can occur as a result of having too many EXISTS clauses at the same level, for example. In this case it is likely you have too many nested subqueries, UNIONs or something of that nature.

In any case, the error message is pretty specific about the problem and what you should do about it. Encountering this sort of error is usually a pretty reliable sign that your query is too complex - probably for humans as well as optimizers. Find a way to break the logic into simpler stages.

more ▼

answered Jan 28 '12 at 02:26 AM

SQL Kiwi gravatar image

SQL Kiwi
1k 1 4

I always like the catastrophic failure errors with malformed merge queries

Jan 28 '12 at 02:58 AM Scot Hauder
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x609
x463

asked: Jan 27 '12 at 10:40 PM

Seen: 691 times

Last Updated: Jan 27 '12 at 10:40 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.