oracle 并行之并行度篇
操作内并行使用的slave process数量就是并行度dop,indextable都有dop 作为默认操作并行度default 1表示不使用并行处理 SQL create table t1 (a int) parallel 6; Table created. SQL select degree from user_tables where table_name=’T1′; DEGREE ——
操作内并行使用的slave process数量就是并行度dop,index&table都有dop 作为默认操作并行度default 1表示不使用并行处理
SQL> create table t1 (a int) parallel 6;
Table created.
SQL> select degree from user_tables where table_name=’T1′;
DEGREE
———-
6
SQL> alter table t1 parallel 3;
Table altered.
SQL> select degree from user_tables where table_name=’T1′;
DEGREE
———-
3
*禁用alter table(index) parallel 1 (noprallel)
#create 时候使用parallel不仅会在创建table&index时使,后续的操作ddl,dml也会使用(如果只想建表时使用,建好后修改)
SQL> create table t2 (a int) parallel;(未指定并行度)
Table created.
SQL> select degree from user_tables where table_name=’T2′;
DEGREE
———-
DEFAULT ~~~这样使用default并行度=(cpu_count*parallel_threads_per_cpu)
SQL> show parameter cpu_count
NAME TYPE VALUE
———————————— ———– ——————————
cpu_count integer 2
SQL> show parameter parallel_thread
NAME TYPE VALUE
———————————— ———– ——————————
parallel_threads_per_cpu integer 2
SQL>
SQL> insert into t2 values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> set autotrace trace exp
SQL> select * from t2;
Execution Plan
———————————————————-
Plan hash value: 1216610266
——————————————————————————–
——————————
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
| TQ |IN-OUT| PQ Distrib |
——————————————————————————–
——————————
| 0 | SELECT STATEMENT | | 1 | 13 | 2 (0)| 00:00:01
| | | |
| 1 | PX COORDINATOR | | | | |
| | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 1 | 13 | 2 (0)| 00:00:01
| Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 1 | 13 | 2 (0)| 00:00:01
| Q1,00 | PCWC | |
| 4 | TABLE ACCESS FULL| T2 | 1 | 13 | 2 (0)| 00:00:01
| Q1,00 | PCWP | |
——————————————————————————–
——————————
Note
—–
– dynamic sampling used for this statement
SQL>
SQL> set autotrace off
SQL> select process from v$pq_tqstat;
no rows selected
可以看到 用set autotrace 后 查v$pq_tqstat norows ,这是2个原因造成的
1.set autotrace的原理
开启autotrace时候 一个process对应 2个 session
通常情况下是一个 session对应一个 server processs,但SErVER PORCESSS 可以对应多个session
SQL> conn xh/a831115
已连接。
SQL> select distinct sid from v$mystat;
SID
———-
144
SQL> select username, sid, serial#, server, paddr, status from v$session where s
id=144;
USERNAME SID SERIAL# SERVER PADDR STATUS
—————————— ———- ———- ——— ——– ——–
XH 144 27 DEDICATED 20E4CC3C INACTIVE
SQL> select program ,addr from v$process where addr=(select paddr from v$session
where sid=144);
PROGRAM ADDR
—————————————————————- ——–
ORACLE.EXE (SHAD) 20E4CC3C
SQL> select sid from v$session where paddr=’20E4CC3C’;
SID
———-
144
SQL> set autotrace on
SQL> select sid from v$session where paddr=’20E4CC3C’;
SID
———-
144
154
2.v$pq_tqstat只提供当前session最后一次并行执行sql语句的信息
综合2点可以看出set autotrace 最后一个session 是 执行计划的,所以v$pq_tqstat为no rows
所以 直接执行
SQL> select * from t2;
A
———-
1
SQL> SELECT dfo_number, tq_id, server_type, process, num_rows, bytes
2 FROM v$pq_tqstat
3 ORDER BY dfo_number, tq_id, server_type DESC, process;
DFO_NUMBER TQ_ID SERVER_TYP PROCESS NUM_ROWS BYTES
———- ———- ———- ———- ———- ———-
1 0 Producer P000 1 24
1 0 Producer P001 0 20
1 0 Producer P002 0 20
1 0 Producer P003 0 20
1 0 Consumer QC 1 84
可以看到启动了4个slave process,这4个process=cpu_count*parallel_threads_per_cpu(2*2)
相关的hint:
parallel(10g,11g),no_parallel(10g,11g),parallel_index(10g,11g,9i),no_parallel_index(10g,11g)
noparallel(9i),noparallel_index(9i)
##需要知道并行hint只是告诉优化器可以使用并行,但不是强制使用并行一切还是从cost出发(重点)
declare
begin
for i in 1..1000 loop
insert into t2 values(i);
end loop;
commit;
end;
SQL> explain plan set statement_id=’t2_pp’ for select /*+parallel(t2 2)*/* from t2 where a>900;
Explained.
SQL> create index t2_id on t2 (a);
Index created.
SQL> explain plan set statement_id=’t2_id’ for select /*+parallel(t2 2)*/* from t2 where a>900;
Explained.
SQL> set linesize 1000
SQL> select * from table (dbms_xplan.display(null,’t2_pp’));
PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
Plan hash value: 1216610266
————————————————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
————————————————————————————————————–
| 0 | SELECT STATEMENT | | 100 | 1300 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 100 | 1300 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 100 | 1300 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
|* 4 | TABLE ACCESS FULL| T2 | 100 | 1300 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
————————————————————————————————————–
PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
Predicate Information (identified by operation id):
—————————————————
4 – filter(“A”>900)
Note
—–
– dynamic sampling used for this statement
20 rows selected.
SQL> select * from table (dbms_xplan.display(null,’t2_id’));
PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
Plan hash value: 523330294
————————————————————————–
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
————————————————————————–
| 0 | SELECT STATEMENT | | 100 | 1300 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| T2_ID | 100 | 1300 | 2 (0)| 00:00:01 |
————————————————————————–
Predicate Information (identified by operation id):
—————————————————
PLAN_TABLE_OUTPUT
————————————————————————————————————————————————————————————————————————————————————————————————————
1 – access(“A”>900)
Note
—–
– dynamic sampling used for this statement
17 rows selected.
可以看到 即使在使用并行与走index时cost一样时候还是选择了走index(cost表面一样,若使用trace alter session set events ’10053 trace name context forever’;看的更详细,并行cpu cost要高些,所以选择了走index,所以hint parallel,parallel_index只是告诉query optimizer
可以考虑并行 不是强制使用)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.
