SQL插入的性能改进

时间:2019-01-29 23:16:25

标签: sql sql-server ssms

我有以下脚本会导致性能下降,并且不确定如何增强性能,并且在SSIS脚本任务中这部分代码超时。

INSERT INTO
   dbo.GEMS_CIX_FL_C_ARCHIVE ([ATTRIBUTE_SET_ID], [CollectionID], [CollectionTypeCode], [InstallationPointID], [NameSpecificationName], [PropertyReferenceID], [RECORDSENTERED], [XmlFile], LoadedDate) 
   SELECT
      [ATTRIBUTE_SET_ID],
      [CollectionID],
      [CollectionTypeCode],
      [InstallationPointID],
      [NameSpecificationName],
      [PropertyReferenceID],
      [RECORDSENTERED],
      [XmlFile],
      '2018-12-13 14:27:15' 
   FROM
      dbo.SSIS_SPT_FC_FL_CW_D001 
   WHERE
      ISNULL(InstallationPointID, '') + ISNULL(PropertyReferenceID, '') + ISNULL(NameSpecificationName, '') IN 
      (
         SELECT
            ISNULL(InstallationPointID, '') + ISNULL(PropertyReferenceID, '') + ISNULL(NameSpecificationName, '') 
         FROM
            dbo.GEMS_CIX_FL_C 
         WHERE
            ISNULL(InstallationPointID, '') + ISNULL(PropertyReferenceID, '') + ISNULL(NameSpecificationName, '') + ISNULL(XmlFile, '') NOT IN 
            (
               SELECT
                  ISNULL( InstallationPointID, '') + ISNULL(PropertyReferenceID, '') + ISNULL(NameSpecificationName, '') + ISNULL(XmlFile, '') 
               FROM
                  dbo.GEMS_CIX_FL_C_ARCHIVE
            )
      )


     [dbo].[GEMS_CIX_FL_C_ARCHIVE]
                                 ([ATTRIBUTE_SET_ID] [nvarchar](500)NULL, 
                              [CollectionID] [nvarchar](500) NULL, 
                                  [CollectionTypeCode][nvarchar](500) NULL,
                              [InstallationPointID] [nvarchar](500) NULL,
                                  [NameSpecificationName] [nvarchar](500) NULL,
                                  [PropertyReferenceID][nvarchar](500) NULL,
                                  [RECORDSENTERED] [nvarchar](500) NULL,
                                  [XmlFile] [nvarchar](500) NULL,
                                  [LoadedDate] [nvarchar](50) NULL )


     [dbo].[GEMS_CIX_FL_C]
     ([ATTRIBUTE_SET_ID] [nvarchar](500) NULL,
     [CollectionID] [nvarchar](500) NULL,
     [CollectionTypeCode][nvarchar](500) NULL,
     [InstallationPointID] [nvarchar](500) NULL,
     [NameSpecificationName] [nvarchar](500) NULL,
     [PropertyReferenceID][nvarchar](500) NULL,
     [RECORDSENTERED] [nvarchar](500) NULL,
     [XmlFile] [nvarchar](500) NULL,
     [LoadedDate] [nvarchar](50) NULL )


 [dbo].[SSIS_SPT_FC_FL_CW_D001](
    [InstallationPointID] [nvarchar](500) NULL,
    [PropertyReferenceID] [nvarchar](500) NULL,
    [NameSpecificationName] [nvarchar](500) NULL,
    [CollectionID] [nvarchar](500) NULL,
    [CollectionTypeCode] [nvarchar](500) NULL,
    [RECORDSENTERED] [nvarchar](500) NULL,
    [ATTRIBUTE_SET_ID] [nvarchar](500) NULL,
    [XmlFile] [nvarchar](500) NULL

目前,以上任何表中均未创建索引。需要什么索引?

插入

X

删除

X

插入

X

1 个答案:

答案 0 :(得分:0)

在不了解您的模型数据的情况下,我唯一可以给您的改进就是避免:

use_idf=True

全选是一种不好的做法,您将获得许多不必要的资源,这些资源可能会导致性能下降,而其余查询对我来说却非常简单