使用具有中等数据的表提高SQL Server查询性能

时间:2014-01-27 11:37:04

标签: sql-server sql-server-2008 azure query-performance

我有一张包含6000条记录的表格,但将来可能会更大。我附加了当前SQL查询的屏幕转储,需要12到14秒来加载6000行数据。

列上已经有最常查询的索引

如何提高查询性能或修改查询性能?

CREATE TABLE [dbo].[Item]
  (
     [Srno]          [BIGINT] IDENTITY(1, 1) NOT NULL,
     [ITEMCode]      [BIGINT] NOT NULL,
     [BranchId]      [BIGINT] NOT NULL,
     [ITEM_No]       [VARCHAR](50) NULL,
     [ITEM_Desc]     [VARCHAR](200) NULL,
     [DeptId]        [BIGINT] NULL,
     [CatId]         [BIGINT] NULL,
     [SizeId]        [BIGINT] NULL,
     [CostPrice]     [DECIMAL](18, 3) NULL,
     [SalesPrice]    [DECIMAL](18, 2) NULL,
     [ITEM_InStock]  [BIGINT] NULL,
     [UserId]        [BIGINT] NULL,
     [Active]        [BIT] NOT NULL,
     [IsDeleted]     [BIT] NOT NULL,
     [Quantity]      [INT] NULL,
     [IsFavourite]   [BIT] NULL,
     [IsProductLink] [BIT] NULL,
     CONSTRAINT [PK_Item_1] PRIMARY KEY CLUSTERED ( [ITEMCode] ASC, [BranchId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  )
ON [PRIMARY]

ALTER TABLE [dbo].[Item]
  WITH CHECK ADD CONSTRAINT [FK_Item_Item] FOREIGN KEY([ITEMCode], [BranchId]) REFERENCES [dbo].[Item] ([ITEMCode], [BranchId])

GO

ALTER TABLE [dbo].[Item]
  CHECK CONSTRAINT [FK_Item_Item]

GO

ALTER TABLE [dbo].[Item]
  ADD CONSTRAINT [DF_Item_ITEM_UnitPrice] DEFAULT ((0)) FOR [CostPrice]

GO

ALTER TABLE [dbo].[Item]
  ADD CONSTRAINT [DF_Item_ITEM_RETAILPRICE] DEFAULT ((0)) FOR [SalesPrice]

GO

ALTER TABLE [dbo].[Item]
  ADD CONSTRAINT [DF_Item_ITEM_InStock] DEFAULT ((0)) FOR [ITEM_InStock]

GO

ALTER TABLE [dbo].[Item]
  ADD CONSTRAINT [DF_Item_Active] DEFAULT ((0)) FOR [Active]

GO

ALTER TABLE [dbo].[Item]
  ADD CONSTRAINT [DF_Item_DelFlag] DEFAULT ((0)) FOR [IsDeleted]

GO 

我已更新查询并删除了部门表的连接,但仍然需要 10秒

   SELECT Item.ITEMCode                 AS ItemId,
       ISNULL(Item.ITEM_No, '0')     AS ItemNo,
       isnull(Item.Barcode, '')      AS Barcode,
       Item.ITEM_Desc                AS ItemName,
       isnull(item_Imagepath, '')    AS ItemImage,
       0                             AS availableQty,
       Item.SalesPrice               AS Price,
       isnull(Item.TaxApply, 0)      AS isTax,
       Item.TaxType,
       ISNULL(Item.ITM_Type, '0')    AS ITMType,
       Item.Profit_Type              AS ProfitType,
       Item.Profit_Amt               AS ProfitAmt,
       Item.CostPrice,
       ISNULL(Item.ITEM_Remarks, '') AS Remark
FROM   Item      

enter image description here

1 个答案:

答案 0 :(得分:0)

如果读取6000(小)记录需要10秒钟,那么我只能假设/希望你的连接在这里引入了很多延迟!?!

您可以尝试以下操作,看看这需要多长时间?

.popup {
    height: 100px;
    width: 100px;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-left: -50px;
    margin-top: -50px;
}

如果这种情况很快就会运行,那么我会寻找加快计算机和Azure服务器之间连接速度的方法。 (网络包大小?)