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'
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'
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条左右,真的很奇怪,请高手指点!
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
或者DBCC CHECKDB试下
tengjian1981:我把三个表以及视图都重建索引了,还是不行
查看下执行的时间,另外可以看下执行计划
ctrl +L
SQLSERVER的设置也有可能。