我正在寻找一些关于加快 SQL Azure 查询速度的建议。这是我们正在运行的两个查询的示例,当我们在其中添加 WHERE 子句时,查询会停止。
TheTime 和 orderType 这两个列都被编入索引。任何人都可以建议如何使这些运行更快,或者对查询做些什么以提高效率?
5.2 秒:
sum(cast(theTime AS INT)) as totalTime from Orders
20.2 秒:
sum(cast(theTime AS INT)) as totalTime from Orders WHERE orderType='something_in_here'
以下是相关信息:
CREATE TABLE [dbo].[Orders] (
[ID] int IDENTITY(1,1) NOT NULL,
[orderType] nvarchar(90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[orderTime] nvarchar(90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PrimaryKey_fe2bdbea-c65a-0b85-1de9-87324cc29bff] PRIMARY KEY CLUSTERED ([ID])
WITH (IGNORE_DUP_KEY = OFF)
)
GO
CREATE NONCLUSTERED INDEX [orderTime]
ON [dbo].[Orders] ([orderTime] ASC)
WITH (IGNORE_DUP_KEY = OFF,
STATISTICS_NORECOMPUTE = OFF,
ONLINE = OFF)
GO
CREATE NONCLUSTERED INDEX [actiontime_int]
CREATE NONCLUSTERED INDEX [orderType]
ON [dbo].[Orders] ([orderType] ASC)
WITH (IGNORE_DUP_KEY = OFF,
STATISTICS_NORECOMPUTE = OFF,
ONLINE = OFF)
GO