- 浏览: 92149 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (81)
- 读书笔记 (14)
- NetBeans学习 (1)
- JavaBeans and Bean Events (3)
- 《Pro Oracle SQL》Chapter 2 SQL Execution (13)
- 《Pro Oracle SQL》Chapter 3 Access and Join Methods (16)
- Pro Oracle SQL Chapter 5 (0)
- Pro Oracle SQL Chapter 6 (0)
- Pro Oracle SQL Chapter 7 (9)
- Pro Oracle SQL Chapter 8 (9)
- 《Pro Oracle SQL》Chapter 9 The Model Clause (11)
- 《Pro Oracle SQL》Chapter 10 Subquery Factoring (7)
最新评论
-
mojunbin:
这个不能不顶。
《Pro Oracle SQL》 Chapter2--2.1 Oracle Architecture Basics -
Branding:
谢谢,获益匪浅
《Pro Oracle SQL》--chapter 5--5.6 Building Logical Expressions -
Branding:
《Pro Oracle SQL》--Chapter 5--5.4 Questions about the Question -
Branding:
谢谢
《Pro Oracle SQL》 翻译序 -- 读书心得 -
jiaoshiguoke:
继续 加油
《Pro Oracle SQL》--Chapter 6--6.1 Explain Plans--之三
《Pro Oracle SQL》Chapter8--8.9 Advanced topics
- 博客分类:
- Pro Oracle SQL Chapter 8
Advanced topics 高级主题
(page 268)
A few advanced topics about the analytic functions are worthy of discussion. I will discuss topics such as dynamic analytic statements, nesting of analytic functions, parallelism, and PGA size.
关于分析函数的一些高级主体很值得讨论。我将讨论如动态分析语句,分析函数的嵌套,并行性
,以及PGA大小。
Dynamic SQL 动态SQL
A common question about the analytic SQL statement is whether a bind variable can be used in place of partitioning or sorting columns. No.
If you want the flexibility to modify the partitioning or sorting columns dynamically, you need to use dynamic SQL statements.
Static analytic SQL statements can not change the partitioning or sorting columns.
分析函数有一个常见的问题是:绑定变量是否能用于替换分区或排序列么?答案是不能。
如果你需要动态修改分区列和排序列(的这种弹性),你就需要使用动态SQL语句。
静态分析SQL语句不能改变分区或排序列。
If your goal is to modify the partitioning columns dynamically, then consider creating a packaged procedure to capture the logic in the procedure. In the Listing 8-24, the procedure Analytic_dynamic_prc accepts a string to be used as partitioning columns. A SQL statement is constructed using the arguments passed and executed dynamically using Execute immediate syntax. Result of the analytic statement is fetched into an array and printed using a call to dbms_output package.
如果你的目标是动态的修改分区列,就要考虑创建打包的存储过程,把逻辑封装在存储过程中。在列表8-24中,存储过程
Analytic_dynamic_prc接收一字符串用做分区列。SQL语句使用传入的参数构造且使用Execute
immediate句法动态的执行。分析语句的结果从数组中取出且调用dbms_output包打印出结果。
In the first call, the analytic_dynamic_prc passes the string product, country, region as the first argument and the columns in this list are used as the partitioning columns. The second call to the procedure uses the string product, country, region, year to use a different list of columns for the partitioning-clause.
在第一次调用中,analytic_dynamic_prc传递字符串“product, country,
region”作为第一个参数,在列表中的列用做分区列。第二次调用过程使用字符串“product, country, region,
year”作为分区子句的不同的列表。
Note that this procedure is given as an example and as such may not be construed as a production-ready code.
注意这个过程仅作为一个例子,可能用于生产环境的代码不能如此构造。
Listing 8-24. Dynamic SQL Statement
create or replace procedure
analytic_dynamic_prc ( part_col_string varchar2, v_country varchar2, v_product varchar2)
is
type numtab is table of number(18,2) index by binary_integer;
l_year numtab;
l_week numtab;
l_sale numtab;
l_rank numtab;
l_sql_string varchar2(512) ;
begin
l_sql_String :=
'select * from (
select year, week,sale,
rank() over(
partition by ' ||part_col_string ||'
order by sale desc
) sales_rank
from sales_fact
where country in (' ||chr(39) || v_country || chr(39) || '
) and
product =' || chr(39) || v_product || chr(39) ||
' order by product, country,year, week
) where sales_rank<=10
order by 1,4';
execute immediate l_sql_string bulk collect into l_year, l_week, l_sale, l_rank;
for i in 1 .. l_year.count
loop
dbms_output.put_line ( l_year(i) ||' |' || l_week (i) ||
'|'|| l_sale(i) || '|' || l_rank(i) );
end loop;
end;
/
exec analytic_dynamic_prc ( 'product, country, region','Australia','Xtend Memory');
...
1998 |48|172.56|9
2000 |46|246.74|3
2000 |21|187.48|5
2000 |43|179.12|7
2000 |34|178.52|8
2001 |16|278.44|1
2001 |4|256.7|2
exec analytic_dynamic_prc ( 'product, country,region, year','Australia','Xtend Memory');
1998 |48|172.56|1
1998 |10|117.76|2
1998 |18|117.56|3
1998 |23|117.56|3
1998 |26|117.56|3
1998 |38|115.84|6
1998 |42|115.84|6
...
Nesting Analytic Functions
Analytic functions can not be nested, but a nesting effect can be achieved with the use of subqueries.
For example, the clause lag(first_value(column,1),1) is syntactically incorrect. Subqueries can be used to
create a nesting effect, as you’ll see below.
分析函数不能嵌套,但是使用子查询能取得嵌套效果。
例如,子句lag(first_value(column,1),1)句法上是错误的。你将看到,使用子查询能创建嵌套效果。
Suppose your goal is to fetch the maximum Sale column value for the year and the prior year in the same row; if so, then analytic functions lag and first_value can be used in the subqueries to write a SQL statement. In Listing 8-25, inner subquery is fetching the Year and Week Sale column value in which the maximum sale occurred, in addition to fetching the maximum Sale column value for that year. The lag function in the outer query retrieves the prior Year Maximum Sale column value.
假设你的目标是在同一行中取出当年和上一年的最大的Sale列值。在列表8-25中,内部子查询取出的是最大sale值所在行的Year,Week列值,还有取出那年的最大Sale列值。外部查询的lag函数检索上一年最大Sale列值。
Notice that the partitioning clause is different between lag and first_value functions. Analytic function first_value is computing the top Sale row in a partition specified by the partitioning columns product, country, region, year whereas the lag is fetching the first row from the prior year specifying only sorting-clause: order by year desc .
注意lag和first_value函数的分区子句是有区别的。分析函数first_value计算的是按分区列product, country,
region, year指定分区的第一Sale列值所在行,而lag则取的是由排序子句“order by year
desc”指定的前一年的第一行。
With multi-level nesting of analytic functions, complex goals can be implemented concisely using the analytic functions.
通过多层分析函数嵌套,复杂的目标就能通过精简的使用分析函数得以执行。
Listing 8-25. Nesting Analytic Functions
select year, week, top_sale_year,
lag( top_sale_year) over ( order by year desc)
prev_top_sale_yer
from (
select distinct
first_value ( year)
over (
partition by product, country, region ,year
order by sale desc
rows between unbounded preceding and unbounded following
) year,
first_value ( week)
over (
partition by product, country, region ,year
order by sale desc
rows between unbounded preceding and unbounded following
) week,
first_value (sale)
over(
partition by product, country, region ,year
order by sale desc
rows between unbounded preceding and unbounded following
) top_sale_year
from sales_fact
where country in ('Australia') and product ='Xtend Memory'
)
order by year, week
/
YEAR WEEK TOP_SALE_YEAR PREV_TOP_SALE_YER
----- ---- ------------- -----------------
1998 48 172.56 148.12
1999 17 148.12 246.74
2000 46 246.74 278.44
2001 16 278.44
Parallelism 并行性
By specifying a parallel hint in the SQL statement or by setting parallelism at the object level, analytic functions can be parallelized.
If you have huge amount of data that needs to be processed using analytic functions, parallelism is a good choice. A SQL statement using multi-level nesting also can benefit from parallelism.
通过在SQL语句中指定并发提示或者通过在对象层级设定并行性,分析函数就能并发化(执行)。
如果你有大量的数据需要使用分析函数处理,并行性就是不错的选择。使用了多层嵌套的SQL语句也能从并行性中获益。
Listing 8-26 shows the execution plan for the query in the Listing 8-25 using parallelism. In the execution plan, there are two WINDOW operations as the SQL statement has nested the lag and first_value analytic functions.
列表8-26展示了列表8-25查询使用并行性后的执行计划。在执行计划中,有两处WINDOW操作,因为SQL语句嵌套了分析函数lag和first_value。
Optimal distribution of rows between the
PQ slaves
is critical to maintain functional correctness and that is automatically handled by Oracle database.
在
PQ副盘(Parallel Query slaves)
之间行集的优化分布对于保持功能正确性是至关重要的,且是由Oracle数据库自动处理的。
Listing 8-26. Parallelism
----------------------------------------------------
Id | Operation | Name
-----------------------------------------------------
0 | SELECT STATEMENT |
1 | SORT ORDER BY |
2 | WINDOW BUFFER
|
3 | PX COORDINATOR |
4 | PX SEND QC(ORDER) | : T Q1 0 0 03
5 | SORT ORDER BY |
6 | PX RECEIVE |
7 | PX SEND RANGE | : T Q1 0 0 02
8 | VIEW |
9 | HASH UNIQUE |
10 | PX RECEIVE |
11 | PX SEND HASH | : T Q1 0 0 01
12 | WINDOW SORT
|
13 | PX RECEIVE |
14 | PX SEND HASH | : T Q1 0 0 00
15 | PX BLOCK ITERATOR |
* 16 | TABLE ACCESS FULL | SALES_FACT
PGA size
Most operations associated with the analytic functions are performed in
the Program Global Area(PGA) of the process.
So, for optimal
performance it is important to have a big enough memory area so that
programs can execute analytic functions without spilling
to the disk.
This is very analogous to a Sort operation. If the Sort operation spills
to the disk due to a lower value of the memory size, then the
performance of the Sort operation will not be optimal.Similarly, the
execution performance of analytic functions will suffer if the operation spills to the disk.
与分析函数有关联的大部分操作在程序全局区(PGA)中执行。
如此以来,对优化性能而言有充足的内存区域将使得程序能执行分析函数而不要溢出
到磁盘中。这同Sort操作如出一辙。如果Sort操作由于低容量的内存溢出到磁盘,则Sort操作将不是优化的了。相似的,如果Sort操作溢出到磁盘则分析函数的执行性能将大打折扣。
Database initialization parameter
PGA_AGGREGATE_TARGET(PGAT) controls the cumulative maximum size of the
PGA. By default, a serial process can allocate a PGA up to the maximum
size of 5% of PGAT value. For parallel processes, the limit is up to 30%
of PGAT. It is essential to keep PGAT to a bigger value to improve the
performance of analytic functions.
数据库初始化参数
PGA_AGGREGATE_TARGET(PGAT)控制着累积的最大PGA尺寸。默认情况下,一串行进程能最多分配5%的PGAT容量的PGA。而对于并行进程,这个限制上升到30%。保持PGAT足够的大对提高分析函数的性能有实质意义。
Organizational Behavior
The hardest thing about analytic function is the organizational
resistance to change. Developers and databae administrators are
comfortable writing SQL statements using conventional syntax. Using
analytic syntax will not come easy. However, these developers and
database administrators need to embrace the change. Another plus: use of
analytic functions forces one to think in terms of sets.
关于分析函数最难的事是团队对(新事物)改变的阻力。开发者和数据库管理员满足于是用传统句法写SQL。推行分析函数将不那么顺利。然而,这些开发者和数据库管理员需要拥抱这种改变。另一个好处:使用分析函数迫使人们依照集合的方式来思考。
Oracel
Corporation releases new features in every major release of Oracle
Database. We need to harness the new features to write more efficient
and concise SQL statements. Proper training for these new features is
also essential and hopefully, this chapter provided an insight in to
analytic functions.
Oracle公司在每一个Oracle数据库主要版本发布新特性。我们需要驾驭这些新特性来写出更加有效,精简的SQL语句。对这些新特性适当的培训也是必要的和有前途的,本章深入讨论了分析函数。
When you start writing SQL statement
utilizing the analytic functions, start with simpler SQL statement. Then
add more complexity to meet tht goal.
当你开始利用分析函数写SQL语句,开始用简单的SQL语句,然后逐渐的复杂,最终达到目的。
Summary
总结
Complex SQL
statements can be written using analytic functions concisely.
Understanding analytic function provides you whole new way of thinking,
analytically speaking.
The ability to reference another row combined with
partitioning and windowing clase allows you to simplify complex SQL
statements. Many performance issues can be resolved rewriting the SQL
statement using analytic functions, and that resistance can be easily
overcome by showing the performance improvements with analytic
functions.
复杂的SQL语句能使用分析函数简明的写出来。理解分析函数给予你全新的方式思考,分析的表述。 行间引用的能力结合分区和窗口子句使得你能够简化复杂的SQL语句。许多性能问题通过使用分析函数重写SQL语句迎刃而解,且通过展示分析函数所带来的性能提升(推广它的)阻力也将容易克服。
发表评论
-
《Pro Oracle SQL》Chapter8--8.8 Performance Tuning
2012-03-02 23:11 728Performance Tuning 性能调优 ... -
《Pro Oracle SQL》Chapter 8 -- 8.7 Other Analytic Functions 之三
2012-02-29 22:09 1034NTILE (page 263) ... -
《Pro Oracle SQL》Chapter 8 -- 8.7 Other Analytic Functions 之二
2012-02-26 22:14 894Ratio_to_report ... -
《Pro Oracle SQL》Chapter 8 -- 8.7 Other Analytic Functions 之一
2012-02-26 14:35 1070Other Analytic Functions ... -
《Pro Oracle SQL》Chapter 8--8.6 First_ value & Last_value
2012-02-21 23:52 914First_value & Last_value ... -
《Pro Oracle SQL》Chapter 8 -- 8.5 Lead and Lag
2012-02-19 16:07 1054Lead and Lag (page 2 ... -
《Pro Oracle SQL》Chapter 8 -- 8.4Aggregation Functions
2012-02-17 01:47 1026Aggregation Functions 聚合 ... -
《Pro Oracle SQL》Chapter 8 -- 8.1-8.2 Anatomy of Analytic Functions -8.3
2012-02-11 11:16 1174Riyaj Shamsudeen (page 243) ...
相关推荐
cmd脚本-bat批处理-RUN.zip
内容概要:本文详细介绍了 MySQL 中的数据类型,将其分为数值、日期/时间和字符串三大类。数值类型涵盖从 TINYINT 到 BIGINT 的整数类型以及浮点数和 DECIMAL 类型,每种类型都有明确的存储大小和取值范围。日期/时间类型包括 DATE、TIME、YEAR、DATETIME 和 TIMESTAMP,适用于不同的日期和时间表达需求,其中 TIMESTAMP 具有自动更新特性。字符串类型则由 CHAR、VARCHAR、BLOB、TEXT、ENUM 和 SET 组成,能够存储固定长度或可变长度的字符及二进制数据。此外,还提及了空间数据类型,如 GEOMETRY 等,用于存储地理信息和几何图形数据。; 适合人群:数据库管理员、软件开发者及其他需要深入了解 MySQL 数据库设计与优化的专业人士。; 使用场景及目标:①为数据库设计提供理论依据,确保选择合适的数据类型以优化性能;②帮助开发者理解各种数据类型的特性和应用场景,以便更好地进行应用程序开发。; 其他说明:正确选择 MySQL 数据类型对于提高数据库效率至关重要,应根据实际需求合理选用不同类型。例如,在存储大量文本时,应考虑使用 TEXT 或 BLOB 类型;对于需要精确计算的数值,则优先选用 DECIMAL 类型。同时,了解每种类型的特点有助于避免潜在的数据丢失或溢出风险。
cmd脚本-bat批处理-去掉字符串头所有的0.zip
cmd脚本-bat批处理-全盘禁止运行指定程序.zip
cmd-bat-批处理-脚本-语音参考字典.zip
内容概要:本文档《Docker 新手入门指南》详细介绍Docker这一开源容器化平台,旨在帮助新手理解并掌握Docker的核心概念和基本操作。文中首先解释了Docker的概念及其相对于传统虚拟机的优势,如更快的启动速度、更低的资源占用和更好的隔离性。接着,文档提供了详细的安装步骤,包括不同操作系统下的安装方法以及针对国内用户的镜像加速配置。随后,文章深入讲解了镜像管理和容器操作的基础命令,如拉取镜像、运行容器等。进一步地,文档介绍了使用Dockerfile构建自定义镜像、实现数据持久化、进行端口映射以及利用Docker Compose管理多容器应用等高级技巧。最后,给出了一些学习建议和注意事项,鼓励读者动手实验并关注安全性。 适合人群:适合对容器技术感兴趣的初学者,尤其是有一定Linux基础或打算深入了解Docker的开发人员。 使用场景及目标:①帮助读者快速上手Docker,掌握从安装到实际操作的一系列技能;②通过实例演示,如构建Python Web服务、部署WordPress和搭建Jenkins环境,让读者能够将所学应用于实际项目中;③强调容器化的优势,如提高部署效率、解决环境差异问题。 阅读建议:建议读者跟随文档逐步操作,亲身体验每个步骤,同时参考官方文档和社区资源,不断实践以巩固所学知识。特别注意安全性和资源管理方面的提示,确保容器环境的安全稳定运行。
cmd-bat-批处理-脚本-九宫格图案.zip
据QYResearch调研团队最新报告“全球斗式提升机链条市场报告2024-2030”显示,预计2030年全球斗式提升机链条市场规模将达到1亿美元,未来几年年复合增长率CAGR为4.4%。 市场驱动因素: 散装物料输送行业的增长:水泥、采矿、农业和发电等行业的需求不断增长,推动了斗式提升机在垂直物料运输中的应用。基础设施建设和工业化:全球建筑活动的不断增长和工业厂房的扩张推动了对重型输送系统的需求。链式系统的效率和耐用性:链式斗式提升机因其强度高、使用寿命长而成为重型和高温应用的首选。自动化和工厂优化:采用自动化和智能控制系统可提高链式输送机的性能和运行效率。 市场制约因素: 初始安装和维护成本高:与基于皮带的替代方案相比,链式系统更昂贵且更复杂,尤其对于小型作业而言。恶劣环境下的磨损:如果不进行适当的维护,持续暴露于磨蚀性或腐蚀性材料中会导致更快的老化。某些设施的空间限制:斗式提升机的垂直设计和占地面积可能并不适合所有场地布局,从而限制了其适用性。 市场机遇: 链条材料的技术进步:耐磨耐腐蚀合金和涂层的开发延长了产品的使用寿命和可靠性。农业和食品加工行业的扩张:新兴市场对谷物处理、化肥运输和散装食品转运的需求不断增长,推动了链条的使用。现有系统的改造和升级:有机会用高性能链条系统替换过时的机械部件,以提高产量。对节能输送解决方案的需求不断增长:对降低能耗的重视推动了链传动系统和铲斗设计的创新。 根据QYResearch头部企业研究中心调研,全球范围内斗式提升机链条生产商主要包括Tsubakimoto Chain、Renold、Thiele、Pewag、RUD Ketten、HEKO Group、John King Chains、B.V.Transmission Industries、Transmin、华通气动等。2024年,全球前五大厂商占有大约51.0%的市场份额。 就
cmd脚本-bat批处理-删除指定路径下指定文件及文件夹外的所有文件及文件夹1.zip
内容概要:本文由麦肯锡发布,探讨了人工智能(AI)特别是生成式AI(gen AI)如何重塑组织架构及创造价值。研究表明,企业正在通过重新设计工作流程、提升治理水平和应对更多与gen AI相关的风险来捕捉AI的价值。CEO对AI治理的监督与工作流的重新设计是取得财务影响的关键因素。大公司正引领这一变革,它们更积极地招聘AI相关人才并进行员工再培训。此外,企业正逐步采用AI于多个业务职能,包括营销、销售、产品开发和服务运营。尽管目前大部分公司尚未看到AI对企业整体利润的显著影响,但已有迹象表明,AI的应用正在增加收入并减少成本。 适合人群:企业高管、AI项目经理、战略规划人员以及对AI技术应用感兴趣的商业人士。 使用场景及目标:①帮助企业管理层理解如何通过AI技术优化内部流程并提高效率;②为AI项目的实施提供参考,确保企业在部署AI时能够最大化其商业价值;③指导企业在风险管理、人才招聘和员工技能升级方面做出明智决策。 其他说明:随着AI技术的发展,企业需要不断调整自身结构和流程以适应新技术带来的变化。文中提到的最佳实践如建立专门团队推动AI采用、定期沟通AI价值、高层领导积极参与等做法,可以为企业成功引入AI提供有益借鉴。此外,文中还强调了AI对不同行业的影响差异,以及个人使用AI工具的趋势变化。
内容概要:本文主要介绍了SQL注入的概念、危害及其防范措施。SQL注入是攻击者通过恶意构造输入,使服务器执行非预期的SQL命令的一种攻击方式,常因用户输入未
cmd脚本-bat批处理-查看工作组.zip
cmd-bat-批处理-脚本-不显示输入密码.zip
Gauss-Seidel迭代,OpenMP并行化本质上是不行的,输入文件
cmd-bat-批处理-脚本-IE不能打开新链接修复.zip
cmd-bat-批处理-脚本-批处理加密.zip
以下是一个基于蒙特卡罗法的可靠性分析Matlab程序代码,该代码能够处理具有任意分布的随机变量,并且可以考虑多个失效模式。代码中包含了测试案例,可以直接在Matlab软件中运行。同时,代码中附有详细注释,便于理解。 该程序基于蒙特卡罗法进行可靠性分析,适用于处理具有任意分布的随机变量以及多个失效模式。 用户可以通过修改random_vars和random_params来定义随机变量的分布类型和参数,通过修改failure_modes来定义失效模式函数。 程序中包含一个测试案例,可以直接在Matlab软件中运行,以验证程序的正确性。 程序代码中附有详细注释,便于用户理解和修改。
cmd-bat-批处理-脚本-断开网络联结.zip
内容概要:本文详细介绍了三种删除 MySQL 数据库的方法:使用 SQL 语句 drop 命令、使用 mysqladmin 命令行工具以及使用 PHP 脚本。drop 命令可以直接删除指定数据库,带有 IF EXISTS 选项可以防止因数据库不存在而报错。mysqladmin 工具提供了一种交互式的删除方式,增强了安全性。PHP 脚本则展示了如何通过编程语言与 MySQL 进行交互,完成数据库的删除操作。文中强调了删除数据库前应确保有足够权限,并提醒操作不可逆,建议先备份。 适合人群:具有基础 MySQL 操作知识的数据库管理员、开发者及运维人员。 使用场景及目标:①了解并掌握多种删除 MySQL 数据库的方式;②提高对数据库管理的安全意识,避免误删重要数据;③学会在不同环境下选择合适的工具进行数据库维护。 阅读建议:由于删除数据库是一项高风险操作,在实际应用中务必谨慎行事。建议读者先在一个测试环境中练习本文提到的各种方法,熟悉每一步骤后再应用于生产环境。同时,对于 PHP 脚本部分,需要具备一定的编程基础。