将表添加到Linq到SQL DBML时,SQL Azure DTU Spike

时间:2017-09-21 19:39:08

标签: visual-studio linq-to-sql azure-sql-database

最近我注意到当我将表拖放到Visual Studio中的DBML文件时,我收到来自SQL azure DB的通知,我的DTU百分比跳到100%。是否有任何建议或提示可以防止这种情况发生(除了撞击我的DTU)?

拖放时生成的查询导致峰值如下:

(@_msparam_0 nvarchar(4000),@_msparam_1 nvarchar(4000),@_msparam_2 nvarchar(4000))SELECT
db_name() AS [Database_Name],
SCHEMA_NAME(tbl.schema_id) AS [Table_Schema],
tbl.name AS [Table_Name],
cstr.name AS [ForeignKey_Name],
cfk.name AS [Name],
fk.constraint_column_id AS [ID],
crk.name AS [ReferencedColumn]
FROM
sys.tables AS tbl
LEFT OUTER JOIN sys.periods as periods ON periods.object_id = tbl.object_id
LEFT OUTER JOIN sys.tables as historyTable ON historyTable.object_id = tbl.history_table_id
INNER JOIN sys.foreign_keys AS cstr ON cstr.parent_object_id=tbl.object_id
INNER JOIN sys.foreign_key_columns AS fk ON fk.constraint_object_id=cstr.object_id
INNER JOIN sys.columns AS cfk ON fk.parent_column_id = cfk.column_id and fk.parent_object_id = cfk.object_id
INNER JOIN sys.columns AS crk ON fk.referenced_column_id = crk.column_id and fk.referenced_object_id = crk.object_id
WHERE
(cstr.name=@_msparam_0)and((SCHEMA_NAME(tbl.schema_id)=@_msparam_1 and tbl.name=@_msparam_2))
ORDER BY
[Database_Name] ASC,[Table_Schema] ASC,[Table_Name] ASC,[ForeignKey_Name] ASC,[ID] ASC
OPTION (FORCE ORDER)

1 个答案:

答案 0 :(得分:2)

我与一些Microsoft工程师分享了这个帖子,结果提出了以下建议:

更新以下统计信息:

 UPDATE STATISTICS sys.syscolpars
 UPDATE STATISTICS sys.sysschobjs
 UPDATE STATISTICS sys.syssingleobjrefs
 UPDATE STATISTICS sys.sysiscols
 GO

查看以下查询选项是否有帮助。

OPTION (USE HINT('FORCE_LEGACY_CARDINALITY_ESTIMATION'))

此问题的可能原因解释为here

希望这有帮助。