索引不能乱用哦
众所周知,索引可以提高查询性能,但是也不能乱用。要衡量得与失后再做定夺
有索引了,在insert,delete,update时就会产生所谓的"索引碎片", 索引碎片可导致查询性能下降
一个朋友的帖子引来的思考
最近系统查询统计的某些报表速度特别慢
分析了下,这些查询都走一个表'T_TABLE_USER',当初我都是加过索引的,一共40来个索引,当时并不慢,现在怎么如此之慢?

看了下,原来是需要重建索引了.

用DBCC SHOWCONTIG('T_TABLE_USER')查看是否需要重建索引
----重建索引前
DBCC SHOWCONTIG scanning 'T_TABLE_USER' table
Table: 'T_TABLE_USER' (1517157096); index ID: 1, database ID: 11
TABLE level scan performed.
- Pages Scanned








..: 75761
- Extents Scanned








: 9538
- Extent Switches








: 75757
- Avg. Pages per Extent






: 7.9
- Scan Density [Best Count:Actual Count]
.: 12.50% [9471:75758]
- Logical Scan Fragmentation 




: 98.90%
- Extent Scan Fragmentation 




.: 78.82%
- Avg. Bytes Free per Page





: 3161.2
- Avg. Page Density (full)





: 60.94%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.


--重建索引 DBCC DBREINDEX('T_TABLE_USER','',90)之后
DBCC SHOWCONTIG scanning 'T_TABLE_USER' table
Table: 'T_TABLE_USER' (1517157096); index ID: 1, database ID: 11
TABLE level scan performed.
- Pages Scanned








..: 51824
- Extents Scanned








: 6478
- Extent Switches








: 6477
- Avg. Pages per Extent






: 8.0
- Scan Density [Best Count:Actual Count]
.: 100.00% [6478:6478]
- Logical Scan Fragmentation 




: 0.00%
- Extent Scan Fragmentation 




.: 0.73%
- Avg. Bytes Free per Page





: 604.7
- Avg. Page Density (full)





: 92.53%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

完成后,查询速度明显提升了
有索引了,在insert,delete,update时就会产生所谓的"索引碎片", 索引碎片可导致查询性能下降
一个朋友的帖子引来的思考
最近系统查询统计的某些报表速度特别慢
分析了下,这些查询都走一个表'T_TABLE_USER',当初我都是加过索引的,一共40来个索引,当时并不慢,现在怎么如此之慢?
看了下,原来是需要重建索引了.
用DBCC SHOWCONTIG('T_TABLE_USER')查看是否需要重建索引
----重建索引前
DBCC SHOWCONTIG scanning 'T_TABLE_USER' table
Table: 'T_TABLE_USER' (1517157096); index ID: 1, database ID: 11
TABLE level scan performed.
- Pages Scanned








..: 75761
- Extents Scanned








: 9538
- Extent Switches








: 75757
- Avg. Pages per Extent






: 7.9
- Scan Density [Best Count:Actual Count]
.: 12.50% [9471:75758]
- Logical Scan Fragmentation 




: 98.90%
- Extent Scan Fragmentation 




.: 78.82%
- Avg. Bytes Free per Page





: 3161.2
- Avg. Page Density (full)





: 60.94%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

--重建索引 DBCC DBREINDEX('T_TABLE_USER','',90)之后
DBCC SHOWCONTIG scanning 'T_TABLE_USER' table
Table: 'T_TABLE_USER' (1517157096); index ID: 1, database ID: 11
TABLE level scan performed.
- Pages Scanned








..: 51824
- Extents Scanned








: 6478
- Extent Switches








: 6477
- Avg. Pages per Extent






: 8.0
- Scan Density [Best Count:Actual Count]
.: 100.00% [6478:6478]
- Logical Scan Fragmentation 




: 0.00%
- Extent Scan Fragmentation 




.: 0.73%
- Avg. Bytes Free per Page





: 604.7
- Avg. Page Density (full)





: 92.53%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
完成后,查询速度明显提升了

浙公网安备 33010602011771号