Top Banner
8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses
34

8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

Mar 27, 2015

Download

Documents

Devin Saunders
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8Copyright © 2005, Oracle. All rights reserved.

Parallel Operations in Data Warehouses

Page 2: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-2 Copyright © 2005, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do the following:

• Determine when partitionwise joins are used

• Use the ALTER SESSION command to force parallel operations

• Create indexes in parallel

• Set initialization parameters relating to parallel operations tuning

• Query dynamic performance views related to parallel operations tuning

• Tune PDML operations

Page 3: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-3 Copyright © 2005, Oracle. All rights reserved.

Parallel Query

The various query types that can be parallelized are:

• Access methods:– Table scans, fast full index scans– Partitioned index range scans– Various SQL operations:

Sorts, aggregations, and set operations

• Join methods:– Nested loop, sort merge– Hash, star transformation, partitionwise join

Page 4: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-4 Copyright © 2005, Oracle. All rights reserved.

Parallel Partitioned Table Scan

Scan by ROWID for partitioned tables.

SELECT /*+ PARALLEL(SALES,9)*/ * FROM SALES;

SALESPQ1

PQ2

PQ3

PQ4 PQ5 PQ6

PQ7

PQ8

PQ9

Page 5: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-5 Copyright © 2005, Oracle. All rights reserved.

Parallel Partitioned Index Scan

Scans can be performed by partition for partitioned indexes and tables. The hint must contain the table name, index name, and degree of parallelism.

SELECT /*+ PARALLEL_INDEX(c,ic,3)*/ *FROM customers c WHERE cust_city = 'MARSEILLE';

Nonprefixed index IC

Indexed column cust_city

PQ1

PQ2

PQ3

Page 6: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-6 Copyright © 2005, Oracle. All rights reserved.

Partitionwise Joins

Query slave Partition Partitioned table

Partial partitionwise join

QS QS

QS QS

Full partitionwise join

QS QS

Page 7: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-7 Copyright © 2005, Oracle. All rights reserved.

Parallel DDL

• The parallel DDL statements for nonpartitioned tables and indexes are:– CREATE INDEX– CREATE TABLE ... AS SELECT– ALTER INDEX ... REBUILD

• The parallel DDL statements for partitioned tables and indexes are:– CREATE INDEX– CREATE TABLE ... AS SELECT– ALTER TABLE ... MOVE PARTITION– ALTER TABLE ... SPLIT PARTITION– ALTER TABLE ... COALESCE PARTITION– ALTER INDEX ... REBUILD PARTITION– ALTER INDEX ... SPLIT PARTITION

Page 8: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-8 Copyright © 2005, Oracle. All rights reserved.

Creating Indexes in Parallel

Object

Parallel executionserver

Nonpartitioned index

Index piece

Data

Page 9: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-9 Copyright © 2005, Oracle. All rights reserved.

Creating Indexes in Parallel

Global partitioned index

Object

Parallel executionserver

Index piece

Data

Page 10: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-10 Copyright © 2005, Oracle. All rights reserved.

Creating Indexes in Parallel

Local partitioned index

Object

Parallel executionserver

Index piece

Data

Page 11: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-11 Copyright © 2005, Oracle. All rights reserved.

Parallel DDL: Example

DDL statements are parallelized by specifying a PARALLEL clause:

CREATE BITMAP INDEX fk_sales_prod ON sales(prod_id)PARALLEL 16 LOCAL NOLOGGING;

Page 12: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-12 Copyright © 2005, Oracle. All rights reserved.

Parallel DML: Overview

• Complement parallel query architecture by providing parallelization for:– INSERT– UPDATE– DELETE– MERGE

• Useful when changing big tables

Page 13: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-13 Copyright © 2005, Oracle. All rights reserved.

Performance Benefits of Parallel DML

Can dramatically speed up DML transactions that can be parallelized

Serial update:

Parallel update:

UPDATE sales

SET amount_sold=amount_sold*6.55957;

alter session enable parallel DML;

UPDATE /*+PARALLEL(sales,12)*/ sales

SET amount_sold=amount_sold*6.55957;

Page 14: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-14 Copyright © 2005, Oracle. All rights reserved.

Enabling Parallel DML

• You must enable PDML.

• The ALTER SESSION statement enables parallel DML mode:

• Parallel queries are still parallelized, even if parallel DML is disabled.

• The default mode of a session is DISABLE PARALLEL DML.

ALTER SESSIONDISABLE

PARALLEL DMLENABLE

ALTER SESSION PARALLEL DMLFORCEPARALLEL n

Page 15: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-15 Copyright © 2005, Oracle. All rights reserved.

Parallel DML: Example

MERGE /*+ PARALLEL(c,3) PARALLEL(d,3) */ INTO customers c USING diff_customers d ON (d.cust_id = c.cust_id)WHEN MATCHED THENUPDATE SET c.cust_last_name = d.cust_last_name, c.cust_city = d.cust_cityWHEN NOT MATCHED THENINSERT (c.cust_id,c.cust_last_name) VALUES (d.cust_id,d.cust_last_name);

Page 16: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-16 Copyright © 2005, Oracle. All rights reserved.

When to Use Parallel DML

Scenarios where parallel DML is used include:

• Refreshing large tables in a data warehouse

• Creating intermediate summary tables

• Using scoring tables

• Updating historical tables

• Running batch jobs

Page 17: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-18 Copyright © 2005, Oracle. All rights reserved.

Restrictions on Parallel DML

• After a PDML statement modifies an object, it is no longer possible to query or modify this object in the same transaction (ORA-12838).

• Limited integrity constraint support is provided.

• Clustered tables are not supported.

• PDML is not allowed:– On tables with enabled triggers– On remote objects– When the operation is part of a distributed

transaction

Page 18: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-19 Copyright © 2005, Oracle. All rights reserved.

Tuning Parameters for Parallel Execution

• The initial computed values of parallel execution parameters should be acceptable in most cases.

• They are based on the values of CPU_COUNT and PARALLEL_THREADS_PER_CPU at database startup.

• Oracle Corporation recommends that you use the default settings.

• Manual tuning of parallel execution is more complex than using default settings.– Manual parallel execution tuning

requires more attentive administration than automated tuning.

– Manual tuning is prone to user-load and system resource miscalculations.

Page 19: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-20 Copyright © 2005, Oracle. All rights reserved.

Using Default Parameter Settings

Increasing 4K to 8K improves parallel performance if SGA is large enough

2 KB (port specific)PARALLEL_EXECUTION_ MESSAGE_SIZE

Maximizes the number of processes used by parallel execution

CPU_COUNT x PARALLEL_THREADS_PER_CPU x (1; 2 if PGA_AGGREGATE_TARGET > 0) x 5

PARALLEL_MAX_SERVERS

Throttles DOP requests to prevent system overload

TRUEPARALLEL_ADAPTIVE_

MULTI_USER

CommentsDefaultsParameter

Page 20: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-21 Copyright © 2005, Oracle. All rights reserved.

Balancing the Workload

• To optimize performance, all parallel execution servers should have equal workloads.

• For parallelization by block range or parallel execution servers, the workload is dynamically divided among the parallel execution servers.

• By choosing an appropriate DOP, you can:– Minimize workload skew – Optimize performance

Page 21: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-23 Copyright © 2005, Oracle. All rights reserved.

Adaptive Multiuser and DOP

• The adaptive multiuser feature adjusts the DOP on the basis of user load.

• PARALLEL_ADAPTIVE_MULTI_USER set to:– TRUE improves performance in a multiuser

environment (default)– FALSE is used for batch processing

• PARALLEL_AUTOMATIC_TUNING has been deprecated in Oracle Database 10g.– Kept for backward compatibility only

Page 22: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-24 Copyright © 2005, Oracle. All rights reserved.

Resource Manager and the DOP

Resource plan: NIGHT_PLAN

Resourceconsumer group

OLTP

DSS

Allocation method parameters

CPU = 25% Max Degree of parallelism = 2

CPU = 75% Max Degree of parallelism = 20

Page 23: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-26 Copyright © 2005, Oracle. All rights reserved.

Are There Execution Problems?

• Use V$PQ_TQSTAT to find out whether there is data distribution skew or bad object statistics:– Contains traffic statistics between slaves at table

queue level– Valid only when queried from the parallel session

• Check I/O and CPU bound at the operating system level and decide on the parallelism.

• Check for contention.

Page 24: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-27 Copyright © 2005, Oracle. All rights reserved.

Data Distribution and V$PQ_TQSTAT

SELECT /*+PARALLEL*/ cust_city, sum(amount_sold)FROM sales s, customers cWHERE s.cust_id=c.cust_idGROUP BY cust_city;

...PX SEND QC (RANDOM) :TQ10002 P->S QC (RAND) HASH GROUP BY PCWP PX RECEIVE PCWP PX SEND HASH :TQ10001 P->P HASH HASH GROUP BY PCWP HASH JOIN PCWP PX RECEIVE PCWP PX SEND BROADCAST :TQ10000 P->P BROADCAST PX BLOCK ITERATOR PCWC TABLE ACCESS FULL CUSTOMERS PCWP PX BLOCK ITERATOR PCWC TABLE ACCESS FULL SALES PCWP

Page 25: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-28 Copyright © 2005, Oracle. All rights reserved.

Data Distribution and V$PQ_TQSTAT

DFO_NUMBER TQ_ID SERVER_TYP PROCESS NUM_ROWS---------- ----- ---------- ---------- --------- 1 0 Consumer P002 55500 1 0 Consumer P003 55500 1 0 Producer P000 55310 1 0 Producer P001 55690 1 1 Consumer P000 613 1 1 Consumer P001 589 1 1 Producer P002 602 1 1 Producer P003 600 1 2 Consumer QC 608 1 2 Consumer P001 309 1 2 Producer P002 299

Page 26: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-29 Copyright © 2005, Oracle. All rights reserved.

Using Other Dynamic Performance Views

• General information:– V$FILESTAT– V$SESSTAT, V$SYSSTAT

• Information about parallel execution:– V$PX_SESSION– V$PX_PROCESS– V$PX_PROCESS_SYSSTAT– V$PX_SESSTAT– V$PQ_SESSTAT– V$PX_BUFFER_ADVICE

• TIMED_STATISTICS should be set to TRUE.

Page 27: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-31 Copyright © 2005, Oracle. All rights reserved.

Using V$PX_SESSION

QCSID SID Group Set Degree ReqDegree----- --- ----- --- ------ ---------- 9 9 9 7 1 1 2 2 9 21 1 1 2 2 9 18 1 2 2 2 9 20 1 2 2 2

SELECT qcsid, sid, server_group "Group", server_set "Set", degree "Degree", req_degree "ReqDegree"FROM V$PX_SESSION ORDER BY 1,3,4;

Page 28: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-32 Copyright © 2005, Oracle. All rights reserved.

Using V$PX_SESSTAT

QCSID SID Group Set StatName VALUE----- --- ----- --- -------------- ----- 9 9 physical reads 3863 9 7 1 1 physical reads 2 9 21 1 1 physical reads 2 9 18 1 2 physical reads 2 9 20 1 2 physical reads 2

SELECT qcsid, sid, server_group "Group", server_set "Set", name "StatName", VALUEFROM V$PX_SESSTAT A, V$STATNAME BWHERE A.statistic# = B.statistic# AND name = 'physical reads' AND value > 0ORDER BY 1,3,4;

Page 29: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-33 Copyright © 2005, Oracle. All rights reserved.

Using V$PX_PROCESS

SERV STATUS PID SPID SID SERIAL---- --------- ------ --------- ------ ------P002 IN USE 16 16955 21 7729P003 IN USE 17 16957 20 2921P004 AVAILABLE 18 16959P005 AVAILABLE 19 16962P000 IN USE 12 6999 18 4720P001 IN USE 13 7004 7 234

SELECT *FROM V$PX_PROCESS;

Page 30: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-34 Copyright © 2005, Oracle. All rights reserved.

Using V$SYSSTAT

SELECT name, value FROM V$SYSSTATWHERE UPPER(name) LIKE '%PARALLEL OPERATIONS%'OR UPPER(name) LIKE '%PARALLELIZED%'OR UPPER(name) LIKE '%PX%';

Page 31: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-35 Copyright © 2005, Oracle. All rights reserved.

Using V$SYSSTAT

NAME VALUE------------------------------------------- -----queries parallelized 347DML statements parallelized 0DDL statements parallelized 0DFO trees parallelized 463Parallel operations not downgraded 28Parallel operations downgraded to serial 31Parallel operations downgraded 75 to 99 pct 252Parallel operations downgraded 50 to 75 pct 128Parallel operations downgraded 25 to 50 pct 43Parallel operations downgraded 1 to 25 pct 12PX local messages sent 74548PX local messages recv'd 74128PX remote messages sent 0PX remote messages recv'd 0

Page 32: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-36 Copyright © 2005, Oracle. All rights reserved.

Tuning PDML

• Using local striping for local indexes

• Using global striping for global indexes

• Increasing INITRANS for global indexes

• Using NOLOGGING• Using multiple archivers

• Using multiple DBWRs or I/O slaves

Page 33: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-37 Copyright © 2005, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:

• Determine when partitionwise joins are used

• Use the ALTER SESSION command to force parallel operations

• Create indexes in parallel

• Set initialization parameters relating to parallel operations tuning

• Query dynamic performance views related to parallel operations tuning

• Tune PDML operations

Page 34: 8 Copyright © 2005, Oracle. All rights reserved. Parallel Operations in Data Warehouses.

8-38 Copyright © 2005, Oracle. All rights reserved.

Practice 8: Overview

This practice covers the following topics:

• Forcing parallelization of queries

• Interpreting a partial parallel partitionwise join execution plan

• Forcing parallelization of DMLs

• Verifying the requested DOP for a parallel DDL operation