在我们的数据库中存在一个大表,或多或少是这样的:
CREATE TABLE dbo.production_data
(
pd_id BIGINT PRIMARY KEY,
serial NVARCHAR(16) NOT NULL UNIQUE,
...
);
Run Code Online (Sandbox Code Playgroud)
但是现在串行字段的大小变得很小,所以我想将其更改为 32。Visual Studio 模式比较工具建议通过以下方式执行此操作:
DROP INDEX ux_production_data_serial ON dbo.production_data;
GO
ALTER TABLE dbo.production_data ALTER COLUMN serial NVARCHAR(32) NOT NULL;
GO
CREATE INDEX ux_production_data_serial ON dbo.production_data(serial ASC);
Run Code Online (Sandbox Code Playgroud)
这真的需要吗?或者更像是这样做的超级保存方式?
另外在重新创建唯一索引时,我的表会被锁定吗?因为这将是一个大问题(因为该表有 3000 万行,我猜重新创建索引需要相当长的时间),因为下一个维护窗口是未来几个月。我的选择是什么?
我有一个包含三个表的数据库items
,parameters
并且measurements
在两个服务器中都想查询该measuerment
表。但是在 PostgeSQL (9.4) 和 SQL Server (2012) 中查询要慢得多。
measurements
:
column | type | attributes
---------------+----------------------+-----------------------------------------------------------
id | int/serial | (identity) primary key
measuretime | datetime/timestamp | not null
parameter_id | int | not null (foreign key) references parameters(id)
item_id | int | not null (foreign key) references items(id)
value | float | not null
Run Code Online (Sandbox Code Playgroud)
和两个nonclustered index
上measuretime
和parameter_id
我插入了 2.609.280 行items
(半年,每行间隔 5 秒)和 31.311.360 行measurements …