Download presentation
Presentation is loading. Please wait.
Published byFrans Brabander Modified over 6 years ago
1
SQLCAT: Customer Experiences with Data Compression
Sanjay Mishra, Sunil Agarwal, Marcel van der Holst Microsoft Corporation
2
SQL Server Customer Advisory Team (SQLCAT)
Works on the largest, most complex SQL Server projects worldwide MySpace million concurrent users at peak time, 8 billion friend relationships, 34 billion s, 1 PetaByte store, scale-out using SSB and SOA Bwin – Most popular European online gaming site – database transactions / second, motto: “Failure is not an option”; 100 TB total storage Korea Telecom - Largest telco in Korea serves 26 million customers; 3 TB Data Warehouse Drives product requirements back into SQL Server from our customers and ISVs Shares deep technical content with SQL Server community SQLCAT.com
3
SQL Server Design Win Program
Target the most challenging and innovative SQL Server applications 10+ TB DW, 3k/tran/s OLTP, Large 500GB+ Cubes, Competitive migrations, Complex deployments, Server Consolidation (1000+) Invest in large scale, referenceable SQL Server projects across the world Provide SQLCAT technical & project experience Conduct architecture and design reviews covering performance, operation, scalability and availability Offer use of HW lab in Redmond with direct access to SQL Server development team Work with Marketing Team Developing PR
4
SQLCAT and SQL CSS Invite You…
To the SQL Server Clinic where the most experienced SQL Server experts in the world will be waiting to talk with you. Bring your toughest Questions / Challenges to the experts who have seen it all Architect and Design your future applications with experts who have done it before with some of the largest, most complex systems in the world Or just stop in to say hello! ROOM 611
5
Agenda Introduction What to Compress Planning Data Compression
Performance Impact of Data Compression How does Data Compression work with other features Unicode Compression in KJ
6
Data Compression in SQL Server 2008
New in SQL Server 2008 (Enterprise and Developer Edition only) You CAN NOT restore / attach a database with compressed tables or indexes onto Standard Edition Types of data compression ROW Compression Stores fixed length values as variable length Row metadata optimized PAGE Compression Includes ROW Compression Column Prefix and Dictionary Data compressed on disk as well as in memory Tables and indexes can be compressed independently Individual partitions can be compressed independently
7
Deciding What to Compress
Estimate space savings sp_estimate_data_compression_savings Type of Data IN_ROW_DATA => compressed ROW_OVERFLOW_DATA ,LOB_DATA => not compressed Application Workload Use ROW Compression for all data if: ROW compression results in space savings, and 10% increase in CPU usage can be accommodated, Careful consideration for PAGE compression: If no CPU headroom, don’t PAGE compress without thorough testing For a DW applications, if sufficient CPU headroom available, PAGE compress all objects in the database. For OLTP applications, detail analysis involves % of Update and % of Scan operations Tables that contain the following patterns of data compress very well: Columns with numeric or fixed-length character data types where most values don’t require all the allocated bytes: For example, integers where most values are less than 1000 Nullable columns where a significant number of the rows have a NULL value for the column Significant amounts of repeating data values or repeating prefix values in the data Some patterns of data that do not benefit much from compression are: Columns with numeric or fixed-length character data types where most values require all the bytes allocated for the specific data type Not much repeating data Repeating data with non-repeating prefixes Data stored out of the row FILESTREAM data Data in IN_ROW_DATA allocation unit is compressed Data in ROW_OVERFLOW_DATA and LOB_DATA allocation units not compressed
8
Customer Example: An SAP Deployment
Inputs: sp_estimate_data_compression_savings, dm_db_physical_index_usage_stats, SAP knowledge Computed: S=% scans; U=% updates Table Size (GB) ROW save % PAGE 1-row Read >1-row Update Delete Insert S U Plan Notes COSP 398 80% 90% 2,797 58,735 886,187 15,747 584,017 3.80% 57.27% Updates! GLPCA 123 15% 89% 929,637 16,802 59,020 92.46% 0.0% Scan mostly COEP 185 30% 81% 19,036 2,927 48,182 27.14% 4.17% Light use, but stay low risk RESB 243 38% 83% 9,837 7,977,629 943,380 1,321 14,877 89.16% 10.54% #updates ACCTIT 210 21% 87% 54,580 0.00% Append only MSEG 183 28% 3,441,918 24,684,252 28 70,797 87.54% FAGLFLEXA 98 29% 88% 298 58,882 0.50% BSIS 148 9,069 67 5,773 64,366 11.44% 0.08% Append mostly COSB 150 84% 92% 88 100.00% ROW ~=PAGE GLFUNCA 40 6 read-mostly ROW ~= PAGE => ROW High Update, Low Scan => ROW High Scan => PAGE Append Only => PAGE Read-only => PAGE High non-append inserts, some update => ROW High Update, High Scan => ROW
9
Customer Example: Gomez
Workload: OLTP (3000 inserts/sec) + Reporting PAGE compressed the 5 largest tables Some tables have 476 partitions All partitions PAGE compressed Size before compression: 7,437 GB Size after compression: 4,540 GB (~40% savings) Increase in CPU usage: 6% No significant change in application performance
10
Planning Compression Estimating Workspace, CPU, I/O
Brand Transformation Presentation Planning Compression Estimating Workspace, CPU, I/O Compressing a table or index uses the same mechanism as rebuilding an index Requires workspace, CPU, and I/O resources The resource requirements depend upon: Type of structure: heap, a clustered index, or a nonclustered index Concurrency : ONLINE = ON or OFF Recovery model: simple, bulk logged, or full recovery model SORT_IN_TEMPDB option is ON (recommended) or OFF When you compress a heap, the non-clustered indexes on the heap are rebuilt (behind the scene, after the compression is done) One by one, if ONLINE = OFF Simultaneously, if ONLINE = ON Account for free space required for rebuilding the non-clustered indexes
11
WorkSpace Requirements General Considerations
Brand Transformation Presentation WorkSpace Requirements General Considerations Free workspace is required in: User database Transaction Log TEMPDB Side effect When you compress a heap, the non-clustered indexes on the heap are rebuilt (behind the scene, after the heap is compressed) One by one, if ONLINE = OFF Simultaneously, if ONLINE = ON Account for free space required for rebuilding the non-clustered indexes When you compress a heap, the non-clustered indexes on the heap are rebuilt (behind the scene, after the compression is done) One by one, if ONLINE = OFF Simultaneously, if ONLINE = ON
12
Free Space Required For …
Brand Transformation Presentation Free Space Required For … The compressed table / index In the user database Estimate based on output of sp_estimate_data_compression_savings Tip: If compressing many tables, compress in the order of smallest to largest Reduce chances of the need to grow the data file(s) Mapping Index Internal structure to map old bookmarks to new bookmarks to support concurrent DML transactions Only for ONLINE = ON Only if you are compressing a Heap or a Clustered Index In TEMPDB, if SORT_IN_TEMPDB = ON, else in the user database Mapping Index: Typically 1.2 to 1.4 times the size of the compressed table / index May be bigger if the clustered index is wider.
13
Free Space Required For …
Brand Transformation Presentation Free Space Required For … Transaction Log Depends upon ONLINE = ON / OFF Depends upon recovery model: FULL / SIMPLE Version Store Only if there are concurrent DML operations Only for ONLINE = ON In TEMPDB Size of version store depends upon Volume of ongoing data modifications Duration of DML transactions Transaction Log: With ONLINE = ON and FULL recovery model, typically 1.1 to 1.4 times the size of the compressed table / index May be bigger if the clustered index is wider. Much less With ONLINE = OFF, or under SIMPLE recovery model.
14
Brand Transformation Presentation
CPU Requirements On average: ROW compression takes approx. 1.5 times the CPU time used for rebuilding an index PAGE compression takes approx. 2 to 5 times the CPU time used for rebuilding an index ONLINE operations require more CPU. Can be parallelized. Caveats: Few unique values for the leading column of the index may reduce parallelism Compressing a heap with ONLINE = ON uses a single CPU for compression (or rebuild) Transaction Log: With ONLINE = ON and FULL recovery model, typically 1.1 to 1.4 times the size of the compressed table / index May be bigger if the clustered index is wider. Much less With ONLINE = OFF, or under SIMPLE recovery model.
15
Planning Compression How and When to Compress
Online vs. Offline: Offline is faster and requires less resources, but reduces concurrency Restrictions of online operations in SQL Server Books Online. One table, index, or partition at a time vs. many concurrently: One at a time is recommended in most cases Multiple compressions at a time may be acceptable, if: you have sufficient resources, and You have efficient mechanism to reclaim the unused space after compression Setting SORT_IN_TEMPDB to ON or OFF: ON is recommended. Uses TEMPDB space for the mapping index Order of compressing the tables: Matters if available space is at a premium Start with the smallest in this list Online vs. Offline: Whether to set the value of ONLINE to ON or OFF depends upon what else is running on the database at the same time. OFF is faster and requires less resources than ON, but the table is locked for the duration of the compression operation. Be aware of the restrictions of online operations as discussed in SQL Server Books Online. One table, index, or partition at a time vs. many concurrently: Compressing one table, index, or partition at a time is recommended in most cases. When doing multiple simultaneous compressions, workspace, I/O, and CPU requirements outlined earlier must be available for all the compressions together. Be mindful of the risk of insufficient free space and the need to expand data files, as well as the likelihood of large amount of unused space in the data files at the end of compression. If you have sufficient resources (workspace, I/O, and CPU), and have an efficient mechanism to reclaim the unused space (refer to section 6 later in this white paper), executing multiple compressions simultaneously may be acceptable. Order of compressing the tables: After you have decided on the list of tables and indexes to compress, compress the objects starting with the smallest in this list. Compressing smaller objects requires less workspace, and it releases space to the data files that can be used as workspace for compressing the larger objects subsequently. This approach minimizes the need for additional disk space during the compression process. Setting SORT_IN_TEMPDB to ON or OFF: ON is recommended. This makes use of tempdb space for the mapping index, and therefore, it requires less workspace in the user database.
16
Reclaiming the Space Released by Data Compression
Brand Transformation Presentation Reclaiming the Space Released by Data Compression Option 1: May decide not to reclaim Use released space for future data growth Option 2: DBCC SHRINKFILE, but be aware: Introduces index fragmentation REORGANIZE (not REBUILD) after SHRINKFILE ROW_OVERFLOW_DATA does move during CREATE CLUSTERED INDEX with DROP_EXISTING
17
Reclaiming the Space Released by Data Compression
Brand Transformation Presentation Reclaiming the Space Released by Data Compression Option 3: If you are compressing all the objects in a filegroup Create a new filegroup Move tables / indexes to the new filegroup while compressing Need to create / recreate clustered index on the table if you want to move it during compression Use CREATE CLUSTERED INDEX with DROP_EXISTING. Example: CREATE UNIQUE CLUSTERED INDEX [PK_TRADE] ON [TRADE_BULK] ([T_ID] ASC) WITH (DATA_COMPRESSION=PAGE, DROP_EXISTING=ON, SORT_IN_TEMPDB=ON, ONLINE=ON) ON [Data] Caveat: LOB_DATA does NOT move during CREATE CLUSTERED INDEX with DROP_EXISTING. Remove the old filegroup and its file(s) after it is empty ROW_OVERFLOW_DATA does move during CREATE CLUSTERED INDEX with DROP_EXISTING
18
Reclaiming the Space Released by Data Compression
Brand Transformation Presentation Reclaiming the Space Released by Data Compression Option 4: Create an empty table in the new filegroup, compress it, and then copy the data over to the new table using INSERT … SELECT. -- Create a new empty table in the new filegroup ALTER DATABASE [TestDB] MODIFY FILEGROUP FG_COMP DEFAULT; SELECT * INTO [Tab1] FROM [Tab] WHERE 1 = 2; -- Compress the newly created empty table ALTER TABLE [Tab1] REBUILD WITH (DATA_COMPRESSION = PAGE); -- Create the appropriate indexes on the table -- Copy the data over to the new table INSERT INTO [Tab1] WITH (TABLOCK) SELECT * FROM [Tab] -- The incoming data will be compressed as it gets inserted -- TABLOCK is required if the target table is a heap -- Trace flag 610 may help enable minimal logging -- The LOB_DATA allocation unit will also be copied -- Drop the old table and rename the new table as old table -- After all the tables are copied like this, remove the old filegroup If you have LOB data, you can’t move the LOB_DATA allocation unit while compressing the data. Work around 1: alter database [HELP] modify filegroup FG_COMP default DROP TABLE [dbo].[test_help_2] select * into [test_help_2] from [test_help] where 1 = 2 alter table [test_help_2] rebuild with (data_compression = page) insert into [test_help_2] select * from [test_help] Work around 2: Use DBCC SHRINKFILE to shrink the file after moving the IN_ROW_DATA to new filegroup. Fragmentation OK with file containing only LOB_DATA. ROW_OVERFLOW_DATA does move during CREATE CLUSTERED INDEX with DROP_EXISTING
19
Data Compression Performance and Resource Considerations
Compressed Data More data in less pages Less pages to read from disk Less Logical I/Os, Less Physical I/Os CPU savings from reduced Logical I/O I/O-intensive workload will benefit performance gain At the cost of extra CPU for compression / de-compression Some workload may not gain performance Doesn’t significantly reduce I/O for workloads dominated by singleton operations Some workload performance presented here: Bulk Load Index Rebuild
20
BULK INSERT with Data Compression
To get PAGE compression while performing BULK INSERT on a heap, make sure to use TABLOCK See next slide if you create a clustered index soon after the BULK INSERT
21
BULK INSERT and CREATE INDEX Choices
BULK INSERT on uncompressed heap, followed by CREATE CLUSTERED INDEX WITH (DATA_COMPRESSION = PAGE) BULK INSERT on PAGE compressed heap, followed by CREATE CLUSTERED INDEX PAGE compress CLUSTERED INDEX, followed by BULK INSERT
22
Index Rebuild with Data Compression
Rebuilding compressed indexes takes longer and consume more CPU, especially for PAGE compression. SORT_IN_TEMPDB = ON, ONLINE = OFF
23
What Happens to New Rows
Table Organization Table Compression Setting ROW PAGE Heap PAGE compressed: If new row goes to an existing page with PAGE compression If BULK INSERT with TABLOCK If INSERT INTO ... (TABLOCK) SELECT ... FROM Otherwise, the row is ROW compressed Clustered Index PAGE compressed, if new row goes to an existing page with PAGE compression Otherwise, ROW compressed until page split. PAGE compression attempted before a page split Two internal thresholds to be aware of: A page is PAGE compressed only if the space savings exceed an internally defined threshold When the number of DML (INSERT / UPDATE / DELETE) operations on a given page exceeds an internally defined threshold, the column prefix and page dictionary may get re-computed
24
Data Compression and Partition Manipulation
Brand Transformation Presentation Data Compression and Partition Manipulation Switch CAN NOT switch if the source and target have different compression property Split New partition inherits the data compression property of the partition being split Merge Resultant partition inherits the data compression property of the destination partition Whether the data in the resultant partition will be PAGE compressed or not, depends upon if you have a Heap or Clustered Index
25
Merging Partitions with Data Compression
Brand Transformation Presentation Merging Partitions with Data Compression Compressed UnCompressed UnCompressed Compressed CREATE PARTITION FUNCTION T_PF_LEFT(INT) AS RANGE LEFT FOR VALUES (1,2) < = 1 > 1, < = 2 > 2 ALTER PARTITION FUNCTION T_PF_LEFT() MERGE RANGE (1) 2 < = 2 > 2 CREATE PARTITION FUNCTION T_PF_RIGHT(INT) AS RANGE RIGHT FOR VALUES(1,2) Resultant partition inherits the data compression attribute of the destination partition The colors can be switched and the above will hold true. < 1 >= 1, < 2 > = 2 ALTER PARTITION FUNCTION T_PF_RIGHT() MERGE RANGE (1) 2 < 2 >= 2
26
Data Compression and TDE
TDE has negligible, if any, impact on data compression TDE encrypts the pages when they are written to disk and decrypts them when they are read from disk into memory
27
Data Compression and Replication
Replication provides lots of flexibility Replication can work between multiple SQL Server versions Replication can work between Standard and Enterprise editions Data compression respects replication’s flexibility You can compress tables/indexes in the publisher and/or the subscriber as per your need If the publisher is compressed, and you don’t want the subscriber to be compressed (or the subscriber doesn’t support compression), When generating the initial schema through the snapshot agent, don’t enable 0x4 option Don’t enable replication of compression in sp_addarticle @schema_option parameter, 0x = replication of compression is enabled If the publisher is NOT compressed, and you WANT the subscriber to be compressed, Enable compression on the subscriber after establishing replication as per your convenience
28
Data Compression Enhancements in SQL Server 2008 R2
29
SQL Server 2008 R2 Unicode Storage Challenge
SQL Server uses UCS-2 encoding scheme for storing Unicode data NCHAR and NVARCHAR data always takes 2 bytes of storage per character Waste of 1 byte per character for commonly deployed locales (e.g. ASCII)
30
SQL Server 2008 R2 Unicode Solution
Use Standard Compression Scheme for Unicode (SCSU) technique No application change needed Compression Achieved Locale SCSU (SQL 2008 R2) UTF-8 English 0.5 Japanese .85 1.0 Korean Turkish .52 .53 German .5 Vietnamese 0.61 0.68 Hindi SCSU => Standard Compression Scheme for Unicode
31
SCSU Compression vs UTF-8
SCSU compression not the same as UTF-8 Why not do UTF-8 encoding Requires application change UTF-8 optimized for ASCII. SCSU gives better compression for non-ASCII languages
32
Example: Unicode Compression
Create Table SQLCOMP (Name NVARCHAR(20)) HEADER 0x53514C “SQL” Col-prefix 0x C “SQLSERVER” 0x53514C “SQLSERVER” 0x “?SERVER” Talking Points Show the row data before Unicode compression Enable ROW compression and you get size reduction by 9 bytes (not 10). We need to make length odd to indicate it is Unicode compressed Enable PAGE compression. Show the column prefix and also show that Unicode compression works with PAGE compression except that the relative savings (compared to PAGE compression in SQL2008RTM) will be less because we already got some savings with Unicode. 0x C E E0045 “SQLENGINE” 0x53514C454E47494E45 “SQLENGINE” 0x 03454E47494E45 “?ENGINE” 0x C004C004F “SQLLOADERS” 0x53514C4C4F “SQLLOADERS” 0x034C4F “?LOADERS” PAGE COMPRESSION ROW COMPRESSION
33
SQL Server 2008 R2: Enabling Unicode Compression
In SQL Server 2008 R2, Unicode compression is included in ROW compression Supported types NVARCHAR and NCHAR NVARCHAR(max) and NCHAR(max) not supported NTEXT type not supported Estimate space savings sp_estimate_data_compression_savings SQL2008R2: Can be used to estimate space savings due to data defragmentation. Talk about changes in SQL2008R2 If you are already ROW compressed on SQL Server 2008, you can use this SP to estimate how much additional space you can save using Unicode compression in SQL Server 2008 R2.
34
SQL Server 2008R2: Unicode Compression Some Customer Results
Application ROW Compression (2008) ROW Compression (2008 R2) SAP ERP Benchmark DB 9% 43% Dynamics AX 30% 53.2% Siebel 45% 64% Customer Projected Storage Cost Reduction Microsoft ( MSIT/SAP) $500 K (1) ERP benchmark databases typically deliver lower compression than production because there are more fields that are empty.
35
Data Compression and Upgrade from SQL Server 2008 R2 to SQL Server 2008
Scenarios ROW compression enabled in SQL Server 2008 No database changes when upgraded Unicode value compressed only if it saves space. It happens when An existing value is updated A new row is inserted Index is rebuilt with ROW or PAGE compression PAGE compression enabled in SQL Server 2008 Same as with ROW compression No changes needed to existing scripts and DDL
36
Key Takeaways Space savings from data compression depends upon the data Estimate space savings prior to compressing Impact on performance and resource utilization depends upon the workload Test with production-like workload to estimate impact on performance and resource utilization General Guidelines: Very minimal CPU increase with ROW compression (usually less than 5-10%) If ROW compression results in space savings, and 10% increase in CPU usage can be accommodated, all data should use ROW compression Careful consideration for PAGE compression: If no CPU headroom, don’t PAGE compress without thorough testing If CPU headroom available, For Data Warehouse workload, PAGE compress all objects in the database For OLTP workload, PAGE compress tables and indexes mostly involved in scan operations, and less involved in update operations If using datatypes NCHAR and NVARCHAR, Unicode compression in SQL Server 2008 R2 can benefit significantly
37
Further Reading
38
Complete the Evaluation Form & Win!
You could win a Dell Mini Netbook – every day – just for handing in your completed form! Each session form is another chance to win! Pick up your Evaluation Form: Within each presentation room At the PASS Booth near registration area Drop off your completed Form: Near the exit of each presentation room Sponsored by Dell
39
for attending this session and the 2009 PASS Summit in Seattle
Thank you for attending this session and the PASS Summit in Seattle
40
Microsoft Technical Learning Center Located in the Expo Hall
Visit the Microsoft Technical Learning Center Located in the Expo Hall Microsoft Ask the Experts Lounge Microsoft Chalk Talk Theater Presentations Microsoft Partner Village
41
Appendix
42
Row Compression Variable Length Encoding (new row format)
Special Handling of NULL and 0s 4-byte integer SQL Server 2005 1 4 bytes SQL Server (Compression enabled) 1
43
Page Compression Column Prefix
9/18/2018 Page Compression Column Prefix Factor out common prefix from the same column across all rows on the page Store these ‘prefix’ values once and then reference them from respective columns Example: Student( Name VARCHAR (10), ID INT, CODE VARBINARY(3)) Emphasize column prefix is not limited to character data. It could be any bytes. It is type agnostic. the prefix does not need to appear in its entirety in every column © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
44
Page Compression Column Prefix
TechReady7 Breakout Chalktalk Template 9/18/2018 Page Compression Column Prefix Page Header Lambert NULL Decimal is HEX 0x4C4840 Lamb 4 0x5B8D80 Lambei 5i 20x41 0x41AABB Lambert 20x42 0x5CAABB Lee 20x43 0x9A4041 Lee 0x112233 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
45
Page Compression Page Dictionary
Find repeating values across all columns on all the rows on the page, irrespective of data type Store these values in a dictionary once, and reference them from respective columns
46
Page Compression Page Dictionary
TechReady7 Breakout Chalktalk Template Page Compression Page Dictionary 9/18/2018 Page Header Lambert NULL Column prefix Lee 0x5B8D80 Page Dictionary 4 1 0x5B8D80 Decimal is HEX 0x5B8D80 5i 20x41 0x41AABB This is maintained per page 20x42 0x5CAABB Lee 20x43 0x9A4041 Lee 600000 1 0x112233 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
47
Free Space in Database Files
--Provided AS IS, without warranty of any kind SELECT a.file_id, LOGICAL_NAME = a.name, PHYSICAL_FILENAME = a.physical_name, FILEGROUP_NAME = b.name, FILE_SIZE_MB = CONVERT(DECIMAL(12,2),ROUND(a.size/ ,2)), SPACE_USED_MB = CONVERT(DECIMAL(12,2),ROUND(FILEPROPERTY(a.name,'SpaceUsed')/ ,2)), FREE_SPACE_MB = CONVERT(DECIMAL(12,2),ROUND((a.size-FILEPROPERTY(a.name,'SpaceUsed'))/ ,2)) FROM sys.database_files a LEFT OUTER JOIN sys.data_spaces b ON a.data_space_id = b.data_space_id
48
Data Volume in Each Allocation Unit Type
-- Provided AS IS, without warranty of any kind SELECT OBJECT_NAME(p.object_id) AS Object_Name , i.name AS Index_Name , ps.in_row_used_page_count AS IN_ROW_DATA , ps.row_overflow_used_page_count AS ROW_OVERFLOW_DATA , ps.lob_used_page_count AS LOB_DATA FROM sys.dm_db_partition_stats ps JOIN sys.partitions p ON ps.partition_id = p.partition_id JOIN sys.indexes i ON p.index_id = i.index_id AND p.object_id = i.object_id WHERE OBJECTPROPERTY (p.[object_id], 'IsUserTable') = 1
49
Percent of Update Operations on the Object
SELECT o.name AS [Table_Name], x.name AS [Index_Name], i.partition_number AS [Partition], i.index_id AS [Index_ID], x.type_desc AS [Index_Type], i.leaf_update_count * / (i.range_scan_count + i.leaf_insert_count + i.leaf_delete_count + i.leaf_update_count + i.leaf_page_merge_count + i.singleton_lookup_count ) AS [Percent_Update] FROM sys.dm_db_index_operational_stats (db_id(), NULL, NULL, NULL) i JOIN sys.objects o ON o.object_id = i.object_id JOIN sys.indexes x ON x.object_id = i.object_id AND x.index_id = i.index_id WHERE (i.range_scan_count + i.leaf_insert_count + i.leaf_delete_count + leaf_update_count + i.leaf_page_merge_count + i.singleton_lookup_count) != 0 AND objectproperty(i.object_id,'IsUserTable') = 1 ORDER BY [Percent_Update] ASC
50
Percent of Scan Operations on the Object
SELECT o.name AS [Table_Name], x.name AS [Index_Name], i.partition_number AS [Partition], i.index_id AS [Index_ID], x.type_desc AS [Index_Type], i.range_scan_count * / (i.range_scan_count + i.leaf_insert_count + i.leaf_delete_count + i.leaf_update_count + i.leaf_page_merge_count + i.singleton_lookup_count ) AS [Percent_Scan] FROM sys.dm_db_index_operational_stats (db_id(), NULL, NULL, NULL) i JOIN sys.objects o ON o.object_id = i.object_id JOIN sys.indexes x ON x.object_id = i.object_id AND x.index_id = i.index_id WHERE (i.range_scan_count + i.leaf_insert_count + i.leaf_delete_count + leaf_update_count + i.leaf_page_merge_count + i.singleton_lookup_count) != 0 AND objectproperty(i.object_id,'IsUserTable') = 1 ORDER BY [Percent_Scan] DESC
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.