SQL语句如下:
select top   16 *  from View_product  WHERE isPassAudit='true' and pagerRank0>0  ORDER BY  pagerrank0 DESC, case   when   datediff(day,releaseTime,getdate())=0   then   1   else   0   end   desc,case  when  ISNUMERIC(price)=1 then '3' when price<>'' then '2' else '1' end desc ,releaseTime desc,productid desc其中 View_product是一个视图,该视图在A服务器上的代码如下:
USE [CNPrice]
GO
/****** 对象:  View [dbo].[View_Product]    脚本日期: 08/06/2009 08:21:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[View_Product]
WITH SCHEMABINDING 
AS
SELECT     dbo.tb_Product.productId, dbo.tb_Product.companyId, dbo.tb_Product.productGroupId, dbo.tb_Product.productName, dbo.tb_Product.productPicture, 
                      dbo.tb_Product.brand, dbo.tb_Product.keyWords, dbo.tb_Product.mainSpecification, dbo.tb_Product.price, dbo.tb_Product.priceUnitName, 
                      dbo.tb_Product.measureUnitName, dbo.tb_Product.priceType, dbo.tb_Product.priceTypeCityName, dbo.tb_Product.priceValidDays, 
                      dbo.tb_Product.supplyAbility, dbo.tb_Product.supplyAbilityMeasureUnit, dbo.tb_Product.netWeight, dbo.tb_Product.netWeightUnitName, 
                      dbo.tb_Product.netWeightMeasureName, dbo.tb_Product.deliveryDays, dbo.tb_Product.packing, dbo.tb_Product.minOrder, 
                      dbo.tb_Product.minOrderUnitName, dbo.tb_Product.payment, dbo.tb_Product.detailSpecification, dbo.tb_Product.productPriority, dbo.tb_Product.isAdv, 
                      dbo.tb_Product.clickedCount, dbo.tb_Product.releaseTime, dbo.tb_Product.isPassAudit, dbo.tb_Product.pagerRank0, 
                      dbo.tb_Seller.companyChineseName, dbo.tb_Seller.companyName, dbo.tb_Product.Model, dbo.tb_Product.displayRank
FROM         dbo.tb_Product INNER JOIN
                      dbo.tb_SellerCompany ON dbo.tb_Product.companyId = dbo.tb_SellerCompany.companyId INNER JOIN
                      dbo.tb_Seller ON dbo.tb_SellerCompany.sellerId = dbo.tb_Seller.sellerIdGO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[47] 4[32] 2[15] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tb_Product"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 121
               Right = 239
            End
            DisplayFlags = 280
            TopColumn = 4
         End
         Begin Table = "tb_SellerCompany"
            Begin Extent = 
               Top = 6
               Left = 277
               Bottom = 159
               Right = 484
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Seller"
            Begin Extent = 
               Top = 11
               Left = 587
               Bottom = 126
               Right = 776
            End
            DisplayFlags = 280
            TopColumn = 8
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 3495
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_Product'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_Product'

解决方案 »

  1.   

    该视图在B服务器上的代码如下:
    USE [CNPrice]
    GO
    /****** 对象:  View [dbo].[View_Product]    脚本日期: 08/06/2009 08:20:32 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE VIEW [dbo].[View_Product]
    WITH SCHEMABINDING 
    AS
    SELECT     dbo.tb_Product.productId, dbo.tb_Product.companyId, dbo.tb_Product.productGroupId, dbo.tb_Product.productName, dbo.tb_Product.productPicture, 
                          dbo.tb_Product.brand, dbo.tb_Product.keyWords, dbo.tb_Product.mainSpecification, dbo.tb_Product.price, dbo.tb_Product.priceUnitName, 
                          dbo.tb_Product.measureUnitName, dbo.tb_Product.priceType, dbo.tb_Product.priceTypeCityName, dbo.tb_Product.priceValidDays, 
                          dbo.tb_Product.supplyAbility, dbo.tb_Product.supplyAbilityMeasureUnit, dbo.tb_Product.netWeight, dbo.tb_Product.netWeightUnitName, 
                          dbo.tb_Product.netWeightMeasureName, dbo.tb_Product.deliveryDays, dbo.tb_Product.packing, dbo.tb_Product.minOrder, 
                          dbo.tb_Product.minOrderUnitName, dbo.tb_Product.payment, dbo.tb_Product.detailSpecification, dbo.tb_Product.productPriority, dbo.tb_Product.isAdv, 
                          dbo.tb_Product.clickedCount, dbo.tb_Product.releaseTime, dbo.tb_Product.isPassAudit, dbo.tb_Product.pagerRank0, 
                          dbo.tb_Seller.companyChineseName, dbo.tb_Seller.companyName, dbo.tb_Product.Model, dbo.tb_Product.displayRank
    FROM         dbo.tb_Product INNER JOIN
                          dbo.tb_SellerCompany ON dbo.tb_Product.companyId = dbo.tb_SellerCompany.companyId INNER JOIN
                          dbo.tb_Seller ON dbo.tb_SellerCompany.sellerId = dbo.tb_Seller.sellerIdGO
    EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
    Begin DesignProperties = 
       Begin PaneConfigurations = 
          Begin PaneConfiguration = 0
             NumPanes = 4
             Configuration = "(H (1[47] 4[32] 2[15] 3) )"
          End
          Begin PaneConfiguration = 1
             NumPanes = 3
             Configuration = "(H (1 [50] 4 [25] 3))"
          End
          Begin PaneConfiguration = 2
             NumPanes = 3
             Configuration = "(H (1 [50] 2 [25] 3))"
          End
          Begin PaneConfiguration = 3
             NumPanes = 3
             Configuration = "(H (4 [30] 2 [40] 3))"
          End
          Begin PaneConfiguration = 4
             NumPanes = 2
             Configuration = "(H (1 [56] 3))"
          End
          Begin PaneConfiguration = 5
             NumPanes = 2
             Configuration = "(H (2 [66] 3))"
          End
          Begin PaneConfiguration = 6
             NumPanes = 2
             Configuration = "(H (4 [50] 3))"
          End
          Begin PaneConfiguration = 7
             NumPanes = 1
             Configuration = "(V (3))"
          End
          Begin PaneConfiguration = 8
             NumPanes = 3
             Configuration = "(H (1[56] 4[18] 2) )"
          End
          Begin PaneConfiguration = 9
             NumPanes = 2
             Configuration = "(H (1 [75] 4))"
          End
          Begin PaneConfiguration = 10
             NumPanes = 2
             Configuration = "(H (1[66] 2) )"
          End
          Begin PaneConfiguration = 11
             NumPanes = 2
             Configuration = "(H (4 [60] 2))"
          End
          Begin PaneConfiguration = 12
             NumPanes = 1
             Configuration = "(H (1) )"
          End
          Begin PaneConfiguration = 13
             NumPanes = 1
             Configuration = "(V (4))"
          End
          Begin PaneConfiguration = 14
             NumPanes = 1
             Configuration = "(V (2))"
          End
          ActivePaneConfig = 0
       End
       Begin DiagramPane = 
          Begin Origin = 
             Top = 0
             Left = 0
          End
          Begin Tables = 
             Begin Table = "tb_Product"
                Begin Extent = 
                   Top = 6
                   Left = 38
                   Bottom = 121
                   Right = 239
                End
                DisplayFlags = 280
                TopColumn = 3
             End
             Begin Table = "tb_SellerCompany"
                Begin Extent = 
                   Top = 6
                   Left = 277
                   Bottom = 159
                   Right = 484
                End
                DisplayFlags = 280
                TopColumn = 0
             End
             Begin Table = "tb_Seller"
                Begin Extent = 
                   Top = 11
                   Left = 587
                   Bottom = 126
                   Right = 776
                End
                DisplayFlags = 280
                TopColumn = 8
             End
          End
       End
       Begin SQLPane = 
       End
       Begin DataPane = 
          Begin ParameterDefaults = ""
          End
          Begin ColumnWidths = 36
             Width = 284
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
          End
       End
     ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_Product'
    GO
    EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'  Begin CriteriaPane = 
          Begin ColumnWidths = 11
             Column = 1440
             Alias = 900
             Table = 1170
             Output = 720
             Append = 1400
             NewValue = 1170
             SortType = 1350
             SortOrder = 1410
             GroupBy = 1350
             Filter = 1350
             Or = 1350
             Or = 1350
             Or = 1350
          End
       End
    End
    ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_Product'
    GO
    EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_Product'
    现在发现在A服务器上执行上面的SQL语句只要不到1秒钟,而在B服务器上需要18秒,两个数据库中的数据都是5w条左右,真的很奇怪,请高手指点!
      

  2.   

    我用了源代码比较器对两个视图代码做了比较,有少许的代码有不同。不同代码段如下:
         Begin ColumnWidths = 36
             Width = 284
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
             Width = 1500
     ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'View_Product'
    GO
    EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'  Begin CriteriaPane = 
          Begin ColumnWidths = 11
             Column = 1440
      

  3.   

    每天进步一点点) :你指的是在视图上重建productId的索引吗?我刚试验重建了,但没有效果。
      

  4.   

    MRAK  建议重新建立索引 
    或者DBCC CHECKDB试下
      

  5.   

    服务器的配置是P4 3G,1G内存。因为目前数据小是用PC机
      

  6.   

     
    tengjian1981:我把三个表以及视图都重建索引了,还是不行
      

  7.   

    请教一下各位:我若想通过运行这个SQL语句来详细查看SQL在执行过程中的一个各个时间分配情况,如何实现?
      

  8.   

    set statistics time on
    查看下执行的时间,另外可以看下执行计划
    ctrl +L
      

  9.   

    性能差异如此之大,是否跟我SQLSERVER的服务器配置的设置有关?请高手指教
      

  10.   

    恩,有可能是服务器的硬件配置或者软件设置的问题。
    SQLSERVER的设置也有可能。
      

  11.   

    netcup:那么配置有哪些需要注意的地方呢
      

  12.   

    你服务器上数据库很多吗?连接的用户很多吗?看一下数据库的CPU和内存的使用情况
      

  13.   

    服务器上就一个数据库,后来我测试的时候还把IIS给关闭了,也就是说是在很理想的状态下测试的,而且在整个查询过程中,SQLSERVER占用的CPU的资源大部分情况下都不高平均下来有10%的样子。SQLSERVER占用的内存为350MB左右。
      

  14.   

    重启一下SQL SERVER和操作系统试试
      

  15.   

    (★触发器专家VS触发器难题★) :我的QQ号:1639738,要不通过QQ聊?