Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

i-catching solutions
Browse by Tags · View All
SQL Server 26
Script toolbox 16
T-SQL 12
SQL 12
Geniiius 8
SQL Server 2012 7
Performance optimization 6
DMV 5
debugging 5
Debugging 5

Archive · View All
November 2011 6
May 2012 4
April 2012 4
January 2012 4
February 2012 3
March 2012 3
October 2011 2
December 2011 2
September 2012 1
June 2012 1

Geniiius's Blog

How much space are you wasting?

Nov 8 2011 12:00AM by Geniiius   

A few weeks back a client of mine asked me to write a script that could tell him the space used by write only indexes. The usage stats from the indexes is pretty easy to get from ‘sys.dm_db_index_usage_stats’ and if you join the DMV ‘sys.dm_db_partition_stats’ onto that, you can from the column ‘used_page_count’ calculate the number of bytes that the particular indexes is wasting.

Here is the script, that I ended up with:

with cte as
(
select
t1.database_id,
t1.object_id,
t1.index_id,
t3.partition_number,
t3.used_page_count
from sys.dm_db_index_usage_stats t1
inner join sys.indexes t2 on (t1.object_id = t2.object_id) AND (t1.index_id = t2.index_id)
inner join sys.dm_db_partition_stats t3 on (t1.object_id = t3.object_id) AND (t1.index_id = t3.index_id)
where
    database_id = DB_ID() and
    user_seeks = 0 and user_scans = 0 and user_lookups = 0 and
    OBJECTPROPERTY(t1.[object_id],'IsUserTable') = 1 and t2.index_id > 1 and
    t2.is_unique = 0 and t2.is_unique_constraint = 0
)
select
database_id,
object_id,
index_id,
COUNT(*) as numofpartitions,
SUM(used_page_count) as UsedPages,
(SUM(used_page_count) * 8) / 1024 as spacewasteinmb
from cte
group by database_id, object_id, index_id
order by 1,2,3

if you add a COMPUTE statement at the end, you will get the total sum of all the write only indexes is your database. That COMPUTE statement could look like this:

COMPUTE SUM((SUM(used_page_count) * 8) / 1024)

Putting it all together, and running the query gives me on one of my databases a output looking like this.

blogCapture

as the pictures shows, I could save almost 300 MB if I would drop the three write only indexes from the list above. As always be careful when you drop indexes – better check an extra time before dropping.

Please post your savings as blog comments, and I’ll reward the biggest number with a Xmas present from Geniiius. The game is on.

@geniiiuscom


Republished from geniiius.com [45 clicks].  Read the original version here [32134 clicks].

Geniiius
133 · 1% · 369
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

4  Comments  

  • can you please explain what you mean by write only indexes?

    commented on Nov 16 2011 2:23PM
    vanne040
    83 · 2% · 657
  • Hi,

    Write covers inserts, updates and deletes, and reads correspond to selects. So write only indexes just means indexes on tables where write operations happen, but the index is never used for selects (seeks/lookups and scans). Such an index just gives you an overhead regarding io operations, as well as wasted space in data files and backup files.

    @geniiiuscom

    commented on Nov 16 2011 3:47PM
    Geniiius
    133 · 1% · 369
  • Thanks @geniiius. I dint know that we create indexes on tables that are not used for select operations at all. I am under the assumption that indexes are used for faster retrieval of data rather than modify data. Correct me if I am wrong and please tell me a situation where you had to create write only indexes.

    commented on Nov 17 2011 8:26AM
    vanne040
    83 · 2% · 657
  • vanne040,

    Write-only indexes has no purpose at all, but they could be old indexes that were used previously. But perhaps updated application code changed the execution plan - or the data in the column is just no longer needed, and then the index is not used for selects. So I cannot give you an example where one would want to create an index without using it for selects. And that's why they should be dropped to save resources.

    @geniiiuscom

    commented on Nov 17 2011 10:15AM
    Geniiius
    133 · 1% · 369

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]