Visual Studio 数据库架构比较非常慢

问题描述 投票:0回答:4

我们一直在使用 Visual Studio 2017 的 SQL Server 架构比较来进行所有 (SQL Server 2016) 迁移和部署。

但是,最近它变得非常慢,需要几个小时才能处理。如果我们取消选中“Tables”对象,它就会很快。但是当检查表格时,它很长时间都停留在“正在初始化比较...”上。

我在网上找不到任何对我们有帮助的东西。有什么想法吗?

正在初始化比较...

sql-server database visual-studio-2017 comparison
4个回答
7
投票

对我们来说似乎有用的是,如果您排除表(在架构比较选项 --> 对象类型 --> 应用程序范围 --> 表中),它运行得很快。

初次运行后,您可以再次与选定的表进行比较,这样就可以了。

除此之外,Visual Studio 数据库架构比较是一个很棒的工具。


1
投票

您可以使用 MSSQL Server Management Studio 自己的比较或使用以下工具之一:

https://www.agile-code.com/blog/choose-your-sql-server-schema-comparison-tool/


0
投票

我有非常相似的问题,我找到了解决方案。
来自

SELECT * FROM (SELECT SCHEMA_NAME([o].[schema_id]) AS [SchemaName],
和其他表的以
[sys].[spatial_indexes]
开头的查询计划不理想,并且运行了几个小时,导致 VS 超时并重试。 下面包含的计划指南解决了我的问题。

因为 VS 在第一次尝试获取结果期间批量发送所有查询,计划指南将不会启动。查询超时后,VS 将在自己的批次中重试此查询,并将应用计划指南。 为了进一步加快该过程并且不等待超时,您可以在 VS 会话卡在该查询上时终止它并强制重试。

EXEC sp_create_plan_guide   
    @name = N'VS Schema Comp Spatial Idxs',  
    @stmt = N'SELECT * FROM (
SELECT 
        SCHEMA_NAME([o].[schema_id])    AS [SchemaName],
        [si].[object_id]                AS [ColumnSourceId],
        [o].[name]                      AS [ColumnSourceName],
        [o].[type]                      AS [ColumnSourceType],
        [ic].[column_id]                AS [ColumnId],
        [c].[name]                      AS [ColumnName],
        [si].[index_id]                 AS [IndexId],
        [si].[name]                     AS [IndexName],
        [ds].[type]                     AS [DataspaceType],
        [ds].[data_space_id]            AS [DataspaceId],
        [ds].[name]                     AS [DataspaceName],
        [si].[fill_factor]              AS [FillFactor],
        [si].[is_padded]                AS [IsPadded],
        [si].[is_disabled]              AS [IsDisabled],
        [si].[allow_page_locks]         AS [DoAllowPageLocks],
        [si].[allow_row_locks]          AS [DoAllowRowLocks],
        [sit].[cells_per_object]        AS [CellsPerObject],
        [sit].[bounding_box_xmin]       AS [XMin],
        [sit].[bounding_box_xmax]       AS [XMax],
        [sit].[bounding_box_ymin]       AS [YMin],
        [sit].[bounding_box_ymax]       AS [YMax],
        [sit].[level_1_grid]            AS [Level1Grid],
        [sit].[level_2_grid]            AS [Level2Grid],
        [sit].[level_3_grid]            AS [Level3Grid],
        [sit].[level_4_grid]            AS [Level4Grid],
        [sit].[tessellation_scheme]     AS [TessellationScheme],
        [s].[no_recompute]              AS [NoRecomputeStatistics],
        [p].[data_compression]          AS [DataCompressionId],
        CONVERT(bit, CASE WHEN [ti].[data_space_id] = [ds].[data_space_id] THEN 1 ELSE 0 END)
                                        AS [EqualsParentDataSpace]
FROM
        [sys].[spatial_indexes]          AS [si] WITH (NOLOCK)
        INNER JOIN [sys].[objects]       AS [o] WITH (NOLOCK) ON [si].[object_id] = [o].[object_id]
        INNER JOIN [sys].[spatial_index_tessellations] [sit] WITH (NOLOCK) ON [si].[object_id] = [sit].[object_id] AND [si].[index_id] = [sit].[index_id]
        INNER JOIN [sys].[data_spaces]   AS [ds] WITH (NOLOCK) ON [ds].[data_space_id] = [si].[data_space_id] 
        INNER JOIN [sys].[index_columns] AS [ic] WITH (NOLOCK) ON [si].[object_id] = [ic].[object_id] AND [si].[index_id] = [ic].[index_id]
        INNER JOIN [sys].[columns]       AS [c] WITH (NOLOCK) ON [si].[object_id] = [c].[object_id] AND [ic].[column_id] = [c].[column_id]
        INNER JOIN [sys].[objects]       AS [o2] WITH (NOLOCK) ON [o2].[parent_object_id] = [si].[object_id]
        INNER JOIN [sys].[stats]         AS [s] WITH (NOLOCK) ON [o2].[object_id] = [s].[object_id] AND [s].[name] = [si].[name]
        INNER JOIN [sys].[partitions]    AS [p] WITH (NOLOCK) ON [p].[object_id] = [o2].[object_id] AND [p].[partition_number] = 1
        LEFT  JOIN [sys].[indexes]       AS [ti] WITH (NOLOCK) ON [o].[object_id] = [ti].[object_id]
        LEFT JOIN [sys].[tables]         AS [t] WITH (NOLOCK) ON [t].[object_id] = [si].[object_id]
WHERE [si].[is_hypothetical] = 0
        AND [ti].[index_id] < 2
        AND OBJECTPROPERTY([o].[object_id], N''IsSystemTable'') = 0
        AND ([t].[is_filetable] = 0 OR [t].[is_filetable] IS NULL)
        AND ([o].[is_ms_shipped] = 0 AND NOT EXISTS (SELECT *
                                        FROM [sys].[extended_properties]
                                        WHERE     [major_id] = [o].[object_id]
                                              AND [minor_id] = 0
                                              AND [class] = 1
                                              AND [name] = N''microsoft_database_tools_support''
                                       ))
) AS [_results];
',  
    @type = N'SQL',  
    @module_or_batch = NULL,  
    @params = NULL,  
    @hints = N'OPTION (FORCE ORDER)';

0
投票

类似问题的另一个答案

我遇到了同样的问题,但现在 VS Schema Compare 正在运行并在 5 分钟内完成。

© www.soinside.com 2019 - 2024. All rights reserved.