哪些场景可以使用并行度
table scan、fast full index scans、partition index range scans(仅限local索引)
create table as、create index、rebuild index、move、split、DML(insert\update\delete)
当使用了并行执行,SQL的执行计划中就会多出一列:in-out。相关视图为:v$pq_sysstat、v$pq_tqstat
alter session force parallel query parallel N --强制使用N个并行度,force parallel会覆盖默认的parallel设置
alter session enable parallel query --使用默认的并行度数量
表打开并行的方法
alter table sales parallel;
alter table sales parallel 8;
hint开启表查询的并行度
select /*+ parallel(tablename,8) */ * from tablename
select /*+ parallel(sales,8) */ * from sales
DML使用hint开启并行时,表必须打开并行,因为update时,是要先查出表的数据即先执行select,所以update开启了并行度,select也要开启并行度,否则只有update是并行,但select却不是。
并行度GRANULES
1.并行工作的一个基本单元被称为GRANULES
2,一个GRANULES只能有一个并行执行的server进行读的操作
3,并行的一个server可以从一个GRANULES到另外一个GRANULES的执行任务,即当一个任务完成了就去接着执行下一个任务。
并行度GRANULES分两种
1.block range granules(自动根据块的数目范围为分)
Block range granules: Server进程在执行的时候就动态的产生。
2.partition granules(用于分区表,比如有8个分区,它可能会分四个并行度,这样四个并行度可能在四个不同分区上)
Partition granules : 有分区的数量静态的决定。
三个著名参数的应用场景
PARALLEL_DEGREE_POLICY
PARALLEL_MIN_PERCENT
PARALLEL_SERVERS_TARGET
比如80个CPU、现在已经使用了60个,剩下20个(PARALLEL_SERVERS_TARGET),现在来了一个60个并行度的查询,怎么办?
如果PARALLEL_MIN_PERCENT=10,就是10%可以用,就是最少使用60*10%=6个并行度,6<20,可以使用
如果PARALLEL_MIN_PERCENT=50,就是使用60*50%=30,30>20,如果PARALLEL_DEGREE_POLICY=MANUAL,则不够,直接报错,如果PARALLEL_DEGREE_POLICY=AUTO,则进入队列。
PARALLEL_FORCE_LOCALcontrols parallel execution in an Oracle RAC environment. By default, the parallel server processes selected to execute a SQL statement can operate on any or all Oracle RAC nodes in the cluster. By setting PARALLEL_FORCE_LOCAL to true, the parallel server processes are restricted so that they can only operate on the same Oracle RAC node where the query coordinator resides (the node on which the SQL statement was executed on).
控制Oracle RAC环境中的并行执行。默认情况下,选择执行SQL语句的并行
服务器进程可以在群集中的任何或所有Oracle RAC节点上运行。通过将PARALLEL_FORCE_LOCAL设置为true,并行服务器进程受到限制,因此它们只能在查询协调程序所在的同一个Oracle RAC节点(执行SQL语句的节点)上运行
默认FORCE,就是可以使用其他节点的CPU,并不是说在其他节点执行SQL,执行SQL还是本节点(即PX在本节点),但是可以使用其他节点的资源做coordinator process即QC(就是管理下面这些并行度的一个进程,一个个的并行程序叫parallel execution servers即PX),此参数最好设置为TRUE
PARALLEL_MAX_SERVERSspecifies the maximum number of parallel execution processes and parallel recovery processes for an instance. As demand increases, Oracle Database increases the number of processes from the number created at instance startup up to this value
PARALLEL_MAX_SERVERS指定实例的并行执行进程和并行恢复进程的最大数量。随着需求的增加,Oracle数据库将实例启动时创建的进程数量增加到此值
PARALLEL_MIN_SERVERSspecifies the minimum number of parallel execution processes for the instance. This value is the number of parallel execution processes Oracle creates when the instance is started
PARALLEL_MIN_SERVERS指定实例的最小并行执行进程数。 该值是在实例启动时由Oracle创建的并行执行进程的数量
PARALLEL_MIN_SERVERS默认是0,如果修改为5,说明就算是空闲不用,也开启5个进程,相关视图v$px_process
比如一开机就有ora_p001_sid、ora_p002_sid、ora_p003_sid、ora_p004_sid、ora_p004_sid这样5个进程,这就是partition slave process they do parallel dml ddl and query jobs..
PARALLEL_DEGREE_POLICYspecifies whether or not automatic degree of Parallelism,statement queuing, and in-memory parallel execution will be enabled
PARALLEL_DEGREE_POLICY指定是否启用并行度,语句排队和内存中并行执行的自动程度
PARALLEL_MIN_PERCENTlets you specify the minimum percentage of the requested number of parallel execution processes required for parallel execution. This parameter controls the behavior for parallel operations when parallel statement queuing is not enabled (when PARALLEL_DEGREE_POLICY is set to manual or limited). It ensures that an operation always gets a minimum percentage of parallel execution servers or errors out. Setting this parameter ensures that parallel operations will not execute unless adequate resources are available. The default value of 0 means that no minimum percentage of processes has been set.
If 8 of the 10 parallel execution processes are busy, only 2 processes are available. If you then request a query with a degree of parallelism of 8, the minimum 50% will not be met.
PARALLEL_MIN_PERCENT可以指定并行执行所需的并行执行进程的最小数量百分比。 并行语句队列未启用时(PARALLEL_DEGREE_POLICY设置为manual or limited),此参数控制并行操作的行为。它确保操作始终获得并行执行服务器的最小百分比或出错。设置此参数可确保并行操作不会执行,除非提供足够的资源。默认值0意味着没有设置最小进程百分比。
PARALLEL_SERVERS_TARGETspecifies the number of parallel server processes allowed to run parallel statements before statement queuing will be used. When the parameter PARALLEL_DEGREE_POLICY is set to AUTO, Oracle will queue SQL statements that require parallel execution, if the necessary parallel server processes are not available.
PARALLEL_SERVERS_TARGE指定在使用语句排队之前允许运行并行语句的并行服务器进程的数量。当参数PARALLEL_DEGREE_POLICY设置为AUTO时,如果必需的并行服务器进程不可用,Oracle将对需要并行执行的SQL语句进行排队。
PARALLEL_MIN_TIME_THRESHOLDspecifies the minimum execution time a statement should have before the statement is considered for automatic degree of parallelism. By default, this is set to 10 seconds. Automatic degree of parallelism is only enabled if PARALLEL_DEGREE_POLICY is set to AUTO or LIMITED.
PARALLEL_MIN_TIME_THRESHOLD指定语句在考虑自动并行度之前语句应该具有的最短执行时间。默认情况下,它被设置为10秒。自动并行度仅在PARALLEL_DEGREE_POLICY设置为AUTO或LIMITED时才能使用。
PARALLEL_ADAPTIVE_MULTI_USER, when set to true, enables an adaptive algorithm designed to improve performance in multiuser environments that use parallel execution. The algorithm automatically reduces the requested degree of parallelism based on the system load at query startup time. The effective degree of parallelism is based on the default degree of parallelism, or the degree from the table or hints, divided by a reduction facto
PARALLEL_ADAPTIVE_MULTI_USER,当设置为true时,启用一个自适应算法,旨在提高使用并行执行的多用户环境的性能。该算法根据查询启动时的系统负载自动降低请求的并行度。并行度的有效程度是基于默认的并行度,或者从表或者提示的程度除以还原因子
分享题目:parallel并行度的相关操作、概念、参数解释
URL链接:
http://shouzuofang.com/article/iiooog.html