Oracle History #5

1,193 views

Published on

Oracle New Features for Version 8i

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,193
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Oracle History #5

  1. 1. New Features forAdministrators(Oracle8i) April, 2001 CloudBox Jang Kyung Sang
  2. 2. Oracle8i New Features http://www.ggola.com/Oracle8i New Features for AdministratorsCourse 1. Java in the database 2. Optimizer and Query Improvements 3. Summary Management 4. Indexes and Index-Organized Tables 5. Basic Partition 6. Partition Maintenance 7. Composite Partitioning 8. Added New Features for partition 9. Universal Installer Migration and Upgrade 10. Tablespace Management 11. Database Resource Manager 12. Manageability Features 13. Availability and Recoverability 14. Features of Net8 15. SQL*Plus, PL/SQL and National Language Support 16. Database Security 17. Partial addition for Oracle8ijkspark@hanafos.com -2-
  3. 3. Oracle8i New Features http://www.ggola.com/1. Java in the databaseWhat does Oracle8i support for java? . Open, portable, productive, internet computing language Oracle8i enterprise class java server - Java Virtual Machine integrated with Database - use java anywhere PL/SQL used - productive programming tools - industry standard components Oracle8i java application server platform application java solution . Supported three products for building java database application - standards-compliant JDBC drivers to access Oracle from JAVA applications - precompiler(SQLJ) for embedding SQL in java applications - Oracle JDeveloper (JDBC, SQLJ, complete development environment) CF. Oracle8i JVM(Java virtual machine) . EJB(Enterprise java bean) transaction server CORBA clients . Five major components that integrated JVM with Oracle8i - Oracle JVM Javasoft JDK specification Oracle architecture optimizing . - Embedded JDBC Driver JVM server locally SQL and PL/SQL access . - SQL and PL/SQL Inter-Language Method Services mechanism JAVA call . SQL PL/SQL call C language external procedure ‘call out’ standard mechanism . , calling mechanism Oracle8i SQL and PL/SQL Java call .jkspark@hanafos.com -3-
  4. 4. Oracle8i New Features http://www.ggola.com/ - Net8 java program SQL ‘publishes’ SQL Java access . - CORBA IIOP(Internet Inter-ORB Protocol) . RDBMS access second protocol ( Net8( SQL*Net) first protocol ) Oracle8i java CORBA2.0-compliant object request broker embed CORBA RDBMS call in and call out . CF. java stored program ORB ‘published’ clients RDBMS java program access alternate mechanism . Major components of JVM - SQLJ Translator : JAVA and SQL program . - Object Memory Management : allocate and free memory in standard chunks called object memories. - Memory manager/Garbage collector : Oracle database environment manager JVM memory heaps, allocating and collecting object memories manage . - Java class loader : Standard “.class” format and in a compressed form Oracle VM other systems java binaries interchange . (both export and import) - Bytecode compiler : “.class” java binary standard java program translate . - Interpretation/run-time : execute standard java binaries. - Native compilation : C language java program execution performance . - Library manager : java program manage . - Standard library : java API specification(java.lang, java.io, java.math, and java.util) standard libraries Oracle Java VM support . CF. The java interpreters and compilers are based on the JDK 1.1.6 standardsjkspark@hanafos.com -4-
  5. 5. Oracle8i New Features http://www.ggola.com/Using JAVA Integrated Java, SQL, and PL/SQL - Integration : Java SQL and PL/SQL call ? SQL and PL/SQL Java call ? Java call SQL and PL/SQL - Java standard JDBC interface database SQL and PL/SQL CALL . - Java VM OCI thin JDBC drivers interface standard JDBC driver embed . - , outside database JDBC java application code Oracle Java VM . - architecture outside or within RDBMS java and SQL same interface application partitioning flexibility and efficiency . SQL and PL/SQL call java - SQL and PL/SQL java call SQL PL/SQL call mechanism . - Oracle8i java stored procedure PL/SQL automatic dependency-checking mechanisms java call . - Oracle8i new DDL extensions “create procedure as java” java stored procedure, function, and triggers . - Oracle8i PL/SQL namespace java stored procedure any PL/SQL .jkspark@hanafos.com -5-
  6. 6. Oracle8i New Features http://www.ggola.com/What is JDBC? JDBC(Java Database Connectivity) - JDBC java RDB access standard set of java classes . - JDBC javasoft SQL92 syntax and types . mechanisms java client database automatic data streaming . - JDBC Oracle performance improvement array interface vendor-specific extensions . JDBC drivers - JDBC Thin driver : web browser applets . (means thin client) driver RDBMS directly communicating java sockets client installation . - JDBC OCI : driver Oracle Call Interface Net8 RDBMS engine communicating client OCI library . - JDBC KPRB : driver java stored procedure server side OCI Oracle KPRB library . - drivers the same syntax and APIs and oracle extensions java application very portable . , connect string minor modification application 3 . Features in JDBC Drivers - 3 JDBC drivers Javasoft JDBC 1.22 specification JDBC 2.0 specification . , JDBC 2.0 specification client side XA support . CF. server side driver XA specification JDBC 2.0 specification . - Oracle JDBC drivers standard JDBC driver Oracle specification extensions important features . 1. access to Oracle7 types (like ROWIDs and REFCURSORs) 2. access to Oracle8i object-relational extensions, REFs, Lobs, and BFILEsjkspark@hanafos.com -6-
  7. 7. Oracle8i New Features http://www.ggola.com/ 3. performance enhancement with operation to prefetch rows and the array interface 4. access to PL/SQL stored procedures with Oracle7 and 8 5. access to java stored procedures with Oracle8i 6. access across all Net8 certified firewallsSQLJ SQLJ Oracle Pro*C precompilers Java application embedded SQL . Preprocessor embedded SQL statements SQLJ Java code(with JDBC call) translate . SQLJ generated code 100% compliant with Javasoft JDBC specification . Improve developer productivity - smaller, cleaner, simpler code than JDBC - SQL syntax errors and identification of SQL/Java type mismatches detection code quality improvement - JDeveloper Java tool integration - Standard language specification, compatible translators - Oracle Translator standard compliant - SQLJ applications binary portability (property) platforms different vendor’s database portable . SQLJ supports - SQLJ JDBC application programs . (concise more than JDBC. easier to write or maintain) - 3 SQLJ . 1. JDBC (character string, prepare and execute statements, and bind and define variables) directly embed SQL statements . 2. SQL statements Java bind variables and expressions .jkspark@hanafos.com -7-
  8. 8. Oracle8i New Features http://www.ggola.com/ 3. application simple default connection and other syntactic elements features . - During the translation phase, SQLJ detects SQL semantic errors and Java and SQL type mismatches. - SQLJ provides strong typed queries through the use of SQLJ Iterators.(first-class java types for cursors) - SQLJ SQL precompilation techniques run- time execution more efficient . precompiling Oracle SQLJ executions . Code example JDBC VS SQLJ - JDBC Java.sql.CallableStatement stmt; Connection conn; ResultSet results; Conn = DriverManager.getConnection 9”jdbc:default”); stmt = conn.prepareStatement (“select ename from emp where sal > ? and deptno = ?”); stmt.setInteger(1, salparm); stmt.setInteger(2, deptnoparm); results = stmt.executeQuery(); - SQLJ ResultSet results ; #sql results = { select ename from emp where sal > :salparm and deptno = :deptnopark} ; Using SQLJ with Oracle - SQLJ JDBC run-time environment deployed configuration deployed . CF. SQLJ run-time : Java + JDBC driver - SQLJ applications deploy JDBC driver . Oracle or users JDBC/OCI/thin JDBC driver . - Oracle8i Java VM embedded SQLJ translator Oracle SQLJ java stored procedures and triggers . - Write program in SQLJ --> SQLJ translator : converts to java + JDBC --> run the programjkspark@hanafos.com -8-
  9. 9. Oracle8i New Features http://www.ggola.com/Java program Java stored programs - open alternative complementing PL/SQL - java is fully functional. PL/SQL Java . - PL/SQL SQL-intensive SQLJ java stored procedure . - Java stored procedures 3 run-time contexts . 1. stored functions and procedures (java program SQL ) 2. all triggers java . 3. java object-relational methods . Developing 1. write java stored programs 2. Java VM load java code. Java classes load . - SQL*Plus “create java ddl”command - standard Oracle utility “LOADJAVA” 3. publish the java procedure to SQL. - expose the top-level java entrypoint - map parameters and SQL and PL/SQL datatypes - set up appropriate user privileges 4. SQL or PL/SQL call java program CF. Oracle PL/SQL call SQL or PL/SQL java program call syntax . Example (java installation . Refer to page 11) create or replace java source named "NewJava" as public class JavaMaster { static public String Msg(String guys) { return "Good morning " + guys ; } } / create or replace function JavaFunc (str varchar2) return varchar2 as language java name JavaMaster.Msg (java.lang.String) return java.lang.String ; / SQL> select JavaFunc(girls) from dual ; JAVAFUNC(GIRLS) -------------------------------------------------------------------------------- Good morning girlsjkspark@hanafos.com -9-
  10. 10. Oracle8i New Features http://www.ggola.com/Components Develop server-side business logic as distributed components - components improve developer productivity in following ways. 1. reuse server-side business logic 2. improve application design as reusable modules 3. simplify deployment in a multitier environment Support java component programming models - Oracle8i traditional CORBA servers Java implemented . , ORB Java VM java applications . - EJB(the industry standard enterprise javabeans) component model database java . Simple declarative transaction commit or rollback transaction operations . CF. Java or EJBs implemented CORBA servers Oracle8i MTS . Server-side ORB (on MTS) - IIOP listener : Oracle8i standard CORBA/IIOP binding protocol extended .(Net8) - IIOP dispatcher : Oracle8i IIOP-based method invocations extened . - Oracle8i integrates a CORBA 2.0 ORB. - MTS platforms : Java VM MTS . MTS . Enterprise JavaBeans (EJBs) - EJBs is a server-oriented component model for Java. Oracle8i EJBs transaction server platforms EJB 1.0 specification . - Significant advantages using EJBs 1. developers advanced system programming skills . 2. Pure Java definition D/COM, CORBAjkspark@hanafos.com - 10 -
  11. 11. Oracle8i New Features http://www.ggola.com/ dependency . 3. platform vendors EJB .Java Configuration Java VM classes installation - Java VM manually initialize script . - $ORACLE_HOME/javavm/install/initjvm.sql (user by “SYS”) CF. test 1 . - script 4000 java classes initial package . - DBMS_JAVA package only used internally by Oracle . - Needed initial parameter values for executing initjvm.sql : shared_pool_size 50M java_pool_size 50M rollback segment 100M Java-related initial parameter - shared_pool_size : static java variables UGA space - java_pool_size : shared java objects space java class loading . large java application system 50M java stored procedure 20M . - java_soft_sessionspace_limit : size user’s session java memory usage RDBMS trace file . default 1M. - java_max_sessionspace_size : size out-of- memory failure session kill . Default 4G invisible java programs memory usage . CF. java-related memory application system java setting .jkspark@hanafos.com - 11 -
  12. 12. Oracle8i New Features http://www.ggola.com/Internet File System iFS Windows OS directories database access . Oracle8i Oracle8i Java VM Java application . Oracle iFS several different protocols access . - SMB : MS windows95, 98, NT protocol - HTTP : Web browser and network computer - FTP : FTP clients command line - SMTP, IMAP4, POP3 : e-mail protocol Data integration - iFS application developers 3 APIs , Java, CORBA, and PL/SQL . - iFS document system document automatically decompose(parse) document recompose(render) . - XML(Extended markup language) . CF. iFS application .jkspark@hanafos.com - 12 -
  13. 13. Oracle8i New Features http://www.ggola.com/2. Optimizer and Query ImprovementsStored Outline Optimizer plan stability - Optimizer feature Oracle8i well-tuned applications SQL hints (good access path) SQL . - Plan Equivalence : plan 1. SQL Statement text must match 2. Plans are maintained through : - new oracle versions - new statistics on objects - init.ora parameter changes - database reorganization - schema changes CF. table index stored outline index . Creating stored outlines - Outline oracle automatic or SQL creation rule-based or cost-based optimizers . oracle outline cost-based optimize . - Session init.ora parameter create_stored_outlines parameter true default category category name category stored outlines . - Test initial parameter database restart error parameter create_stored_outlines SVRMGRL> show parameter SQL> select name from v$parameter . Oracle8.1.5 Reference parameter session level test . CF. system user “create any outline” privilege outline user grant .jkspark@hanafos.com - 13 -
  14. 14. Oracle8i New Features http://www.ggola.com/ - Session category name default category name . SQL> alter session set create_stored_outlines = true ; Session altered. SQL> select d.dname, e.ename from emp e, dept d 2 where e.deptno = d.deptno ; DNAME ENAME -------------- ---------- RESEARCH12 SMITH SALES12 ALLEN .............. ACCOUNTING12 MILLER 14 rows selected.……….. SQL> alter session set create_stored_outlines = false ; SQL> select * from user_outlines ; NAME CATEGORY USED TIMESTA VERSION SQL_TEXT ---------------------------------------------------------------------------------------------------------------- SYS_OUTLINE_0107311031050000 DEFAULT UNUSED 31Jul01 8.1.6.2.0 select d.dname, e.ename from emp e, dept d where e.deptno = d.deptno SQL> alter session set create_stored_outlines = cat_emp ; Session altered. SQL> select e.ename, d.loc from emp e, dept d where e.deptno = d.deptno ; ENAME LOC -------------- ---------- SMITH DALLAS189 ALLEN CHICAGO189 .............. MILLER NEW YORK189 14 rows selected.……….. SQL> select * from user_outlines ; NAME CATEGORY USED TIMESTA VERSION SQL_TEXT -------------------------------------------------------------------------------- ------------------------------- SYS_OUTLINE_0107311031050000 DEFAULT UNUSED 31Jul01 8.1.6.2.0 select d.dname, e.ename from emp e, dept d where e.deptno = d.deptno SYS_OUTLINE_0107311026420001 CAT_EMP UNUSED 31Jul01 8.1.6.2.0 select e.ename, d.loc from emp e, dept d where e.deptno = d.deptno SYS_OUTLINE_0107311024590000 CAT_EMP UNUSED 31Jul01 8.1.6.2.0 select * from user_outlines SQL> alter session set create_stored_outlines = false ; - category DEFAULT category . outline name system default . - Outline parameter false select * from outlines stored outline . - outline category shared_pool pinning execution plan .jkspark@hanafos.com - 14 -
  15. 15. Oracle8i New Features http://www.ggola.com/ - stored outline . SQL> create or replace outline emp_join for category cat_emp on select /*+ FULL(DEPT) */ d.dname, e.ename from emp e, dept d where e.deptno = d.deptno order by 1, 2 ; Outline created. SQL> select * from user_outlines ; NAME CATEGORY USED TIMESTA VERSION SQL_TEXT ---------------------------------------------------------------------------------------------------------------- SYS_OUTLINE_0107311031050000 DEFAULT UNUSED 31Jul01 8.1.6.2.0 select d.dname, e.ename from emp e, dept d where e.deptno = d.deptno SYS_OUTLINE_0107311026420001 CAT_EMP UNUSED 31Jul01 8.1.6.2.0 select e.ename, d.loc from emp e, dept d where e.deptno = d.deptno SYS_OUTLINE_0107311024590000 CAT_EMP UNUSED 31Jul01 8.1.6.2.0 select * from user_outlines EMP_JOIN CAT_EMP UNUSED 31Jul01 8.1.6.2.0 select /*+ FULL(DEPT) */ d.dname, e.ename from emp e, dept d where e.deptno = d.deptno order by 1, 2 - outline name outline sys name . category . category . Using stored outlines - outline command . SQL> alter session set use_stored_outlines = true or category_name ; - create category name true outline . - Category category default category text match . , category match outline default category outline outline . - To determine a SQL statement’s execution plan 1. shared pool matching text and outline category 2. 1 data dictionary outline query 3. 2 SQL outline execution plan . 4. 2 normal methods(non-outline) . - , outline hints outline user_outlines user_outline_hints view .jkspark@hanafos.com - 15 -
  16. 16. Oracle8i New Features http://www.ggola.com/ Maintaining stored outlines - Package ‘OUTLN_PKG’ 1. drop_unused : drop unused outline 2. drop_by_cat : drops categories of outlines 3. update_by_cat : rename categories - ALTER OUTLINE outline_name command 1. rename to new_outline_name ; (outline name ) 2. rebuild ; (outline execution path ) 3. change category to new_category_name ; (category )Database creation automatically - Stored outlines in tables in schema OUTLN schema OUTLN 1. OL$ : outline name, category, timestamp, statement texttables outlines . 2. OL$HINTS : hints for the outlines in OL$(system tablespace ) - Data dictionary view 1. DBA/ALL/USER_OUTLINES 2. DBA/ALL/USER_OUTLINE_HINTS DBMS_STATS This package enables you to generate and manage statistics for cost-based optimization. The statistics can reside in the data dictionary or in a table created in the user’s schema. Only statistics stored in the dictionary itself will have an impact on the cost-based optimizer. (but cannot gather cluster statistics) Generating statistics - Gathering sub-procedure 1. gather_index_stats : index 2. gather_table_stats : table, column and index 3. gather_schema_stats : all objects in a schema 4. gather_database_stats : all objects in a database - usage for table statistic DBMS_STATS.GATHER_TABLE_STATS ( schema, table, partition, sample size(%), block sample?(or row), columns, parallelism degree, table and all partitions, cascade to indexes) ; - How can you gather the statistics ? 1. statistics serially or in parallel index statistics only serially 2. random sampling or computed 3. block sampling faster than row sampling 4. column lists 5. table index statistics 6. statistics tables can hold statistics to enable you to experiment with different sets of statistics. jkspark@hanafos.com - 16 -
  17. 17. Oracle8i New Features http://www.ggola.com/ Moving statistics scott emp table export file dump database import statistic import source database target database . 1. table statistics . usage : dbms_stats. gather_table_stats(schema, table, partition, sample size(%), block sample?(or row), columns, parallelism degree, table and all partitions, cascade to indexes) meaning : table statistic . (index statistics cascade to indexes TRUE ) example : SQL> exec dbms_stats.gather_table_stats( SCOTT, EMP, NULL, 20, FALSE, FOR ALL COLUMNS, 4, DEFAULT, TRUE) ; 2. Statistics table schema . usage : dbms_stats. create_stat_table(‘SCOTT’, ’stat_tab_name’, ’tablespace_name’) meaning : data dictionary statistics export table . example : SQL> exec dbms_stats.create_stat_table(SCOTT, STAT_SCOTT, USERS) ; 3. Statistics data table copy . usage : dbms_stats. export_table_stats(‘SCOTT’, ‘EMP’, NULL(partition ), ‘stat_tab_name’, ‘stat_id’(ID ), TRUE(index stat) ) ; Source Database meaning : statistics user’s table export . table export backup or copy . example : SQL> exec dbms_stats.export_table_stats(SCOTT, EMP, NULL, STAT_SCOTT, Stat 20010731, TRUE) ; File dump exp/imp 4. database table file dump OR export table import database Database link copy link copy table , stat_scott table database data data dictionary . usage : dbms_stat. Target Database import_table_stat (export_table_stas argument) meaning : schema table data dictionary . example : SQL> exec dbms_stats.import_table_stats(SCOTT, EMP, NULL, STAT_SCOTT, STAT 20010731, TRUE) ;jkspark@hanafos.com - 17 -
  18. 18. Oracle8i New Features http://www.ggola.com/ 5. user schema table drop . usage : dbms_stats. drop_stat_table(‘SCOTT’, ‘stat_tab_name’) meaning : table drop . example : SQL> exec dbms_stats.drop_stat_table (SCOTT, STAT_SCOTT) ;Top-N SQL Now Oracle8i supports ordering of views and in-line views. Sorts only the required number of rows - Oracle8i in-line view order by . - Oracle rownum < 3 2 value memory rows 2 value . - Example : order by SQL> select * from (select empno, deptno, hiredate from emp order by hiredate desc) where rownum < 3 ; EMPNO DEPTNO HIREDAT ---------- ---------- ------- 7876 20 12Jan83 7788 20 09Dec82 SQL> select * from (select empno, deptno, hiredate from emp) where rownum < 3 ; EMPNO DEPTNO HIREDAT ---------- ---------- ------- 7369 20 17Dec80 7499 30 20Feb81 - Query (searching for the top few values) run considerably faster in Oracle8i.jkspark@hanafos.com - 18 -
  19. 19. Oracle8i New Features http://www.ggola.com/ROLLUP and CUBE Aggregate operators group by rollup and cube crosstab report . 1 2 3 Total 1 2 3 6 1 2 3 6 Total 2 4 6 12 Rollup operation SQL> select , , sum(year) from emp group by rollup( , ); - group by total grand total . sum(year) 1 1 2 2 3 3 6 1 1 ……………….. ……………….. 6 ……………….. 12 - function data result rows n types( ) m status( ) ROLLUP group by (n X (m+1)) + 1 = ? rows . - (2 X (3+1)) + 1 = 9 rows .jkspark@hanafos.com - 19 -
  20. 20. Oracle8i New Features http://www.ggola.com/ Cube operation SQL> select , , sum(year) from emp group by cube( , ) order by , ; sum(year) 1 1 2 2 ROLLUP 3 3 6 1 1 2 2 + 3 3 6 CUBE 1 2 2 4 3 6 GRAND 12 - function data result rows n types( ) m status( ) CUBE group by ((n+1) X (m+1)) + 1 = ? rows . - . , (type + 1) X (status + 1) . (2 + 1) X (3 + 1) = 12 . Grouping function Rollup and cube total value null . data value null null . new function grouping . - grouping(column_name) decode 0 value null 1 rollup or cube null . - , . decode(grouping(column),1,’null of total’,’value’)jkspark@hanafos.com - 20 -
  21. 21. Oracle8i New Features http://www.ggola.com/TRIM New function trim ltrim rtrim . ANSI . Using function SQL> select last_name, trim(leading ‘X’ from last_name) as trimmed from emp where last_name like ‘X%’ ; - TRIM(leading ‘X’ from column) : LTRIM - TRIM(trailing ‘X’ from column) : RTRIM - TRIM(both ‘X’ from column) : L + R (default) - TRIM( ‘X’ from column) : both . - TRIM(last_name) : character space trim characters . CF. trim character . trim character only one character .New and Obsolete Obsolete parameter : sort_direct_writes, sort_write_buffers, sort_write_buffer_size, sort_read_fac New parameter : sort_multiblock_read_count this parameter define the number of blocks read from temporary segments during sorts. (db_multiblock_read_count )jkspark@hanafos.com - 21 -
  22. 22. Oracle8i New Features http://www.ggola.com/3. Summary ManagementMaterialized Views In general, this will be used for Data Warehouse, Distributed Computing, Mobile Computing Summary and aggregate data - View view base table data view , summary and aggregate data(pre-computed) data segment view . - , expensive and complex joins view . Create materialized view day_of_booking as Select bkg_no, sum(amt) as total_amount From booking Where bkg_dt = sysdate Group by bkg_no ; - M-View SQL base table M-View .( query rewrite ) CF. The process of modifying a query to use the view rather than the base table is called a query rewrite. - Create materialized view is synonym for create snapshot. - M-View SQL> create materialized view view_name build deferred refresh …. as select ….. “build” clause M-View . Build clause “immediate or deferred” option . 1. immediate 2. deferred refresh . CF. build clause default “build immediate” . CF. remote tables . CF. M-View order by clause creation refresh . , order by clause M-View query definition . query performance order by clause column M-View select list column index recommend .jkspark@hanafos.com - 22 -
  23. 23. Oracle8i New Features http://www.ggola.com/ Materialized view refresh option Base table M-View base table sync . ‘Refresh’ . - Complete : Base table M-View M-View query data . - Fast : last refresh 1. M-View log 2.Direct loader log (direct loads new rows rowid M-Views refresh) - Force : . complete fast . (This is default refresh type.) - Never : Refresh . CF. M-View system user user grant ‘create materialized view’ privilege . Refresh mode : Refresh . - ON DEMAND Manually DBMS_MVIEW package procedure . 1 …REFRESH(‘BOOKING’,PARALLELISM => 3); >> specified M-View 2 …REFRESH_DEPENDENT(VN_FAIL_CNT, ‘EMP’) ; >> M-Views on based 1 base tables (number_of_failures out variable ) 3 …REFRESH_ALL_MVIEWES ; >> all M-Views - Automatic Refresh 1. ON COMMIT ( synchronous) : base table commit . 2. START WITH-NEXT(asynchronous) : specified time supported complete mode only. (must initiate job processes) CF. , ON COMMIT M-View join or aggregate views Oracle8.1.5 manual only join view single table aggregate .( Nested M-View join and aggregate view fast on commit )jkspark@hanafos.com - 23 -
  24. 24. Oracle8i New Features http://www.ggola.com/ Materialized view types (UNION set operation ) - joins and aggregates type M-View fast refresh new data direct path method add fast refresh . The where clause can contain inner equi-joins only.(no outer joins) 1. group by column select list . 2. function : sum, count(x), count(*), count(distinct x), avg, variance, stddev, min, max - single table aggregate M-View log fast refresh count sum count count or sum group function count sum . count(*) where clause . 1. function : count, sum, avg, variance, stddev - only joins : fast refresh 1. each detail tables M-View log 2. select list detail table rowid . 3. outer join inner table column unique constraint . CF. M-View log rowid column speed up refresh M-View rowid column index recommend . CF. detail tables rowid tables tables DML fast refresh . Test M-View - Test Oracle8.1.6.2 M-View . Oracle Manual . - , Oracle version Oracle9i fixed Test . - Refresh complete . dbms_mview package refresh M-View . - Refresh fast on commit on demand M-View log Test Query Rewrite Usage .jkspark@hanafos.com - 24 -
  25. 25. Oracle8i New Features http://www.ggola.com/ Example - complete on demand (joins and aggregates) SQL> sho user USER is "SYSTEM" SQL> grant create materialized view to scott ; Grant succeeded. SQL> conn scott/tiger Connected. SQL> set timing on SQL> set serveroutput on SQL> create materialized view mv_emp_sales refresh complete on demand 2 as select e.empno, d.deptno, sum(sal) from emp e, dept d 3 where e.deptno = d.deptno group by e.empno, d.deptno ; Materialized view created. Elapsed: 00:00:46.95 SQL> select * from mv_emp_sales ; EMPNO DEPTNO SUM(SAL) ---------- ---------- ---------- 7369 20 52428800 .................... 9022 95 6553600 21 rows selected.EMPNO SAL update SQL> update emp set sal = 10 where empno = 9022; 256 rows updated. . SQL> commit ; MV creation Commit complete. refresh SQL> select * from mv_emp_sales ; . EMPNO DEPTNO SUM(SAL) ---------- ---------- ---------- 7369 20 52428800 .................... 9022 95 6553600 21 rows selected.Refresh procedure SQL> exec dbms_mview.refresh(MV_EMP_SALES) ; PL/SQL procedure successfully completed. . Elapsed: 00:00:48.04 SQL> select * from mv_emp_sales ; EMPNO DEPTNO SUM(SAL) ---------- ---------- ---------- 7369 20 52428800 .................... 9022 95 655360 21 rows selected. CF. M-View performance M-View partitioning parallel operation . jkspark@hanafos.com - 25 -
  26. 26. Oracle8i New Features http://www.ggola.com/ SQL> update emp set sal = 100 where empno = 9022 ; 256 rows updated. SQL> commit ; Commit complete.refresh_dependent procedure SQL> declare 2 vn_fail_cnt BINARY_INTEGER; 3 begin 4 dbms_mview.refresh_dependent(vn_fail_cnt, EMP); . 5 dbms_output.put_line(vn_fail_cnt); 6 end; 7 / 0 PL/SQL procedure successfully completed. Elapsed: 00:00:47.74 SQL> select * from mv_emp_sales ; EMPNO DEPTNO SUM(SAL) ---------- ---------- ---------- 7369 20 52428800 .................... 9022 95 6553600 21 rows selected. - fast on commit (single table aggregate) SQL> create materialized view log on emp 2 with rowid(empno, ename, job, mgr, hiredate, sal, comm, deptno) 3 including new values ; Materialized view log created. SQL> create materialized view mv_emp_sales refresh fast on commit 2 as select count(*), empno, sum(sal), count(sal) 3 from emp log M- 4 group by empno ; View . base Materialized view created. table SQL> select * from mv_emp_sales ; refresh COUNT(*) EMPNO SUM(SAL) COUNT(SAL) commit refresh ---------- ---------- ---------- ---------- data 256 7369 204800 256 ........................... . 256 9022 25600 256 21 rows selected. SQL> update emp set sal = 10 where empno = 9022 ; 256 rows updated. SQL> commit; Commit complete. SQL> select * from mv_emp_sales ; COUNT(*) EMPNO SUM(SAL) COUNT(SAL) ---------- ---------- ---------- ---------- 256 7369 204800 256 ........................... 256 9022 2560 256 21 rows selected. jkspark@hanafos.com - 26 -
  27. 27. Oracle8i New Features http://www.ggola.com/ - fast on demand (single table aggregate) SQL> drop materialized view log on emp ; Materialized view log dropped. SQL> drop materialized view mv_emp_sales ; Materialized view dropped. SQL> create materialized view log on emp 2 with rowid(empno, ename, job, mgr, hiredate, sal, comm, deptno) 3 including new values ; Materialized view log created. SQL> create materialized view mv_emp_sales refresh fast on demand 2 as select count(*), empno, sum(sal), count(sal) log 3 from emp MV . base table 4 group by empno ; Materialized view created. refresh procedure SQL> select * from mv_emp_sales ; MV COUNT(*) EMPNO SUM(SAL) COUNT(SAL) ---------- ---------- ---------- ---------- data . 256 7369 204800 256 ......................... 256 9022 2560 256 21 rows selected. SQL> update emp set sal = 1000 where empno = 9022 ; 256 rows updated. SQL> commit; Commit complete. SQL> exec dbms_mview.refresh(MV_EMP_SALES) ; PL/SQL procedure successfully completed. SQL> select * from mv_emp_sales ;Test join and COUNT(*) EMPNO SUM(SAL) COUNT(SAL) ---------- ---------- ---------- ----------aggregate M-View 256 7369 204800 256 M-View log .........................error fast refresh 256 9022 256000 256 21 rows selected. refresh data CF. M-View table . prebuilt table M-View . query rewrite . (start with-next refresh M-View query rewrite ) CF. Nested Materialized Views : M-View fact(/detail/base) table M-View user request Nested Materialized View . join only M-View base table single-table aggregate M-View refresh fast on commit join and aggregate M-View performance . , space . jkspark@hanafos.com - 27 -
  28. 28. Oracle8i New Features http://www.ggola.com/Query Rewrite M-View base table performance . Oracle8i M-View statement ‘Query Rewrite’ mechanism M-View query query . Query Rewrite Attributes - M-View index transparent to applications . - Base table privileges M-View M-View enable, disable M-View control . - Initial parameter : QUERY_REWRITE_ENABLED=TRUE ”QUERY REWRITE” privilege M-View enable . DBMS_OLAP package has options to use M-Views CF. Query Rewrite : grant query rewrite to username ; “global query rewrite” for outside schema “explicit select privilege” for M-View using different schema Usage : create materialized view mview_name tablespace ts_name --> skip user default tablespace parallel (degree 4) --> option build immediate/deferred --> skip default immediate refresh complete/fast/force/never --> skip default force on demand/on commit/start with .… next …. enable/disable query rewrite --> query rewrite as select count(*), count(sal), sum(sal) from emp; --> query restriction : join equip only aggregate operator outermost part . (AVG(AVG(x)) ) sequence, user, sys owner objects, subquery order by, remote table, pl/sql function, having, connect by, inline views, nested subquery, sysdate, rownum, bind variable, raw or long raw . case 1) select count(*), count(sal), sum(sal) from emp ; ==> Oracle M-View mview_name execution plan performance . case 2) select /*+ NOREWRITE */ count(),count(sal),sum(sal) from emp ; ==> Case 1 norewrite hint M-View base table execution plan full table scan .jkspark@hanafos.com - 28 -
  29. 29. Oracle8i New Features http://www.ggola.com/ Example - Creation materialized view for query rewrite SQL> create materialized view mv_emp_sales tablespace users 2 parallel(degree 4) build immediatestart and next time 10 3 refresh complete start with sysdate+1/6/24 next sysdate+1/6/24 query 4 enable query rewrite as select e.empno, d.deptno, sum(sal) from emp e, dept drewrite enable 5 where e.deptno = d.deptno group by e.empno, d.deptno ;MV Materialized view created. Elapsed: 00:01:02.80 user_jobslast date, next date 10 SQL> select job, what, last_date, next_date from user_jobs ; JOB WHAT ---- ----------------------------------------------- . 243 dbms_refresh.refresh("SCOTT"."MV_EMP_SALES"); LAST_DATE NEXT_DATE ----------------- ----------------- 20010802 14:35:31 20010802 14:45:31 SQL> select sysdate from dual ; SYSDATE ----------------- 20010802 14:36:41 SQL> select * from mv_emp_sales ; EMPNO DEPTNO SUM(SAL) 14 36 ---------- ---------- ----------empno 9022 sal 10 7369 20 52428800 ................ update . 9022 95 6553600MV query 21 rows selected. SQL> update emp set sal = 10 where empno = 9022 ; . user_jobs 256 rows updated. next date SQL> commit ; . Commit complete. SQL> select * from mv_emp_sales ; EMPNO DEPTNO SUM(SAL) ---------- ---------- ---------- 7369 20 52428800 ................ 9022 95 6553600 38 21 rows selected. refresh SQL> select sysdate from dual ; . 45 SYSDATErefresh ----------------- MV 20010802 14:38:20 ( 1 )46 40 query SQL> select sysdate from dual ; SYSDATE data ----------------- . 20010802 14:46:41 , refresh MV query SQL> select * from mv_emp_sales ;“no rows selected” return EMPNO DEPTNO SUM(SAL) . ---------- ---------- ---------- 7369 20 52428800 ................ 9022 95 655360 21 rows selected. jkspark@hanafos.com - 29 -
  30. 30. Oracle8i New Features http://www.ggola.com/ - Query rewrite SQL> select e.empno, d.deptno, sum(sal) from emp e, dept d 2 where e.deptno = d.deptno group by e.empno, d.deptno ; EMPNO DEPTNO SUM(SAL) ---------- ---------- ----------MV SQL 7369 20 52428800 ................ 9022 95 655360 . , 21 rows selected.query rewrite . Elapsed: 00:00:00.08 hint query rewrite SQL> select /*+ NOREWRITE */ 2 e.empno, d.deptno, sum(sal) from emp e, dept d . 3 where e.deptno = d.deptno group by e.empno, d.deptno ; EMPNO DEPTNO SUM(SAL) ---------- ---------- ---------- 7369 20 52428800 ................ 9022 95 655360 21 rows selected. Elapsed: 00:00:49.50 SQL> explain plan for select e.empno, d.deptno, sum(sal) from emp e, dept d 2 where e.deptno = d.deptno group by e.empno, d.deptno ; Explained. SQL> select substr(lpad( ,2*(level-1))||operation|| ||options 2 || ||object_name,1,79) "Plan View" 3 from plan_table 4 start with id=0 5 connect by prior id = parent_id 6 order by id; Plan View ------------------------------------------------------------------------------- SELECT STATEMENT TABLE ACCESS FULL MV_EMP_SALES SQL> delete plan_table; plan 2 rows deleted. query rewrite SQL> commit; MV execution Commit complete.plan hint SQL> explain plan for select /*+ NOREWRITE */ 2 e.empno, d.deptno, sum(sal) from emp e, dept dexecution plan 3 where e.deptno = d.deptno group by e.empno, d.deptno ; . Explained. SQL> select substr(lpad( ,2*(level-1))||operation|| ||options 2 || ||object_name,1,79) "Plan View" 3 from plan_table 4 start with id=0 5 connect by prior id = parent_id 6 order by id; Plan View ------------------------------------------------------------------------------- SELECT STATEMENT SORT GROUP BY NESTED LOOPS TABLE ACCESS FULL EMP INDEX RANGE SCAN XPKDEPT jkspark@hanafos.com - 30 -
  31. 31. Oracle8i New Features http://www.ggola.com/ Control Rewrite - optimizer mode cost-based only . (rule base ) - QUERY_REWRITE_ENABLED : FALSE setting query rewrite . dynamically instance level(initial parameter) or session level(alter session command) . - QUERY_REWRITE_INTEGRITY : this parameter reset dynamically for instance and session level. 1. ENFORCED(default) : consistency query rewrite . (updated M-view and validated constraints only) 2. TRUSTED : All updated M-Views and dimensions and constraints with RELY flag are used for query rewrites. (RELY flag constraint new features invalid constraint valid ) 3. STALE_TOLERATED : last DML and relationships(are declared) refresh all M-Views rewrite .(data M-View validate ) CF. register M-View QUERY_REWRITE_INTEGRITY parameter value . Support utility & System privileges - SQL*Loader : Rowid range M-View reference table direct path loading HWMK data incremental refresh . - Export/Import : 1. M-View definition export & import (full mode or user mode) 2. MVDATA=Y export & import data in M-Views MVDATA=N table ROWS=N . ( , M-View data segment object ) 3. MVBUILDDEFERRED=Y export all M-Views definition and created for deferred refresh - M-Views privileges . create materialized view . create/drop/alter any materialized view . query rewrite (enable and disable of own schema) . global query rewrite (enable and disable of in the grantee’s schema for query rewrite)jkspark@hanafos.com - 31 -
  32. 32. Oracle8i New Features http://www.ggola.com/ Registration of an Existing Materialized View - Data Warehouse system ordinary user tables summary and aggregate data tables . tables table build cost . , data . - table Query Rewrite incremental refresh tables M-View . - M-View base table M-View .( name table name ) SQL> create materialized view ….name on prebuilt table … - prebuilt table M-View query rewrite parameter query_rewrite_integrity “TRUSTED” set . - QUERY_REWRITE_INTEGRITY : (Oracle 8.1.6 ) enforced : M-View data relationship query rewrite . trusted : prebuilt table M-View data and RELY constraint (17 constraints ) correct trust query rewrite . stale_tolerated : M-View valid query rewrite maximum rewrite capability . , query rewrite wrong result . CF. Oracle 8.1.5 enforce/no_enforce/use_stale . - , prebuilt table M-View drop table drop . Data dictionary for M-Views - ALL_REFRESH_DEPENDENCIES : dependent or container tables in the current schema - DBA_MVIEW_AGGREGATES : grouping functions in an aggregated M-Views - DBA_MVIEW_ANALYSIS : M-Views information - DBA_MVIEW_DETAIL_RELATIONS : the named detail relations (base(fact) tables information) - DBA_MVIEW_JOINS : information about the joined columns of base tables - DBA_MVIEW_KEYS : detail columns information about the relations of DBA_MVIEW_DETAIL_RELATIONSjkspark@hanafos.com - 32 -
  33. 33. Oracle8i New Features http://www.ggola.com/Dimension Additional query rewrites are possible if summaries are created at the lowest level of aggregation, supported with dimensions. What is a Dimension ? - data dictionary structures that define hierarchical relationship between pairs of columns and column sets. based on existing columns(M-View segment ) - dimension optional highly recommended 1. enable additional query rewrite possibilities (without use of constraints, M-Views ) 2. hierarchies( ) summary . 3. can be used by OLAP tools ( DBMS_OLAP ) - level dimension . date month month quarter quarter year level query rewrite . CF. create dimension attribute level level value column .( “ ” level “ ” ) SQL> conn system/manager Connected. SQL> grant create dimension to dimuser ; Grant succeeded. SQL> conn dimuser/dimuser Connected. SQL> create table emp ( 2 hiredate date, 3 month varchar2(2), 4 month_name varchar2(10), 5 quarter varchar2(1), 6 year varchar2(4)) ; Table created. SQL> Create dimension emp_dim 2 Level hiredate is emp.hiredate 3 Level month is emp.month 4 Level qtr is emp.quarter 5 Level yr is emp.year 6 Hierarchy calendar_rollup ( 7 Hiredate child of 8 Month child of 9 Qtr child of yr ) 10 Attribute month determines month_name ; Dimension created.jkspark@hanafos.com - 33 -
  34. 34. Oracle8i New Features http://www.ggola.com/ - 3 multiple hierarchies time dimension . SQL> create table sales ( 2 sal_date date, 3 month varchar2(2), 4 quarter varchar2(1), 5 year varchar2(4), 6 season varchar2(6), 7 week varchar2(1), 8 dayweek_name varchar2(3), 9 month_name varchar2(3)) ; Table created. SQL> create dimension sales_dim 2 level sal_date is sales.sal_date 3 level month is sales.month 4 level quarter is sales.quarter 5 level year is sales.year 6 level season is sales.season 7 level week is sales.week 8 hierarchy cal_rollup ( 9 sal_date child of 10 month child of 11 quarter child of 12 year ) 13 hierarchy week_rollup ( 14 sal_date child of 15 week ) 16 hierarchy season_rollup ( 17 sal_date child of 18 season ) 19 attribute sal_date determines sales.dayweek_name 20 attribute month determines sales.month_name ; Dimension created. SQL> select * from user_dimensions ; OWNER DIMENSION_NAME INVALID REVISION ---------- -------------------- - ---------- DIMUSER EMP_DIM N 1 DIMUSER SALES_DIM N 1 CF. time level, category level, location level .( , , )jkspark@hanafos.com - 34 -

×