search
HomeDatabaseMysql Tutorial【转】Oracle Parallel 多线程

对于一个大的任务,一般的做法是利用一个进程,串行的执行,如果系统资源足够,可以采用parallel技术,把一个大的任务分成若干个小的任务,同时启用n个进程/线程,并行的处理这些小的任务,这些并发的进程称为并行执行服务器(parallel executeion? server )

对于一个大的任务,一般的做法是利用一个进程,串行的执行,如果系统资源足够,可以采用parallel技术,把一个大的任务分成若干个小的任务,同时启用n个进程/线程,并行的处理这些小的任务,这些并发的进程称为并行执行服务器(parallel executeion?server),这些并发进程由一个称为并发协调进程的进程来管理。

启用Parallel前的忠告:只有在需要处理一个很大的任务,如需要几十分钟,几个小时的作业中,并且要有足够的系统资源的情况下(这些资源包括cpu,内存,io),您才应该考虑使用parallel。否则,在一个多并发用户下,系统本身资源负担已经很大的情况下,启用parallel,将会导致某一个会话试图占用了所有的资源,其他会话不得不去等待,从而导致系统系能反而下降的情况,一般情况下,oltp系统不要使用parallel,oltp系统中可以考虑去使用。

Parallel分类

l??并行查询parallel query

l??并行dml parallel dml pdml

l??并行ddl parallel ddl pddl

一、 并行查询

并行查询允许将一个sql?select语句划分为多个较小的查询,每个部分的查询并发地运行,然后将各个部分的结果组合起来,提供最终的结果,多用于全表扫描,索引全扫描等,大表的扫描和连接、创建大的索引、分区索引扫描、大批量插入更新和删除

1.??? 启用并行查询

SQL> ALTER TABLE T1 PARALLEL;

告知oracle,对T1启用parallel查询,但并行度要参照系统的资源负载状况来确定。

利用hints提示,启用并行,同时也可以告知明确的并行度,否则oracle自行决定启用的并行度,这些提示只对该sql语句有效。

SQL> select /*+ parallel(t1 8) */ count(*)from t1;

SQL> select degree from user_tables?where?table_name=’T1′;

DEGREE

——————–

??DEFAULT

并行度为Default,其值由下面2个参数决定

SQL> show parameter cpu

NAME????????????????????????????????TYPE???????VALUE

———————————————– ——————————

cpu_count???????????????????????????integer????2

parallel_threads_per_cpu????????????integer????2

cpu_count表示cpu数

parallel_threads_per_cpu表示每个cpu允许的并行进程数

default情况下,并行数为cpu_count*parallel_threads_per_cpu

2.??? 取消并行设置

SQL> alter table t1 noparallel;

SQL> select degree from user_tables wheretable_name=’T1′;

DEGREE

—————————————-

????????1

3.??? 数据字典视图

v$px_session

sid:各个并行会话的sid

qcsid:query coordinator sid,查询协调器sid

二、 并行dml

并行dml包括insert,update,delete,merge,在pdml期间,oracle可以使用多个并行执行服务器来执行insert,update,delete,merge,多个会话同时执行,同时每个会话(并发进程)都有自己的undo段,都是独立的一个事务,这些事务要么由pdml协调器进程提交,要么都rollback。

在一个有充足I/o带宽的多cpu主机中,对于大规模的dml,速度可能会有很大的提升,尤其是在大型的数据仓库环境中。

并行dml需要显示的启用

SQL> alter session enable parallel dml;

Disable并行dml

SQL> alter session disable parallel dml;

三、 并行ddl

并行ddl提供了dba使用全部机器资源的能力,常用的pddl有

create table as select?……

create index

alter index rebuild

alter table move

alter table split

在这些sql语句后面加上parallel子句

SQL> alter table t1 move parallel;

Table altered

SQL> create index T1_IDX on T1 (OWNER,OBJECT_TYPE)

?2???tablespace SYSTEM

3????????parallel;

4????????;

1.  用途
强行启用并行度来执行当前SQL。这个在Oracle 9i之后的版本可以使用,之前的版本现在没有环境进行测试。也就是说,加上这个说明,可以强行启用Oracle的多线程处理功能。举例的话,就像电脑装了多核的CPU,但大多情况下都不会完全多核同时启用(2核以上的比较明显),使用parallel说明,就会多核同时工作,来提高效率。
但本身启动这个功能,也是要消耗资源与性能的。所有,一般都会在返回记录数大于100万时使用,效果也会比较明显。
2.  语法
/*+parallel(table_short_name,cash_number)*/
这个可以加到insert、delete、update、select的后面来使用(和rule的用法差不多,有机会再分享rule的用法)
开启parallel功能的语句是:
alter session enable parallel dml;
这个语句是DML语句哦,如果在程序中用,用execute的方法打开。
3.  实例说明
用ERP中的transaction来说明下吧。这个table记录了所有的transaction,而且每天数据量也算相对比较大的(根据企业自身业务量而定)。假设我们现在要查看对比去年一年当中每月的进、销情况,所以,一般都会写成:
select to_char(transaction_date,'yyyymm') txn_month,
       sum(
        decode(
            sign(transaction_quantity),1,transaction_quantity,0
              )
          ) in_qty,
       sum(
        decode(
            sign(transaction_quantity),-1,transaction_quantity,0
              )
          ) out_qty
  from mtl_material_transactions mmt
 where transaction_date >= add_months(
                            to_date(    
                                to_char(sysdate,'yyyy')||'0101','yyyymmdd'),
                                -12)
   and transaction_date 
    <p class="copyright">
        原文地址:【转】Oracle Parallel 多线程, 感谢原作者分享。
    </p>
    
    


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does MySQL's licensing compare to other database systems?How does MySQL's licensing compare to other database systems?Apr 25, 2025 am 12:26 AM

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

When would you choose InnoDB over MyISAM, and vice versa?When would you choose InnoDB over MyISAM, and vice versa?Apr 25, 2025 am 12:22 AM

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

Explain the purpose of foreign keys in MySQL.Explain the purpose of foreign keys in MySQL.Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

What are the different types of indexes in MySQL?What are the different types of indexes in MySQL?Apr 25, 2025 am 12:12 AM

There are four main index types in MySQL: B-Tree index, hash index, full-text index and spatial index. 1.B-Tree index is suitable for range query, sorting and grouping, and is suitable for creation on the name column of the employees table. 2. Hash index is suitable for equivalent queries and is suitable for creation on the id column of the hash_table table of the MEMORY storage engine. 3. Full text index is used for text search, suitable for creation on the content column of the articles table. 4. Spatial index is used for geospatial query, suitable for creation on geom columns of locations table.

How do you create an index in MySQL?How do you create an index in MySQL?Apr 25, 2025 am 12:06 AM

TocreateanindexinMySQL,usetheCREATEINDEXstatement.1)Forasinglecolumn,use"CREATEINDEXidx_lastnameONemployees(lastname);"2)Foracompositeindex,use"CREATEINDEXidx_nameONemployees(lastname,firstname);"3)Forauniqueindex,use"CREATEU

How does MySQL differ from SQLite?How does MySQL differ from SQLite?Apr 24, 2025 am 12:12 AM

The main difference between MySQL and SQLite is the design concept and usage scenarios: 1. MySQL is suitable for large applications and enterprise-level solutions, supporting high performance and high concurrency; 2. SQLite is suitable for mobile applications and desktop software, lightweight and easy to embed.

What are indexes in MySQL, and how do they improve performance?What are indexes in MySQL, and how do they improve performance?Apr 24, 2025 am 12:09 AM

Indexes in MySQL are an ordered structure of one or more columns in a database table, used to speed up data retrieval. 1) Indexes improve query speed by reducing the amount of scanned data. 2) B-Tree index uses a balanced tree structure, which is suitable for range query and sorting. 3) Use CREATEINDEX statements to create indexes, such as CREATEINDEXidx_customer_idONorders(customer_id). 4) Composite indexes can optimize multi-column queries, such as CREATEINDEXidx_customer_orderONorders(customer_id,order_date). 5) Use EXPLAIN to analyze query plans and avoid

Explain how to use transactions in MySQL to ensure data consistency.Explain how to use transactions in MySQL to ensure data consistency.Apr 24, 2025 am 12:09 AM

Using transactions in MySQL ensures data consistency. 1) Start the transaction through STARTTRANSACTION, and then execute SQL operations and submit it with COMMIT or ROLLBACK. 2) Use SAVEPOINT to set a save point to allow partial rollback. 3) Performance optimization suggestions include shortening transaction time, avoiding large-scale queries and using isolation levels reasonably.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)