Anda di halaman 1dari 56

Oracle Application Express

Schema Design Guidelines


Presenter: Flavio Casetta, Yocoa!com
a"out me

Flavio Casetta

Founder o# Yocoa!com

Editor o# "log Oracle$uir%s!"logspot!com

&'( ears in the )*

+,( ears developing applications on Oracle

+'( ears developing data"ase applications

apex developer since htmld" +!'


June 24, 2009 Flavio Casetta - www.yocoya.com 3
summar

goals

d" o"-ects mapping to apex components

ta"les, vie.s, indexes

per#ormance

pac%ages vs standalone procedures

snapshots or cached reports/

snonms and d" lin%s

$0A
June 24, 2009 Flavio Casetta - www.yocoya.com 4
goals
June 24, 2009 Flavio Casetta - www.yocoya.com 5
goals

the goals o# ever apex developer should "e

to "uild #ast, scala"le applications that are


eas to use, deplo and maintain

to avoid reinventing the .heel

to avoid .riting the same code over and over


again

the aim o# this presentation is to stress the


importance o# proper data"ase design as a
strong #oundation #or our apex applications
June 24, 2009 Flavio Casetta - www.yocoya.com 6
d" o"-ects mapping to apex components
June 24, 2009 Flavio Casetta - www.yocoya.com 7
mapping
June 24, 2009 Flavio Casetta - www.yocoya.com 8
ta"les, vie.s, indexes
June 24, 2009 Flavio Casetta - www.yocoya.com 9
ta"les, vie.s, indexes

oracle provides di##erent tpes o# ta"les tailored


#or di##erent situations

standard heap ta"les

index organi1ed ta"les a%a )O*s

cluster ta"les

temporar ta"les

external ta"les

oracle EE allo.s ta"le partitioning


June 24, 2009 Flavio Casetta - www.yocoya.com 10
ta"les, vie.s, indexes

apex2s ta"le "uilder .i1ard creates onl heap


ta"les
June 24, 2009 Flavio Casetta - www.yocoya.com 11
ta"les, vie.s, indexes

S$3 Developer2s ta"le "uilder instead comes


.ith advanced options
June 24, 2009 Flavio Casetta - www.yocoya.com 12
ta"les, vie.s, indexes

heap ta"les are "est #or data that gro.s over


time! *he developer must properl design
indexes #or improving data access!

.hen evaluating the indexes to "e created,


consider that an column4s5 declared as #oreign
%e4s5 should "e indexed in order to avoid
contention

i# using oracle EE, consider using "itmap indexes


#or columns containing #e. distinct values on
large ta"les .ith lo. transactional activit 4li%e
#act ta"les in a D65
June 24, 2009 Flavio Casetta - www.yocoya.com 13
ta"les, vie.s, indexes

)O*s are "est #or ta"les accessed " primar %e


and .ith lo. transactional activit!

o#ten reports and page items need to displa a


description starting #rom a #oreign %e value
4.hich is the primar %e o# the )O*5

unli%e ordinar indexes, the primar %e o# an


)O* cannot "e re"uilt online
June 24, 2009 Flavio Casetta - www.yocoya.com 14
ta"les, vie.s, indexes

cluster ta"les come in t.o #orms:

index clusters

hash clusters

clusters improve )7O " storing data together

cluster ta"les 8pre9-oin: ta"les

index clusters re;uire t.o logical reads

hash clusters re;uire one logical read

hash clusters are "est #or ver static data

hash clusters need precise si1ing in#ormation


June 24, 2009 Flavio Casetta - www.yocoya.com 15
ta"les, vie.s, indexes

external ta"les are use#ul .hen importing data


#rom texts #ile stored in a director on the same
data"ase server

i# deploing an application on a multi9tenant


hosting server, ou might have no access to local
#olders

#inding the right #ormat #or an external ta"le can


"e challenging! Certain com"inations o#
parameters ma introduce erratic "ehavior
June 24, 2009 Flavio Casetta - www.yocoya.com 16
ta"les, vie.s, indexes

temporar ta"les are good #or volatile data! *here


are t.o tpes o# G**s and the di##er in scope:

transaction 4on commit delete ro.s5

oracle session 4on commit preserve ro.s5

given the nature o# apex architecture, usage o#


temporar ta"les is limited to operations that
"egin and end .ithin the same transaction

practical uses: reporting on data returned " a


procedure
June 24, 2009 Flavio Casetta - www.yocoya.com 17
ta"les, vie.s, indexes

vie.s are meant to simpli# the .or% o# a


developer ":

hiding complex expressions or -oins that .ould


ma%e a ;uer di##icult to deal .ith

en#orcing data access rules, i!e! to limit the


results to data relevant to a certain user

decoding values to human understanda"le


language
June 24, 2009 Flavio Casetta - www.yocoya.com 18
ta"les, vie.s, indexes

in apex, vie.s are great #or:

reporting 4user de#ined vie.s5

chec%ing apex metadata 4APE<=<<<5

chec%ing d" dictionar 4>SE?=<<<,


A33=<<< and a #e. @A dnamic vie.s5

chec%ing certain #eatures li%e oracle text


metadata and values 4C*<=<<< vie.s5
June 24, 2009 Flavio Casetta - www.yocoya.com 19
per#ormance
June 24, 2009 Flavio Casetta - www.yocoya.com 20
per#ormance

tools #or anal1ing the per#ormance o# an


apex page:

monitor activit reports

apex page de"ug mode

explain plan

trace #iles 0 *BP?OF


June 24, 2009 Flavio Casetta - www.yocoya.com 21
per#ormance

Conitor activit report

Page @ie.s " 6eighted Page Per#ormance

Page @ie.s " Application and Page


June 24, 2009 Flavio Casetta - www.yocoya.com 22
per#ormance
page vie.s " .eighted page per#ormance
June 24, 2009 Flavio Casetta - www.yocoya.com 23
per#ormance
apex page de"ug mode:

turn on de"ug " clic%ing on the 8de"ug: lin% in


the developer2s tool"ar o# apex 4restrictions
appl5

enter de"ug mode " adding YES as #i#th


parameter in the apex >?3

http:77localhost:D,D,7apex7#/pE+&FG':+:,::YES
in all cases de"ug mode must "e ena"led
June 24, 2009 Flavio Casetta - www.yocoya.com 24
per#ormance

inspect de"ug output and spot elapsed


time anomalies
June 24, 2009 Flavio Casetta - www.yocoya.com 25
per#ormance

the most li%el candidates #or "ig delas in


page rendering are non9optimi1ed ;ueries
June 24, 2009 Flavio Casetta - www.yocoya.com 26
per#ormance

the next step is to chec% .hat2s .rong .ith


the ;uer " using explain plan

statistics must "e up9to9date


June 24, 2009 Flavio Casetta - www.yocoya.com 27
per#ormance

the #ull ta"le scan indicates that .e are missing


an index

as the ;uer re#erences three columns, the most


e##ective index .ill contain those three columns

the order o# the columns in the index is important

the analss is carried out entirel using apex


#eatures
June 24, 2009 Flavio Casetta - www.yocoya.com 28
per#ormance

A#ter creating the index, the cost has


decreased dramaticall
June 24, 2009 Flavio Casetta - www.yocoya.com 29
per#ormance

this is con#irmed " the time elapsed


recorded in the de"ug output
June 24, 2009 Flavio Casetta - www.yocoya.com 30
per#ormance

additional considerations a"out the index:

i created a compressed index, consuming


#e.er "loc%s

the ta"le is +,,H static, so i set PC*F?EEE,,


saving even more "loc%s

*he di##erence in the num"er o# "loc%s


"et.een the index created .ith de#ault
parameters and its 8extreme: version is do.n
GGH
June 24, 2009 Flavio Casetta - www.yocoya.com 31
per#ormance
index options comparison
June 24, 2009 Flavio Casetta - www.yocoya.com 32
per#ormance

example o# ;uer involving a single ta"le


hash cluster containing hal# million ro.s
June 24, 2009 Flavio Casetta - www.yocoya.com 33
per#ormance

explain plan o# the ;uer on single ta"le


hash cluster
June 24, 2009 Flavio Casetta - www.yocoya.com 34
per#ormance
.hat .as the di##erence the da a#ter/
June 24, 2009 Flavio Casetta - www.yocoya.com 35
per#ormance

.hen the previousl mentioned techni;ues are


not enough, tracing can "e ena"led

instrumenting the code in the right .a can "e a


li#e sa#er

i# properl designed, code instrumentation can "e


ena"led selectivel, .ith minimal impact .hen it
is not in use and .ithout collecting unnecessar
in#ormation
June 24, 2009 Flavio Casetta - www.yocoya.com 36
per#ormance

ena"ling oracle tracing is eas:

http:77localhost:D,D,7apex7#/pE+&FG':+:,0P=*?ACEEYES

tracing ma%es sense onl i# ou have access to


#olders on the data"ase server 4on a multi9tenant
hosting service this tpe o# action might have
"een restricted " the DIA5
June 24, 2009 Flavio Casetta - www.yocoya.com 37
per#ormance

depending on apex2s con#iguration 4either using


em"edded P37S$3 gate.a as Oracle <E or
Apache J**P server, trace #iles .ill "e #ound in
either in the background_dump_dest #older or in
user_dump_dest

#or shared servers trace #ile name pattern is


sid=snnn=pid!trc

#or dedicated sessions the trace #ile name pattern


is sid=proc=pid_[tracefile_identifier]!trc

user=dump=dest and trace#ile=identi#ier


parameters don2t appl #or shared servers
June 24, 2009 Flavio Casetta - www.yocoya.com 38
per#ormance

in order to spot the relevant S$3 statements


;uic%l, ou can em"ed comments containing
custom identi#iers:

select 7K m=app 3O@=ECP K7 emp=name d, emp=id r


#rom emploees

update order=items
7K m=app m=page=num process x1 K7
set ;t E :PG'=$*Y
.here order=id E :PG'=O?DE?=)D
June 24, 2009 Flavio Casetta - www.yocoya.com 39
P37S$3 and apex
June 24, 2009 Flavio Casetta - www.yocoya.com 40
pl7s;l

apex ma%e2s possi"le to .rite an application


.ithout entering a single line o# P37S$3

Functionalities that don2t come o##9the9shel# ma


re;uire a little or a lot o# custom P37S$3

*he developer must "e a.are o# pros and cons


.hen adopting a method #or executing P37S$3
June 24, 2009 Flavio Casetta - www.yocoya.com 41
pl7s;l

P37S$3 can "e used in man places

Processes 0 Computations

@alidations 0 conditions

Post calculation, item source 0 initiali1ation

?eport ;ueries 0 report headings

Dnamic 3O@s

P37S$3 regions

Authentication #unctions 0 authori1ation schemes

Shortcuts

Supporting O"-ects
June 24, 2009 Flavio Casetta - www.yocoya.com 42
pl7s;l

Given the potential u"i;uit o# P37S$3 inside


apex components, the developer must choose
ho. to handle this source code:

as anonmous "loc%s

as standalone procedures or #unctions

as pac%aged procedures or #unctions


June 24, 2009 Flavio Casetta - www.yocoya.com 43
pl7s;l

anonmous "loc%s are the most straight#or.ard


method to execute pl7s;l

more di##icult to maintain or %eep trac% o#

in case o# an exception the source is exposed

source code cannot "e o"#uscated

edita"le onl inside apex


June 24, 2009 Flavio Casetta - www.yocoya.com 44
pl7s;l

standalone procedures or #unctions can "e


reasona"le i# their num"er is lo.

source code can "e o"#uscated

edita"le inside apex or .ith other s;l clients

potentiall the are reusa"le

potentiall the can inter#ere .ith existing o"-ects


i# installed in a preexisting schema

version management is harder than .ith


pac%ages
June 24, 2009 Flavio Casetta - www.yocoya.com 45
pl7s;l

pac%ages are the .a to go #or large e##orts

source code can "e o"#uscated

edita"le inside apex or .ith other s;l clients

pac%ages are potentiall reusa"le

less prone to con#licts .ith existing o"-ects i#


installed in a preexisting schema

version management is easier than .ith


standalone procedure and #unctions
June 24, 2009 Flavio Casetta - www.yocoya.com 46
pl7s;l

reusa"le procedures and #unctions are the "est


candidates #or inclusion in pac%ages:

logging procedures

"lac% list #iltering

general purpose utilities 4the s.iss9%ni#e o#


each developer5

page #ormatting utilities li%e J*F7J*P #or


di##erent .e" languages
June 24, 2009 Flavio Casetta - www.yocoya.com 47
snapshots or cached reports/
June 24, 2009 Flavio Casetta - www.yocoya.com 48
snapshots or cache

snapshots a%a materiali1ed vie.s can save


considera"le resources

the can "e com"ined .ith cached report regions


to achieve top per#ormance

snapshots come in hand .hen:

ou need to ;uer a column resulting #rom a


com"ination o# multiple columns

ou need to ;uic%l return aggregated results


4sums, averages, etc!5
June 24, 2009 Flavio Casetta - www.yocoya.com 49
snapshots or cache
.eighted page per#ormance 4G .%s5
June 24, 2009 Flavio Casetta - www.yocoya.com 50
snapshots or cache
.eighted page per#ormance 4& .%s5
June 24, 2009 Flavio Casetta - www.yocoya.com 51
snapshots or cache

the signi#icant di##erence .as achieved "


removing a cached region #rom page 1ero

caching is not supported in page 1ero 4a #act not


mentioned in the manual or help, "ut mentioned
in the output log in page de"ug mode 5

.ithout snapshots, upon expiration o# the region


cache, page rendering .ill incur in a signi#icant
increase o# response time

this occurrence can "e eliminated " creating a


snapshot updated in "ac%ground
June 24, 2009 Flavio Casetta - www.yocoya.com 52
snonms and d" lin%s
June 24, 2009 Flavio Casetta - www.yocoya.com 53
snonms and d" lin%s

the main reason #or using snonms is to ma%e


transparent to the application .here the data
come #rom

a snonm can point to an o"-ect:

in the same schema

in another schema

in a remote data"ase 4through a d"9lin%5

the tpe o# target o"-ect can "e decided during


the installation #or instance
June 24, 2009 Flavio Casetta - www.yocoya.com 54
snonms and d" lin%s

developing an application "asing on snonms


can "e tric%

apex does not list pu"lic snonms in .i1ards

it can "e more productive to develop using local


o"-ects that are later replaced " corresponding
snonms

tpical situations are #orms on ta"les, ta"ular


#orms and the ;uer "uilder
June 24, 2009 Flavio Casetta - www.yocoya.com 55
snonms and d" lin%s

another tpical usage #or pu"lic snonms in


apex is to ma%e procedures calla"le "
anonmous users #rom the >?3

creating a pu"lic snonm #or ?PC calls


simpli#ies the >?3 sntax:

...!acme!com7!!!7user!pac%age!procedure/arg+E!!!

...!acme!com7!!!7snonm/arg+E!!!

#or securit reasons the snonm must also "e


8registered: in procedure
..v=#lo.=epg=include=mod=local
June 24, 2009 Flavio Casetta - www.yocoya.com 56
$0A session

Anda mungkin juga menyukai