env:Windows Server 2016
SQL Server 2016 SP2
There is a form to fill clustered index and non-clustered index. This is both a form and have 400 million pen data, which also has a non-clustered index.
The extent of statistical information is updated 80000000 pen.
1. Perform create non-clustered index before performing clustered index
command:
CREATE NONCLUSTERED INDEX [IX_TESTId_CreatOn]
ON [dbo].[TESTTB] ([TESTId],[CreatOn])
INCLUDE ([Id],[LISTId],[Amount],[Revenue],[Session])
WITH(ONLINE=ON, DATA_COMPRESSION=ON)
GO
CREATE CLUSTERED INDEX [IX_CreatOn] ON [dbo].[TESTTB]
(
[CreatOn] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = ON, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, DATA_COMPRESSION=PAGE) ON [PRIMARY]
GO
Spend a lot of time in the build clustered index, the index was mainly caused by scanning both. Use SSMS to establish cluster index will prompt other cited will rebuild.
Execution order |
servername |
db_date |
table_name |
idx_id |
index_name |
row_count |
data_used_mb |
Exec(Mins) |
1 |
TESTDB01 |
TESTDB01 |
dbo.TESTTB |
7 |
IX_TESTId_CreatOn |
404502153 |
17368 |
51 |
2 |
TESTDB01 |
TESTDB01 |
dbo.TESTTB |
1 |
IX_CreatOn |
404502153 |
47358 |
94 |
2. The establishment of priority so that clustered index
command:
CREATE CLUSTERED INDEX [IX_CreatOn] ON [dbo].[TESTTB]
(
[CreatOn] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = ON, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, DATA_COMPRESSION=PAGE) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_TESTId_CreatOn]
ON [dbo].[TESTTB] ([TESTId],[CreatOn])
INCLUDE ([Id],[LISTId],[Amount],[Revenue],[Session])
WITH(ONLINE=ON, DATA_COMPRESSION=ON)
GO
The establishment can be found clustered index time is considerably reduced.
Execution order |
servername |
db_date |
table_name |
idx_id |
index_name |
row_count |
data_used_mb |
Exec(Mins) |
1 |
TESTDB01 |
TESTDB01 |
dbo.TESTTB |
1 |
IX_CreatOn |
404502153 |
47358 |
50 |
2 |
TESTDB01 |
TESTDB01 |
dbo.TESTTB |
7 |
IX_TESTId_CreatOn |
404502153 |
17368 |
43 |
in conclusion:
To create the index in both tables, clustered index's main priorities.
If in the table have been many non-clustered index, if you want to create an empty table and then perform data replication transfer? This is a question worth considering.