Azure SQL 数据库 - 查询处理器 运行 内部资源不足,无法生成查询计划

Azure SQL Database - The query processor ran out of internal resources and could not produce a query plan

在 Azure SQL 数据库中,我有一个 MERGE INTO USING(VALUES... 查询,它应该将大约 8000 行值合并到 table。我收到以下错误,当我尝试执行查询时:

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.

数据库的定价层是 S1(20 个 DTU)。我已经尝试将它增加到 S6(400 个 DTU),但我仍然遇到同样的错误。 当我有大约 6000 行值时,我遇到了同样的问题。但是,当时我使用的是 S0(10 个 DTU)并将其增加到 S1(20 个 DTU)以获得更多值。现在看来,提高定价层级也无济于事。我无法简化查询,因为这是一个简单的 MERGE INTO post 部署脚本。我该怎么办?

What should I do?

您必须确保没有太长的 TSQL 查询。您可以有很多查询或长字符串文字,但不能有很长的查询。

所以使用JSON或XML存储在一个字符串字面量中,然后OPENJSON/xml.Nodes去切碎它。

创建临时文件 table 并使用多个 INSERT 语句加载它,然后执行更新插入。