高级性能调整建议 - 超越基本索引
Advice for advanced performance tuning - Beyond basic indexing
总结
我计划使用以下架构在 SQL Azure 数据库中存储车牌列表:
架构
CREATE TABLE [dbo].[events](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[dateTimeCreated] [datetime] NOT NULL,
[registration] [varchar](14) NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[events] ADD CONSTRAINT [DF_events_dateTimeCreated] DEFAULT (getdate()) FOR [dateTimeCreated]
GO
我只能想到 运行 以下一个查询:
- 在给定的 date/time 范围内搜索注册
目前我只能想到创建非聚集索引反对dateTimeCreated并注册
问题
最终可能有数百万行。
* 当行数最终大幅增加时,有哪些选项(是否特定于 Azure)可以提高性能?
* 对于给定行数,查询性能将如何降低有任何指南吗?
您绝对应该为 dateTimeCreated
创建一个 集群 索引。 registration
列也应该被索引,但是它是否(以及如何)应该被索引取决于数据:你的 registration
有一些序列还是随机的?
Clustered Indexes背后的关键思想:
The only time the data rows in a table are stored in sorted order is
when the table contains a clustered index.
这意味着,当您对聚集的列进行搜索并且值具有一些可排序的语义(您的 dateTimeCreated
列)时,您获取正确数据的可能性会显着增加。 (SQL 服务器不必获取 - table 个页面来收集必要的数据。)
Microsoft Azure SQL Database does not support tables without clustered
indexes. A table must have a clustered index. If a table is created
without a clustered constraint, a clustered index must be created
before an insert operation is allowed on the table.
我会让 ID 成为 PK(和聚簇索引)
为什么是 bigint?
int 上升到 40 亿(如果使用负数则为 80 亿)
不只是更少的磁盘 space,而且您在相同数量的内存中缓存了更多的记录。
count(*) 将是顺序 n
两倍的记录将花费两倍的时间来计数
至于其他列,如果您要对其进行搜索或排序,请创建索引。
总结
我计划使用以下架构在 SQL Azure 数据库中存储车牌列表:
架构
CREATE TABLE [dbo].[events](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[dateTimeCreated] [datetime] NOT NULL,
[registration] [varchar](14) NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[events] ADD CONSTRAINT [DF_events_dateTimeCreated] DEFAULT (getdate()) FOR [dateTimeCreated]
GO
我只能想到 运行 以下一个查询: - 在给定的 date/time 范围内搜索注册
目前我只能想到创建非聚集索引反对dateTimeCreated并注册
问题
最终可能有数百万行。 * 当行数最终大幅增加时,有哪些选项(是否特定于 Azure)可以提高性能? * 对于给定行数,查询性能将如何降低有任何指南吗?
您绝对应该为 dateTimeCreated
创建一个 集群 索引。 registration
列也应该被索引,但是它是否(以及如何)应该被索引取决于数据:你的 registration
有一些序列还是随机的?
Clustered Indexes背后的关键思想:
The only time the data rows in a table are stored in sorted order is when the table contains a clustered index.
这意味着,当您对聚集的列进行搜索并且值具有一些可排序的语义(您的 dateTimeCreated
列)时,您获取正确数据的可能性会显着增加。 (SQL 服务器不必获取 - table 个页面来收集必要的数据。)
Microsoft Azure SQL Database does not support tables without clustered indexes. A table must have a clustered index. If a table is created without a clustered constraint, a clustered index must be created before an insert operation is allowed on the table.
我会让 ID 成为 PK(和聚簇索引)
为什么是 bigint?
int 上升到 40 亿(如果使用负数则为 80 亿)
不只是更少的磁盘 space,而且您在相同数量的内存中缓存了更多的记录。
count(*) 将是顺序 n
两倍的记录将花费两倍的时间来计数
至于其他列,如果您要对其进行搜索或排序,请创建索引。