Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 13 ■ PARTITIONING 603 5 select 'p3' pname, empno, job, loc from emp partition(p3) 6 union all 7 select 'p4' pname, empno, job, loc from emp partition(p4) 8 / PN EMPNO JOB LOC -- ---------- --------- ------------- p2 7499 SALESMAN CHICAGO 7698 MANAGER CHICAGO 7654 SALESMAN CHICAGO 7900 CLERK CHICAGO 7844 SALESMAN CHICAGO 7521 SALESMAN CHICAGO p3 7369 CLERK DALLAS 7876 CLERK DALLAS 7902 ANALYST DALLAS 7788 ANALYST DALLAS 7566 MANAGER DALLAS p4 7782 MANAGER NEW YORK 7839 PRESIDENT NEW YORK 7934 CLERK NEW YORK 14 rows selected. This shows the distribution of data, by location, into the individual partitions. We can now review some query plans to see what we could expect performance-wise: ops$tkyte@ORA10G> variable x varchar2(30); ops$tkyte@ORA10G> begin 2 dbms_stats.set_table_stats 3 ( user, 'EMP', numrows=>100000, numblks => 10000 ); 4 end; 5 / PL/SQL procedure successfully completed. ops$tkyte@ORA10G> delete from plan_table; 3 rows deleted. ops$tkyte@ORA10G> explain plan for 2 select empno, job, loc from emp where empno = :x; Explained. ops$tkyte@ORA10G> select * from table(dbms_xplan.display);
604 CHAPTER 13 ■ PARTITIONING PLAN_TABLE_OUTPUT ------------------------------------------------------------------------ | Operation | Name |Rows |Bytes|Pstart|Pstop| ------------------------------------------------------------------------ | SELECT STATEMENT | | 1| 27| | | | TABLE ACCESS BY GLOBAL INDEX ROWID| EMP | 1| 27|ROWID |ROWID| | INDEX UNIQUE SCAN | EMP_PK | 1| | | | ------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("EMPNO"=TO_NUMBER(:X)) ■Note The explain plan format has been edited to fit on the page. Columns in the report not relevant to the discussion have been omitted. The plan here shows an INDEX UNIQUE SCAN of the nonpartitioned index EMP_PK that was created in support of our primary key. Then there is a TABLE ACCESS BY GLOBAL INDEX ROWID, with a PSTART and PSTOP of ROWID/ROWID, meaning that when we get the ROWID from the index, it will tell us precisely which index partition to read to get this row. This index access will be as effective as on a nonpartitioned table and perform the same amount of I/O to do so. It is just a simple, single index unique scan followed by a “get this row by ROWID.” Now, let’s look at one of the other global indexes, the one on JOB: ops$tkyte@ORA10G> delete from plan_table; 3 rows deleted. ops$tkyte@ORA10G> explain plan for 2 select empno, job, loc from emp where job = :x; Explained. ops$tkyte@ORA10G> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT --------------------------------------------------------------------------- | Operation |Name |Rows |Bytes|Pstart|Pstop| --------------------------------------------------------------------------- | SELECT STATEMENT | | 1000|27000| | | | TABLE ACCESS BY GLOBAL INDEX ROWID|EMP | 1000|27000|ROWID |ROWID| | INDEX RANGE SCAN |EMP_JOB_IDX| 400| | | | --------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("JOB"=:X)
- Page 598 and 599: CHAPTER 12 ■ DATATYPES 553 equall
- Page 600 and 601: CHAPTER 12 ■ DATATYPES 555 ROWID/
- Page 602 and 603: CHAPTER 13 ■ ■ ■ Partitioning
- Page 604 and 605: CHAPTER 13 ■ PARTITIONING 559 6 (
- Page 606 and 607: CHAPTER 13 ■ PARTITIONING 561 els
- Page 608 and 609: CHAPTER 13 ■ PARTITIONING 563 BIG
- Page 610 and 611: CHAPTER 13 ■ PARTITIONING 565 Enh
- Page 612 and 613: CHAPTER 13 ■ PARTITIONING 567 Tab
- Page 614 and 615: CHAPTER 13 ■ PARTITIONING 569 tha
- Page 616 and 617: CHAPTER 13 ■ PARTITIONING 571 PAR
- Page 618 and 619: CHAPTER 13 ■ PARTITIONING 573 35
- Page 620 and 621: CHAPTER 13 ■ PARTITIONING 575 If
- Page 622 and 623: CHAPTER 13 ■ PARTITIONING 577 We
- Page 624 and 625: CHAPTER 13 ■ PARTITIONING 579 14
- Page 626 and 627: CHAPTER 13 ■ PARTITIONING 581 ops
- Page 628 and 629: CHAPTER 13 ■ PARTITIONING 583 In
- Page 630 and 631: CHAPTER 13 ■ PARTITIONING 585 ops
- Page 632 and 633: CHAPTER 13 ■ PARTITIONING 587 | S
- Page 634 and 635: CHAPTER 13 ■ PARTITIONING 589 12
- Page 636 and 637: CHAPTER 13 ■ PARTITIONING 591 ops
- Page 638 and 639: CHAPTER 13 ■ PARTITIONING 593 •
- Page 640 and 641: CHAPTER 13 ■ PARTITIONING 595 Now
- Page 642 and 643: CHAPTER 13 ■ PARTITIONING 597 the
- Page 644 and 645: CHAPTER 13 ■ PARTITIONING 599 imp
- Page 646 and 647: CHAPTER 13 ■ PARTITIONING 601 OLT
- Page 650 and 651: CHAPTER 13 ■ PARTITIONING 605 Sur
- Page 652 and 653: CHAPTER 13 ■ PARTITIONING 607 On
- Page 654 and 655: CHAPTER 13 ■ PARTITIONING 609 Row
- Page 656 and 657: CHAPTER 13 ■ PARTITIONING 611 So,
- Page 658 and 659: CHAPTER 13 ■ PARTITIONING 613 Aud
- Page 660 and 661: CHAPTER 14 ■ ■ ■ Parallel Exe
- Page 662 and 663: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 664 and 665: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 666 and 667: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 668 and 669: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 670 and 671: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 672 and 673: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 674 and 675: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 676 and 677: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 678 and 679: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 680 and 681: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 682 and 683: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 684 and 685: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 686 and 687: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 688 and 689: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 690 and 691: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 692 and 693: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 694 and 695: CHAPTER 15 ■ ■ ■ Data Loading
- Page 696 and 697: CHAPTER 15 ■ DATA LOADING AND UNL
CHAPTER 13 ■ PARTITIONING 603<br />
5 select 'p3' pname, empno, job, loc from emp partition(p3)<br />
6 union all<br />
7 select 'p4' pname, empno, job, loc from emp partition(p4)<br />
8 /<br />
PN EMPNO JOB LOC<br />
-- ---------- --------- -------------<br />
p2 7499 SALESMAN CHICAGO<br />
7698 MANAGER CHICAGO<br />
7654 SALESMAN CHICAGO<br />
7900 CLERK CHICAGO<br />
7844 SALESMAN CHICAGO<br />
7521 SALESMAN CHICAGO<br />
p3 7369 CLERK DALLAS<br />
7876 CLERK DALLAS<br />
7902 ANALYST DALLAS<br />
7788 ANALYST DALLAS<br />
7566 MANAGER DALLAS<br />
p4 7782 MANAGER NEW YORK<br />
7839 PRESIDENT NEW YORK<br />
7934 CLERK NEW YORK<br />
14 rows selected.<br />
This shows the distribution of data, by location, into the individual partitions. We can now<br />
review some query plans to see what we could expect performance-wise:<br />
ops$tkyte@ORA10G> variable x varchar2(30);<br />
ops$tkyte@ORA10G> begin<br />
2 dbms_stats.set_table_stats<br />
3 ( user, 'EMP', numrows=>100000, numblks => 10000 );<br />
4 end;<br />
5 /<br />
PL/SQL procedure successfully completed.<br />
ops$tkyte@ORA10G> delete from plan_table;<br />
3 rows deleted.<br />
ops$tkyte@ORA10G> explain plan for<br />
2 select empno, job, loc from emp where empno = :x;<br />
Explained.<br />
ops$tkyte@ORA10G> select * from table(dbms_xplan.display);