|
¹®Á¦Á¡À» ¹ß°ßÇÑ SQL ¹®ÀÇ Æ©´×.....
1. ½Ã½ºÅÛÀ» ÆľÇÇØ¾ß ÇÑ´Ù.
- µ¥ÀÌÅÍÀÇ ¼º°ÝÀ» ¸íÈ®È÷ ¾Ë¾Æ¾ß¸¸ ÇÑ´Ù.
- Æ©´× ¹æ¹ýÀ» ¼±ÅÃÇϱâ À§ÇÑ Ã¼Å©¸®½ºÆ®¸¦ ÀÛ¼ºÇÑ´Ù.
- »ç¿ëÇÏ´Â SQL Äõ¸®¸¦ ºÐ¼®ÇÑ´Ù.
1) SQL*PLUS ¿¡¼ "set autotrace on" ¸í·ÉÀ» ¼öÇàÇÏ°í TKPROF¸¦ ÀÌ¿ëÇÏ¿© ºÐ¼®ÇÑ´Ù.
2) ¹®Á¦°¡µÇ´Â SQL ¹®ÀÇ explain planÀ» Á¶È¸ÇÑ´Ù.
3) "set timing on" ¸í·ÉÀ» ¼öÇàÇÏ¿© ½ÇÇà ½Ã°£À» °Ë»çÇÑ´Ù.
** ÇÑ ¼¼¼Ç¸¸ Æ®·¹À̽º¸¦ °Å´Â ¹æ¹ý
1) select sid, serial# from v$session where username='SCOTT';
ÇØ´ç À¯ÀúÀÇ id¸¦ ¾Ë¾Æ³½´Ù.
2) execute dbms_system.set_sql_trace_in_session({SID},{Serial#},TRUE);
2. Analyze ¸¦ ÇÑ´Ù.
OptimizerÀÇ ÆĽ̿¬»êÀ» ´õ¿í Á¤È®ÇÏ°Ô ¼öÇàÅä·Ï À¯µµÇÒ ¼ö ÀÖ´Ù.
-Analyze table [table ¸í] compute statistics; Å×À̺í Àüü ¿¬»ê.
-Analyze table [table ¸í] estimate statistics; Å×À̺íÀÌ Å« °æ¿ì 1064row ±îÁö¸¸ ¿¬»ê.
-Analyze table [table ¸í] delete statistics; ÀÌÀü ¿¬»ê°á°ú »èÁ¦.
- ÇÑ À¯ÀúÀÇ ¸ðµç Å×À̺íÀ» ºÐ¼®ÇÒ°æ¿ì
exec dbms_utility.analyze_schema('SCOTT','COMPUTE');
3. Hint ¸¦ »ç¿ëÇÑ´Ù.
- table Full ScanÀ» À¯µµ
select /*+ FULL(table_name) */ column1, 2 .. from table_name ... ;
- index »ç¿ëÀ» À¯µµ
select /*+ INDEX(table_name index_name1, 2 .. ) */ column1,2 .. from table_name ... ;
- table À» ¼ø¼´ë·Î Á¶ÀÎÇϵµ·Ï À¯µµ
select /*+ ORDERED */ column1,2 .. from table1, table2 ... ;
- Cost-based ¿¬»ê½Ã ¶Ç´Â ¸ðµç row ¸¦ ij½¬Çϵµ·Ï À¯µµ(À妽º¸¦ »ç¿ë ¾ÊÇϵµ·Ï À¯µµ)
select /*+ ALL_ROWS */ .... ;
- Cost-based ¿¬»ê½Ã ÀÀ´ä¼Óµµ¸¦ ºü¸£°Ô ÇϱâÀ§ÇØ (À妽º °É¸° Ä÷³ Äõ¸®½Ã)
select /*+ FIRST_ROWS */ .... ;
[/pre]
4. À妽º¸¦ »ý¼º/»èÁ¦ ÇÑ´Ù.
EX1) À妽º°¡ Ç×»ó ÁÁÀº°¡ ??
EMP Å×À̺íÀº 10¸¸°ÇÀÇ µ¥ÀÌÅÍ°¡ ÀÖ°í DEPT_NO=10 °ÍÀº 2¸¸5õ°Ç
Á¸ÀçÇÑ´Ù°í ÇÒ¶§ ¼öÇà½Ã°£ ºñ±³.
select ENAME from EMP where DEPT_NO=10;
1) À妽º°¡ ¾øÀ»¶§ : ¾à 55ÃÊ ¼Ò¿ä
2) À妽º°¡ ÀÖÀ»¶§ : ¾à 70ÃÊ ¼Ò¿ä
3) dept_no, ename ÀÇ º¹ÇÕ À妽º°¡ ÀÖÀ»¶§ : ¾à 0.1ÃÊ ¼Ò¿ä.
(´Ü, enameÀº unique)
** À妽º°¡ °É¸®´Â Ä÷³Àº Áߺ¹°ªÀÌ ÀûÀº°ÍÀÌ ÁÁ´Ù. ¸¸ÀÏ ÀüüÀÇ 25% ÀÌ»óÀÇ Áߺ¹
°ªÀ» °¡Áö´Â °ªÀ» Äõ¸®½Ã ½Ã°£ÀÌ ´õ °É¸®°Ô µÈ´Ù.
EX2) À妽º¿Í ÈùÆ®ÀÇ ÀûÀýÇÑ »ç¿ë....
EMP Å×À̺íÀº 1¸¸°ÇÀÇ µ¥ÀÌÅÍ°¡ ÀÖ°í, DEPT_NO¿¡ À妽º°¡ °É·ÁÀÖ°í,
DEPT_NO>9990 °ÍÀº 5õ°Ç Á¸ÀçÇÑ´Ù°í ÇÒ¶§ ¼öÇà½Ã°£ ºñ±³.
select ENAME, DEPT_NO from EMP where DEPT_NO>9990;
-> ¾à 53ÃÊ ¼Ò¿ä
select /*+ FULL(EMP) */ ENAME, DEPT_NO from EMP where DEPT_NO>9990;
-> ¾à 4ÃÊ ¼Ò¿ä
EX3) join Å×À̺íÀÇ Äõ¸®½Ã ¼Óµµºñ±³
EMP Å×À̺íÀº 10¸¸°Ç, DEPT Å×À̺íÀº 10°ÇÀÇ µ¥ÀÌÅÍ°¡ ÀÖÀ»¶§.
select ENAME, DEPT_NO from EMP, DEPT
where EMP.DEPT_NO = DEPT.DEPT_NO and EMP_NO=5 and DEPT_NO=10 ;
-> ¾à 4ºÐ ¼Ò¿ä µÈ´Ù¸é
select /*+ ORDERED */ ENAME, DEPT_NO from EMP, DEPT
where EMP.DEPT_NO = DEPT.DEPT_NO and EMP_NO=5 and DEPT_NO=10 ;
-> ¾à 15ÃÊ ¼Ò¿ä
select ENAME, DEPT_NO from EMP where EMP_NO=5 and EXISTS
( select 'X' from DEPT where EMP.DEPT_NO = DEPT.DEPT_NO
and DEPT_NO=10 ) ;
-> ¾à 8ÃÊ ¼Ò¿ä
** Exists, Union µîÀÇ ¿¬»êÀÚ´Â ¼Óµµ¸¦ °³¼±½ÃÄÑÁÜ.
5. Å×À̺íÀ» Á¶Á¤ÇÑ´Ù.
|