efcore: SqlServer Error 8623 The query processor ran out of internal resources and could not produce a query plan

When doing the following sql with ids containing more than 16000 ids:

db.Table.Where(p=>p.ids.Contains(p.ID)).ToList();

I’m receiving the following exception:

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.

I was expecting Sql Server to be able to filter the results correctly.

Is it possible this query into multiple times to avoid this error?

Further technical details

EF Core version: 2.01 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 7 IDE: Visual Studio 2017 15.5 Sql Server: 2008 SP2

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

@smitpatel & @ErikEJ For a better understanding of what is happening: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/in-transact-sql#remarks

updated the link to specific section