JAKARTAPROJECT
JAKARTA TIPJSP TIPJSP Áú¹®&´äº¯DATABASE TIPJAVASCRIPT TIPWEBHACKING TIP±âŸ TIP
µ¥ÀÌÅͺ£À̽º ÆÁ
µ¥ÀÌÅͺ£À̽º ÆÁ
µ¥ÀÌÅͺ£À̽º ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
´ë¿ë·® Å×À̺íÀ» À§ÇÑ Hash Join
GoodBug
À̹ÌÁö ½½¶óÀÌ´õ º¸±â

Hash Join ½ÇÇà


 

(1) °³¿ä

JOIN ÀÇ Á¾·ù´Â 3°¡Áö·Î ³ª´µ´Âµ¥, Sort merge join, Nested loop join, Hash join ÀÌ´Ù.
ÀÌÁß Hash Join (HJ) Àº  7.3 ºÎÅÍ »ç¿ë°¡´ÉÇÏ¸ç ±× ÁÖ¿ä ±â´ÉÀ» »ìÆ캸¸é

 

 - index °¡ ¿©·¯ level ÀÇ depth ¸¦ °¡Áú ¶§  Sort Merge Join (SMJ) À̳ª 
   Nested   Loops (NL)º¸´Ù ÁÁÀº È¿°ú¸¦ ³½´Ù.

 

 - sort ¸¦ ÇÏÁö ¾ÊÀ¸¹Ç·Î SMJ º¸´Ù ÁÁÀº ¼º´ÉÀ» ³»¸ç, ÀÛÀº table °ú Å« table ÀÇ join ½Ã¿¡ À¯¸®ÇÏ´Ù.

 

 - ÁÖÀÇÇØ¾ß ÇÒ °ÍÀº hash  join Àº equi join ¿¡¼­¸¸ °¡´ÉÇÏ´Ù´Â °ÍÀÌ´Ù.

 

 - HJ Àº driving table ¿¡ index ¸¦ ÇÊ¿ä·Î ÇÏÁö ¾Ê´Â´Ù.

 

 - SMJ ³ª NL º¸´Ù È¿À²ÀûÀε¥, ÀÌ´Â SMJ °¡ merge ´Ü°è¿¡ µé¾î°¡±â À§ÇØ ¾çÂÊ table ÀÌ ¸ðµÎ sort µÇ¾î¾ß Çϱ⠶§¹®ÀÌ´Ù.

    ¶Ç NLÀº driving table ÀÌ ¸¹Àº row ÀÇ data ¸¦ °®´Â °æ¿ì ºñÈ¿À²ÀûÀ̼­ inner table À» ¿©·¯¹ø probe(Ž»ö)ÇÏ°Ô ÇÑ´Ù.

    ÀÌ¿¡ ¹ÝÇØ HJ´Â °¢ table ¿¡ ´ëÇØ 1 ¹ø¸¸ pass ÇÑ´Ù.


(2) CostÀÇ ºñ±³

ÆíÀÇ»ó join µÇ´Â sql ¹®ÀÌ ´ÙÀ½°ú °°´Ù°í °¡Á¤ÇÏÀÚ.

 

SELECT S.a, B.a FROM S,B WHERE S.a = B.a

 

S´Â small table ÀÌ°í, B´Â big table ÀÌ´Ù.

(* analyze ¸¦ ¼öÇàÇϸé CBO ´Â ÀÌ¹Ì S°¡ out table ÀÌ°í B °¡ inner table  À̸ç , S °¡ driving table ÀÓÀ» ÀνÄÇÑ´Ù. )

NLJ ´Â S table ÀÇ ¸ðµç row ¿¡ ´ëÇØ a column À» B table ÀÇ ¸ðµç column À»match Çϱ⠶§¹®¿¡  rS* rB key ºñ±³°¡ ¿ä±¸µÈ´Ù.:
 
Cost(NLJ) ´Â Read(S) + [ rS *Read(B) ] ¿¡ ºñ·Ê

¶Ç SMJ ´Â S ¿Í B ¸¦ memory ¿¡ Àоî¿Í join key ¸¦ °¢°¢ sort ÇÏ°í, join À»¼öÇàÇϹǷΠcost ´Â

 

Cost(SMJ) ´Â Read(S) + Write(SortRuns(S))

     + Read(B) + Write(SortRuns(B))

     + Merge(S,B)

     + CPUSortCost(S + B) ¿¡ ºñ·ÊÇÑ´Ù.

 

memory ¿¡¼­ ¼öÇàµÇ´Â HJ ÀÇ  algorithm Àº ¾Æ·¡¿¡¼­ ¼³¸íµÈ¾î Áö´Âµ¥ ÀÌÀÇ cost ¸¦ ¹Ì¸® check ÇØ º¸ÀÚ¸é
 
Cost(HJ) = Read(S) + Build Hash Table in Memory (cpu)

     + Read(B) + Perform In memory Join(cpu)

ÀÌ °æ¿ì CPU costs¸¦ ¹«½ÃÇϸé , 

Cost(HJ)´Â Read(S) + Read(B) ¿¡ ºñ·ÊÇÑ´Ù°í ÇÒ¼ö ÀÖ´Ù.

 


(3) Hash join À» ¼öÇàÇϱâ À§ÇØ Oracle Àº ´ÙÀ½ÀÇ °úÁ¤À» °ÅÄ£´Ù.:

À̸¦ ¼öÇàÇϱâ À§ÇØ partition ´Ü°è¿Í join ´Ü°è¸¦ °ÅÄ¡¸ç ÀÌÀÇ algorithm À» grace join À̶ó ÇÑ´Ù.
ÀÌÀÇ ÇÑ°è´Â join value ÀÇ ºÐ¹è°¡ ÇÑÂÊÀ¸·Î Ä¡¿ìħÀÌ ¾øÀÌ partition ¿¡ °í¸£°Ô ºÐÆ÷µÇ¾î¾ß ÇÑ´Ù´Â °ÍÀÌ´Ù. ÀÌ algorithm Àº ´ÙÀ½°ú °°´Ù.

 

1. partiton °¹¼ö¸¦ °áÁ¤ÇÑ´Ù.À̸¦ fan out À̶óÇÑ´Ù.
   high fan out Àº ¿©·¯°³ÀÇ ÀÛÀº partition À» ¸¸µé¾î i/o ÀÇ È¿À²À» ¶³¾î
   ¶ß¸®¸ç,low fan out Àº Ä¿´Ù¶õ partition À» ¸¸µé¾î hash memory ÀÇ hit
   À²À» ¶³¾î¶ß¸°´Ù . ±×·¯¹Ç·Î À̸¦ ÀûÀýÈ÷ °¡Á®°¡´Â °ÍÀÌ performance ÀÇ
   ÁÖ ¿äÁ¡À̸ç(ÀÌ´Â bit map °¹¼ö¸¦ °áÁ¤) ÀÌÀÇ È¿À²À» ³ôÀ̱â À§ÇØ hash
   area size¸¦ ´Ã¸®°í, hash multi block io ¸¦ ÁÙÀδÙ.
  
2. driving table À» °áÁ¤ÇÑ´Ù.(ÀÛÀº table ·Î °áÁ¤)

 

3. small table ÀÇ ÇÊ¿ä column À» Àоîµé¿© hash area ÀÇ partition ¿¡ ºÐ¹è
   Çϴµ¥ ÀÌ´Â join column À¸·Î hash function1À» Åë°ú ½ÃÅ°¸é¼­
   partition ¿¡ hash function2 ÀÇ hash value ¿Í ÇÔ²² ºÐ¹èÇÑ´Ù.
   À̶§ bitmap vector ¸¦ ¸¸µç´Ù.
   ÀÌ bitmap Àº 2Â÷¿ø bucket Àε¥ hash function 1 °ú 2 ¸¦ Åë°ú½ÃÄÑ ¸¸µç
   ´Ù.Áï partition ÀÌ 100 °³¶ó¸é 100* 100 ÀÇ 10000 °³ÀÇ cell ·Î ÀÌ·ç¾î
   Áø´Ù.

 

4. °¢ row ¿¡ ´ëÇØ bitmap ÀÇ (a,b) ¿¡ marking À» ÇÑ´Ù.

 

5  À§ÀÇ step ÀÌ ¸ðµÎ ³¡³ª¸é driving table ÀÌ ¾Æ´Ñ Å« table À» Àоîµé¿©
   function1,2 ¸¦ Åë°úÇÑ´Ù.
   À̶§ ³ª¿Â hash value ¸¦ driving table ÀÌ ¸¸µé¾î ³õÀº bitmap °ú
   ´ëÁ¶ÇÏ¿© 1 À̸é join À» ÇØ¾ß ÇÏ´Â column À¸·Î ÀνÄÇÏ°í  ¾Æ´Ï¸é join
   ÇÒ ÇÊ¿ä°¡ ¾ø´Â row À̹ǷΠ¹ö¸°´Ù.
   À̸¦ bit vector filtering À̶óÇÑ´Ù.  

 

À̶§ hash table À» ±¸¼ºÇϱâ À§ÇØ Ç×»ó full table À» scan ÇÏ´Â °ÍÀº ¾Æ´Ï´Ù.
¸ÕÀú where Á¶°ÇÀÇ index ¸¦ Ÿ¼­ Á¶°Ç¿¡ ¸Â°Ô row ¸¦ °É·¯³½ ´ÙÀ½ ±×
°á°ú¿¡ ´ëÇØ hash table À» ±¸¼ºÇÑ´Ù. ¶Ç hash array size °¡ Å©¸é ¹®Á¦°¡
¾ÈµÇ´Âµ¥, ÀÛÀ¸¸é disk ÀÇ temp segment ¿¡ ³»·Á º¸³»¾ß ÇϹǷÎ
problem ÀÌ ¹ß»ýÇÑ´Ù.

6. B ÀÇ joined value ¸¦ hash function 1 À» Åë°ú½ÃÄÑ ÀÌ row °¡ bit vector¿¡ ÀÖ°í,
memory À§ÀÇ partition ¿¡ ÀÖÀ¸¸é join ÀÌ ¼öÇàµÇ°í °á°ú°¡
return µÈ´Ù. memory ¿¡ ÀÖÁö ¾ÊÀ¸¸é disk ¿¡ ÀÖ´Â ÀûÀýÇÑ S partition ¿¡
¾º¿©Áø´Ù.
 
7. 1¹ø° B °¡ pass µÈÈÄ S ÀÇ ¼öÇàµÇÁö ¾Ê´Â partition µéÀÌ  ÃÖ´ëÇÑ
   temp segment ¿¡¼­ memory ·Î ¿Ã·ÁÁö°í hash table ÀÌ »ý¼ºµÈ´Ù.
   ±×¸®°í B ÀÇ partition ÀÌ ´Ù½Ã ÀÐÇôÁ® memory join ÀÌ ½ÇÇàµÈ´Ù.

 Áï ¼öÇàµÇÁö ¾Ê´Â disk ÀÇ  partition (S,B) ÀÌ ÀÐÇôÁø´Ù.

 

(4) parameter
 
-HASH_JOIN_ENABLED
  : true ·Î ÁöÁ¤½Ã »ç¿ë°¡´É

-HASH_AREA_SIZE
   : sort_area_size ÀÇ 2¹è°¡ ±âº»

-HASH_MULTIBLOCK_IO_COUNT
   : DB_BLOCK_READ_COUNT °¡ ±âº»

-USE_HASH
   : hint

 

 

(5) partition °¹¼ö °áÁ¤

ù¹ø°·Î ¿ì¸®´Â partition (bucket) ÀÇ °¹¼ö¸¦ °áÁ¤ÇØ¾ß ÇÑ´Ù.
¿©±â¿¡ ¿ì¸®´Â hashed row ¸¦ ³ÖÀ» °ÍÀÌ´Ù.
À̴  hash_area_size, db_block_size and hash_multiblock_io_count
parameters¿¡ ÀÇÇØ °áÁ¤µÈ´Ù.

¶Ç ÀÌ °ªÀº 20% Á¤µµÀÇ overhead ¸¦ °í·ÁÇØ¾ß ÇÑ´Ù.- storing partitions,
the bitmap of unique left input and the hash table

ÇÔ¼ö :

Partitions °¹¼ö  =  0.8 x hash_area_size)
                   ----------------------------
               (db_block_size x hash_multiblock_io_count)


row °¡ °¡Àå ÀÛÀº table ÀÌ ÀÐÇôÁö°í (R À̶ó°í ºÎ¸£ÀÚ)  , °¢ row ´Â
hash algorithm À» µû¸¥´Ù.

°¢ row ¸¦ bucket ¿¡ °ñ°í·ç ÆîÃÄÁö°Ô Çϱâ À§ÇØ 2°¡ÁöÀÇ algorithm À»
µû¸¥´Ù.

hash µÇ´Â row °¡ partition ¿¡ °ñ°í·ç ºÐ»êµÇ±â À§ÇØ 1 ¹ø° hash function À» µû¸£¸ç,
2 ¹ø° hash value ´Â ´ÙÀ½ hash µÇ´Â °æ¿ì¸¦ À§ÇØ row ¿Í ÇÔ²²
ÀúÀåµÈ´Ù.
ÀÌ¿Í µ¿½Ã¿¡ µÎ°¡ÁöÀÇ hash  value ¸¦ ÀÌ¿ëÇÑ bitmap ÀÌ ¸¸µé¾îÁø´Ù.


 
(6) Bitmap building ¿¹Á¦ :

              Hash
              Algorithm 1 ->

              1  2  3  4

           1  0  0  0  0
Second
Hash       2  0  0  0  0     ------>  
Algorithm
   |       3  0  0  0  0
   V
           4  0  0  0  0

driving table Àº hash function 1, 2 ¸¦ Åë°úÇÏ¿© bitmap À» ¸¸µç´Ù .
¸¸ÀÏ hash area °¡ ¸ðµÎ Â÷¸é °¡Àå Å« partition ÀÌ disk ·Î ³»·Á°£´Ù.

disk ÀÇ partition Àº partition ¿¡ ÇÒ´çµÇ´Â row ¿¡ ÀÇÇØ disk ¿¡¼­ update
µÇ¾îÁø´Ù. ¸¸ÀÏ hash area ÀÇ ºÎÁ·À¸·Î 1 partition ¸¸ÀÌ memeory ¿¡
¿Ã¶ó°£´Ù¸é ³ª¸ÓÁö partition Àº ¸ðµÎ disk ¿¡ ³õ¿©Áö°Ô µÈ´Ù. ÀÌ·±
°æ¿ì´Â »ý±âÁö ¾Êµµ·Ï Á¶½ÉÇÏ¿©¾ß ÇÑ´Ù.
ÀÌ ÀÛ¾÷ÀÌ R table ÀÇ ¸ðµç row ¿¡ ´ëÇØ ÇàÇØÁø´Ù.

ÀÌ ÀÛ¾÷½Ã °¡´ÉÇÑ ¸ðµç partition ÀÌ memeory ¿¡ À§Ä¡Çϵµ·Ï ÇØ¾ß ÇÑ´Ù.
ÀÌ ÀÛ¾÷ÀÌÈÄ B table À» ÀоîµéÀδÙ.À̵µ ¿ª½Ã hash function À» Åë°ú½ÃÄÑ
 hash value °¡ memory ¿¡ ÀÖ´Â partition À» hit ÇÏ´ÂÁö check ÇÑ´Ù.
¸¸ÀÏ ±×·¯¸é ÀÌ row ´Â joined row ·Î ¹ÝȯÇÑ´Ù.
¸¸ÀÏ ¾Æ´Ï¸é ÇØ´ç row ¸¦ »õ·Î¿î partiion ¿¡ write ÇÑ´Ù.
À̶§ S ¿Í °°Àº hash function À» »ç¿ëÇϸç ÀÌÀÇ Àǹ̴ S¿Í B ÀÇ °°Àº value´Â
°°Àº  partition number ¸¦ °®°Ô Çϱâ À§ÇÔÀÌ´Ù.

 

 

(7) unique join keys ÀÇ bitmap

bitmap Àº partition ¿¡ µé¾îÀÖ´Â value ÀÇ flag À̶ó ÇÒ¼ö ÀÖ´Ù.
ÀÌ´Â S ÀÇ row °¡ disk ÀÇ partititon ¿¡ ¾ºÀ̱â Àü¿¡ »ý¼ºµÇ¾î Áø´Ù.

 

 

from otn

2005-06-22 13:39:20
211.189.124.***

 

ÁÁÀº»ý°¢ ^^

0Á¡ (0¸í)
µ¡±Û 0°³ | ÅÂ±× 0°³ | °ü·Ã±Ûº¸±â
ű×ÀÔ·Â
½±Ç¥(,)±¸ºÐÀ¸·Î Çѹø¿¡ ¿©·¯ ű׸¦ ÀÔ·ÂÇÒ¼ö ÀÖ½À´Ï´Ù
À̸§ ºñ¹Ð¹øÈ£
µ¥ÀÌÅͺ£À̽º ÆÁ
µ¥ÀÌÅͺ£À̽º ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
! ¹øÈ£ Á¦¸ñ ±Û¾´ÀÌ ÀÏÀÚ Á¶È¸
181 import DB ºÎºÐÀûÀÎ µ¥ÀÌÅÍ export / import ¹æ¹ý 2 kaiser 2008-12-29 7,795
180 NOT IN NOT EXISTS not in °ú not existsÀÇ °³³ä ÀÌÇØ 1 kaiser 2008-12-17 19,574
179 IP Á¢¼ÓÀÚ ¾ÆÀÌÇÇ º¸±â 1 GoodBug 2008-06-27 9,451
178 meta ¿À¶óŬ ½ºÅ°¸¶ ½ºÅ©¸³Æ® ¹Þ±â 1 GoodBug 2008-06-05 19,843
177 ORA-00054 ORA-00054: resource busy and acquire with NOWAIT specified 1 GoodBug 2007-10-27 13,058
176 ÇÑ±Û MYSQL ¼­¹ö ij¸¯¼ÂÀÌ EUCKRÀÌ ¾Æ´Ò°æ¿ì Ŭ¶óÀ̾ðÆ® ¼³Á¤ 1 GoodBug 2007-10-09 8,344
175 archive ¾ÆÄ«ÀÌºê ¼º´É Çâ»ó 1 GoodBug 2007-10-02 7,939
174 Dictionary Dict table 1 GoodBug 2007-10-02 7,224
173 ¿À¶óŬƩ´× redo log file ±¸¼º ¸ð´ÏÅÍ 1 GoodBug 2007-09-20 7,905
172 dictionary ÀÚÁÖ¾²´Â µñ¼Å³Ê¸® Á¤º¸ 1 1 GoodBug 2007-09-20 8,352
171 TableSpace Tablespace º° »ç¿ë·® È®ÀÎ 1 GoodBug 2007-09-20 8,766
170 ¿À¶óŬ üũÆ÷ÀÎÆ® °ü·Ã ÆĶó¹ÌÅÍ 2 GoodBug 2007-09-20 7,420
169 ¿À¶óŬƩ´× Å×ÀÌºí ½ºÄµ Åë°è 1 GoodBug 2007-09-19 7,265
168 ¿À¶óŬƩ´× v$filestat·Î µð½ºÅ© I/O ¸¦ È®ÀÎÇغ¸ÀÚ 1 GoodBug 2007-09-19 10,248
167 ¿À¶óŬƩ´× ORA-04031 ¿¡·¯ ´ëó¹ý ¹× ¿¹¹æ¹ý 1 GoodBug 2007-09-17 13,717
166 ¿À¶óŬƩ´× DB_FILE_MULTIBLOCK_READ_COUNT 1 GoodBug 2007-09-17 7,272
165 TableSpace TableSpace °ü¸® (Dictionary, Locally) 1 GoodBug 2007-09-16 7,774
164 ¿À¶óŬƩ´× ¹®Á¦ÇØ°á ¹× Æ©´× °ü·Ã ºä 2 GoodBug 2007-09-16 7,698
163 segment ¿À¶óŬ SEGMENT 1 GoodBug 2007-09-16 8,628
162 startup ¿À¶óŬ startup½Ã ´Ü°èº° ¿ÀÇ ÆÄÀÏ 1 GoodBug 2007-09-16 7,531
copyright 2005-2024 by Unicorn