Misunderstanding of DML's use of parallelism and misunderstanding of DML's use of Parallelism

Source: Internet
Author: User

Misunderstanding of DML's use of parallelism and misunderstanding of DML's use of Parallelism

I always think that we can use parallelism for DML. We only need to add the hint of parallel. Actually, no. Using alter session force parallel dml is the real parallel operation. Here is an experiment:

SQL> drop table test purge;

SQL> create table test as select * from dba_objects;
SQL> insert into test select * from test;
SQL> insert into test select * from test;
SQL> commit;
SQL> exec dbms_stats.gather_table_stats (user, 'test ');

SQL> set timing on
SQL> update test t set object_name = 'ggg ';
318988 rows updated.
Elapsed: 00:00:05. 06
SQL> commit;

SQL> update test t set object_name = 'ggg ';
318988 rows updated.
Elapsed: 00:00:03. 68 -- Parallel update time is not used.
SQL> commit;

SQL> update/* + parallel (t, 4) */test t set object_name = 'ggg ';
318988 rows updated.
Elapsed 00:00:03. 81
SQL> commit;

SQL> update/* + parallel (t, 4) */test t set object_name = 'ggg ';
318988 rows updated.
Elapsed: 00:00:03. 31 -- Parallel is used, but the effect is not obvious.
SQL> commit;

SQL>Alter session force parallel dml;

Or alter session enableParallel dml;


SQL> update/* + parallel (t, 4) */test t set object_name = 'ggg ';
318988 rows updated.
Elapsed: 00:00:00. 51
SQL> commit;

SQL> update/* + parallel (t, 4) */test t set object_name = 'ggg ';
318988 rows updated.
Elapsed: 00:00:00. 38 -- very effective
SQL> commit;

Why? Open another session, observe their execution plan, and use alter session force parallel dml to scan the test table in the whole table in parallel, and then use it in the update:
SQL> EXPLAIN PLAN FOR update/* + parallel (t, 4) */test t set object_name = 'ggg ';
Explained.

SQL> select * from table (DBMS_XPLAN.DISPLAY );
PLAN_TABLE_OUTPUT
Bytes ---------------------------------------------------------------------------------------------------------------------
Plan hash value: 3695425075
Bytes ---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | TQ | IN-OUT | PQ Distrib |
Bytes ---------------------------------------------------------------------------------------------------------------
| 0 | update statement | 318K | 7787K | 245 (1) | 00:00:04 |
| 1 | UPDATE | TEST |
| 2 | px coordinator |
| 3 | px send qc (RANDOM) |: TQ10000 | 318K | 7787K | 245 (1) | 00:00:04 | Q1, 00 | P-> S | QC (RAND) |
| 4 | px block iterator | 318K | 7787K | 245 (1) | 00:00:04 | Q1, 00 | PCWC |
| 5 | table access full | TEST | 318K | 7787K | 245 (1) | 00:00:04 | Q1, 00 | PCWP |
Bytes ---------------------------------------------------------------------------------------------------------------
12 rows selected.

SQL> alter session force parallel dml;


SQL> EXPLAIN PLAN FOR update/* + parallel (t, 4) */test t set object_name = 'ggg ';
Explained.

SQL> select * from table (DBMS_XPLAN.DISPLAY );
PLAN_TABLE_OUTPUT
Bytes -------------------------------------------------------------------------------------------------------------------
Plan hash value: 2059761527
Bytes ---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (% CPU) | Time | TQ | IN-OUT | PQ Distrib |
Bytes ---------------------------------------------------------------------------------------------------------------
| 0 | update statement | 318K | 7787K | 245 (1) | 00:00:04 |
| 1 | px coordinator |
| 2 | px send qc (RANDOM) |: TQ10000 | 318K | 7787K | 245 (1) | 00:00:04 | Q1, 00 | P-> S | QC (RAND) |
| 3 | UPDATE | TEST | Q1, 00 | PCWP |
| 4 | px block iterator | 318K | 7787K | 245 (1) | 00:00:04 | Q1, 00 | PCWC |
| 5 | table access full | TEST | 318K | 7787K | 245 (1) | 00:00:04 | Q1, 00 | PCWP |
Bytes ---------------------------------------------------------------------------------------------------------------
12 rows selected.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.