Oracle 并行计算 JOIN HINT

背景

Oracle的并行查询在处理JOIN时,可以通过调整优化器的HINT,指定优化器在处理JOIN时表的分布与关联策略。

例如,两张表JOIN时,如果是HASH或者MERGE JOIN,可以使用HASH分片,然后每个并行的计算单元处理一个数据分片,达到提高效率的目的。

又或者可以将某个较小的表进行broadcast,然后另一张表使用随机的分片策略,每个计算单元可以独立的运算。

这些算法与MPP如Greenplum的JOIN策略比较类似。

PostgreSQL 9.6也支持CPU的并行计算了,学习一下Oracle多年的并行计算是非常有必要的。

Oracle 并行计算 JOIN HINT

https://docs.oracle.com/cd/B12037_01/server.101/b10752/hintsref.htm

PQ_DISTRIBUTE

The PQ_DISTRIBUTE hint improves the performance of parallel join operations.

Do this by specifying how rows of joined tables should be distributed among producer and consumer query servers.

Using this hint overrides decisions the optimizer would normally make.

Use the EXPLAIN PLAN statement to identify the distribution chosen by the optimizer.

The optimizer ignores the distribution hint, if both tables are serial.

pq_distribute_hint::=

/*+ PQ_DISTRIBUTE ( [@queryblock] tablespec outer_distribution inner_distribution ) */

where:

  • outer_distribution is the distribution for the outer table.
  • inner_distribution is the distribution for the inner table.

For a description of the queryblock syntax, see "Specifying a Query Block in a Hint".

For a description of the tablespec syntax, see "Specifying Global Table Hints".

There are six combinations for table distribution.

Only a subset of distribution method combinations for the joined tables is valid, as explained in Table 17-1.

Table 17-1 Distribution Hint Combinations

Distribution | Interpretation
-- | --
Hash, Hash | Maps the rows of each table to consumer query servers, using a hash function on the join keys. When mapping is complete, each query server performs the join between a pair of resulting partitions. This hint is recommended when the tables are comparable in size and the join operation is implemented by hash-join or sort merge join.
Broadcast, None | All rows of the outer table are broadcast to each query server. The inner table rows are randomly partitioned. This hint is recommended when the outer table is very small compared to the inner table. As a general rule, use the Broadcast/None hint when inner table size * number of query servers > outer table size.
None, Broadcast | All rows of the inner table are broadcast to each consumer query server. The outer table rows are randomly partitioned. This hint is recommended when the inner table is very small compared to the outer table. As a general rule, use the None/Broadcast hint when inner table size * number of query servers < outer table size.
Partition, None | Maps the rows of the outer table, using the partitioning of the inner table. The inner table must be partitioned on the join keys(当内表的JOIN字段正好是它的partition 字段,并且分区个数正好等于或接近并行度时建议使用。外表将依据内表的分区mapping rows。). This hint is recommended when the number of partitions of the outer table is equal to or nearly equal to a multiple of the number of query servers; for example, 14 partitions and 15 query servers. Note: The optimizer ignores this hint if the inner table is not partitioned or not equijoined on the partitioning key.
None, Partition | Maps the rows of the inner table using the partitioning of the outer table. The outer table must be partitioned on the join keys. This hint is recommended when the number of partitions of the outer table is equal to or nearly equal to a multiple of the number of query servers; for example, 14 partitions and 15 query servers. Note: The optimizer ignores this hint if the outer table is not partitioned or not equijoined on the partitioning key.
None, None | Each query server performs the join operation between a pair of matching partitions, one from each table. Both tables must be equipartitioned on the join keys(当内表和外表都在JOIN字段上进行了分区时,则内表和外表直接在匹配的分区上进行JOIN).

For example: Given two tables, r and s, that are joined using a hash-join, the following query contains a hint to use hash distribution:

SELECT /*+ORDERED PQ_DISTRIBUTE(s HASH, HASH) USE_HASH (s)*/ column_list
  FROM r,s
  WHERE r.c=s.c;

To broadcast the outer table r, the query is:

SELECT /*+ORDERED PQ_DISTRIBUTE(s BROADCAST, NONE) USE_HASH (s) */ column_list
  FROM r,s
  WHERE r.c=s.c;

Count

时间: 2025-01-08 14:34:37

Oracle 并行计算 JOIN HINT的相关文章

oracle left join 后怎么取前10条数据?

问题描述 oracle left join 后怎么取前10条数据? 如题 oracle left join 后怎么取前10条数据? 求大神帮帮忙,谢谢了 解决方案 where rownum <= 10 解决方案二: ORACLE取前10条数据Oracle获取前10条数据Oracle查询前10条数据 解决方案三: 直接select top10 * from a表 left join b表 on --; 解决方案四: select * from (select ROWNUM as num,A.* f

Oracle中基于hint的3种执行计划控制方法详细介绍_oracle

hint(提示)无疑是最基本的控制执行计划的方式了:通过在SQL语句中直接嵌入优化器指令,进而使优化器在语句执行时强制的选择hint指定的执行路径,这种使用方式最大的好处便是方便和快捷,定制度也很高,通常在对某些SQL语句执行计划进行微调的时候我会首选这种方式,不过尽管如此,hint在使用中仍然有很多不可忽视的问题: 使用hint过程中有一些值得注意的细则,首先便是要准确的识别对应的查询块,如果需要使用注释也可以hint中声明:对于使用别名的对象一律使用别名来引用,并且诸如"用户名.对象&quo

Oracle原厂老兵:从负面案例看Hint的最佳使用方式

作者介绍 罗敏,从事Oracle技术研究.开发和服务工作20余年,在Oracle中国公司的10多年,分别在顾问咨询部.技术服务部担任资深技术顾问.曾参与国内银行.电信.政府等多个行业大型IT系统的建设和运维服务工作,为国内主要软件开发商和集成商进行过多场Oracle高级技术应用培训和交流活动.著有书籍<品悟性能优化>.<感悟Oracle核心技术>.<Oracle数据库技术服务案例精选>.   Oracle真灵活     某银行广泛采用了Oracle和IBM DB2两种数

【微信公众号● DBAplus】Oracle原厂老兵:从负面案例看Hint的最佳使用方式

原创 2016-10-12 罗敏  Oracle原厂老兵:从负面案例看Hint的最佳使用方式 作者介绍 罗敏,从事Oracle技术研究.开发和服务工作20余年,在Oracle中国公司的10多年,分别在顾问咨询部.技术服务部担任资深技术顾问.曾参与国内银行.电信.政府等多个行业大型IT系统的建设和运维服务工作,为国内主要软件开发商和集成商进行过多场Oracle高级技术应用培训和交流活动.著有书籍<品悟性能优化>.<感悟Oracle核心技术>.<Oracle数据库技术服务案例精选

用智能优化限制提高Oracle数据库性能

Oracle SQL运行时间的最主要的组成部分是花在为执行准备新的SQL语句上的时间.不过,如果了解了可执行计划产生的内在机制,你就可以控制Oracle花费在评估表的连接顺序的时间,并在总体上提高查询的性能. 准备为执行提供的SQL语句 在一个SQL语句进入Oracle库的cache之后.而真正被执行之前,将会依次发生如下事件: 语法检查--检查该SQL语句的拼写和词序是否正确. 语义解析--Oracle根据数据词典(data dictionary)来验证所有的表格(table)和列(colum

RDS for PG加入Plan Hint功能

有一个功能,是社区官方版"永远"不考虑引入的(参见PG TODO,查找"Oracle-style"),即类似Oracle的Plan Hint.社区开发者的理念是,引入Hint功能,会掩盖优化器本身的问题,导致缺陷不被暴露出来.但对于我们的使用者来讲,遇到某些SQL的查询计划不好,性能出了问题,使用了其他方法又不奏效的情况下,首先的目标还是想尽快解决问题.而Hint就可以在这种时候帮助到我们.可喜的是,通过集成"民间"的pg_hint_plan插件

PgSQL · 特性分析 · Plan Hint

背景 有一个功能,是社区官方版"永远"不考虑引入的(参见PG TODO,查找"Oracle-style"),即类似Oracle的Plan Hint.社区开发者的理念是,引入Hint功能,会掩盖优化器本身的问题,导致缺陷不被暴露出来.但对于我们的使用者来讲,遇到某些SQL的查询计划不好,性能出了问题,使用了其他方法又不奏效的情况下,首先的目标还是想尽快解决问题,而Hint就可以在这种时候帮助到我们.可喜的是,通过集成"民间"的 pg_hint_pl

Oracle中的优化器--CBO和RBO

Oracle中的优化器--CBO和RBO Oracle数据库中的优化器又叫查询优化器(Query Optimizer).它是SQL分析和执行的优化工具,它负责生成.制定SQL的执行计划.Oracle的优化器有两种,基于规则的优化器(RBO)与基于代价的优化器(CBO)          RBO: Rule-Based Optimization 基于规则的优化器          CBO: Cost-Based Optimization 基于代价的优化器 RBO自ORACLE 6以来被采用,一直沿

About Oracle WITH clause

About Oracle WITH clauseStarting in Oracle9i release 2 we see an incorporation of the SQL-99 "WITH clause", a tool for materializing subqueries to save Oracle from having to re-compute them multiple times. The SQL "WITH clause" is very