Primary Key GUID olan bir tabloloya PARTITION'a bölmek

by Nurgün Özgür 26. January 2010 18:56

Bu yazımda Primary Key GUID olan büyük bir tabloyu PARTITION’lara   nasıl bölebileceğinizi göstereceğim. Küçük tablolarda bu yöntem performansın kötüleşmesine neden olur fakat büyük tablolarda çok iyi sonuçlar alınabilir. Yine de her zaman sonucun test edilmesi gerekiyor ve sonuca göre production sistemlere uygulanmalı.

use master

alter database MyDB set RESTRICTED_USER

-- DB backup all !!!

 

--önce TPropertyValue tablonun full scriptini al (defaultlar dahil) indexler, FK, Constraint

 

use MyDB

 

--geciçi tablo yarat

select * into TPropertyValue_20100114 from TPropertyValue

 

--tabloyu hızlandırmak için PK ekle

ALTER TABLE TPropertyValue_20100114 add CONSTRAINT PK__TPropertyValue_20100114__33758E3C PRIMARY KEY NONCLUSTEReD (ID)

 

--geçici tablonun içini kontrol et

--kayıt sayısını kontrol et

select count(*) from TPropertyValue_20100114

select count(*) from TPropertyValue

 

 

-- partition yapılacak tabloyu TPropertyValue drop et. Daha

ALTER INDEX ALL ON TPropertyValue DISABLE

 

 

--tüm foreign keyleri drop et. us_fkeys kullanabilirsin

--ilişkili view var ise ÖNCE view indexlerin scriplerini all !!!

--var ise ilişkili viewlar'daki SHEMABINDING leri kaldır,

 

drop table TPropertyValue

--Partition Function yarat

--------drop partition function PFuncNurgun_TPropertyValueN

CREATE PARTITION FUNCTION PFuncNurgun_TPropertyValue (uniqueidentifier)

AS RANGE RIGHT FOR VALUES

('00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-090000000000',

 '00000000-0000-0000-0000-100000000000', '00000000-0000-0000-0000-190000000000',

 '00000000-0000-0000-0000-200000000000', '00000000-0000-0000-0000-290000000000',

 '00000000-0000-0000-0000-300000000000', '00000000-0000-0000-0000-390000000000',

 '00000000-0000-0000-0000-400000000000', '00000000-0000-0000-0000-490000000000',

 '00000000-0000-0000-0000-500000000000', '00000000-0000-0000-0000-590000000000',

 '00000000-0000-0000-0000-600000000000', '00000000-0000-0000-0000-690000000000',

 '00000000-0000-0000-0000-700000000000', '00000000-0000-0000-0000-790000000000',

 '00000000-0000-0000-0000-800000000000', '00000000-0000-0000-0000-890000000000',

 '00000000-0000-0000-0000-900000000000', '00000000-0000-0000-0000-9F0000000000',

 '00000000-0000-0000-0000-A00000000000', '00000000-0000-0000-0000-AF0000000000',

 '00000000-0000-0000-0000-B00000000000', '00000000-0000-0000-0000-BF0000000000',

 '00000000-0000-0000-0000-C00000000000', '00000000-0000-0000-0000-CF0000000000',

 '00000000-0000-0000-0000-D00000000000', '00000000-0000-0000-0000-DF0000000000',

 '00000000-0000-0000-0000-E00000000000', '00000000-0000-0000-0000-EF0000000000',

 '00000000-0000-0000-0000-F00000000000', 'FFFFFFFF-FFFF-FFFF-FFFF-FEFFFFFFFFFF')

 

 

--FileGroup ekle

Declare @i int, @s varchar(5)

Declare @stmt varchar(2000)

select @i =0

while @i < 33

begin

      select @i = @i + 1;

      select @s = convert(varchar,@i)

      select @stmt = 'ALTER DATABASE [CardioReferans_Mirror] ADD FILEGROUP TPropertyValue_fg'+@s

--    select @stmt = 'ALTER DATABASE [CardioReferans_Mirror]  REMOVE FILEGROUP TPropertyValue_fg'+@s

      exec (@stmt)

end

 

 

--FILE ekle burada S:\MSSQLDATA\REFERANS\ path ve SIZE değiştirilebilir !

Declare @i int, @s varchar(5)

Declare @stmt varchar(2000)

select @i =0

while @i < 33

begin

      select @i = @i + 1;

      select @s = convert(varchar,@i)

      select @stmt = 'ALTER DATABASE [CardioReferans_Mirror] '

      select @stmt = @stmt + ' ADD FILE (NAME = TPropertyValue_file'+@s+', FILENAME = '

      select @stmt = @stmt + '''S:\MSSQLDATA\REFERANS\TellcomCardioReferans_TPropertyValue_fg'+@s+'.ndf'''

      select @stmt = @stmt + ', SIZE = 100MB,FILEGROWTH = 50MB ) TO FILEGROUP TPropertyValue_fg'+@s+';'

 

      --select @stmt = 'ALTER DATABASE [CardioReferans_Mirror]  REMOVE FILE TPropertyValue_file'+@s

      exec (@stmt)

end

 

--sp_helpdb MyDB

 

--Partition şema ekle

CREATE PARTITION SCHEME PSchemeNurgun_TPropertyValue

AS PARTITION PFuncNurgun_TPropertyValue

TO ( TPropertyValue_fg1, TPropertyValue_fg2, TPropertyValue_fg3, TPropertyValue_fg4,

      TPropertyValue_fg5, TPropertyValue_fg6, TPropertyValue_fg7, TPropertyValue_fg8,

      TPropertyValue_fg9, TPropertyValue_fg10, TPropertyValue_fg11, TPropertyValue_fg12,

      TPropertyValue_fg13, TPropertyValue_fg14, TPropertyValue_fg15, TPropertyValue_fg16,

      TPropertyValue_fg17,TPropertyValue_fg18,TPropertyValue_fg19,TPropertyValue_fg20 ,

      TPropertyValue_fg21,TPropertyValue_fg22,TPropertyValue_fg23,TPropertyValue_fg24 ,

      TPropertyValue_fg25, TPropertyValue_fg26,TPropertyValue_fg27,TPropertyValue_fg28 ,

      TPropertyValue_fg29,TPropertyValue_fg30,TPropertyValue_fg31,TPropertyValue_fg32 ,

      TPropertyValue_fg33)

 

--Tabloyu şema içinde yarat !!!

CREATE TABLE [dbo].[TPropertyValue](

      [ID] [uniqueidentifier] ROWGUIDCOL  NOT NULL CONSTRAINT [DF_TPropertyValue_ID]  DEFAULT (newid()),

      [PropertyId] [uniqueidentifier] NULL,

      [PropertyLovId] [uniqueidentifier] NULL,

      [ValueString] [nvarchar](800) NULL,

      [ValueFloat] [float] NULL,

      [ValueDatetime] [datetime] NULL,

      [ValueMlstringTr] [nvarchar](200) NULL,

      [ValueMlstringEn] [nvarchar](200) NULL,

      [ValueMlstringDe] [nvarchar](200) NULL,

      [ValueMlstringFr] [nvarchar](200) NULL,

      [ValueMlstringRu] [nvarchar](200) NULL,

      [ValuePassword] [nvarchar](800) NULL,

      [CreateUserId] [uniqueidentifier] NULL,

      [CreateUserPositionId] [uniqueidentifier] NULL,

      [CreateUserTime] [datetime] NULL,

      [UpdateUserId] [uniqueidentifier] NULL,

      [UpdateUserPositionId] [uniqueidentifier] NULL,

      [UpdateUserTime] [datetime] NULL,

      [OrderBy] [int] NULL,

      [EntityType] [uniqueidentifier] NULL,

      [EditStatus] [int] NULL CONSTRAINT [TPropertyValue_EditStatus_Dflt]  DEFAULT ((0)),

      [AutoId] [int] IDENTITY(1,1) NOT NULL,

      [GcRecordId] [uniqueidentifier] NULL,

      [UpdateUserIP] [nvarchar](30) NULL,

      [CreateUserIP] [nvarchar](30) NULL,

      [BulkUpdateFlag] [bit] NULL

 

,PRIMARY KEY NONCLUSTERED

(

      [ID] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,

      IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON PSchemeNurgun_TPropertyValue(ID)

) ON PSchemeNurgun_TPropertyValue(ID)

 

 

--TPropertyValue tabloyu yedekten geri al

BEGIN

      SET IDENTITY_INSERT TPropertyValue ON

      insert into TPropertyValue ( ID, PropertyId, PropertyLovId, ValueString, ValueFloat, ValueDatetime, ValueMlstringTr, ValueMlstringEn, ValueMlstringDe, ValueMlstringFr, ValueMlstringRu, ValuePassword, CreateUserId, CreateUserPositionId, CreateUserTime, UpdateUserId, UpdateUserPositionId, UpdateUserTime, OrderBy, EntityType, EditStatus, AutoId, GcRecordId, UpdateUserIP, CreateUserIP, BulkUpdateFlag)

      select  ID, PropertyId, PropertyLovId, ValueString, ValueFloat, ValueDatetime, ValueMlstringTr, ValueMlstringEn, ValueMlstringDe, ValueMlstringFr, ValueMlstringRu, ValuePassword, CreateUserId, CreateUserPositionId, CreateUserTime, UpdateUserId, UpdateUserPositionId, UpdateUserTime, OrderBy, EntityType, EditStatus, AutoId, GcRecordId, UpdateUserIP, CreateUserIP, BulkUpdateFlag

            from TPropertyValue_20100114

      SET IDENTITY_INSERT TPropertyValue OFF

END

--

 

--TPropertyValue tablonun Contrain ve FK 'lerini yeniden yarat

 

--TPropertyValue tablonun INDEX'lerini ŞEMA içinde yarat ve incele

      CREATE NONCLUSTERED INDEX [IX_TPropertyValue_ValueString] ON [dbo].[TPropertyValue]

      (

            [PropertyId] ASC,

            [ValueString] ASC

      )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF,

      IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON,

      ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80)

      ON PSchemeNurgun_TPropertyValue(ID)

 

 

sp_helpindex TPropertyValue

 

update statistics [TPropertyValue]

 

--viewların SHEMABINDING lerini geri koy ve view'ların indexleri yarat

 

 

--Partition Row dağılımı incele

select partition_number, rows from sys.partitions where object_id =object_id('TPropertyValue') and index_id <=1

 

--sadece bir partition nın index'ini rebuild et

alter index [IX_TPropertyValue_ValueString] on TPropertyValue rebuild PARTITION =2

 

--herkese izin ver

alter database  MyDB set MULTI_USER

 

--THE END

 

Comments

3/3/2010 7:56:09 AM #

payday loans

If you're interested in having a guest blog poster please  let me know. I will provide you with unique content for your blog, thanks.

payday loans United States | Reply

4/29/2010 5:27:23 PM #

foam inserts

I cannot WAIT to read more of this.  I mean, you just know so much about this.  So much of it Ive never even thought of.  You sure did put a new twist on something that Ive heard so much about.  I dont believe Ive actually read anything that does this subject as good justice as you just did.

foam inserts United States | Reply

4/30/2010 11:49:31 PM #

watches online

How did you get to be this good?  Its amazing to see someone put so much passion into a subject.  Im glad I came across this.  Im glad I took the time to read on past the first paragraph.  Youve got so much to say, so much to offer.  I hope people realise this and look into your page.

watches online United States | Reply

5/3/2010 12:56:44 AM #

catalina island

How could I have missed this blog!  Its incredible.  Your design is flawless, like you know exactly what to do to do make people flock to your page!  I also like the perspective you brought to this subject.  Its like you have an insight that most people havent seen before.  So great to read a blog like this.

catalina island United States | Reply

5/3/2010 4:17:32 AM #

wtf boom origin

The count says that 10 are still available, but how can you get it without the link? I don’t want to miss out on the sale!! Hi First time bounded here on your site, founde on Yahoo. I just wanted to say Thank you very much for the advice and wisdom you shared with me. It really did help me to accept the process and keep myself honest and nurtured regardless of what was going on. wtf boom origin Send me news to 371Inzana@o2.pl

wtf boom origin United States | Reply

5/3/2010 6:52:36 PM #

bathroom ceiling fan

I think more people need to read blogs like this.  Its so important to know how to construct a great blog to get people interested and youve done just that.  The content is great, the videos are perfect for what youre trying to say.  Awesome, man. Really awesome!  Cant wait to read more.

bathroom ceiling fan United States | Reply

5/17/2010 9:26:25 PM #

pingback

Pingback from topsy.com

Twitter Trackbacks for
        
        MSSQL ve Oracle Blog, MSSQL, Oracle, Telekom | Primary Key GUID olan bir tabloloya PARTITION'a bölmek
        [nurgun.net]
        on Topsy.com

topsy.com | Reply

5/27/2010 9:25:21 AM #

Designer handbags

I have a few in the same niche and I would like to add my button somwhere on your site.

Designer handbags United States | Reply

5/27/2010 3:09:17 PM #

Plugin SEO

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

Plugin SEO United States | Reply

5/28/2010 9:50:29 PM #

Panic and Anxiety Attacks

What you said made a lot of sense.  But, think about this, what if you added a little content?  I mean, I dont want to tell you how to run your blog, but what if you added something to maybe get peoples attention?  Just like a video or a picture or two to get people excited about what youve got to say.  In my opinion, it would make your blog come to life a little bit.

Panic and Anxiety Attacks United States | Reply

5/29/2010 2:41:20 PM #

ediets review

Thanks very much for the information. I have been searching for this for awhile with Yahoo and it has been a real chore.

ediets review United States | Reply

5/29/2010 9:41:53 PM #

xbox 360 repair

Dude, please tell me that youre going to write more.  I notice you havent written another blog for a while (Im just catching up myself).  Your blog is just too important to be missed.  Youve got so much to say, such knowledge about this subject it would be a shame to see this blog disappear.  The internet needs you, man!

xbox 360 repair United States | Reply

5/29/2010 11:31:45 PM #

guru blueprint review

Thanks for taking the time to post this.

guru blueprint review United States | Reply

5/30/2010 5:40:24 AM #

Outsourceable SEO

I would like to say "wow" what a inspiring post. This is really great. Keep doing what you're doing!!

Outsourceable SEO United States | Reply

5/30/2010 10:56:16 AM #

windows registry cleaner

Nice article. I just stumbled upon your website and wanted to say that I have really enjoyed reading your blog posts. Anyway I'll be subscribing to your feed and I hope you post again soon.

windows registry cleaner United States | Reply

5/30/2010 1:56:16 PM #

Karl

Cool, there are actually some great points on here some of my readers will maybe find this useful, will send a link, thanks.

Karl United States | Reply

5/31/2010 2:49:45 AM #

pingback

Pingback from 9.renters.ws

2001 - 2006 @ F53 Direct Fit Oe Replacement, F53 Discount Replacement Auto Parts - 9.renters.ws

9.renters.ws | Reply

5/31/2010 4:15:31 AM #

designer handbags

I love to read posts that are informative and acutally have good content. Thank you for sharing your knowledge and I look forward to reading more.

designer handbags United States | Reply

5/31/2010 10:06:55 AM #

Netflix Coupon Code

Really a educative and informative post, the post is good in all regards,I am glad to read this post.

www.articlesbase.com/.../...nal-codes-2086623.html
www.articlesbase.com/.../...nal-codes-2086568.html

Netflix Coupon Code United States | Reply

6/1/2010 7:06:59 AM #

lilly pulitzer dresses

For what its worth, the layout is definitely amazing.  You know how to balance writing and images/videos.  However, I cant get over how little you actually bring to light here.  I think that everyones said the same thing that youve said over and over again.  Dont you think its time for something more?

lilly pulitzer dresses United States | Reply

6/2/2010 3:11:09 PM #

dave

I found your blog via blog catalog. I thought I'd check out the post as I just wrote on this subject today. You add some great suggestions that I didn't have. Thanks for the tips.

dave Luxembourg | Reply

6/3/2010 2:00:25 AM #

 jute sisal rugs

Hey, found your site by accident doing a search on Bing but I'll definitely be coming back. As for your post... I must agree with a lot of what you're talking about here but wouldn't it be just as easy to try something else? I mean why monkey with your quality of life if you don't have to?

jute sisal rugs United States | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Nurgün Özgür

Facebook

 

Nurgün Özgür Photo

1993'ten bu yana profesyonel olarak yazılım ve sistem yönetimi konularında çeşitli yerli ve yabanci kuruluşların farklı kademelerinde aktif olarak yer aldım. 2011 yılında emekliliğe ayrıldım.

 

Valid XHTML 1.0 Transitional


Tag cloud


Facebook ile giriş