`
jianchen
  • 浏览: 344832 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Improving Query Performance with the SQL WITH Clause

阅读更多

有一篇文章讲解了水平(列)分区的情况下,如何进行优化?

原文链接如下:http://everythingoracle.com/obieehp.htm

 

总结: 如果如果查询对应到两个表,两个表中存在同样的维度,只是相关的指标被分割到两张表中,比如A(product_id,sales_quantity),B(product_id,unit_price),如果简单的分别引入两张表,做好跟product维度表的关联,会发出两条sql。如果能够尽量的合并,只发出一条sql,这样会对性能有显著地提升。当然了,我们是在两张表位于同一个库的情况下了,如果不同的库,则比较难办了。可以在BIEE admin tool的物理层,采用“select”视图的方式,预先将表进行关联,从而指定了发出的sql,该文章中就用到了with语句的写法。具体如下图:


       

 

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.

  • 大小: 67.7 KB
分享到:
评论

相关推荐

    Improving the Lightning Performance

    该标准文档的标题“Improving the Lightning Performance”(提升雷电性能)主要指通过一系列技术和方法来提高电力系统中架空配电线路对于雷电冲击的抵抗能力。在电力行业中,“雷电性能”的提升通常涉及到对现有...

    Improving the Performance of an IP-over-P2P

    The investigation produced detailed measurements in order to profile the application and help on improving the performance. Code analysis shows that the current IPOP version suffers from ...

    Improving TCP Performance over Wireless Networksat the Link Lay

    Improving TCP Performance over Wireless Networksat the Link Lay 英文原版 We present the transport unaware link improvement protocol (TULIP), which dramatically improves the performance of TCP over ...

    Designing with Data: Improving the User Experience with A/B Testing

    Designing with Data: Improving the User Experience with A/B Testing by Rochelle King English | 29 Mar. 2017 | ASIN: B06XY9TTN8 | 370 Pages | AZW3 | 4.61 MB On the surface, design practices and data ...

    Improving TCP Performance During the Intra LTE Handover

    ### 提升LTE网络内部切换期间TCP性能的关键技术 #### 摘要与研究背景 随着移动数据使用量的显著增加以及在线游戏、移动电视、Web2.0等新应用的出现,LTE(Long Term Evolution)作为UMTS(通用移动通信系统)的后续...

    High Performance in-memory computing with Apache Ignite.pdf

    Sharing Spark RDD states between different Spark applications for improving performance. Processing events & streaming data, integrate Apache Ignite with other frameworks like Storm, Camel, etc. ...

    Java Performance: The Definitive Guide, Scott Oaks

    With this comprehensive guide, developers and performance engineers alike will learn a variety of features, tools, and processes for improving the way Java 7 and 8 applications perform.

    微软内部资料-SQL性能优化5

    Indexes are the most useful tool for improving query performance. Without a useful index, Microsoft® SQL Server™ must search every row on every page in table to find the rows to return. With a ...

    Optimizing Java_Practical Techniques for Improving JVM Application Performance

    Optimizing Java_Practical Techniques for Improving JVM Application Performance-O’Reilly(2018) How do you define performance? Most developers, when asked about the performance of their application, ...

    Paper Improving routing performance

    这篇文章探讨了在无线传感器网络(WSN)中,当同时使用多种路由协议时,如何改进路由性能。无线传感器网络的主要用途是监测应用,当前的趋势是同时支持多种应用以保证多层次的服务质量(QoS)。...

    improving-network-performance-in-multi-core-systems-paper

    And with the growth of server virtualization and consolidation, high-volume data transactions, real-time technologies such as VoIP and video on demand, and the increase to 10GbE bandwidth, the ...

    Improving forecasts of GARCH family models with the ANN.pdf

    在金融市场分析中,波动性(volatility)是一个关键的指标,因为它反映了资产价格变动的不确定性。自Engle在1982年提出自回归条件异方差(Autoregressive Conditional Heteroskedasticity, ARCH)模型以来,一系列的...

    SSD7: Database Systems

    From data abstraction, the course then turns to transaction management, with some additional material on improving query performance. Finally, there is an introduction of up-to-date trends in ...

    Improving the performance of a Gigabit Ethernet driver

    ### 提升Linux下千兆以太网驱动性能 #### 概览 本文档主要讨论了在Linux环境下如何提升千兆以太网驱动的性能。它不仅涵盖了基础的驱动原理介绍,还包括了一些具体的优化方法,例如发送中断节制、TCP慢启动改进以及...

    Improving Lookup Performance over a widely-deployed DHT

    本文《Improving Lookup Performance over a widely-deployed DHT》聚焦于Kademlia协议,一种广泛部署的DHT,旨在探讨并优化其查找性能。 ### 核心知识点 #### 1. DHT与Kademlia简介 DHT是一种分布式数据存储机制...

    Improving WS-Security Performance with a Template-Based Approach

    ### 基于模板的方法提升WS-Security性能 #### 概述 随着Web服务在全球范围内的广泛应用,确保这些服务的安全性和可靠性的需求日益增长。为了满足这一需求,一系列与Web服务安全相关的规范被提出,其中最核心的是WS...

    论文研究-Improving Text Models with Latent Feature Vector Representations.pdf

    本文的主题是围绕如何利用潜在特征向量来改进文本表示模型,这一研究方向在自然语言处理(NLP)领域具有重要地位。文本表示是NLP中的一个关键问题,它直接关系到文本分类等研究课题的效果。一个良好的文本表示模型应该...

    Improving iForest with Relative Mass.pdf

    本文标题《Improving iForest with Relative Mass.pdf》表明本篇文档是关于异常检测领域的一篇论文,旨在探讨如何通过“相对质量(Relative Mass)”的概念来优化iForest算法。iForest是一种在数据挖掘中广泛应用的...

Global site tag (gtag.js) - Google Analytics