Oracle APEX Performance

127

Click here to load reader

description

Over the years there have been countless technical and social presentations doting on 5, 10, 12 ways to improve this, that and the other. I will go through various performance tweaks (not tweets) for Oracle Application Express without limiting myself to a golden number. These improvements will vary from simple PL/SQL refactoring; to monitoring for bottlenecks in your application; to cutting down maintenance time - which relates to the performance of you as an Oracle developer with only 24 hours in a day. We may even visit a little APEX instrumentation on the way.

Transcript of Oracle APEX Performance

Page 1: Oracle APEX Performance

SAGE Computing ServicesCustomised Oracle Training Workshops and

Consulting

‘n’ methods to improve Apex performance

Why stop at 10?

Scott WesleySystems Consultant & Trainer

Page 2: Oracle APEX Performance

who_am_i;

Page 3: Oracle APEX Performance

http://strategy2c.wordpress.com/2009/01/10/strategy-for-goldfish-funny-illustration-by-frits/

Page 4: Oracle APEX Performance
Page 5: Oracle APEX Performance
Page 6: Oracle APEX Performance
Page 7: Oracle APEX Performance

Agenda

• Introduction• Prevention• Fluff• Diagnosis• Fluff• Time Management• Fluff• Conclusion• Drinks

Page 8: Oracle APEX Performance

Larry Lessig?

Page 9: Oracle APEX Performance

the law is strangling creativity

http://www.ted.com/talks/larry_lessig_says_the_law_is_strangling_creativity.htmlhttp://presentationzen.blogs.com/presentationzen/2005/10/the_lessig_meth.html

Page 10: Oracle APEX Performance

This presentation

what you can explore

Page 11: Oracle APEX Performance

prevention - innovatetime management - educate

diagnosis - interactnot just Apex - maximise

Page 12: Oracle APEX Performance

prevention - innovatetime management - educate

diagnosis - interactnot just Apex - maximise

Page 13: Oracle APEX Performance

example

Page 14: Oracle APEX Performance

checkboxes

Page 15: Oracle APEX Performance

begin<< chk >>for i in 1.. apex_application.g_f20.count loop update resources set deleted = 'Y' where code = apex_application.g_f20(i); end loop chk;end;

Page 16: Oracle APEX Performance

begin forall i in indices of apex_application.g_f20 update resources set deleted = 'Y' where code = apex_application.g_f20(i);end;

Page 17: Oracle APEX Performance
Page 18: Oracle APEX Performance

http://www.perthnow.com.au/sport/fremantle-defender-chris-tarrant-in-doubt-for-afl-finals/story-e6frg1wu-1225899762230

Page 19: Oracle APEX Performance

move away from Oracle Forms (to Apex)

Page 20: Oracle APEX Performance
Page 21: Oracle APEX Performance

authentication

Page 22: Oracle APEX Performance

LDAP

Page 23: Oracle APEX Performance

FUNCTION return_ldap_groupsRETURN t_ldap_group PIPELINED;

Page 24: Oracle APEX Performance

CREATE OR REPLACE TYPE r_ldap_groupAS OBJECT (username VARCHAR2(100) ,group_name VARCHAR2(100))/

CREATE OR REPLACE TYPE t_ldap_groupAS TABLE OF r_ldap_group;/

Page 25: Oracle APEX Performance

CREATE MATERIALIZED VIEW mv_ldap_groupsREFRESH COMPLETESTART WITH SYSDATENEXT TRUNC(SYSDATE) + 1ASSELECT username, group_nameFROM TABLE(return_ldap_groups);

http://www.amazon.com/Pro-Oracle-Application-Express-ebook/dp/B001U0PFCC

Page 26: Oracle APEX Performance

authorisation

Page 27: Oracle APEX Performance
Page 28: Oracle APEX Performance

-- To populate application item F_ADMIN_SCHEME-- (preferably via perhaps app_auth_pkg.post_authentication_process

app_auth_pkg.fn_admin_scheme(:APP_USER);

Page 29: Oracle APEX Performance

:F_ADMIN_SCHEME = 'Y'

Page 30: Oracle APEX Performance

conditions

Page 31: Oracle APEX Performance
Page 32: Oracle APEX Performance

pagination style

Page 33: Oracle APEX Performance
Page 34: Oracle APEX Performance
Page 35: Oracle APEX Performance
Page 36: Oracle APEX Performance

ajax methods

Page 37: Oracle APEX Performance

SELECT name d, org_id rFROM organisationsSTART WITH parent_org_id = :P12_PARENT_ORG_IDCONNECT BY PRIOR org_id = parent_org_idORDER BY 1

Page 38: Oracle APEX Performance
Page 39: Oracle APEX Performance

function getEmail(pUser) { var get = new htmldb_Get(null,$v('pFlowId'), 'APPLICATION_PROCESS=GET_EMAIL',0); get.addParam('x01',pUser); gReturn = get.get(); json_SetItems(gReturn);}

http://www.itworkedyesterday.com/blog/2010/2/23/apex_util-ready-set-json.html

Page 40: Oracle APEX Performance

post calculation computation

Page 41: Oracle APEX Performance

post query

Page 42: Oracle APEX Performance

REPLACE(:P1_EMAIL_LIST, ':', '<br>')

Page 43: Oracle APEX Performance

my_pkg.get_description(:P1_CODE)

Page 44: Oracle APEX Performance

bulk collects

Page 45: Oracle APEX Performance
Page 46: Oracle APEX Performance

<< email_loop >>FOR r_rec IN (SELECT email FROM employees) LOOP lc_emails := lc_emails ||r_rec.email ||',';END LOOP email_loop;

lc_emails := RTRIM(lc_emails,',');

Page 47: Oracle APEX Performance

SELECT DISTINCT emailBULK COLLECTINTO lt_emailsFROM employees;

lc_emails := apex_util.table_to_string (p_table => lt_emails ,p_string => ',');

Page 48: Oracle APEX Performance

validation sequence

Page 49: Oracle APEX Performance

Apex_application.g_inline_validation_error_cnt = 0

Page 50: Oracle APEX Performance

CSS in SQL

Page 51: Oracle APEX Performance

SELECT emp_id ,'<b>'||ename||'</b>' ,salaryFROM emp

Page 52: Oracle APEX Performance
Page 53: Oracle APEX Performance

network traffic

Page 54: Oracle APEX Performance
Page 55: Oracle APEX Performance
Page 56: Oracle APEX Performance
Page 57: Oracle APEX Performance

-- Is the current page a help/contact popup/login-- these pages don't need jquery, cancel page calculations.FUNCTION is_popup_page RETURN BOOLEAN ISBEGIN RETURN wwv_flow.get_page_alias IN ('ITEMHELP' -- help popup ,'LOGIN' -- not a popup, but doesn't need dates ,'CONTACTS' -- contact manager popup ,'FINDSPP' -- SPP lookup ,'EMAIL' -- not worth cancelling to and doesn't need jquery ,'EMAILSENT' -- closes in a few seconds );END is_popup_page;

Page 58: Oracle APEX Performance

javascript validation

Page 59: Oracle APEX Performance
Page 60: Oracle APEX Performance

#TIMING#

Page 61: Oracle APEX Performance
Page 62: Oracle APEX Performance
Page 63: Oracle APEX Performance

cache

Page 64: Oracle APEX Performance

http://forums.oracle.com/forums/thread.jspa?threadID=486516

Page 65: Oracle APEX Performance

deterministic functions

Page 66: Oracle APEX Performance

SELECT *FROM my_tableWHERE my_column = v('MY_ITEM')

Page 67: Oracle APEX Performance

SELECT *FROM my_tableWHERE my_column = :MY_ITEM

Page 68: Oracle APEX Performance

SELECT * FROM my_tableWHERE my_column = my_own_function(another_column)

Page 69: Oracle APEX Performance

SELECT *FROM my_tableWHERE my_column = v('MY_ITEM')

Page 70: Oracle APEX Performance

SELECT *FROM my_tableWHERE my_column = v('MY_ITEM')

Page 71: Oracle APEX Performance

From 10gR2

Page 72: Oracle APEX Performance

Pre Apex3.x

Page 73: Oracle APEX Performance

ie - Oracle XEpre-patch

Page 74: Oracle APEX Performance

CREATE OR REPLACE FUNCTION V ( p_item IN VARCHAR2 , p_flow IN NUMBER := NULL , p_scope IN VARCHAR2 := 'SESSION_AND_USER' , p_escape IN VARCHAR2 := 'N' ) RETURN VARCHAR2 DETERMINISTIC--==============================================================================-- Wraps the existing APEX V function and adds the DETERMINISTIC optimizer hint-- so that the function isn't called for each row the query engine is verifying.-- See /2006/11/caution-when-using-plsql-functions-in.html-- for details.--==============================================================================ISBEGIN RETURN FLOWS_020200.V ( p_item => p_item , p_flow => p_flow , p_scope => p_scope , p_escape => p_escape );END V;/

http://www.inside-oracle-apex.com/drop-in-replacement-for-v-and-nv-function/

Page 75: Oracle APEX Performance

SELECT *FROM my_table-- scalar subquery cachingWHERE my_column = (SELECT v('MY_ITEM') FROM DUAL)

http://www.oratechinfo.co.uk/scalar_subqueries.html

Page 76: Oracle APEX Performance

scalar subquery caching

Page 77: Oracle APEX Performance

implicit vs explicit conversion

Page 78: Oracle APEX Performance

To ensure your program does exactly what you expect, use explicit conversions wherever possible.

Page 79: Oracle APEX Performance

create or replace function nv ( p_item in varchar2) return number-- Copyright (c) Oracle Corporation 1999. All Rights Reserved.---- DESCRIPTION-- Function to return a numeric flow value. V stands for value.---- SECURITY---- NOTES--isbegin return to_number(v(p_item));end nv;/

Page 80: Oracle APEX Performance

select * from organisations where name = 123;

Page 81: Oracle APEX Performance

sequences

Page 82: Oracle APEX Performance
Page 83: Oracle APEX Performance

BEGIN INSERT INTO my_table (my_pk, ... VALUES (my_seq.NEXTVAL, ...);END;/

Page 84: Oracle APEX Performance

prevention – innovatetime management – educate

diagnosis - interactnot just Apex - maximise

Page 85: Oracle APEX Performance

PL/SQL APIs

Page 86: Oracle APEX Performance
Page 87: Oracle APEX Performance
Page 88: Oracle APEX Performance

create or replace package "PARTIES_API" is

---------------------------------------------------------------- create procedure for table "PARTIES" procedure "INS_PARTIES" (...---------------------------------------------------------------- update procedure for table "PARTIES" procedure "UPD_PARTIES" (...---------------------------------------------------------------- delete procedure for table "PARTIES" procedure "DEL_PARTIES" (...---------------------------------------------------------------- get procedure for table "PARTIES" procedure "GET_PARTIES" (...---------------------------------------------------------------- get procedure for table "PARTIES" including MD5 procedure "GET_PARTIES" (...---------------------------------------------------------------- build MD5 function for table "PARTIES" function "BUILD_PARTIES_MD5" (... ) return varchar2; end "PARTIES_API";

Page 89: Oracle APEX Performance

merge vs insert/update

Page 90: Oracle APEX Performance

multi-table insert

Page 91: Oracle APEX Performance

BEGIN INSERT INTO my_table (my_pk, ... VALUES (my_seq.NEXTVAL, ...);END;/

Page 92: Oracle APEX Performance

BEGIN INSERT INTO my_table (my_pk, ... VALUES (fn_get_my_seq, ...);END;/

Page 93: Oracle APEX Performance

CREATE OR REPLACE TRIGGER my_table_br_trgBEFORE INSERT OR UPDATE ON sage.my_tableFOR EACH ROWBEGIN IF :NEW.my_id IS NULL THEN SELECT my_seq.NEXTVAL INTO :NEW.my_id FROM dual;-- :NEW.my_id := my_seq.NEXTVAL -> 11g END IF;END;/

Page 94: Oracle APEX Performance

re-use

shared components

page zero

copy object

ui defaults

subscriptions pl/sql packages

Page 95: Oracle APEX Performance

-- apex_application.g_inline_validation_error_cnt = 0

return my_pkg.run_validation

Page 96: Oracle APEX Performance

prevention - innovatetime management – educate

diagnosis – interactnot just Apex - maximise

Page 97: Oracle APEX Performance

apex_dml_lock_wait_time

Page 98: Oracle APEX Performance
Page 99: Oracle APEX Performance

debug mode

Page 100: Oracle APEX Performance
Page 101: Oracle APEX Performance
Page 102: Oracle APEX Performance

wwv_flow.debug('my debug information');

Page 103: Oracle APEX Performance

firebug

Page 104: Oracle APEX Performance
Page 105: Oracle APEX Performance

tracing

Page 106: Oracle APEX Performance

http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/debug.htm#BABGDGEH

http:/.../f?p=100:1&p_trace=YES

Page 107: Oracle APEX Performance

http://www.talkapex.com/2010/10/oracle-xe-and-apex-where-is-my-trace.html

show parameter USER_DUMP_DEST

Page 108: Oracle APEX Performance

jmeter

Page 110: Oracle APEX Performance

page performance

Page 111: Oracle APEX Performance
Page 112: Oracle APEX Performance
Page 113: Oracle APEX Performance

monitor activity

Page 114: Oracle APEX Performance
Page 115: Oracle APEX Performance
Page 116: Oracle APEX Performance

prevention - innovatetime management - educate

diagnosis - interactnot just Apex - maximise

Page 117: Oracle APEX Performance

short circuit evaluation

Page 118: Oracle APEX Performance

SELECT NVL(a_column ,expensive_fn(b_column)) my_columnFROM a_table;

SELECT COALESCE(a_column ,expensive_fn(b_column)) my_columnFROM a_table;

Page 119: Oracle APEX Performance

IF a != bOR (a IS NULL AND b IS NOT NULL )OR( a IS NOT NULL AND b IS NULL )

IF (COALESCE(a,-1) != COALESCE(b,-2))

IF NVL(a,-1) != NVL(b,-1)

Page 120: Oracle APEX Performance

queries

Page 121: Oracle APEX Performance

SELECT name, TO_CHAR(dt,'DD-MM-YYYY') dt, amt, cum_amt -- Model resultsFROM ( SELECT name, TRUNC(dt, 'MM') dt, SUM(amt) amt FROM customer GROUP BY name, TRUNC(dt, 'MM'))MODELPARTITION BY (name)DIMENSION BY (dt)MEASURES (amt, cast(NULL AS NUMBER) cum_amt) -- Define calculated colIGNORE NAVRULES SEQUENTIAL ORDER( amt[FOR dt FROM TO_DATE('01-01-2007', 'DD-MM-YYYY') TO TO_DATE('01-12-2007', 'DD-MM-YYYY') INCREMENT NUMTOYMINTERVAL(1, 'MONTH') ] = amt[CV(dt)] -- Apply amt for given date, if found ,cum_amt[ANY] = SUM(amt)[dt <= CV(dt)] -- Calculate cumulative)ORDER BY name, dt/

Page 122: Oracle APEX Performance

remote database queries

Page 123: Oracle APEX Performance

small_table big_table

Page 124: Oracle APEX Performance

SELECT st.info, sum(bt.measure) totalFROM small_table stJOIN big_table@remote_db btON st.id = bt.id

Page 125: Oracle APEX Performance

SELECT /*+ DRIVING_SITE(bt) */ st.info, sum(bt.measure) totalFROM small_table stJOIN big_table@remote_db btON st.id = bt.id

Page 126: Oracle APEX Performance

experiment

database versionhardware

table size

statisticsphase of the moon

load

data distribution

Page 127: Oracle APEX Performance

SAGE Computing ServicesCustomised Oracle Training Workshops and

Consulting

Question time

Presentations are available from our website:http://www.sagecomputing.com.au

[email protected]@sagecomputing.com.auhttp://triangle-circle-square.blogspot.com