apex schem a

Upload: shobaki

Post on 03-Jun-2018

241 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Apex Schem A

    1/56

    Oracle Application ExpressSchema Design Guidelines

    Presenter: Flavio Casetta, Yoco a!com

  • 8/12/2019 Apex Schem A

    2/56

    a"out me

    Flavio Casetta Founder o# Yoco a!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" +!'

  • 8/12/2019 Apex Schem A

    3/56

  • 8/12/2019 Apex Schem A

    4/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 4

    goals

  • 8/12/2019 Apex Schem A

    5/56

    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 areeas to use, deplo and maintain

    to avoid reinventing the .heelto avoid .riting the same code over and overagain

    the aim o# this presentation is to stress theimportance o# proper data"ase design as astrong #oundation #or our apex applications

  • 8/12/2019 Apex Schem A

    6/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 6

    d" o"-ects mapping to apex components

  • 8/12/2019 Apex Schem A

    7/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 7

    mapping

  • 8/12/2019 Apex Schem A

    8/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 8

    ta"les, vie.s, indexes

  • 8/12/2019 Apex Schem A

    9/56

  • 8/12/2019 Apex Schem A

    10/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 10

    ta"les, vie.s, indexes apex2s ta"le "uilder .i1ard creates onl heap

    ta"les

  • 8/12/2019 Apex Schem A

    11/56

    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

  • 8/12/2019 Apex Schem A

    12/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 12

    ta"les, vie.s, indexes

    heap ta"les are "est #or data that gro.s overtime! *he developer must properl designindexes #or improving data access!

    .hen evaluating the indexes to "e created,consider that an column4s5 declared as #oreign%e 4s5 should "e indexed in order to avoidcontention

    i# using oracle EE, consider using "itmap indexes#or columns containing #e. distinct values onlarge ta"les .ith lo. transactional activit 4li%e#act ta"les in a D65

  • 8/12/2019 Apex Schem A

    13/56

    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 value4.hich is the primar %e o# the )O*5 unli%e ordinar indexes, the primar %e o# an

    )O* cannot "e re"uilt online

  • 8/12/2019 Apex Schem A

    14/56

    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

  • 8/12/2019 Apex Schem A

    15/56

    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 samedata"ase server

    i# deplo ing an application on a multi9tenanthosting 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

  • 8/12/2019 Apex Schem A

    16/56

    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 t pes 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 " aprocedure

  • 8/12/2019 Apex Schem A

    17/56

    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"lelanguage

  • 8/12/2019 Apex Schem A

    18/56

    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

  • 8/12/2019 Apex Schem A

    19/56

  • 8/12/2019 Apex Schem A

    20/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 20

    per#ormance tools #or anal 1ing the per#ormance o# an

    apex page: monitor activit reports apex page de"ug mode explain plan trace #iles 0 *BP?OF

  • 8/12/2019 Apex Schem A

    21/56

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

    per#ormance onitor activit report

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

  • 8/12/2019 Apex Schem A

    22/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 22

    per#ormance

    page vie.s " .eighted page per#ormance

  • 8/12/2019 Apex Schem A

    23/56

    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

    appl 5

    enter de"ug mode " adding YES as #i#thparameter in the apex >?3

    http:77localhost: 7apex7#/p +& ':+: ::YES

    in all cases de"ug mode must "e ena"led

    http://localhost:8080/apex/f?p=12345:1:0::YEShttp://localhost:8080/apex/f?p=12345:1:0::YES
  • 8/12/2019 Apex Schem A

    24/56

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

    per#ormance inspect de"ug output and spot elapsed

    time anomalies

  • 8/12/2019 Apex Schem A

    25/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 25

    per#ormance the most li%el candidates #or "ig dela s in

    page rendering are non9optimi1ed ;ueries

  • 8/12/2019 Apex Schem A

    26/56

    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

  • 8/12/2019 Apex Schem A

    27/56

    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 anal s s is carried out entirel using apex

    #eatures

  • 8/12/2019 Apex Schem A

    28/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 28

    per#ormance A#ter creating the index, the cost has

    decreased dramaticall

  • 8/12/2019 Apex Schem A

    29/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 29

    per#ormance this is con#irmed " the time elapsed

    recorded in the de"ug output

  • 8/12/2019 Apex Schem A

    30/56

    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?EE ,saving even more "loc%s

    *he di##erence in the num"er o# "loc%s"et.een the index created .ith de#aultparameters and its 8extreme version is do.nH

  • 8/12/2019 Apex Schem A

    31/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 31

    per#ormance

    index options comparison

  • 8/12/2019 Apex Schem A

    32/56

  • 8/12/2019 Apex Schem A

    33/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 33

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

    hash cluster

  • 8/12/2019 Apex Schem A

    34/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 34

    per#ormance

    .hat .as the di##erence the da a#ter/

  • 8/12/2019 Apex Schem A

    35/56

    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 itis not in use and .ithout collecting unnecessarin#ormation

  • 8/12/2019 Apex Schem A

    36/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 36

    per#ormance ena"ling oracle tracing is eas :

    http:77localhost: 7apex7#/p +& ':+: 0P=*?ACE YES tracing ma%es sense onl i# ou have access to

    #olders on the data"ase server 4on a multi9tenanthosting service this t pe o# action might have"een restricted " the DIA5

    http://localhost:8080/apex/f?p=12345:1:0&P_TRACE=YEShttp://localhost:8080/apex/f?p=12345:1:0&P_TRACE=YES
  • 8/12/2019 Apex Schem A

    37/56

    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

  • 8/12/2019 Apex Schem A

    38/56

    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 containingcustom identi#iers:

    select 7K m =app 3O@=E P K7 emp=name d, emp=id r#rom emplo ees

    update order=items7K m =app m =page=num process x 1 K7

    set ;t :P '=$*Y.here order=id :P '=O?DE?=)D

  • 8/12/2019 Apex Schem A

    39/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 39

    P37S$3 and apex

  • 8/12/2019 Apex Schem A

    40/56

    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

  • 8/12/2019 Apex Schem A

    41/56

    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 D namic 3O@s P37S$3 regions Authentication #unctions 0 authori1ation schemes Shortcuts Supporting O"-ects

  • 8/12/2019 Apex Schem A

    42/56

    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 chooseho. to handle this source code:

    as anon mous "loc%s as standalone procedures or #unctions as pac%aged procedures or #unctions

  • 8/12/2019 Apex Schem A

    43/56

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

    pl7s;l anon mous "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

  • 8/12/2019 Apex Schem A

    44/56

  • 8/12/2019 Apex Schem A

    45/56

  • 8/12/2019 Apex Schem A

    46/56

    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 #ordi##erent .e" languages

  • 8/12/2019 Apex Schem A

    47/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 47

    snapshots or cached reports/

  • 8/12/2019 Apex Schem A

    48/56

    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

  • 8/12/2019 Apex Schem A

    49/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 49

    snapshots or cache

    .eighted page per#ormance 4 .%s5

  • 8/12/2019 Apex Schem A

    50/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 50

    snapshots or cache

    .eighted page per#ormance 4& .%s5

  • 8/12/2019 Apex Schem A

    51/56

    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 mentionedin the output log in page de"ug mode 5 .ithout snapshots, upon expiration o# the region

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

    this occurrence can "e eliminated " creating asnapshot updated in "ac%ground

  • 8/12/2019 Apex Schem A

    52/56

  • 8/12/2019 Apex Schem A

    53/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 53

    s non ms and d" lin%s

    the main reason #or using s non ms is to ma%etransparent to the application .here the datacome #rom

    a s non m can point to an o"-ect: in the same schema in another schema in a remote data"ase 4through a d"9lin%5

    the t pe o# target o"-ect can "e decided duringthe installation #or instance

  • 8/12/2019 Apex Schem A

    54/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 54

    s non ms and d" lin%s

    developing an application "asing on s non mscan "e tric% apex does not list pu"lic s non ms in .i1ards

    it can "e more productive to develop using localo"-ects that are later replaced " correspondings non ms

    t pical situations are #orms on ta"les, ta"ular#orms and the ;uer "uilder

  • 8/12/2019 Apex Schem A

    55/56

    June 24, 2009 Flavio Casetta - www.yocoya.com 55

    s non ms and d" lin%s another t pical usage #or pu"lic s non ms in

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

    creating a pu"lic s non m #or ?PC calls

    simpli#ies the >?3 s ntax: ...!acme!com7!!!7user!pac%age!procedure/arg+ !!! ...!acme!com7!!!7s non m/arg+ !!!

    #or securit reasons the s non m must also "e8registered in procedure..v=#lo.=epg=include=mod=local

  • 8/12/2019 Apex Schem A

    56/56