'db'에 해당되는 글 2건

  1. 2009.05.26 with clause - 9i 기능.
  2. 2009.04.29 오라클의 Middleware 시장 투자.

2009. 5. 26. 22:07 IT가

with clause - 9i 기능.

반응형
with clause 를 이용하여 쿼리시 메모리에 쿼리결과를 저장하여 처리할 수 있도록 추가된 기능.
단, 9i JDBC Driver 에서는 안되는듯하다... (9i Driver 에서는 안되었습니다...)
"Subquery Factoring Clause" 라고도 한다.

Improving Query Performance with the SQL WITH Clause
   

Oracle9i significantly enhances both the functionality and performance of SQL to address the requirements of business intelligence queries. The SELECT statement’s WITH clause, introduced in Oracle9i, provides powerful new syntax for enhancing query performance. It optimizes query speed by eliminating redundant processing in complex queries.

Consider a lengthy query which has multiple references to a single subquery block. Processing subquery blocks can be costly, so recomputing a block every time it is referenced in the SELECT statement is highly inefficient. The WITH clause enables a SELECT statement to define the subquery block at the start of the query, process the block just once, label the results, and then refer to the results multiple times.

The WITH clause, formally known as the subquery factoring clause, is part of the SQL-99 standard. The clause precedes the SELECT statement of a query and starts with the keyword “WITH.” The WITH is followed by the subquery definition and a label for the result set. The query below shows a basic example of the clause:

WITH channel_summary AS
  ( SELECT channels.channel_desc,
       SUM(amount_sold) AS channel_total
    FROM sales, channels
    WHERE sales.channel_id = channels.channel_id
    GROUP BY channels.channel_desc )
SELECT channel_desc, channel_total
FROM channel_summary
WHERE channel_total >
  ( SELECT SUM(channel_total) * 1/3
    FROM channel_summary );

This query uses the WITH clause to calculate the sum of sales for each sales channel and label the results as channel_summary. Then it checks each channel's sales total to see if any channel's sales are greater than one third of the total sales. By using the new clause, the channel_summary data is calculated just once, avoiding an extra scan through the large sales table.

Although the primary purpose of the WITH clause is performance improvement, it also makes queries easier to read, write and maintain. Rather than duplicating a large block repeatedly through a SELECT statement, the block is localized at the very start of the query. Note that the clause can define multiple subquery blocks at the start of a SELECT statement: when several blocks are defined at the start, the query text is greatly simplified and its speed vastly improved.

The SQL WITH clause in Oracle9i significantly improves performance for complex business intelligence queries. Together with the many other SQL enhancements in Oracle9i, the WITH clause extends Oracle's leadership in business intelligence.

More Info

Oracle9i SQL Reference: Chapter 17 - SELECT Statement
Oracle9i Data Warehousing Guide: Chapter 18 - SQL for Aggregation in Data Warehouses

Oracle9i Daily Features
Archives


추가적 참고내용...

The Oracle WITH clause is an incredibly powerful tool available since Oracle9i R2 that enables the user to create virtual views that become reusable via an alias throughout the main body of a query. A WITH clause (officially called a Subquery Factoring Clause) is pre-pended to a SELECT statement. The power of the WITH clause becomes evident in situations where a subquery, or indeed any portion of a query, is used in more than one location throughout a SELECT statement. Since the results from a WITH clause are calculated only once, dramatic performance improvements may be realized. As an added benefit, WITH clauses tend to simplify the look of a query since repeated sections are centralized and aliased. The basic syntax for a SELECT statement using a WITH clause may look a little strange at first and some tools (i.e. Oracle Reports in some cases) may be unable to properly parse this construct:

WITH
 alias_name         -- Alias to use in the main query
AS
(insert a query here)
SELECT... -- Beginning of the query main body

It should be noted that multiple aliases can be defined in the WITH clause:

WITH
alias_name1
AS
(query1)
aleas_name2
AS
(query2)
SELECT...

As previously indicated, the intended use of a WITH clause is to increase efficiency by eliminating repeated query sections in a SELECT statement. The following query (which we realize could be written in a more efficient manner!), returns customers from a fictitious SALES table that were found in the top ten for both January and February. This query is constructed using two in-line views, one for the January calculation and one for February. Notice the duplication in the in-line views aliased as “jan” and “feb”; only the date ranges are different:

For this exercise, we employ the simple table Sales
with three columns:
customer_name VARCHAR2;
sales_date DATE;
customer_sales NUMBER;

SELECT top_10_jan.customer_name,
top_10_jan.total_sales_jan,
top_10_feb.total_sales_feb
FROM (
SELECT customer_name,
total_sales_jan
FROM (
SELECT customer_name,
SUM(customer_sales) total_sales_jan
FROM sales
WHERE sales_date
BETWEEN '01-jan-06' AND '31-JAN-06'
GROUP BY customer_name
ORDER BY 2 DESC
) jan
WHERE rownum <11
) top_10_jan,
(
SELECT customer_name,
total_sales_feb
FROM (
SELECT customer_name,
SUM(customer_sales) total_sales_feb
FROM sales
WHERE sales_date
BETWEEN '01-FEB-06' AND '28-FEB-06'
GROUP BY customer_name
ORDER BY 2 DESC
) feb
WHERE rownum <11
) top_10_feb
WHERE top_10_jan.customer_name = top_10_feb.customer_name;

By substituting WITH clause in place of the two in-line views, the above query can be rewritten in a more efficient manner:

WITH
tot_sales
AS
(
SELECT customer_name,
sales_date,
total_sales,
RANK() OVER (PARTITION BY sales_date
ORDER BY total_sales DESC) month_rank
FROM (
SELECT customer_name,
TRUNC(sales_date,'MONTH') sales_date,
SUM(customer_sales) total_sales
FROM sales
WHERE sales_date >= '01-JAN-06'
AND sales_date <= '28-FEB-06'
GROUP BY customer_name,
TRUNC(sales_date,'MONTH')
) jan
)
SELECT tot_jan.customer_name,
tot_jan.total_sales,
tot_feb.total_sales
FROM tot_sales tot_jan,
tot_sales tot_feb
WHERE tot_jan.sales_date = '01-JAN-06'
AND tot_feb.sales_date = '01-FEB-06'
AND tot_jan.month_rank <11
AND tot_feb.month_rank <11
AND tot_jan.customer_name = tot_feb.customer_name;

Just how much more efficient is our new query? Explain plans for each query using Oracle 10G R2 and a table with 25000 rows yields the following query costs:

Query method 1: In-line views

Query Method 2: WITH Clause

The query using in-line views shows a cost of 1449, but re-writing the query to use a WITH clause shows a drop to 861! This big savings comes from the elimination of a second full table scan of the SALES table. A WITH clause calculates its result set only once and re-uses it throughout the query. In our simulations, this query actually resulted in a 40% improvement in execution time. Not a bad little tuning trick!

We realize of course that this query could have been written without the need for in-line views OR the WITH clause and perhaps even more efficiently. Take for example the following query, which has a cost of 727 (but in practice was actually slower than the WITH query in terms of execution time):

SELECT customer_name,
jan_sales,
feb_sales
FROM
(
SELECT customer_name,
jan_sales,
feb_sales,
RANK() OVER (ORDER BY jan_sales DESC) jan_rank,
RANK() OVER (ORDER BY feb_sales DESC) feb_rank
FROM
(
SELECT customer_name,
SUM(DECODE(TRUNC(sales_date,'MONTH'),
'01-JAN-06', customer_sales,0)) jan_sales,
SUM(DECODE(TRUNC(sales_date,'MONTH'),
'01-FEB-06', customer_sales,0)) feb_sales
FROM sales
WHERE sales_date >= '01-JAN-06'
AND sales_date <= '28-FEB-06'
GROUP BY customer_name
)
)
WHERE jan_rank <11
AND feb_rank <11;

Clearly, there are many ways to solve a problem, and Subquerey Factoring adds another powerful tool to facilitate writing both efficient and elegant queries. Use it, but remember that the WITH clause comes with limitations and sometimes returns unexpected results. But more on that in a different post.


Posted by 상피리꿈
반응형
오라클이 IBM 과 전면전에 나서기 위하여 준비를 계속 해왔군요.

2008년 1월 오라클의  BEA 합병 소식.
2009년 4월 오라클의 Sun 인수 소식.

이렇게 되면 오라클은 DB,Weblogic, Java 에 두루두루 발을 뻗히는 격이 되는군요.
캬.. DB 가 MiddleWare 를 다 점유해 버렸네요. 향후 IBM 과의 대결이 궁금해 집니다.
대단하군요 래리 앨리슨 오라클 CEO!!!


아래 기사내용...

2008년

[종합]오라클, 85억 달러에 BEA 인수
미들웨어 부문 보강…IBM과 치열한 경쟁 예상
왕성한 식욕을 자랑하는 오라클이 두 번의 구애 끝에 BEA 시스템즈를 삼키는 데 성공했다.

오라클이 16일(현지 시간) BEA시스템즈를 85억 달러에 인수하기로 합의했다고 월스트리트저널을 비롯한 주요 외신들이 일제히 보도했다. 이번 인수로 기업용 소프트웨어 시장을 통합하겠다는 래리 엘리슨 최고경영자(CEO)의 야심이 한층 힘을 받게 됐다.

래리 엘리슨 오라클 CEO도 합병 사실 발표 직후 컨퍼런스 콜을 통해 "이번 합병으로 미들웨어 부분을 비롯한 주요 기업용 서비스 시장으로 영향력을 확대하는 발판을 마련했다"고 강조했다.

◆"BEA 웹로직에 가장 큰 관심"

오라클은 그 동안 피플소프트, JD 에드워즈 같은 경쟁업체들을 인수하면서 전사적자원관리(ERP) 부문에서 SAP와 양강 체제를 구축했다. 또 시벨 시스템즈까지 손에 넣으면서 사실상 통합 소프트웨어업체로 자리매김했다.

하지만 미들웨어 시장에서는 약세를 면치 못했다. 퓨전 미들웨어란 제품을 내놓긴 했지만 이 분야 최강으로 군림하고 있는 IBM의 위세에 눌려 있는 상황이었다.

이번에 인수한 BEA는 바로 이 부분을 채워줄 수 있을 것으로 기대되고 있다. BEA는 그 동안 웹로직을 앞세워 IBM 등과 미들웨어 시장을 놓고 치열한 경쟁을 해 왔다. BEA는 회계연도 3분기에 3억8천44만 달러 매출에 5천600만 달러 수익을 기록했다.

실제로 오라클은 BEA의 웹로직 애플리케이션 서버에 가장 큰 관심을 갖고 있다고 공언해 왔다. 오라클 입장에선 웹로직을 확보함으로써 자신들의 라인업에서 취약한 부분을 커버할 수 있게 됐다는 판단이다.

실제로 BEA의 웹로직 자바 서버를 오라클의 퓨전 소프트웨어들과 결합할 경우엔 상당한 시너지 효과가 기대된다. 앞으로 오라클은 BEA의 기술을 활용해 자사가 개발해 오던 퓨전 미들웨어를 한층 개량할 수 있을 전망이다.

엘리슨 CEO는 BEA 인수로 자바 기반 미들웨어 기술과 서비스지향 아키텍처(SOA)를 확산시키는 데 큰 힘을 받을 수 있을 것이라고 강조했다. 또 중국 시장과 통신부문으로 영역을 확대하는 효과도 기대된다고 밝혔다.

반면 BEA의 아쿠아로직 SOA는 오라클의 소프트웨어와 기능 면에서 겹치는 부분이 있기 때문에 미래가 불투명한 것으로 판단된다.

오라클은 BEA의 제품 라인을 그대로 유지하면서 고객 지원을 계속한다는 계획이다. 이는 오라클이 그 동안 피플소프트, JD에드워즈, 시벨 시스템즈 등을 인수할 때 택했던 방식이다.

.....................

2009년

[종합]썬, IBM 대신 오라클 택했다
74억달러에 합병 합의…IT시장 대형 후폭풍 예고
태양(SUN)이 선택한 것은 '빅블루'가 아니라 오라클이었다.

래리 엘리슨이 이끄는 오라클이 썬마이크로시스템스를 74억달러(주당 9.50달러)에 인수하기로 했다고 월스트리트저널을 비롯한 주요 외신들이 20일(현지 시간) 보도했다.

오라클은 썬 인수로 15억달러 이상의 영업 이익을 추가할 수 있을 것으로 기대하고 있다.

두 회사 간 합병 작업은 올 여름 쯤 마무리될 것으로 기대하고 있다.

◆"애플리케이션-컴퓨터-스토리지 함께 제공"

오라클과 썬은 그 동안 긴밀한 유대 관계를 유지해 왔다. 썬의 서버에 오라클의 데이터베이스 소프트웨어를 탑재하면서 서로 공생 관계를 유지해 왔던 것.

하지만 썬은 최근 IBM을 비롯해 휴렛패커드(HP), 델 등 대형 업체들의 공세 때문에 서버 시장에서 고전을 면치 못했다. 여기에다 최근엔 시스코까지 서버 사업에 뛰어들면서 힘을 보탤 수 있는 파트너가 절실하게 필요한 상황이었다.

오라클 입장에서도 경쟁업체인 IBM이 썬을 삼킬 경우 큰 위협 요인이 될 수 있다는 판단에 따라 썬 인수에 적극적으로 나선 것으로 풀이된다.

이번 인수로 오라클은 썬이 보유하고 있는 자바 기술에 대한 주도권을 확실하게 확보할 수 있게 됐다. 또 솔라리스 등 썬의 운영체제까지 손에 쥘 수 있게 돼 향후 시장 경쟁에서 큰 힘을 받을 전망이다.

래리 엘리슨 오라클 최고경영자(CEO)는 썬 인수로 고객들에게 애플리케이션 프로그램, 컴퓨터, 데이터 스토리지 하드웨어 등을 번들 제공할 수 있을 것이라고 강조했다.

....

Posted by 상피리꿈
이전버튼 1 이전버튼

반응형
블로그 이미지
상피리꿈
Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함


반응형