Oracle Learnings

March 3, 2018 | Author: G Rajakannu | Category: Database Index, Oracle Database, Sql, Computer Engineering, Computer Data
Share Embed Donate


Short Description

Oracle Learnings...

Description

1. To get data thats deleted or updated and commited... FLASHBACK TABLE table_name TO TIMESTAMP systimestamp - interval '1' minute; SELECT * FROM table_name AS OF TIMESTAMP systimestamp - interval '1' minute; Select * from v$Parameter where name like 'undo%'; -- the value needs to be AUTO -- and undo retention value is in seconds, thats the time allowed to undo 2. temporal validity CREATE TABLE table_name( emp_id integer not null, in_date date not null, out_date date not null, PERIOD FOR emp (in_date, out_date) ); SELECT * FROM table_name AS OF PERIOD FOR emp sysdate; exec DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME('ALL'); exec DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME('CURRENT'); 3. Performance gain on tables which we access frequently and not changing frequently ALTER TABLE table_name RESULT_CACHE (MODE FORCE); /*+ result_cache */ ALTER SESSION SET RESULT_CACHE_MODE = 'FORCE'; First execution takes normal time, Sus sequent execution will not take time. 4. Column Update Mystery - Update one column and automatically update another column Use Virtual Column column_name varchar2(20) GENERATED ALWAYS AS ( CAST(get_char(col1) as varchar2(20) ) ) Declare function as DETERMINISTIC Only on standard heap tables, not on Index organized, clustered tables... 5. ALTER SESSION SET plsql_warnings = 'enable:all' To get the possible run time errors while compilation itself. Also suggests the possible changes that help in performance. Does unreachablility analysis as well.

--------------------------------------------------------------------------------------https://www.youtube.com/watch?v=SxEQbz8tOwU

1. Use the benefits of RESULT CACHE -- /*+ result_cache */ 2. Enable RESULT CACHE whenever needed. -- ALTER SESSION SET RESULT_CACHE_MODE = 'FORCE'; Create the function with RESULT_CACHE whenever needed. RESULT_CACHE Session, DETERMINISTIC - Whole SGA 3. Gather extended statistics if necessary -- SELECT dbms_stats.create_extended_stats (numm,'TABLE','(Col1,Col2)') FROm dual; exec dbms_stats.gather_table_stats (null,'TABLE',method_opt=>'for all columns size skewonly for columns(Col1,Col2)'); 4. Take advantage of bulk processing fetures SELECT col1,col2 BULK COLLECT INTO v_col1, v_col2 FROM Table; FORALL i IN v_col1.FIRST .. v_col1.LAST UPDATE table SET col2 = col2 +1 WHERE col1 = v_col1(i); use IF or CASE in between these

-- We cant

5. Certain syntax can cause the optimizer to not consider an index 1. Operators such as , != 2. Where upper(col1) = 'SMITH' 3. Implicit conversions 4. LIKE '%A' -- wild card string in starting of the 5. Arithimetic operators or || operator 6. Pass parameters by reference Use the NOCOPY option when passing the parameter 7. Perform joins with the correct join methord Nested loop, Hash, Sort-Merge Nested loop - better for joining small result sets whhere the join columns are indexed Hash - better for joining larger result set where one or more indexes are missing on the join column Sort-Merge - better than nested loop joins for joining larger result sets but typically not as good as hash 8. Compare performance between alternative syntax for your code. 9. Use correlation ids when performing joins, even on columns where they are not required. 10. Analyze joins one by one and check that their use makes sense in each circumstance 11. Eliminate rows as early as possible in the join order If filters are in the query along with joins, where in the execution plan do the filters take place in regards to where the joins take place... 12. Understand potential bottlenecks within Oracle's architecture Memory Structures Buffer cache - All flavors of data Shared pool - Code and supporting information PGA - Temporary work area - sorts for example Redo log buffer - Data chnages Redo logs

Data changes 13. Undesrtanding blocks and block size PCTFREE PCTUSED Read the fewest no of blocks possible to get the desired result set 14. Be aware of session and system parameters and their settings. OPTIMIZER_MODE DB_FILE_MULTIBLOCK_READ_COUNT OPTIMIZER_INDEX_CACHING -- Higher this no, its high possibility that this index is there in buffer OPTIMIZER_COST_ADJ -- default is 100. Lower this no, Index costs less than FTS 15. When creating multi column index, choose an optimal order of the columns 16. Avoid unnecessary sorts Its done in PGA casued by -- ORDER BY, DISTINCT, GROUP BY, UNION, INTERSECT, MINUS, Hashjoin, Sort-Merge join, Creating an index, generating statistics 17. Do not overuse SELECT ... FROM DUAL; instead use like assignment operation. v_var := SYSDATE; 18. Follow SQL and PL/SQl standards. Have a document and code reviews 19. Take advantage of available tuning tools SQL Tuning Advisor PL/SQL Profiler Explain Plan Autotrace Trace events 10046 and 10053(Shows the plan which it choose and tells the list of plans it generated and rejected) 20. Use hints as a temporary solution

--------------------------------------------------------------------------------------Oracle PL/SQL Best Practices Part 1 https://www.youtube.com/watch?v=IvsVGaTuHhY 1. Avoid initilization in declaration step. Because its not handled in the exception... 2. Instead of CURSOR r1 is SELECT .... FOR UPDATE; BEGIN FOR v_rec IN r1 LOOP IF ... UPDATE ... END IF; END LOOP; COMMIT;

END; Use this... CURSOR r1 is SELECT .... FOR UPDATE OF e.sal;
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF