Rank: Administration
Medals: Groups: Administrators
Joined: 10/20/2012 Posts: 106 Points: 327 Location: Tbilisi
Thanks: 0 times Was thanked: 0 time(s) in 0 post(s)
|
დიდ მონაცემთა ბაზაში, სადაც ძალიან ბევრი რაოდენობის ინდექსები არსებობს რთული ხდება აღმოვაჩინოთ ზედმეტი (დუბლირებული) ინდექსი, რისი არსებობაც თავის მხრივ არასასურველია.
გთავაზობთ სკრიპტს, რომლის საშუალებითაც სწრაფად აღმოაჩენთ დუბლირებული ინდექსების არსებობას და მისი განადგურებით მოახდენთ თქვენი მონაცემთა ბაზის ოპტიმიზირებას. თუ SELECT არცერთ სტრიქონს არ გიბრუნებთ, ე.ი. თქვენს მონაცემთა ბაზაში ამ მხრივ ყველაფერი რიგზეა.
რათქმაუნდა შესაძლებელია ამ სკრიპტზე დაყრდნობით Stored Procedure-ს მომზადება და საჭიროების სემთხვევაში ის შეიძლება ჩაისვას SQLJOB-ში, რომ სისტემამ თვითონ შეასრულოს ის გარკვეული პერიოდულობით.BB კოდი: with ct as ( select t.name as tableName, p.* from sys.tables as t inner join sys.indexes as i1 on i1.object_id = t.object_id cross apply ( select top 1 * from sys.indexes as i where i.object_id = i1.object_id and i.index_id > i1.index_id and i.type_desc <> 'xml' order by i.index_id ) as i2 cross apply ( select min(a.index_id) as ind1, min(b.index_id) as ind2 from ( select ic.* from sys.index_columns ic where ic.object_id = i1.object_id and ic.index_id = i1.index_id and ic.is_included_column = 0 ) as a full outer join ( select * from sys.index_columns as ic where ic.object_id = i2.object_id and ic.index_id = i2.index_id and ic.is_included_column = 0 ) as b on a.index_column_id = b.index_column_id and a.column_id = b.column_id and a.key_ordinal = b.key_ordinal having count(case when a.index_id is null then 1 end) = 0 and count(case when b.index_id is null then 1 end) = 0 and count(a.index_id) = count(b.index_id) ) as p where i1.type_desc <> 'xml' ) select a.tablename, a.ind1, s1.name as ind1Name, a.ind2, s2.name as ind2Name from ct as a inner join sys.indexes s1 on s1.object_id = object_id(a.tablename) AND s1.index_id = a.ind1 inner join sys.indexes s2 on s2.object_id = object_id(a.tablename) AND s2.index_id = a.ind2
|
|
Apex ltd. http://www.apex.ge
|