Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL server query processor ran out of internal resources

Query:

update mytable 
    set mycol = null
    where id in (
        583048,
        583049,
        ... (50000 more)
)

Message:

The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.

My query is very simple, how should I write it so it works ok?

like image 822
Softlion Avatar asked Oct 18 '11 08:10

Softlion


1 Answers

Insert the list of values into a #temp table then use in on that.

As explained in this answer a large number of IN values can cause it to run out of stack as they get expanded to OR

See also related connect item

like image 141
Martin Smith Avatar answered Nov 06 '22 18:11

Martin Smith