Download presentation
Presentation is loading. Please wait.
Published byJune Robinson Modified over 8 years ago
1
16 Copyright © 2007, Oracle. All rights reserved. Miscellaneous New Features
2
Copyright © 2007, Oracle. All rights reserved. 16 - 2 Objectives After completing this lesson, you should be able to: Describe enhancements to locking mechanisms Use the SQL query result cache Use the enhanced PL/SQL recompilation mechanism Create and use invisible indexes Describe Adaptive Cursor Sharing Manage your SPFILE
3
Copyright © 2007, Oracle. All rights reserved. 16 - 3 Foreground Statistics New columns report foreground-only statistics: V$SYSTEM_EVENT : – TOTAL_WAITS_FG – TOTAL_TIMEOUTS_FG – TIME_WAITED_FG – AVERAGE_WAIT_FG – TIME_WAITED_MICRO_FG V$SYSTEM_WAIT_CLASS : – TOTAL_WAITS_FG – TIME_WAITED_FG
4
Copyright © 2007, Oracle. All rights reserved. 16 - 4 Online Redefinition Enhancements Online table redefinition supports the following: –Tables with materialized views and view logs –Triggers with ordering dependency Online redefinition does not systematically invalidate dependent objects.
5
Copyright © 2007, Oracle. All rights reserved. 16 - 5 Minimizing Dependent Recompilations Adding a column to a table does not invalidate its dependent objects. Adding a PL/SQL unit to a package does not invalidate dependent objects. Fine-grain dependencies are tracked automatically. No configuration is required.
6
Copyright © 2007, Oracle. All rights reserved. 16 - 6 Locking Enhancements DDL commands can now wait for DML locks to be released: – DDL_LOCK_TIMEOUT initialization parameter New WAIT [ ] clause for the LOCK TABLE command The following commands will no longer acquire exclusive locks (X), but shared exclusive locks (SX): – CREATE INDEX ONLINE – CREATE MATERIALIZED VIEW LOG – ALTER TABLE ENABLE CONSTRAINT NOVALIDATE
7
Copyright © 2007, Oracle. All rights reserved. 16 - 7 INVISIBLE Index Invisible Index: Overview VISIBLE Index Optimizer view point Data view point Use index Do not use index Update index Update table OPTIMIZER_USE_INVISIBLE_INDEXES=FALSE
8
Copyright © 2007, Oracle. All rights reserved. 16 - 8 Invisible Indexes: Examples Index is altered as not visible to the optimizer: Optimizer does not consider this index: Optimizer will always consider the index: Creating an index as invisible initially: ALTER INDEX ind1 INVISIBLE; SELECT /*+ index(TAB1 IND1) */ COL1 FROM TAB1 WHERE …; ALTER INDEX ind1 VISIBLE; CREATE INDEX IND1 ON TAB1(COL1) INVISIBLE;
9
Copyright © 2007, Oracle. All rights reserved. 16 - 9 SQL Query Result Cache: Overview Cache the result of a query or query block for future reuse. Cache is used across statements and sessions unless it is stale. Benefits: –Scalability –Reduction of memory usage Good candidate statements: –Access many rows –Return few rows SELECT … SQL Query Result Cache SELECT … Session 1Session 2 1 23
10
Copyright © 2007, Oracle. All rights reserved. 16 - 10 Setting Up SQL Query Result Cache Set at database level using the RESULT_CACHE_MODE initialization parameter. Values: AUTO : The optimizer determines the results that need to be stored in the cache based on repetitive executions. MANUAL : Use the result_cache hint to specify results to be stored in the cache. FORCE : All results are stored in the cache.
11
Copyright © 2007, Oracle. All rights reserved. 16 - 11 Managing the SQL Query Result Cache Use the following initialization parameters: RESULT_CACHE_MAX_SIZE –It sets the memory allocated to the result cache. –Result cache is disabled if you set the value to 0. –Default is dependent on other memory settings (0.25% of memory_target or 0.5% of sga_target or 1% of shared_pool_size ) –Cannot be greater than 75% of shared pool RESULT_CACHE_MAX_RESULT –Sets maximum cache memory for a single result –Defaults to 5% RESULT_CACHE_REMOTE_EXPIRATION –Sets the expiry time for cached results depending on remote database objects –Defaults to 0
12
Copyright © 2007, Oracle. All rights reserved. 16 - 12 Using the RESULT_CACHE Hint EXPLAIN PLAN FOR SELECT /*+ RESULT_CACHE */ department_id, AVG(salary) FROM employees GROUP BY department_id; SELECT /*+ NO_RESULT_CACHE */ department_id, AVG(salary) FROM employees GROUP BY department_id; -------------------------------------------------------------- | Id | Operation | Name |Rows -------------------------------------------------------------- | 0 | SELECT STATEMENT | | 11 | 1 | RESULT CACHE | 8fpza04gtwsfr6n595au15yj4y | | 2 | HASH GROUP BY | | 11 | 3 | TABLE ACCESS FULL| EMPLOYEES | 107 --------------------------------------------------------------
13
Copyright © 2007, Oracle. All rights reserved. 16 - 13 In-Line View: Example SELECT prod_subcategory, revenue FROM (SELECT /*+ RESULT_CACHE */ p.prod_category, p.prod_subcategory, sum(s.amount_sold) revenue FROM products p, sales s WHERE s.prod_id = p.prod_id and s.time_id BETWEEN to_date('01-JAN-2006','dd-MON-yyyy') and to_date('31-DEC-2006','dd-MON-yyyy') GROUP BY ROLLUP(p.prod_category, p.prod_subcategory)) WHERE prod_category = 'Women';
14
Copyright © 2007, Oracle. All rights reserved. 16 - 14 Using the DBMS_RESULT_CACHE Package Use the DBMS_RESULT_CACHE package to: Manage memory allocation for the query result cache View the status of the cache: Retrieve statistics on the cache memory usage: Remove all existing results and clear cache memory: Invalidate cached results depending on specified object: EXECUTE DBMS_RESULT_CACHE.MEMORY_REPORT; EXECUTE DBMS_RESULT_CACHE.FLUSH; SELECT DBMS_RESULT_CACHE.STATUS FROM DUAL; EXEC DBMS_RESULT_CACHE.INVALIDATE('JFV','MYTAB');
15
Copyright © 2007, Oracle. All rights reserved. 16 - 15 Viewing SQL Result Cache Dictionary Information The following views provide information about the query result cache: (G)V$RESULT_CACHE_STATISTICS Lists the various cache settings and memory usage statistics (G)V$RESULT_CACHE_MEMORY Lists all the memory blocks and the corresponding statistics ( G)V$RESULT_CACHE_OBJECTS Lists all the objects (cached results and dependencies) along with their attributes (G)V$RESULT_CACHE_DEPENDENCY Lists the dependency details between the cached results and dependencies
16
Copyright © 2007, Oracle. All rights reserved. 16 - 16 SQL Query Result Cache: Considerations Result cache is disabled for queries containing: –Temporary or dictionary tables –Nondeterministic PL/SQL functions –Sequence CURRVAL and NEXTVAL –SQL functions current_date, sysdate, sys_guid, and so on DML/DDL on remote database does not expire cached results. Flashback queries can be cached.
17
Copyright © 2007, Oracle. All rights reserved. 16 - 17 SQL Query Result Cache: Considerations Result cache does not automatically release memory. –It grows until maximum size is reached. – DBMS_RESULT_CACHE.FLUSH purges memory. Bind variables –Cached result is parameterized with variable values. –Cached results can only be found for the same variable values. Cached result will not be built if: –Query is built on a noncurrent version of data (read consistency enforcement) –Current session has outstanding transaction on table(s) in query
18
Copyright © 2007, Oracle. All rights reserved. 16 - 18 OCI Client Query Cache Extends server-side query caching to client-side memory Ensures better performance by eliminating round-trips to the server Leverages client-side memory Improves server scalability by saving server CPU resources Result cache automatically refreshed if the result set is changed on the server Particularly good for lookup tables
19
Copyright © 2007, Oracle. All rights reserved. 16 - 19 Using Client-Side Query Cache You can use client-side query caching by: Setting initialization parameters – CLIENT_RESULT_CACHE_SIZE – CLIENT_RESULT_CACHE_LAG Using the client configuration file – OCI_RESULT_CACHE_MAX_SIZE – OCI_RESULT_CACHE_MAX_RSET_SIZE – OCI_RESULT_CACHE_MAX_RSET_ROWS Client result cache is then used depending on: –Tables result cache mode – RESULT CACHE hints in your SQL statements
20
Copyright © 2007, Oracle. All rights reserved. 16 - 20 PL/SQL Function Cache Stores function results in cache, making them available to other sessions. Uses the Query Result Cache exec Calculate(…); Cached results First query Subsequent queries exec Calculate(…); BEGIN … SELECT … FROM table; … END;
21
Copyright © 2007, Oracle. All rights reserved. 16 - 21 Using PL/SQL Function Cache Include the RESULT_CACHE option in the function declaration section of a package or function definition. Optionally include the RELIES_ON clause to specify any tables or views on which the function results depend. CREATE OR REPLACE FUNCTION productName (prod_id NUMBER, lang_id VARCHAR2) RETURN NVARCHAR2 RESULT_CACHE RELIES_ON (product_descriptions) IS result VARCHAR2(50); BEGIN SELECT translated_name INTO result FROM product_descriptions WHERE product_id = prod_id AND language_id = lang_id; RETURN result; END;
22
Copyright © 2007, Oracle. All rights reserved. 16 - 22 PL/SQL Function Cache: Considerations PL/SQL Function Cache cannot be used when: The function is defined in a module that has the invoker ’ s rights or in an anonymous block. The function is a pipelined table function. The function has OUT or IN OUT parameters. The function has IN parameter of the following types: BLOB, CLOB, NCLOB, REF CURSOR, collection, object, or record. The function’s return type is: BLOB, CLOB, NCLOB, REF CURSOR, object, record, or collection with one of the preceding unsupported return types.
23
Copyright © 2007, Oracle. All rights reserved. 16 - 23 PL/SQL and Java Native Compilation Enhancements 100+% faster for pure PL/SQL or Java code 10–30% faster for typical transactions with SQL PL/SQL –Just one parameter: On/Off –No need for C compiler –No file system DLLs Java –Just one parameter: On/Off –JIT “on the fly” compilation –Transparent to user (asynchronous, in background) –Code stored to avoid recompilations
24
Copyright © 2007, Oracle. All rights reserved. 16 - 24 Setting Up and Testing PL/SQL Native Compilation 1.Set PLSQL_CODE_TYPE to NATIVE : – ALTER SYSTEM | ALTER SESSION | ALTER … COMPILE 2.Compile your PL/SQL units (example): 3.Make sure you succeeded: CREATE OR REPLACE PROCEDURE hello_native AS BEGIN DBMS_OUTPUT.PUT_LINE('Hello world.'); END hello_native; / ALTER PROCEDURE hello_native COMPILE PLSQL_CODE_TYPE=NATIVE; SELECT plsql_code_type FROM all_plsql_object_settings WHERE name = 'HELLO_NATIVE';
25
Copyright © 2007, Oracle. All rights reserved. 16 - 25 Recompiling the Entire Database for PL/SQL Native Compilation 1.Shut down the database. 2.Set PLSQL_CODE_TYPE to NATIVE. 3.Start up the database in UPGRADE mode. 4.Execute the dbmsupgnv.sql script. 5.Shut down/start up your database in restricted mode. 6.Execute the utlrp.sql script. 7.Disable restricted mode.
26
Copyright © 2007, Oracle. All rights reserved. 16 - 26 Notes only page
27
Copyright © 2007, Oracle. All rights reserved. 16 - 27 Adaptive Cursor Sharing: Overview Adaptive Cursor Sharing allows for intelligent cursor sharing only for statements that use bind variables. Adaptive Cursor Sharing is used to compromise between cursor sharing and optimization. Adaptive Cursor Sharing benefits: –Automatically detects when different executions would benefit from different execution plans –Limits the number of generated child cursors to a minimum –Automated mechanism that cannot be turned off One plan not always appropriate for all bind values
28
Copyright © 2007, Oracle. All rights reserved. 16 - 28 Adaptive Cursor Sharing: Architecture Initial selectivity cube Bind-sensitive cursor SELECT * FROM emp WHERE sal = :1 and dept = :2. 0.15 0.0025 :1=A & :2=B S(:1)=0.15 S(:2)=0.0025. 0.18 0.003 :1=C & :2=D S(:1)=0.18 S(:2)=0.003 HJ GB HJ Initial plan HJ GB HJ No need for new plan. 0.3 0.009 :1=E & :2=F S(:1)=0.3 S(:2)=0.009 HJ GB HJ GB HJ. 0.28 0.004 :1=G & :2=H S(:1)=0.28 S(:2)=0.004 HJ GB HJ GB HJ Same selectivity cube Second selectivity cube Need new plan Merged selectivity cubes Cubes merged No need for new plan Bind-aware cursor S o f t P a r s e H a r d a r s e P H a r d a r s e P 1 2 3 4 System observes statement for a while.
29
Copyright © 2007, Oracle. All rights reserved. 16 - 29 Notes only page
30
Copyright © 2007, Oracle. All rights reserved. 16 - 30 Adaptive Cursor Sharing Views The following views provide information about Adaptive Cursor Sharing usage: V$SQL Two new columns show whether a cursor is bind-sensitive or bind- aware. V$SQL_CS_HISTOGRAM Shows the distribution of the execution count across the execution history histogram. V$SQL_CS_SELECTIVITY Shows the selectivity cubes stored for every predicate containing a bind variable and whose selectivity is used in the cursor sharing checks. V$SQL_CS_STATISTICS Shows execution statistics of a cursor using different bind sets.
31
Copyright © 2007, Oracle. All rights reserved. 16 - 31 Interacting with Adaptive Cursor Sharing CURSOR_SHARING : –If CURSOR_SHARING <> EXACT, then statements containing literals may be rewritten using bind variables. –If statements are rewritten, Adaptive Cursor Sharing may apply to them. SQL Plan Management (SPM): –If OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES is set to TRUE, then only the first generated plan is used. –As a workaround, set this parameter to FALSE, and run your application until all plans are loaded in the cursor cache. –Manually load the cursor cache into the corresponding plan baseline.
32
Copyright © 2007, Oracle. All rights reserved. 16 - 32 Temporary Tablespace Shrink Sort segment extents are managed in memory after being physically allocated. This method can be an issue after big sorts are done. To release physical space from your disks, you can shrink temporary tablespaces: –Locally managed temporary tablespaces –Online operation CREATE TEMPORARY TABLESPACE temp TEMPFILE 'tbs_temp.dbf' SIZE 600m REUSE AUTOEXTEND ON MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1m; ALTER TABLESPACE temp SHRINK SPACE [KEEP 200m]; ALTER TABLESPACE temp SHRINK TEMPFILE 'tbs_temp.dbf';
33
Copyright © 2007, Oracle. All rights reserved. 16 - 33 DBA_TEMP_FREE_SPACE Lists temporary space usage information Central point for temporary tablespace space usage Column nameDescription TABLESPACE_NAME Name of the tablespace TABLESPACE_SIZE Total size of the tablespace, in bytes ALLOCATED_SPACE Total allocated space, in bytes, including space that is currently allocated and used and space that is currently allocated and available for reuse FREE_SPACE Total free space available, in bytes, including space that is currently allocated and available for reuse and space that is currently unallocated
34
Copyright © 2007, Oracle. All rights reserved. 16 - 34 Tablespace Option for Creating Temporary Table Specify which temporary tablespace to use for your global temporary tables. Decide a proper temporary extent size. CREATE TEMPORARY TABLESPACE temp TEMPFILE 'tbs_temp.dbf' SIZE 600m REUSE AUTOEXTEND ON MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1m; CREATE GLOBAL TEMPORARY TABLE temp_table (c varchar2(10)) ON COMMIT DELETE ROWS TABLESPACE temp;
35
Copyright © 2007, Oracle. All rights reserved. 16 - 35 Easier Recovery from Loss of SPFILE The FROM MEMORY clause allows the creation of current systemwide parameter settings. CREATE PFILE [= 'pfile_name' ] FROM { { SPFILE [= 'spfile_name'] } | MEMORY } ; CREATE SPFILE [= 'spfile_name' ] FROM { { PFILE [= 'pfile_name' ] } | MEMORY } ;
36
Copyright © 2007, Oracle. All rights reserved. 16 - 36 Summary In this lesson, you should have learned how to: Describe enhancements to locking mechanisms Use the SQL query result cache Use the enhanced PL/SQL recompilation mechanism Create and use invisible indexes Describe Adaptive Cursor Sharing Manage your SPFILE
37
Copyright © 2007, Oracle. All rights reserved. 16 - 37 Practice 16: Overview This practice covers the following topics: Using the client result cache Using the PL/SQL result cache
38
Copyright © 2007, Oracle. All rights reserved. 16 - 38
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.