Skip to content
Microsoft SQL Server

SQL Server Error 8624

Internal Query Processor Error: could not produce a query plan

Applies to: All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance; specific to the query shape and build
Last technically reviewed 24 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.
Other forms of this message
Different error, same symptom: hints made the plan impossible (8622)
Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query without specifying any hints and without using SET FORCEPLAN.
Error number
8624
Severity
16 (user-correctable error)
State
Not documented by Microsoft (not reproduced here)
Product
Microsoft SQL Server Database Engine
Versions
All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance; specific to the query shape and build
Last reviewed
24 October 2026

What it means

Error 8624 means the Query Optimizer hit an internal problem while building a plan for one statement; it points to a product defect for that query shape, not to a mistake in your data.

Every statement is compiled into a plan before it runs. With 8624 the compilation fails inside the query processor itself: the optimiser reached a state it should never reach, gave up, and asks you to contact Microsoft support. Nothing runs, so no data is changed, and other statements on the instance are not affected. The same statement fails every time it is compiled on that build, which makes the problem reproducible for you even though it is a defect in the product.

Do not confuse it with 8622 (your hints make a plan impossible) or 8623 (the statement is too complex to optimise). 8624 is the "internal error" member of this family: the practical answers are to find the exact statement, check whether a cumulative update fixes it, and change the query shape so that it compiles in the meantime.

Common causes

  • A defect in the query processor for a particular combination of query features (for example complex views, nested subqueries, computed columns, indexed views or unusual join patterns).
  • A build that lacks a cumulative update containing the fix for that defect.
  • A change of database compatibility level or optimiser setting that sends the statement down a different, faulty optimisation path.
  • A statement generated by a tool or ORM in an unusual shape that hand-written queries rarely produce.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

Which build and update level is the instance on?

SELECT SERVERPROPERTY('ProductVersion') AS product_version,
       SERVERPROPERTY('ProductLevel') AS product_level,
       SERVERPROPERTY('ProductUpdateLevel') AS update_level,
       SERVERPROPERTY('ProductUpdateReference') AS update_kb,
       SERVERPROPERTY('Edition') AS edition;
What to look for

Compare the version with the latest cumulative update for your major version on Microsoft's latest updates page. Being several updates behind makes it likely a fix already exists.

Which compatibility level and optimiser settings does the database use?

SELECT name, compatibility_level
FROM sys.databases
WHERE database_id = DB_ID();

SELECT name, value
FROM sys.database_scoped_configurations
WHERE name IN (N'QUERY_OPTIMIZER_HOTFIXES', N'LEGACY_CARDINALITY_ESTIMATION');
What to look for

Note these values for a support case. If the error started right after a compatibility level change, the new optimiser behaviour is a strong suspect.

Is a forced plan attached to the query?

SELECT p.plan_id, p.query_id, p.is_forced_plan,
       p.force_failure_count, p.last_force_failure_reason_desc
FROM sys.query_store_plan AS p
WHERE p.is_forced_plan = 1;
What to look for

Forced plans in Query Store change how statements compile. A forced plan for the failing query is worth testing without, before you open a case.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Isolate the statement and simplify it

Client or network side

Find the single statement that fails (run a batch or procedure piece by piece). Then change its shape until it compiles: split it into steps that stage intermediate results in a temporary table, replace a complex view with the tables it needs, move expressions out of join conditions, or rewrite a nested subquery as a join or APPLY. A different but equivalent shape usually avoids the faulty optimisation path.

-- Instead of one large statement, stage the first step
SELECT o.customer_id, SUM(o.total) AS total_spent
INTO #spend
FROM dbo.Orders AS o
GROUP BY o.customer_id;

SELECT c.name, s.total_spent
FROM dbo.Customers AS c
JOIN #spend AS s ON s.customer_id = c.customer_id;

Try the previous optimiser model for this query only

Client or network side

If the error appeared after a compatibility level change, a documented USE HINT can compile just this statement with an earlier optimiser model while you wait for a fix. Keep it as a temporary, documented workaround.

SELECT c.name, SUM(o.total) AS total_spent
FROM dbo.Customers AS c
JOIN dbo.Orders AS o ON o.customer_id = c.customer_id
GROUP BY c.name
OPTION (USE HINT ('QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_150'));

Apply the latest cumulative update

Changes configuration

Query processor defects are fixed in cumulative updates. Check the latest update for your version, read its fix list, install it on a test instance first and confirm the statement compiles there.

Caution: Installing an update restarts the SQL Server service. Test it, take backups, and schedule a maintenance window.

Open a support case if it persists

Read-only

As the message says, contact Microsoft support when the latest update still fails. Provide the statement, the table and index definitions (scripted without data), the build from diagnostic 1 and the settings from diagnostic 2.

Examples

A statement fails at compile time on an affected build

Shown as documented in the engine message catalogue; not reproduced here. 8624 depends on a defect in a specific build for a specific query shape, and no such repro is known for the current build, so the query below only illustrates where the error appears. The level and state were not observed, so no header is shown.

SELECT c.name, SUM(o.total) AS total_spent
FROM dbo.Customers AS c
JOIN dbo.Orders AS o ON o.customer_id = c.customer_id
GROUP BY c.name;
Result
Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.

How to prevent it

Stay current with cumulative updates, and test them, so that known optimiser defects are fixed before you meet them. Test compatibility level changes against your real workload (Query Store makes before and after comparisons easy) before switching production.

Keep very large generated statements in check: queries built in simpler steps are easier for the optimiser and for people to reason about. See the advanced query optimisation lesson.

Common questions

Is my data or database damaged?

No. The error happens while the statement is being compiled, before it reads or changes anything. Other statements and databases are not affected.

Why does the same query work on another server?

The other server is likely on a different build, compatibility level or optimiser setting, or has different indexes and statistics. Compare the values from the diagnostics.

Will clearing the plan cache help?

Usually not: the statement fails to compile, so there is no cached plan to clear, and it fails again on the next compile. Change the query or the build.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.