Parallel Query Tuning(并行化查询优化)

以下情况可用到并行查询优化:
full table scans,joining of large tables,large range-scans of indexes,insertion of massive amounts of data to a data warehouse,and so on.

The number of parallel query slaves for a single task is called the degree of parallelism.Normally, PQ would attempt to use parallel query slave processes equal to the value of degree of parallelism.But if a sorting operation is involved,the number of processes required is doubled.

It is very important to note here that PQ will utilize twice the number of processes defined in the degree if the SQL statement requires a sort operation.

there are the following ways to set this degree of parallelism:
1.At the table or index level
2.At the SQL statement level with a parallel hint
3.As default based on the number of CPUs or the number of storage devices that Oracle believes that you are using

set the degree of parallelism when creating a new table.

SQL> create table MYTABLE
(ColA number(2),
ColB number(2)
)
parallel (degree 4);

Table created.


You can see the value of the degree of parallelism for the table in the
USER_TABLES,ALL_TABLES,and DBA_TABLES views in a column titled Degree:

SQL> select Degree
from USER_TABLES
where TABLE_NAME='MYTABLE';

DEGREE
--------------------
         4


You can change the degree of parallelism for a table using the alter table command.

SQL> alter table MYTABLE parallel(degree 6);

Table altered.

SQL> select Degree
from USER_TABLES
where TABLE_NAME='MYTABLE'; 

DEGREE
--------------------
         6

set the degree of parallelism on an index to 4 while creating the index.Depending on your Oracle version,the data dictionary views USER_INDEXES,DBA_INDEXES,and ALL_INDEXES will have a column titled Degree,which will contain the value of the degree of parallelism for the index.

SQL> create index MYINDEX
on MYTABLE (ColA)
storage (initial 1M next 1M)
parallel (degree 4);//创建过程中initial需要4M的空间,在创建过程中每个parallel query slaves都会使用自己独立的临时表空间。

Index created.

SQL> select Degree
from USER_INDEXES
where Index_Name='MYINDEX';

DEGREE
----------------------------------------
4

You can also use the alter index command to change the degree of parallelism for an index, as shown here:

SQL> alter index MYINDEX parallel(degree 6);

Index altered.

SQL>  select Degree
from USER_INDEXES
where Index_Name='MYINDEX';

DEGREE
----------------------------------------
6

set the degree of parallelism on a table to 6,via a PARALLEL hint in a SQL statement.
select /*+PARALLEL (CM , 6)*/ Customer_Id Custid, Last_Contract_Yr Lcy
from CUSTOMER_MASTER CM
order by Customer_Id;

Please note that since the previous example users an "order by" clause to sort the result set, Oracle may attempt to allocate at least twelve parallel query slaves to this operation.

sets the degree of parallelism on a table to a value of default.

SQL> select degree from user_tables where table_name='TEST';

DEGREE
--------------------
         1

SQL> alter table test parallel;

Table altered.

SQL> select degree from user_tables where table_name='TEST';

SQL>
SQL>
SQL> select degree from user_tables where table_name='TEST';

DEGREE
--------------------
   DEFAULT

In Oracle 8.1.6,a new initialization parameter,PARALLEL_THREADS_PER_CPU,defines the default degree of parallelism.Its default value is platform-specific and is adequate in most cases.
It is very easy to determine this if you look at V$SESSION_WAIT for wait events that relate to parallel query slaves.

优先级:
1.SQL statement with the PARALLEL hint
2.Parallel degree set at the table or index
3.Default degree of parallelism

取消并行度:
alter table MYTABLE noparallel;

select /*+NOPARALLEL*/ count(*)
from CUSTOMER_MASTER;

--未完待续--

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23135684/viewspace-662069/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23135684/viewspace-662069/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值