Script to find duplicate index and how can we tell if an index is REALLY a duplicate?

Does any one have script to find duplicate index? and how can we tell if an index is REALLY a duplicate?
Rahul

One more written by Itzik Ben-Gan
The first query finds exact matches. The indexes must have 
the same key columns in the same order, and the same included columns but in any order. 
These indexes are sure targets for elimination. The only caution would be to check for index hints. 
-- exact duplicates
with indexcols as
select object_id as id, index_id as indid, name,
(select case keyno when 0 then NULL else colid end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by keyno, colid
for xml path('')) as cols,
(select case keyno when 0 then colid else NULL end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by colid
for xml path('')) as inc
from sys.indexes as i
select
object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',
c1.name as 'index',
c2.name as 'exactduplicate'
from indexcols as c1
join indexcols as c2
on c1.id = c2.id
and c1.indid < c2.indid
and c1.cols = c2.cols
and c1.inc = c2.inc;
The second variation of this query finds partial, or duplicate, indexes 
that share leading key columns, e.g. Ix1(col1, col2, col3) and Ix2(col1, col2) 
would be considered duplicate indexes. This query only examines key columns and does not consider included columns. 
These types of indexes are probable dead indexes walking. 
-- Overlapping indxes
with indexcols as
select object_id as id, index_id as indid, name,
(select case keyno when 0 then NULL else colid end as [data()]
from sys.sysindexkeys as k
where k.id = i.object_id
and k.indid = i.index_id
order by keyno, colid
for xml path('')) as cols
from sys.indexes as i
select
object_schema_name(c1.id) + '.' + object_name(c1.id) as 'table',
c1.name as 'index',
c2.name as 'partialduplicate'
from indexcols as c1
join indexcols as c2
on c1.id = c2.id
and c1.indid < c2.indid
and (c1.cols like c2.cols + '%' 
or c2.cols like c1.cols + '%') ;
Be careful when dropping a partial duplicate index if the two indexes differ greatly in width. 
For example, if Ix1 is a very wide index with 12 columns, and Ix2 is a narrow two-column index 
that shares the first two columns, you may want to leave Ix2 as a faster, tighter, narrower index.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • I'm having trouble turning on my ipad and how can I tell when it's fully charged?

    I'm having trouble turning on my ipad and how can I tell when it's fully charged?

    Try a Reset - hold the Home and Sleep/Wake buttons down together for 15 seconds.
    Have you read the User Guide?
    Unless the charge indicator has bee turned off you see the percentage charged in the top right of the screen.

  • When are I-Tunes updates legitimate and how can I tell?

    When are I-Tunes updates legit and how can I tell?

    I have no idea what you're ranting and rambling about. Your "simple question", if you're referring to the one in this thread, makes little sense other than how I addressed it. If my answer didn't cover your question, post back and clarify what it is you're asking. Don't just come back and post a rant; it's insulting (and the "human" crack doubly so) to all those here, who are just fellow users trying to help out other users and who don't owe you one second of their time.
    If you want tech support directly from Apple, you call them; it's that simple. Contact information is linked from the bottom of every Apple web page, including this one.
    Geez; the old saying that "no good deed goes unpunished" continues to get proven true every day.

  • ITunes 12-Please please restore side bar functions for playlists -and how can i tell when and if it is safe to "eject" devices after synching

    ITUNES 12-4points
    1) Please restore the easy function whereby the side bar easily accommodates playlists
    2) How do i know when devices can be ejected following synch--no visible drop down ?
    3) How can i change the fonts and font sizes of the library-over and above the noddy large/small toggle in preferences
    4) Look forward to a proper Apple update which includes  full functions of iTunes radio. Hurry up with the latter-Spotify is overtaking you guys!

    How do i know when devices can be ejected following synch--no visible drop down ?
    I can only tell you based on what I see w/ my iPhone...
    When I plug in my iPhone I get the following icon on the top bar:
    If I click on that (that's when it turns blue), I get a sidebar.  At the top I see this while it is syncing:
    The circle-arrows spin.  Once the sync is finished, I see this:
    I then know the sync is over and I click on the Eject icon that replaced the circle-arrows.
    Are you seeing something different?

  • Where can I find archived mail and how can I retrieve it?

    I archived emails I wanted to keep and retread later, but I don't know where they've gone to or how to get them to read. Any help will be appreciated. I have an iPad mini , the iOS is 6.1 I'm pretty sure.

    What email service are you using POP3, IMAP, Google, iCloud, your internet service provider?
    With POP3 by default the iPad is set to delete old emails automatically. POP3 accounts such as the one your internet service provider gave you will have settings on the iPad you can change. Go to Settings/Mail, Contacts, Calendars/"Your Email Account"/Advanced and set Deleted Emails/Remove to never. I find this option is not labeled very well and gives the impression it is for the messages in the Trash, but auto deletes messages in the Inbox as well.
    IMAP accounts such as iCloud and GMail are on the server and effect all devices.

  • How do I most effectively use find my phone and how can I help a family member use find my phone?

    What is the most effective way for me to use FIND MY PHONE?
    What is the most effective way for me to help my family member FIND THEIR PHONE?
    Thank you

    Effectively use is for what? On your computer you can log into iCloud at www.icloud.com and locate your device. Or you can use a different iOS device and the Find My iPhone app to do the same thing.

  • What happens if you misswire your speakers AND how can you tell if it is misswired?

    The red mark came off the wire and i don`t know which wire was the red one.

    Hmmm... the best way to determine which wire is the '+' is by using a electronic meter and do a continuity test. The center pin of the RCA cable is the '+' and the ground is '-'. If you don't have a meter, only way you can try is using music, try to differentiate whether that particular spk does it sound out of phase or correct phase. If out of phase, the vocal will not sound very centerised. Good luck.

  • What permissions do signed applets get? And how can I tell?

    This could be a JNLP question, but it's really about signing versus not signing.
    I find that if I sign the applet's jar, I get permissions I don't get if I don't sign it, even though I haven't asked for any permissions. What's disturbing about this is that neither the JNLP spec (look under Launch) nor the Permissions spec (look here [http://download.oracle.com/javase/1.4.2/docs/guide/security/permissions.html#SecMgrChecks] -- I don't know if there's a more recent version) make any mention of signing. (Well, the JNLP spec says you need to sign if you ask for permissions, but I'm not asking for any permissions in the JNLP.)
    So, my question is: Where is the set if permissions that an applet gets solely by virtue of being signed documented? Failing that, is it possible to get the security manager to list out the permissions I have?

    bump
    having the same existential question about the secret mysteries of jnlp applets, I'd be highly interested by the answer :)

  • My MacBook Air shuts down when its more than half way charged and won't turn on unless I plug it in to the adapter? Why is this happening and how can I fix it?

    My MacBook Air shuts down when its more than half way charged and won't turn on unless I plug it in to the adapter? Why is this happening and how can I fix it?

    If you really do have a Mid 2013 Mac Air model then it is still in warranty, as the standard Apple warranty is one year from date of purchase. So take it into an Apple store and have it diagnosed and fixed under the warranty. There is some type of hardware problem that only Apple can fix.

  • Help Please! How can I tell what is stored on my iPod?

    I just recently got a new iPod Nano, and started using iTunes to upload music to it. But, for some reason, I can only fit like 60 or so songs onto it. I have a 1 GB Nano. If I click onto my iPod in iTunes, it says at the bottom of the screen that I have 59 songs, 3.2 hrs of music, 223.2 MB, but just above that, where the bar is that shows how much is stored to my iPod, it says I have used 750.5 MB and have 142.1 MB free. Where is the other 527.3 MB being used and how can I tell? Is it being used in the games? I have no pics or videos at all on my iPod. It's getting very frustrating because I can't fit very much at all on my 1GB Nano. Help!

    sussan-b,
    Does the bar showing used space have a portion labeled "Other"?
    Usually other is files that have been copied to the iPod directly, or space you have told the iPod to reserve for other files by enabling disk use.
    This article has more information and screenshots:
    http://docs.info.apple.com/article.html?artnum=61131

  • Buying 2nd hand iPhone 3GS. How can I tell it's not a 3G?

    Sorry if this is a stupid question, but never had/used an iPhone before. Thinking about buying a second hand iPhone 3GS.
    How can I tell if it's a 8gb, 16gb or 32gb and how can I tell it's not an iPhone 3G?
    Thanks

    Spiface,
    If you can get a look at the back of the phone, here are some things to look for:
    Is the Writing on the back of the phone in Silver or in Grey?
    If it is Silver, then it is a 3GS.
    16GB and 32GB models have the storage capacity printed on their backs. The current 8GB model does not have any storage capacity printed on its back, although you can still identify it as a 3GS if it has silver print.
    Hope this helps,
    David

  • Script to find out table and index candidates to keep in the buffer pool

    I am looking for a script to find out tables and indexes to keep in the buffer pool.
    Could you help me on this ?
    thanks...
    Markus

    this is more of a open question. As you know ur data well. We do not know whats ur data. cachin tables in buffer pool is okay, but it might age out after not being used...instead you can use the KEEP POOL...to cache small tables/popular tables into the keep pool...as keep pool guarantees full caching .....
    here are some links on keep pool cacheing
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/memory.htm#sthref410
    http://www.dba-oracle.com/oracle_tips_cache_small_fts.htm
    http://www.dba-oracle.com/t_script_automate_keep_pool_tables_indexes.htm
    http://www.dba-oracle.com/oracle_news/news_caching_keep_pool_large_objects_clob_blob.htm
    Edited by: user630084 on Apr 8, 2009 5:48 AM

  • I put in my memory card to the left side of the computer, but I cannot find the file of pictures anywhere. Its not even on my desktop. What should I do and how can I get it to show up on my desktop?

    I put in my memory card to the left side of the computer, but I cannot find the file of pictures anywhere. Its not even on my desktop. What should I do and how can I get it to show up on my desktop?

    If your Mac is new-ish and has one of the Lions as its OS, the drives, cards, USB sticks no longer show up, even though they're there. Go to Finder's Preferences and tick the corresponding items in the General and Sidebar tabs.

  • "Volume not found" I have 3 iphoto_libraries stored in a external disk, while the actual files are in other external disk. Ive moved together iphotolibraries and files but: HOW CAN I TELL THE LIBRARIES WHERE TO FIND THEM NOW?

    I have three iphoto_libraries stored in a external disk PASSPORT (one for each trip imovie Im making -Ive managed this way the libraries so to not confuse the trips) while the actual files are in OTHER external disk LACIE. And everything was fine: imovie find each library, could work with it, or iphoto could edit the files.
    But one day everything crashed at the same time: i opened iphoto to find 3 different scenarios:
    1) iphoto_library GREECE was there, but not the albums i prepared. no events. when double click in any of them: "Volume not found"
    2) iphoto_library ITALY was there, and the albums i prepared too, but empty.
    in both cases I can only see the photos in 'photos'  because 'events'  shows some events with photo preview and some with no preview, just some kind of preset clipart palm tree, but if i enter the event, photos are there but again: when double click in any item: "Volume not found"
    3)  iphoto_library ISRAEL was there, the albums too, when double click in any of them: all OK
    The 3 libraries was managed the same way. Meaning: Ive imported photos to iphoto from external disk LACIE in a iphotolibrary stored in another external disk PASSPORT. Also: I don't have unchecked the option "copy to file" or something like that. photos where moved, not copied. Also i have all the movie_libraries in the PASSPORT as well. What happened??
    Solution? Nothing yet. Ive moved now all the photo folders from LACIE together in PASSPORT with the iphotolibraries but problem persist:
    HOW CAN I TELL THE LIBRARIES WHERE TO LOOK FOR THE VOLUMES NOW?
    "Volumes" are the original files aren't them?
    Please help. this is so annoying to try and find in the forum, to tricky to explain
    I have a Macbook pro retina Yosemite 10.10.1 / iphoto 9.6 (910-29)/ iMovie 10.0.6
    THANK YOU
    Vicky

    The 3 libraries was managed the same way. Meaning: Ive imported photos to iphoto from external disk LACIE in a iphotolibrary stored in another external disk PASSPORT.
    This is not clear, especially when you say
    I don't have unchecked the option "copy to file" or something like that. photos where moved, not copied.
    Especially as the message you're getting is typical of a library where the ' option "copy to file" or something like that' is unchecked.
    So it's a simple question:
    Are you these Managed or Referenced Libraries?
    A Managed Library, is the default setting, and iPhoto copies files into the iPhoto Library when Importing. The files are then stored in the Library package
    A Referenced Library is when iPhoto is NOT copying the files into the iPhoto Library when importing because you made a change at iPhoto -> Preferences -> Advanced. (You unchecked the option to copy files into the Library on import) The files are then stored where ever you put them and not in the Library package. In this scenario you are responsible for the File Management.

  • Hi there, I pay for extra iCloud space online. However I cannot seem to find any of my photos or account? As my iPod/iPhone only hold 1000 pictures, where are the previous pictures? And how can I access them?

    Hi there, I pay for extra iCloud space online. However I cannot seem to find any of my photos or account? As my iPod/iPhone only hold 1000 pictures, where are the previous pictures? And how can I access them?

    You cannot use iCloud Storage to suppliment your iPad. They are mainly used to backup iPad.
    Free up space on iPad
    Settings>General>Usage>Storage>Delete what is not needed to free up space on iPad.

Maybe you are looking for

  • I can't open a folder in a New Tab, nor have the option to after right-click.

    Basically exactly what it says on the tin. After changing my Finder preferences back and forth, restarting, and trashing my library files to no avail, I'm wondering if anyone has a solution. I can create new tabs, but only by using the '+' button in

  • Creating Logical Database

    hi,    i need to display Outstanding Liability GRNs in my report. for that report, i have created a Logical Database. The structure of ldb is, BSIS>Bkpf->Bseg--->Rseg     My Input fields                     GL Account                     Plant       

  • IPhoto '11 crashes on assembling books

    I have a number of books in iPhoto '11. Some of them were created in iPhoto '09, one was created in iPhoto '11. The last time I ordered a book was in February (2011). Everything worked flawlessly then. Last week (April 7th) it has become totally impo

  • Creating Separation lines between rows of content

    I have several hundreds pages from a catalog we are creating that need separation lines between columns to segragate the products. I am wondering if there is an easy way to automate the creation of these. I tried using the Grid feature ( by drawing a

  • User Profile Services start in all sharepoint servers in farm

    Hi, Do we need to start the below services in all sharepoint servers in farm? 1) User Profile Service 2) User Profile Synchronization Service  Thanks....