ํƒœ๊ทธ ๋ณด๊ด€๋ฌผ: clustered-index

clustered-index

ํž™์— ๋Œ€ํ•œ ๋น„ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค์™€ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค์˜ ์„ฑ๋Šฅ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. ํ‘œ. ์ผ๋ฐ˜์ ์œผ๋กœ ํด๋Ÿฌ์Šคํ„ฐ

์ด 2007 ๋ฐฑ์„œ ๋Š” ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๋กœ ๊ตฌ์„ฑ๋œ ํ…Œ์ด๋ธ”์— ๋Œ€ํ•œ ๊ฐœ๋ณ„ ์„ ํƒ / ์‚ฝ์ž… / ์‚ญ์ œ / ์—…๋ฐ์ดํŠธ ๋ฐ ๋ฒ”์œ„ ์„ ํƒ ๋ฌธ์˜ ์„ฑ๋Šฅ๊ณผ CI์™€ ๋™์ผํ•œ ํ‚ค ์—ด์— ํด๋Ÿฌ์Šคํ„ฐ๋˜์ง€ ์•Š์€ ์ธ๋ฑ์Šค๊ฐ€์žˆ๋Š” ํž™์œผ๋กœ ๊ตฌ์„ฑ๋œ ํ…Œ์ด๋ธ”์˜ ์„ฑ๋Šฅ์„ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. ํ‘œ.

์ผ๋ฐ˜์ ์œผ๋กœ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค ์˜ต์…˜์€ ์œ ์ง€ ๊ด€๋ฆฌ ํ•  ๊ตฌ์กฐ๊ฐ€ ํ•˜๋‚˜ ๋ฟ์ด๊ณ  ์ฑ…๊ฐˆํ”ผ ์กฐํšŒ๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ํ…Œ์ŠคํŠธ์—์„œ ๋” ๋‚˜์€ ์„ฑ๋Šฅ์„ ๋ณด์˜€์Šต๋‹ˆ๋‹ค.

์ด ๋ฐฑ์„œ์—์„œ ๋‹ค๋ฃจ์ง€ ์•Š์€ ์ž ์žฌ์ ์œผ๋กœ ํฅ๋ฏธ๋กœ์šด ์‚ฌ๋ก€๋Š” ํž™์˜ ํด๋Ÿฌ์Šคํ„ฐ๋˜์ง€ ์•Š์€ ์ธ๋ฑ์Šค์™€ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค์˜ ๋น„ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๋ฅผ ๋น„๊ต ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ NCI ๋ฆฌํ”„ ์ˆ˜์ค€์—์„œ SQL Server์— ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค๋ฅผ ์ˆœํšŒํ•˜์ง€ ์•Š๊ณ  ์ง์ ‘ ๋”ฐ๋ผ์•ผ ํ•  RID๊ฐ€ ์žˆ์œผ๋ฉด ํž™ ์„ฑ๋Šฅ์ด ํ•œ ๋ฒˆ ๋” ํ–ฅ์ƒ ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ˆ„๊ตฌ๋“ ์ง€์ด ์˜์—ญ์—์„œ ์ˆ˜ํ–‰ ๋œ ์œ ์‚ฌํ•œ ๊ณต์‹ ํ…Œ์ŠคํŠธ๋ฅผ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๊นŒ? ๊ทธ๋ ‡๋‹ค๋ฉด ๊ทธ ๊ฒฐ๊ณผ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?



๋‹ต๋ณ€

๊ท€ํ•˜์˜ ์š”์ฒญ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์ด ๊ตฌ์„ฑํ‘œ์— ๋”ฐ๋ผ 2 ๊ฐœ์˜ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

  • ์ž”์•ก ์ •๋ณด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 790 ๋งŒ ๊ฐœ์˜ ๋ ˆ์ฝ”๋“œ.
  • 1-7 ๋ฐฑ๋งŒ์— ์ด๋ฅด๋Š” ์‹ ์› ํ•„๋“œ
  • ์•ฝ 500k ๊ทธ๋ฃน์œผ๋กœ ๋ ˆ์ฝ”๋“œ๋ฅผ ๊ทธ๋ฃนํ™”ํ•˜๋Š” ์ˆซ์ž ํ•„๋“œ.

์ฒซ ๋ฒˆ์งธ ํ…Œ์ด๋ธ” heap์€ ํ•„๋“œ์—์„œ ํด๋Ÿฌ์Šคํ„ฐ๋˜์ง€ ์•Š์€ ์ธ๋ฑ์Šค๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค group. ํ˜ธ์ถœ ๋œ ๋‘ ๋ฒˆ์งธ ํ…Œ์ด๋ธ”์€ ํ˜ธ์ถœ clust๋œ ์ˆœ์ฐจ ํ•„๋“œ์—์„œ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๋ฅผ ์–ป์—ˆ๊ณ  ํ•„๋“œ key์—์„œ ๋น„ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค.group

ํ…Œ์ŠคํŠธ๋Š” 2 ๊ฐœ์˜ ํ•˜์ดํผ ์Šค๋ ˆ๋“œ ์ฝ”์–ด, 4Gb ๋ฉ”๋ชจ๋ฆฌ ๋ฐ 64 ๋น„ํŠธ ์ฐฝ 7์„ ๊ฐ–์ถ˜ I5 M540 ํ”„๋กœ์„ธ์„œ์—์„œ ์‹คํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
Apr  2 2010 15:48:46
Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)  

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ : Sql Server Profiler์—์„œ ๋‹ค์Œ .net ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  Duration, CPU, Reads, Writes ๋ฐ RowCounts๋ฅผ ๋กœ๊น…ํ•˜์—ฌ ๋‘ ๋ฒˆ์งธ๋กœ ๊ด‘๋ฒ”์œ„ํ•œ ๋ฒค์น˜ ๋งˆํฌ๋ฅผ ์ˆ˜ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ ๋œ CommandText๊ฐ€ ๊ฒฐ๊ณผ์— ์–ธ๊ธ‰๋ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ  : CPU ๋ฐ ์ง€์† ์‹œ๊ฐ„์€ ๋ฐ€๋ฆฌ ์ดˆ๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค

  • ์ฟผ๋ฆฌ 1000 ๊ฐœ
  • ์ œ๋กœ CPU ์ฟผ๋ฆฌ๋Š” ๊ฒฐ๊ณผ์—์„œ ์ œ๊ฑฐ
  • ์˜ํ–ฅ์„๋ฐ›๋Š” 0 ๊ฐœ์˜ ํ–‰์ด ๊ฒฐ๊ณผ์—์„œ ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
int[] idList = new int[] { 6816588, 7086702, 6498815 ... }; // 1000 values here.
using (var conn = new SqlConnection(@"Data Source=myserver;Initial Catalog=mydb;Integrated Security=SSPI;"))
            {
                conn.Open();
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "select * from heap where common_key between @id and @id+1000";
                    cmd.Parameters.Add("@id", SqlDbType.Int);
                    cmd.Prepare();
                    foreach (int id in idList)
                    {
                        cmd.Parameters[0].Value = id;

                        using (var reader = cmd.ExecuteReader())
                        {
                            int count = 0;
                            while (reader.Read())
                            {
                                count++;
                            }
                            Console.WriteLine(String.Format("key: {0} => {1} rows", id, count));
                        }
                    }
                }
            }

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .

์„ฑ๋Šฅ ์„ ํƒ

Performanc ๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ํž™ ํ…Œ์ด๋ธ”์—์„œ ํ•œ ๋ฒˆ, clust ํ…Œ์ด๋ธ”์—์„œ ํ•œ ๋ฒˆ ๋‹ค์Œ ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

select * from heap/clust where group between 5678910 and 5679410
select * from heap/clust where group between 6234567 and 6234967
select * from heap/clust where group between 6455429 and 6455729
select * from heap/clust where group between 6655429 and 6655729
select * from heap/clust where group between 6955429 and 6955729
select * from heap/clust where group between 7195542 and 7155729

์ด ๋ฒค์น˜ ๋งˆํฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ heap๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- --------
1503  1510  31ms  309ms
401   405   15ms  283ms
2700  2709  0ms   472ms
0     3     0ms   30ms
2953  2962  32ms  257ms
0     0     0ms   0ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :
cmd.CommandText = "select * from heap where group between @id and @id+1000";

  • 721 ๊ฐœ์˜ ํ–‰์— 0 ๊ฐœ ์ด์ƒ์˜ CPU๊ฐ€ ์žˆ์œผ๋ฉฐ 0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1001      69788    6368         -
Cpu            15        374      37   0.00754
Reads        1069      91459    7682   1.20155
Writes          0          0       0   0.00000
Duration   0.3716   282.4850 10.3672   0.00180

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


ํ‘œ์˜ clust๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- --------
1503  4827  31ms  327ms
401   1241  0ms   242ms
2700  8372  0ms   410ms
0     3     0ms   0ms
2953  9060  47ms  213ms
0     0     0ms   0ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :
cmd.CommandText = "select * from clust where group between @id and @id+1000";

  • 721 ๊ฐœ์˜ ํ–‰์— 0 ๊ฐœ ์ด์ƒ์˜ CPU๊ฐ€ ์žˆ์œผ๋ฉฐ 0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1001      69788    6056         -
Cpu            15        468      38   0.00782
Reads        3194     227018   20457   3.37618
Writes          0          0       0       0.0
Duration   0.3949   159.6223 11.5699   0.00214

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


์ฐธ์—ฌ ์„ฑ๊ณผ๋กœ ์„ ํƒ

cmd.CommandText = "select * from heap/clust h join keys k on h.group = k.group where h.group between @id and @id+1000";


์ด ๋ฒค์น˜ ๋งˆํฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ heap๊ฐ™์Šต๋‹ˆ๋‹ค.

873 ๊ฐœ์˜ ํ–‰์—> 0 ๊ฐœ์˜ CPU๊ฐ€ ์žˆ๊ณ  0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„ ๋ฏธ์นจ

Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1009       4170    1683         -
Cpu            15         47      18   0.01175
Reads        2145       5518    2867   1.79246
Writes          0          0       0   0.00000
Duration   0.8215   131.9583  1.9095   0.00123

์ด ๋ฒค์น˜ ๋งˆํฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ clust๊ฐ™์Šต๋‹ˆ๋‹ค.

865 ๊ฐœ์˜ ํ–‰์—> 0 ๊ฐœ์˜ CPU๊ฐ€ ์žˆ์œผ๋ฉฐ 0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„์ค๋‹ˆ๋‹ค.

Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1000       4143    1685         -
Cpu            15         47      18   0.01193
Reads        5320      18690    8237   4.97813
Writes          0          0       0   0.00000
Duration   0.9699    20.3217  1.7934   0.00109

์—…๋ฐ์ดํŠธ ์„ฑ๋Šฅ

๋‘ ๋ฒˆ์งธ ์ฟผ๋ฆฌ ๋ฐฐ์น˜๋Š” ์—…๋ฐ์ดํŠธ ๋ช…๋ น๋ฌธ์ž…๋‹ˆ๋‹ค.

update heap/clust set amount = amount + 0 where group between 5678910 and 5679410
update heap/clust set amount = amount + 0 where group between 6234567 and 6234967
update heap/clust set amount = amount + 0 where group between 6455429 and 6455729
update heap/clust set amount = amount + 0 where group between 6655429 and 6655729
update heap/clust set amount = amount + 0 where group between 6955429 and 6955729
update heap/clust set amount = amount + 0 where group between 7195542 and 7155729

์ด ๋ฒค์น˜ ๋งˆํฌ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ heap๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- -------- 
1503  3013  31ms  175ms
401   806   0ms   22ms
2700  5409  47ms  100ms
0     3     0ms   0ms
2953  5915  31ms  88ms
0     0     0ms   0ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :
cmd.CommandText = "update heap set amount = amount + @id where group between @id and @id+1000";

  • 811 ๊ฐœ์˜ ํ–‰์— 0 ๊ฐœ ์ด์ƒ์˜ CPU๊ฐ€ ์žˆ๊ณ  0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1001      69788    5598       811
Cpu            15        873      56   0.01199
Reads        2080     167593   11809   2.11217
Writes          0       1687     121   0.02170
Duration   0.6705   514.5347 17.2041   0.00344

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


์ด ๋ฒค์น˜ ๋งˆํฌ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ clust๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- -------- 
1503  9126  16ms  35ms
401   2444  0ms   4ms
2700  16385 31ms  54ms
0     3     0ms   0ms
2953  17919 31ms  35ms
0     0     0ms   0ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :
cmd.CommandText = "update clust set amount = amount + @id where group between @id and @id+1000";

  • 853 ๊ฐœ์˜ ํ–‰์—> 0 ๊ฐœ์˜ CPU๊ฐ€ ์žˆ์œผ๋ฉฐ 0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„์ค๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1001      69788    5420         -
Cpu            15        594      50   0.01073
Reads        6226     432237   33597   6.20450
Writes          0       1730     110   0.01971
Duration   0.9134   193.7685  8.2919   0.00155

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


๋ฒค์น˜ ๋งˆํฌ ์‚ญ์ œ

๋‚ด๊ฐ€ ์‹คํ–‰ ํ•œ ์„ธ ๋ฒˆ์งธ ์ฟผ๋ฆฌ๋Š” ์‚ญ์ œ ๋ฌธ์ž…๋‹ˆ๋‹ค.

delete heap/clust where group between 5678910 and 5679410
delete heap/clust where group between 6234567 and 6234967
delete heap/clust where group between 6455429 and 6455729
delete heap/clust where group between 6655429 and 6655729
delete heap/clust where group between 6955429 and 6955729
delete heap/clust where group between 7195542 and 7155729

์ด ๋ฒค์น˜ ๋งˆํฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ heap๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- -------- 
1503  10630 62ms  179ms
401   2838  0ms   26ms
2700  19077 47ms  87ms
0     4     0ms   0ms
2953  20865 62ms  196ms
0     4     0ms   9ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :
cmd.CommandText = "delete heap where group between @id and @id+1000";

  • 724 ๊ฐœ์˜ ํ–‰์—> 0 ๊ฐœ์˜ CPU๊ฐ€ ์žˆ์œผ๋ฉฐ 0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„์ค๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts     192      69788    4781         -
Cpu            15        499      45   0.01247
Reads         841     307958   20987   4.37880
Writes          2       1819     127   0.02648
Duration   0.3775  1534.3383 17.2412   0.00349

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


์ด ๋ฒค์น˜ ๋งˆํฌ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ clust๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- -------- 
1503  9228  16ms  55ms
401   3681  0ms   50ms
2700  24644 46ms  79ms
0     3     0ms   0ms
2953  26955 47ms  92ms
0     3     0ms   0ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :

cmd.CommandText = "delete clust where group between @id and @id+1000";

  • 751 ๊ฐœ์˜ ํ–‰์—> 0 ๊ฐœ์˜ CPU๊ฐ€ ์žˆ์œผ๋ฉฐ 0 ๊ฐœ ์ด์ƒ์˜ ํ–‰์— ์˜ํ–ฅ์„์ค๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts     144      69788    4648         -
Cpu            15        764      56   0.01538
Reads         989     458467   30207   6.48490
Writes          2       1830     127   0.02694
Duration   0.2938  2512.1968 24.3714   0.00555

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


INSERT ๋ฒค์น˜ ๋งˆํฌ

๋ฒค์น˜ ๋งˆํฌ์˜ ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์€ insert ๋ฌธ์˜ ์‹คํ–‰์ž…๋‹ˆ๋‹ค.

ํž™ / ํด๋Ÿฌ์Šคํ„ฐ (โ€ฆ) ๊ฐ’์— ์‚ฝ์ž… (โ€ฆ), (โ€ฆ), (โ€ฆ), (โ€ฆ), (โ€ฆ), (โ€ฆ)


์ด ๋ฒค์น˜ ๋งˆํฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ heap๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- -------- 
6     38    0ms   31ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :

string str = @"insert into heap (group, currency, year, period, domain_id, mtdAmount, mtdAmount, ytdAmount, amount, ytd_restated, restated, auditDate, auditUser)
                    values";

                    for (int x = 0; x < 999; x++)
                    {
                        str += string.Format(@"(@id + {0}, 'EUR', 2012, 2, 0, 100, 100, 1000 + @id,1000, 1000,1000, current_timestamp, 'test'),  ", x);
                    }
                    str += string.Format(@"(@id, 'CAD', 2012, 2, 0, 100, 100, 1000 + @id,1000, 1000,1000, current_timestamp, 'test') ", 1000);

                    cmd.CommandText = str;
  • 912 ๋ฌธ์—> 0 CPU
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1000       1000    1000         -
Cpu            15       2138      25   0.02500
Reads        5212       7069    6328   6.32837
Writes         16         34      22   0.02222
Duration   1.6336   293.2132  4.4009   0.00440

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


์ด ๋ฒค์น˜ ๋งˆํฌ์˜ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ clust๊ฐ™์Šต๋‹ˆ๋‹ค.

rows  reads CPU   Elapsed
----- ----- ----- -------- 
6     50    0ms   18ms

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :

string str = @"insert into clust (group, currency, year, period, domain_id, mtdAmount, mtdAmount, ytdAmount, amount, ytd_restated, restated, auditDate, auditUser)
                    values";

                    for (int x = 0; x < 999; x++)
                    {
                        str += string.Format(@"(@id + {0}, 'EUR', 2012, 2, 0, 100, 100, 1000 + @id,1000, 1000,1000, current_timestamp, 'test'),  ", x);
                    }
                    str += string.Format(@"(@id, 'CAD', 2012, 2, 0, 100, 100, 1000 + @id,1000, 1000,1000, current_timestamp, 'test') ", 1000);

                    cmd.CommandText = str;
  • 946 ๊ฐœ์˜ ๋ช…๋ น๋ฌธ์€> 0 CPU๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1000       1000    1000         -
Cpu            15       2403      21   0.02157
Reads        6810       8997    8412   8.41223
Writes         16         25      19   0.01942
Duration   1.5375   268.2571  6.1463   0.00614

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


๊ฒฐ๋ก 

ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค์™€ ๋น„ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค (๋น„ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ)๋กœ ํ…Œ์ด๋ธ”์— ์•ก์„ธ์Šค ํ•  ๋•Œ ๋” ๋งŽ์€ ๋…ผ๋ฆฌ์  ์ฝ๊ธฐ๊ฐ€ ์ง„ํ–‰๋˜์ง€๋งŒ ์„ฑ๋Šฅ ๊ฒฐ๊ณผ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • SELECT ๋ฌธ์€ ๋น„๊ต ๊ฐ€๋Šฅ
  • ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๊ฐ€ ์žˆ์œผ๋ฉด UPDATE ๋ฌธ์ด ๋” ๋น ๋ฆ…๋‹ˆ๋‹ค.
  • ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๊ฐ€ ์žˆ์œผ๋ฉด DELETE ๋ฌธ์ด ๋” ๋น ๋ฆ…๋‹ˆ๋‹ค.
  • ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค๊ฐ€ ์žˆ์œผ๋ฉด INSERT ๋ฌธ์ด ๋” ๋น ๋ฆ…๋‹ˆ๋‹ค.

๋ฌผ๋ก  ๋‚ด ๋ฒค์น˜ ๋งˆํฌ๋Š” ํŠน์ • ์ข…๋ฅ˜์˜ ํ…Œ์ด๋ธ”๊ณผ ๋งค์šฐ ์ œํ•œ๋œ ์ฟผ๋ฆฌ ์ง‘ํ•ฉ์œผ๋กœ ๋งค์šฐ ์ œํ•œ๋˜์—ˆ์ง€๋งŒ์ด ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ…Œ์ด๋ธ”์—์„œ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์‹ค์ œ๋กœ ํ•ญ์ƒ ๋” ๋‚ซ๋‹ค๋Š” ๊ฒƒ์„ ์ด๋ฏธ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ :

์ถ”๊ฐ€ ๋œ ๊ฒฐ๊ณผ์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ์ด ์ œํ•œ๋œ ํ…Œ์ŠคํŠธ์— ๋Œ€ํ•œ ๊ฒฐ๋ก ์€ ๋ชจ๋“  ๊ฒฝ์šฐ์— ์ •ํ™•ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

๊ฒฐ๊ณผ๋Š” ์ด์ œ ํด๋Ÿฌ์Šคํ„ฐํ˜• ์ธ๋ฑ์Šค์˜ ์ด์ ์ด์žˆ๋Š” ์œ ์ผํ•œ ๋ช…๋ น๋ฌธ์ด ์—…๋ฐ์ดํŠธ ๋ช…๋ น๋ฌธ์ž„์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ธ๋ฑ์Šค๋Š” ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๊ฐ€์žˆ๋Š” ํ…Œ์ด๋ธ”์—์„œ ์•ฝ 30 % ๋Š๋ฆฝ๋‹ˆ๋‹ค.

ํž™ ๋Œ€ ํด๋Ÿฌ์Šคํ„ฐ์— ๋Œ€ํ•œ ์ฟผ๋ฆฌ ๋‹น ๊ฐ€์ค‘์น˜ ์ง€์† ์‹œ๊ฐ„์„ ํ‘œ์‹œ ํ•œ ์ผ๋ถ€ ์ถ”๊ฐ€ ์ฐจํŠธ.

๋ณด์‹œ๋‹ค์‹œํ”ผ insert ๋ฌธ์˜ ์„ฑ๋Šฅ ํ”„๋กœํ•„์€ ๋งค์šฐ ํฅ๋ฏธ ๋กญ์Šต๋‹ˆ๋‹ค. ๊ธ‰์ฆ์€ ์™„๋ฃŒํ•˜๋Š” ๋ฐ ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” ๋ช‡ ๊ฐ€์ง€ ๋ฐ์ดํ„ฐ ์š”์†Œ๋กœ ์ธํ•ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

2011 ๋…„ 3 ์›” 9 ์ผ ์—…๋ฐ์ดํŠธ ์ข…๋ฃŒ .


๋‹ต๋ณ€

์ธ๋ฑ์‹ฑ์˜ ์—ฌ์™• โ€“ โ€“ ํ‚ด๋ฒŒ๋ฆฌ ํŠธ๋ฆฝ์œผ๋กœ ์•„์ฃผ ๋Šฅ์ˆ™ํ•˜๊ฒŒ ๊ทธ๋…€๋ฅผ ํฌ์ŠคํŠธ ๋ธ”๋กœ๊ทธ์— ์„ค๋ช… ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค ํ† ๋ก ์„ โ€ฆ ๊ณ„์† ๊ฑฐ์˜ ์†๋„๊นŒ์ง€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…Œ์ด๋ธ”์˜ ํด๋Ÿฌ์Šคํ„ฐ๋ง ํ‚ค๋ฅผ ๊ฐ€์ง„, ๋ชจ๋“  ์ž‘์—… โ€“ ๋‹จ์ง€ SELECT.

์ข‹์€ ํด๋Ÿฌ์Šคํ„ฐ๋ง ํ‚ค (์˜ˆ ๐Ÿ™‚ ๋ฅผ ์„ ํƒํ•˜๊ธฐ ๋งŒํ•˜๋ฉด SELECT๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ํ…Œ์ด๋ธ”์— ๋น„ํ•ด ํž™์—์„œ ๋Š๋ ค์ง‘๋‹ˆ๋‹ค INT IDENTITY. GUID ๋˜๋Š” ๊ฐ€๋ณ€ ๊ธธ์ด ๊ตฌ์„ฑ ์š”์†Œ๊ฐ€ ๋งŽ์€ ๋ณตํ•ฉ ํ‚ค์™€ ๊ฐ™์ด ์‹ค์ œ๋กœ ๋‚˜์œ ํด๋Ÿฌ์Šคํ„ฐ๋ง ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํž™์ด ๋” ๋น ๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜์ด ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋””์ž์ธ์„ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ •๋ฆฌํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ผ๋ฐ˜์ ์œผ๋กœ ํž™์— ์–ด๋–ค ์ ์ด ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์œ ์šฉํ•˜๊ณ  ์œ ์šฉํ•œ ํด๋Ÿฌ์Šคํ„ฐ๋ง ํ‚ค๋ฅผ ์„ ํƒํ•˜๋ฉด ๋ชจ๋“ ๋ฉด์—์„œ ์ด์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.


๋‹ต๋ณ€

๊ทธ๋ƒฅ ๊ฑด๋„ˆ ์šฐ์—ฐํžˆ ์ด ๊ธ€ ์ฃผ์†Œ์ด ์งˆ๋ฌธ์— ๊ทธ ์กฐ ์žฅ์—์„œํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜์— ๊ทธ์˜ ๊ฒฐ๋ก ์„ ๋ถ™์—ฌ ๋„ฃ์—ˆ๋‹ค.

์ธ๋ฑ์Šค์— ๊นŠ์ด๊ฐ€ 4 ์ธ ํ…Œ์ด๋ธ”์„ ๊ณ ๋ คํ•˜์—ฌ ๋ฃจํŠธ ๋ ˆ๋ฒจ, 2 ๊ฐœ์˜ ์ค‘๊ฐ„ ๋ ˆ๋ฒจ ๋ฐ ๋ฆฌํ”„ ๋ ˆ๋ฒจ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ธ๋ฑ์Šค๋Š” ๋‹จ์ผ ์ธ๋ฑ์Šค ํ‚ค (ํ‚ค ๊ฒ€์ƒ‰ ์—†์Œ)๋ฅผ ๊ฒ€์ƒ‰ํ•˜์—ฌ 4 ๊ฐœ์˜ ๋…ผ๋ฆฌ IO (LIO)๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด์ œ ํ‚ค ์กฐํšŒ๊ฐ€ ํ•„์š”ํ•œ์ง€ ๊ณ ๋ คํ•˜์‹ญ์‹œ์˜ค. ํ…Œ์ด๋ธ”์— ๊นŠ์ด 4์˜ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค๊ฐ€์žˆ๋Š” ๊ฒฝ์šฐ ๊ฐ ํ‚ค ์กฐํšŒ๋Š” 4 ๊ฐœ์˜ LIO๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํ…Œ์ด๋ธ”์ด ํž™์ธ ๊ฒฝ์šฐ ๊ฐ ํ‚ค ์กฐํšŒ๋Š” 1 ๊ฐœ์˜ LIO๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์‹ค์ œ๋กœ, ํž™์— ๋Œ€ํ•œ ํ‚ค ์กฐํšŒ๋Š” 4 : 1 LIO ๋น„์œจ์— ๊ฐ€๊นŒ์šด ๊ณณ์ด ์•„๋‹ˆ๋ผ ํด๋Ÿฌ์Šคํ„ฐ ๋œ ์ธ๋ฑ์Šค์— ๋Œ€ํ•œ ํ‚ค ์กฐํšŒ๋ณด๋‹ค ์•ฝ 20-30 % ์ €๋ ดํ•ฉ๋‹ˆ๋‹ค.


๋‹ต๋ณ€


์ด ๊ธ€์€ Sql ์นดํ…Œ๊ณ ๋ฆฌ์— ๋ถ„๋ฅ˜๋˜์—ˆ๊ณ  , ํƒœ๊ทธ๊ฐ€ ์žˆ์œผ๋ฉฐ ๋‹˜์— ์˜ํ•ด ์— ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.