문제> 아래의 SQL문을 튜닝하여 튜닝전/후의 결과를 비교하시오.
SELECT
t.calendar_month_desc, SUM(s.amount_sold) FROM sales s, times t WHERE
s.time_id = t.time_id GROUP BY t.calendar_month_desc;
48 개의 행이
선택되었습니다.
경 과: 00:00:07.51
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 60 | 2220 | 578 (14)|
00:00:07 | | | | 1 | HASH GROUP BY | | 60
| 2220 | 578 (14)| 00:00:07 | | | |* 2 | HASH JOIN
| | 1460 | 54020 | 577 (14)| 00:00:07 | | | | 3 |
VIEW | VW_GBC_5 | 1460 | 30660 | 558 (14)| 00:00:07 | |
| | 4 | HASH GROUP BY | | 1460 | 18980 | 558 (14)|
00:00:07 | | | | 5 | PARTITION RANGE ALL| | 918K|
11M| 499 (4)| 00:00:06 | 1 | 28 | | 6 | TABLE ACCESS FULL |
SALES | 918K| 11M| 499 (4)| 00:00:06 | 1 | 28 | | 7 |
TABLE ACCESS FULL | TIMES | 1826 | 29216 | 18 (0)| 00:00:01 | |
|
----------------------------------------------------------------------------------------------------
모범답안> MATERIALIZED VIEW 생성 후 rewirte 힌트 적용 CREATE
MATERIALIZED VIEW mv_cal_month_sales ENABLE QUERY REWRITE AS
SELECT t.calendar_month_desc, SUM(s.amount_sold) AS dollars FROM sales s,
times t WHERE s.time_id = t.time_id GROUP BY t.calendar_month_desc;
SELECT /*+ rewirte(mv_cal_month_sales) */
t.calendar_month_desc, SUM(s.amount_sold) FROM sales s, times t WHERE
s.time_id = t.time_id GROUP BY t.calendar_month_desc;
경 과:
00:00:00.09
Execution Plan
---------------------------------------------------------- Plan hash
value: 1726579226
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 48 | 912 |
3 (0)| 00:00:01 | | 1 | MAT_VIEW REWRITE ACCESS FULL| MV_CAL_MONTH_SALES
| 48 | 912 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------
|
댓글 없음:
댓글 쓰기