小编Sta*_*eff的帖子

更改 nvarchar 列的大小时,是否需要删除唯一索引?重新创建索引时表会被锁定吗?

在我们的数据库中存在一个大表,或多或少是这样的:

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 万行,我猜重新创建索引需要相当长的时间),因为下一个维护窗口是未来几个月。我的选择是什么?

index sql-server alter-table locking unique-constraint

14
推荐指数
1
解决办法
4万
查看次数

PostgreSQL 中对大表的简单平均查询比 SQL Server 慢得多

我有一个包含三个表的数据库itemsparameters并且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 indexmeasuretimeparameter_id

我插入了 2.609.280 行items(半年,每行间隔 5 秒)和 31.311.360 行measurements …

postgresql performance group-by postgresql-performance

5
推荐指数
1
解决办法
1556
查看次数