Oracle 24p

  • Upload
    prassu1

  • View
    231

  • Download
    0

Embed Size (px)

Citation preview

  • 8/17/2019 Oracle 24p

    1/25

    Data pump Schema Refresh

    Schema refresh is an regular job for any DBA specially during migration projects, so today I decide to post abouta schema refresh. Assuming here schema(SCO! is refreshed from source("#OD! to arget($S! on oracle%%g ser&er S') select banner from &*&ersion+BA$# --------------------------------------------------------------------------------Oracle Database %%g $nterprise $dition #elease %%../../ - 01bit "roduction

    "2S' #elease %%../../ - "roductionCO#$ %%../../ "roductionS for inu34 5ersion %%../../ - "roduction

     S# 5ersion %%../../ - "roductionOn Source side ("#OD! ,Create a directory or use an e3isting directory (e34 data6pump6dir! and grant read and 7rite permissions on thisdirectory to user 8S9S$:8S' ) grant read, 7rite on directory data6pump6dir to system+;rant Succeeded.Step %4 $3porting the data from prod(source!* &i e3pdp6refresh6schema.sh

    * e3pdp system2 scott

    * nohup sh e3pdp6refresh6schema.sh)refresh6schema.out ?Step 4 Copying the dumpfiles from source to target@or copying Dumpfiles from one ser&er to another ser&er 7e can use either inscp(;raphical tool for copyingfiles from 7indo7s to linu3 and &ice &ersa!,@", S@", SC", etc.

    * scp e3pdpschema.dmp system=argetostname42home2oracle2datapump

    ere Im copying dumpfile from source to the target 2home2oracle2datapump locationStep 4 Importing data from dumpfile into target databaseBefore importing dunpfile into target($S! maEe sure you delete or bacEup all the objects in that schema, toclear all objects from particular schema run the script from here

    * impdp system2 scott4ne7scottStep 1 4 5erify target database objects 7ith sourceS') select count($SCO +S') select count($SCO+

    he abo&e results should be same as that of source 8scott schemaConfiguring Kernel Parameters For Oracle 10g Installationhis section documents the checEs and modifications to the inu3 Eernel that should be made by the DBA tosupport Oracle Database 10 g . Before detailing these indi&idual Eernel parameters, it is important to fully understand theEey Eernel components that are used to support the Oracle Database en&ironment.he Eernel parameters and shell limits presented in this section are recommended &alues only as documented by Oracle. @or 

     production database systems, Oracle recommends that 7e tune these &alues to optimiFe the performance of the system.5erify that the Eernel parameters sho7n in this section are set to &alues greater than or eGual to the recommended &alues.Shared Memor ! Shared memory allo7s processes to access common structures and data by placing them in a sharedmemory segment. his is the fastest form of Inter-"rocess Communications (I"C! a&ailable - mainly due to the fact that noEernel in&ol&ement occurs 7hen data is being passed bet7een the processes. Data does not need to be copied bet7een

     processes .Oracle maEes use of shared memory for its Shared ;lobal Area (S;A! 7hich is an area of memory that is shared by allOracle bacEup and foreground processes. AdeGuate siFing of the S;A is critical to Oracle performance since it isresponsible for holding the database buffer cache, shared S', access paths, and so much more.o determine all current shared memory limits, use the follo7ing 4

  • 8/17/2019 Oracle 24p

    2/25

    H ipcs -lm------ Shared :emory imits --------ma3 number of segments > 1/0ma3 seg siFe (Ebytes! > 1%1/ma3 total shared memory (Ebytes! > %/JJ1%K1min seg siFe (bytes! > %

    he follo7ing list describes the Eernel parameters that can be used to change the shared memory configuration for theser&er4

    1"# shmma$  - Defines the ma3imum siFe (in bytes! for a shared memory segment. he Oracle S;A is comprised of sharedmemory and it is possible that incorrectly setting shmma3 could limit the siFe of the S;A. hen setting shmma3, Eeep inmind that the siFe of the S;A should fit 7ithin one shared memory segment. An inadeGuate shmma3 setting could result inthe follo7ing4O#A-J%4 unable to attach to shared memory segmente can determine the &alue of shmma3 by performing the follo7ing 4

    H cat 2proc2sys2Eernel2shmma3%&'%'()&'*

    @or most inu3 systems, the default &alue for shmma3 is :B. his siFe is often too small to configure the Oracle S;A.he default &alue for shmma3 in CentOS L is 1;B 7hich is more than enough for the Oracle configuration. ote that this

    &alue of 1;B is not the MnormalM default &alue for shmma3 in a inu3 en&ironment inserts the follo7ing t7o entries in thefile 2etc2sysctl.conf4

    H Controls the ma3imum shared segment siFe, in bytesEernel.shmma3 > 110JL&"# shmmni  !  his Eernel parameter is used to set the ma3imum number of shared memory segments system 7ide. hedefault &alue for this parameter is 1/0. his &alue is sufficient and typically does not need to be changed. e candetermine the &alue of shmmni by performing the follo7ing4

    H cat 2proc2sys2Eernel2shmmni%0'(

    +"# shmall  4 his parameter controls the total amount of shared memory (in pages! that can be used at one time on the

    system. he &alue of this parameter should al7ays be at least4 e can determine the &alue of shmall by performing thefollo7ing 4

    H cat 2proc2sys2Eernel2shmall&(,%+*%*(

    @or most inu3 systems, the default &alue for shmall is /J%L and is adeGuate for most configurations. he default &aluefor shmall in CentOS L is 0K1L1L0 (see abo&e! 7hich is more than enough for the Oracle configuration described in thisarticle. ote that this &alue of 0K1L1L0 is not the MnormalM default &alue for shmall in a inu3 en&ironment , inserts thefollo7ing t7o entries in the file-etc-ssctl"conf!

    H Controls the ma3imum number of shared memory segments, in pages

    Eernel.shmall > 0K1L1L0%"# shmmin !  his parameter controls the minimum siFe (in bytes! for a shared memory segment. he default &alue for shmmin is % and is adeGuate for the Oracle configuration described in this article.e can determine the &alue of shmmin by

     performing the follo7ing4H ipcs -lm N grep Mmin seg siFeMmin seg siFe (bytes! > %Semaphores !

    After the DBA has configured the shared memory settings, it is time to taEe care of configuring the semaphores. he best7ay to describe a semaphore is as a counter that is used to pro&ide synchroniFation bet7een processes (or threads 7ithin a

     process! for shared resources liEe shared memory. Semaphore sets are supported in System 5 7here each one is a countingsemaphore. hen an application reGuests semaphores, it does so using MsetsM. o determine all current semaphore limits,

    use the follo7ing4H ipcs -ls

    ------ Semaphore imits --------ma3 number of arrays > %Kma3 semaphores per array > L/ma3 semaphores system 7ide > ///

  • 8/17/2019 Oracle 24p

    3/25

    ma3 ops per semop call > semaphore ma3 &alue > J0Je can also use the follo7ing command4H cat 2proc2sys2Eernel2sem&*0 +&000 +& 1&,

    he follo7ing list describes the Eernel parameters that can be used to change the semaphore configuration for the ser&er4i"# semmsl  - his Eernel parameter is used to control the ma3imum number of semaphores per semaphore set. Oraclerecommends setting semmsl to the largest "#OC$SS instance parameter setting in the init.ora file for all databases on theinu3 system plus %/. Also, Oracle recommends setting the semmsl to a &alue of no less than %//.

    ii"# semmni - his Eernel parameter is used to control the ma3imum number of semaphore sets in the entire inu3 system.Oracle recommends setting semmni to a &alue of no less than %//.iii"# semmns - his Eernel parameter is used to control the ma3imum number of semaphores (not semaphore sets! in theentire inu3 system. Oracle recommends setting the semmns to the sum of the "#OC$SS$S instance parameter setting for each database on the system, adding the largest "#OC$SS$S t7ice, and then finally adding %/ for each Oracle database onthe system. se the follo7ing calculation to determine the ma3imum number of semaphores that can be allocated on ainu3 system. It 7ill be the lesser of4S$::S -or- (S$::S < S$::I!

    i."# semopm- his Eernel parameter is used to control the number of semaphore operations that can be performed per semopsystem call. he semop system call (function! pro&ides the ability to do operations for multiple semaphores 7ith one semopsystem call. A semaphore set can ha&e the ma3imum number of semmslsemaphores per semaphore set and is therefore

    recommended to set semopm eGual to semmsl in some situations. Oracle recommends setting the semopm to a &alue of noless than %//.File /andles! hen configuring the inu3 ser&er, it is critical to ensure that the ma3imum number of file handles is largeenough. he setting for file handles denotes the number of open files that you can ha&e on the inu3 system. se thefollo7ing command to determine the ma3imum number of file handles for the entire system4H cat 2proc2sys2fs2file-ma310&+1&

    Oracle recommends that the file handles for the entire system be set to at least 0LL0. e can Guery the current usage of file handles by using the follo7ing 4

    H cat 2proc2sys2fs2file-nr +0)& 0 10&+1&

    he file-nr file displays three parameters4P otal allocated file handlesP Currently used file handlesP :a3imum file handles that can be allocated

    If 7e need to increase the &alue in 2proc2sys2fs2file-ma3, then maEe sure that the ulimit is set properly. sually for inu3 .1and .0 it is set to unlimited. 5erify theulimit setting my issuing the ulimit command 4

    H ulimitunlimitedIP ocal Port Range ! Oracle strongly recommends to set the local port range ip6local6port6range for outgoing messagesto M%/1 0L///M 7hich is needed for systems 7ith high-usage. his Eernel parameter defines the local port range for C"and D" traffic to choose from.he default &alue for ip6local6port6range is ports J0K through 0%/// 7hich is inadeGuate for a successful Oracleconfiguration. se the follo7ing command to determine the &alue of ip6local6port6range4

    H cat 2proc2sys2net2ip&12ip6local6port6rangeJ0K 0%///et2or3ing Settings ! ith Oracle ../.% and later, Oracle maEes use of D" as the default protocol on inu3 for inter-

     process communication (I"C!, such as Cache @usion and Cluster :anager buffer transfers bet7een instances 7ithin the#AC cluster.Oracle strongly suggests to adjust the default and ma3imum recei&e buffer siFe (SO6#C5B@ socEet option! to %:B and

    the default and ma3imum send buffer siFe (SO6SDB@ socEet option! to L0QB.he recei&e buffers are used by C" andD" to hold recei&ed data until it is read by the application. he recei&e buffer cannot o&erflo7 because the peer is notallo7ed to send data beyond the buffer siFe 7indo7.his means that datagrams 7ill be discarded if they donRt fit in the socEet recei&e buffer, potentially causing the sender too&er7helm the recei&er. se the follo7ing commands to determine the current buffer siFe (in bytes! of each of the I"Cnet7orEing parameters4H cat 2proc2sys2net2core2rmem6default

  • 8/17/2019 Oracle 24p

    4/25

    %/L0K

    H cat 2proc2sys2net2core2rmem6ma3%%/J%

    H cat 2proc2sys2net2core27mem6default%/L0K

    H cat 2proc2sys2net2core27mem6ma3

    %%/J%Setting Kernel Parameters for OracleIf the &alue of any Eernel parameter is different to the recommended &alue, they 7ill need to be modified. @or this article, Iidentified and pro&ide the follo7ing &alues that 7ill need to be added to the -etc-ssctl"conf  file 7hich is used during the

     boot process.

    Eernel.shmma3 > %1J1K01KEernel.shmmni > 1/0Eernel.shmall > /J%LEernel.sem > L/ /// %// %Kfs.file-ma3 > 0LL0net.ip&1.ip6local6port6range > %/1 0L///

    net.core.rmem6default > %/1KLJ0net.core.rmem6ma3 > %/1KLJ0net.core.7mem6default > 0%11net.core.7mem6ma3 > 0%11After adding the abo&e lines to the -etc-ssctl"conf file, they persist each time the system reboots. If 7e 7ould liEe to maEe

    these Eernel parameter &alue changes to the current system 7ithout ha&ing to first reboot, enter the follo7ing command4

    H 2sbin2sysctl p

    Resol.ing 4aps in Data 4uard 5ppl 6sing Incremental RM5 75c3up#ecently, 7e had a glitch on a Data ;uard (physical standby database! on infrastructure. his is not a critical database+ sothe monitoring 7as relati&ely la3. And that being done by an outsourcer does not help it either. In any case, the la3nessresulted in a failure remaining undetected for Guite some time and it 7as e&entually disco&ered only 7hen the customer

    complained. his standby database is usually opened for read only access from time totime.his time, ho7e&er, thecustomer sa7 that the data 7as significantly out of sync 7ith primary and raised a red flag. nfortunately, at this time it had

     become a rather political issue. Since the DBA in charge couldnt resol&e the problem, I 7as called in. In this post, I 7illdescribe the issue and ho7 it 7as resol&ed. In summary, there are t7o parts of the problem4(%! hat happened (! o7 to fi3 it8hat /appened

    ets looE at the first Guestion 7hat caused the standby to lag behind. @irst, I looEed for the current SC numbers of the primary and standby databases.On the primar!

    S') select current6scn from &*database+C##$6SC-----------%11J%/On the standb!

    S') select current6scn from &*database+C##$6SC-----------%/%LJ%Clearly there is a difference. But this by itself does not indicate a problem+ since the standby is e3pected to lag behind the

     primary (this is an asynchronous non-real time apply setup!. he real Guestion is ho7 much it is lagging in the terms of 7allclocE. o Eno7 that I used the scn6to6timestamp function to translate the SC to a timestamp4S') select scn6to6timestamp(%11J%/! from dual+SC6O6I:$SA:"(%11J%/!

    -------------------------------%K-D$C-/ /K.L1.K.///////// A:I ran the same Guery to Eno7 the timestamp associated 7ith the SC of the standby database as 7ell (note, I ran it on the

     primary database, though+ since it 7ill fail in the standby in a mounted mode!4S') select scn6to6timestamp(%/%LJ%! from dual+SC6O6I:$SA:"(%/%LJ%!

  • 8/17/2019 Oracle 24p

    5/25

    -------------------------------%L-D$C-/ /J.%.J.///////// ":his sho7s that the standby is t7o and half days laggingT he data at this point is not just stale+ it must be rotten.he ne3t Guestion is 7hy it 7ould be lagging so far bacE in the past. his is a %/. database 7here @A ser&er shouldautomatically resol&ed any gaps in archi&ed logs. Something must ha&e happened that caused the @A (fetch archi&ed log!

     process to fail. o get that ans7er, first, I checEed the alert log of the standby instance. I found these lines that sho7ed theissue clearly4@ri Dec %K /04%40 //aiting for all non-current O#s to be archi&ed...

    :edia #eco&ery aiting for thread % seGuence J//@etching gap seGuence in thread %, gap seGuence J//-J//U U@ri Dec %K /04%4J //@AVclientW4 @ailed to reGuest gap seGuence;A" - thread % seGuence J//-J//DBID K10/0K branch 0J%/K10/@AVclientW4 All defined @A ser&ers ha&e been attempted.4oing bac3 in the alert log9 I found these lines!

    ue Dec %L %J4%04%L //@etching gap seGuence in thread %, gap seGuence J//-J//$rror %L%1 recei&ed logging on to the standby

    @AVclient, :#"/W4 $rror %L%1 connecting to D$% for fetching gap seGuenceue Dec %L %J4%04%L //$rrors in file 2opt2oracle2admin2D$2bdump2del6mrp/6%K/K.trc4O#A-%L%14 S4listener does not currently Eno7 of ser&ice reGuested in connect descriptor ue Dec %L %J4%041L //$rror %L%1 recei&ed logging on to the standby@AVclient, :#"/W4 $rror %L%1 connecting to D$% for fetching gap seGuenceue Dec %L %J4%041L //$rrors in file 2opt2oracle2admin2D$2bdump2del6mrp/6%K/K.trc4O#A-%L%14 S4listener does not currently Eno7 of ser&ice reGuested in connect descriptor his clearly sho7ed the issue. On December %Lth at %J4%04%L, the :anaged #eco&ery "rocess encountered an error 7hilerecei&ing the log information from the primary. he error 7as O#A-%L%1 XS4listener does not currently Eno7 of ser&ice

    reGuested in connect descriptorY. his is usually the case 7hen the S connect string is incorrectly specified. he primaryis called D$% and there is a connect string called D$% in the standby ser&er.he connect string 7orEs 7ell. Actually, right no7 there is no issue 7ith the standby getting the archi&ed logs+ so thereconnect string is fine - no7. he standby is recei&ing log information from the primary. here must ha&e been sometemporary hiccups causing that specific archi&ed log not to tra&el to the standby. If that log 7as someho7 sEipped (could bean intermittent problem!, then it should ha&e been picEed by the @A process later on+ but that ne&er happened. Since theseGuenceH J// 7as not applied, none of the logs recei&ed later J/%, J/ and so on 7ere applied either. his has causedthe standby to lag behind since that time.So, the fundamental Guestion 7as 7hy @A did not fetch the archi&ed log seGuenceH J// from the primary. o get to that, IlooEed into the alert log of the primary instance. he follo7ing lines 7ere of interest4U

    ue Dec %L %4%4LK //hread % ad&anced to log seGuence J/% (;# s7itch!Current logH seGH J/% memH /4 2u/%2oradata2D$%2onlinelog2o%6mf66LbhbEg6.logue Dec %L %4/4 //$rrors in file 2opt2oracle2product2%/g#2db%2admin2D$%2bdump2del%6arc%6%110.trc4O#A-///K4 cannot open archi&ed log R2u/%2orabacE2%6J//60J%/K10/.dbfRO#A-J/J4 unable to obtain file statusinu3 $rror4 4 o such file or directoryAdditional information4 ue Dec %L %4/4 //@AVser&er, A#C%W4 @A archi&e failed, see trace file.ue Dec %L %4/4 //$rrors in file 2opt2oracle2product2%/g#2db%2admin2D$%2bdump2del%6arc%6%110.trc4

    O#A-%0/LL4 @A reGuest rejectedA#C4 @A archi&e failed.Archi&er continuingue Dec %L %4/4 //O#AC$ Instance D$% - Archi&al $rror.Archi&er continuing.U

  • 8/17/2019 Oracle 24p

    6/25

    :hese lines sho2ed e.erthing clearl" :he issue 2as!

    O#A-///K4 cannot open archi&ed log R2u/%2orabacE2%6J//60J%/K10/.dbfRO#A-J/J4 unable to obtain file statusinu3 $rror4 4 o such file or directoryhe archi&ed log simply 7as not a&ailable. he process could not see the file and couldnt get it across to the standby site.pon further in&estigation I found that the DBA actually remo&ed the archi&ed logs to maEe some room in the filesystem7ithout realiFing that his action has remo&ed the most current one 7hich 7as yet to be transmitted to the remote site. hemystery surrounding 7hy the @A did not get that log 7as finally cleared.Solution! o7 that I Eno7 the cause, the focus 7as no7 on the resolution. If the archi&ed log seGuenceH J// 7as a&ailable

    on the primary, I could ha&e easily copied it o&er to the standby, registered the log file and let the managed reco&ery process picE it up. But unfortunately, the file 7as gone and I couldnt just recreate the file. ntil that logfile 7as applied, thereco&ery 7ill not mo&e for7ard. So, 7hat are my optionsZOne option is of course to recreate the standby - possible one but not technically feasible considering the time reGuired. heother option is to apply the incremental bacEup of primary from that SC number. hats the Eey the bacEup must be froma specific SC number. I ha&e described the process since it is not &ery ob&ious. he follo7ing sho7s the step by stepapproach for resol&ing this problem. I ha&e sho7n 7here the actions must be performed VStandbyW or V"rimaryW.1" ;Standb< Stop the managed standb appl process!

    S') alter database reco&er managed standby database cancel+Database altered.&" ;Standb< Shutdo2n the standb database

    +" ;Primar< On the primar9 ta3e an incremental bac3up from the SC number 2here the standb has been stuc3!

    #:A) run [) allocate channel c% type disE format R2u/%2orabacE2\.rmbR+) bacEup incremental from scn %/%LJ% database+1) ]using target database control file instead of reco&ery catalogallocated channel4 c%channel c%4 sid>% de&type>DISQ Starting bacEup at %K-D$C-/channel c%4 starting full datafilebacEupsetchannel c%4 specifying datafile(s! in bacEupsetinput datafilefno>////% name>2u/%2oradata2D$%2datafile2o%6mf6system6LbhbhLc6.dbf U U

     piece handle>2u/%2orabacE2/0l%0u%G6%6%.rmb tag>A;//%%K/K0% comment>O$channel c%4 bacEup set complete, elapsed time4 //4//4/0@inished bacEup at %K-D$C-/released channel4 c%%" ;Primar< On the primar9 create a ne2 standb controlfile!

    S') alter database create standby controlfile as R2u/%2orabacE2D$%6standby.ctlR+Database altered.*" ;Primar< Cop these files to standb host!

    oracle=oradba% 2u/%2orabacEH scp

  • 8/17/2019 Oracle 24p

    7/25

    using target database control file instead of reco&ery catalogsearching for all files that match the pattern 2u/%2orabacE ist of Files 6n3no2n to the Database

    @ile ame4 2u/%2orabacE2D$%6standby.ctl@ile ame4 2u/%2orabacE2/0l%0u%G6%6%.rmb

    Do you really 7ant to catalog the abo&e files (enter 9$S or O!Z yescataloging files...

    cataloging doneist of Cataloged Files

    @ile ame4 2u/%2orabacE2D$%6standby.ctl@ile ame4 2u/%2orabacE2/0l%0u%G6%6%.rmb1&"Reco.er these files! #:A) reco&er database+

    Starting reco&er at %K-D$C-/using channel O#A6DISQ6%channel O#A6DISQ6%4 starting incremental datafilebacEupset restorechannel O#A6DISQ6%4 specifying datafile(s! to restore from bacEup setdestination for restore of datafile ////%4 2u/%2oradata2D$2datafile2o%6mf6system6Llpt77f6.dbf ...U

    channel O#A6DISQ6%4 reading from bacEup piece 2u/%2orabacE2/Ll%0u/6%6%.rmbchannel O#A6DISQ6%4 restored bacEup piece %

     piece handle>2u/%2orabacE2/Ll%0u/6%6%.rmb tag>A;//%%K/K0%channel O#A6DISQ6%4 restore complete, elapsed time4 //4//4/Jstarting media reco.er

    archi&e log thread % seGuence K/% is already on disE as file 2u/%2oradata2%6K/%60J%/K10/.dbf archi&e log thread % seGuence K/% is already on disE as file 2u/%2oradata2%6K/%60J%/K10/.dbf U U1+" 5fter some time9 the reco.er fails 2ith the message!

    archi&e log filename>2u/%2oradata2%6K//K60J%/K10/.dbf thread>% seGuence>K//#:A-//LJ%4 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#:A-//L04 >>>>>>>>>>>>>>> $##O# :$SSA;$ SACQ @OOS >>>>>>>>>>>>>>>

    #:A-//LJ%4 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#:A-///4 failure of reco&er command at %2%K2// /04L4/#:A-%%//4 failure during parse2e3ecution of S' statement4 alter database reco&er logfileR2u/%2oradata2%6K//K60J%/K10/.dbfRO#A-//%/4 archi&ed log contains seGuence K//K+ seGuence K// reGuiredO#A-//14 archi&ed log4 R2u/%2oradata2%6K//K60J%/K10/.dbfRhis happens because 7e ha&e come to the last of the archi&ed logs. he e3pected archi&ed log 7ith seGuenceH K//K has not

     been generated yet.1%"5t this point e$it RM5 and start managed reco.er process!

    S') alter database reco&er managed standby database disconnect from session+Database altered.

    1*"Chec3 the SCs in primar and standb! VStandbyW S') select current6scn from &*database+C##$6SC-----------%11J1J1V"rimaryW S') select current6scn from &*database+

    C##$6SC-----------%11J1JK

     o7 they are &ery close to each other. he standby has no7 caught up.

    O.er.ie2 of Data 8arehousing 2ith Materialied Eie2s! ypically, data flo7s from one or more onlinetransaction processing (O"! databases into a data 7arehouse on a monthly, 7eeEly, or daily basis. he data isusually processed in a staging file before being added to the data 7arehouse. Data 7arehouses typically range in

    siFe from tens of gigabytes to a fe7 terabytes, usually 7ith the &ast majority of the data stored in a fe7 &ery largefact tables. One techniGue employed in data 7arehouses to impro&e performance is the creation of summaries, oraggregates. hey are a special Eind of aggregate &ie7 that impro&es Guery e3ecution times by precalculatinge3pensi&e joins and aggregation operations prior to e3ecution and storing the results in a table in the database. @or e3ample, a table could be created to contain the sum of sales by region and by product. "rior to OracleKi,organiFations using summaries spent a significant amount of time manually creating summaries, identifying

  • 8/17/2019 Oracle 24p

    8/25

    7hich ones to create, inde3ing the summaries, updating them, and ad&ising their users on 7hich ones to use. heintroduction of summary management in the Oracle ser&er eases the 7orEload of the DBA and means the end user no longer has to be a7are of 7hich summaries ha&e been defined. he DBA creates one or more materialiFed&ie7s, 7hich are the eGui&alent of a summary. he end user Gueries the tables and &ie7s in the database and theGuery re7rite mechanism in the Oracle ser&er automatically re7rites the S' Guery to use the summary tables.his mechanism significantly impro&es the response time for returning results from the Guery and eliminates theneed for the end user or database application to be a7are of the materialiFed &ie7s that e3ist 7ithin the data7arehouse. he summaries or aggregates that are referred to in this booE and in literature on data 7arehousing

    are created in Oracle using a schema object called a materialized  view. :aterialiFed &ie7s can perform a numberof roles, such as impro&ing Guery performance or pro&iding replicated data, as described belo7. AlthoughmaterialiFed &ie7s are usually accessed &ia the Guery re7rite mechanism, an end-user or database application canconstruct Gueries that directly access the summaries. o7e&er, serious consideration should be gi&en to 7hetherusers should be allo7ed to do this, because, once the summaries are directly referenced in Gueries, the DBA 7illnot be free to drop and create summaries 7ithout affecting applications.

    Materialied Eie2s for Data 8arehouses! In data 7arehouses, materialiFed &ie7s can be used to precompute and store aggregated data such as the sum of sales. :aterialiFed &ie7s in these en&ironments aretypically referred to as summaries, because they store summariFed data. hey can also be used to precompute

     joins 7ith or 7ithout aggregations. A materialiFed &ie7 eliminates the o&erhead associated 7ith e3pensi&e joinsor aggregations for a large or important class of Gueries.

    Materialied Eie2s for Distributed Computing! In distributed en&ironments, materialiFed &ie7s are usedto replicate data at distributed sites and to synchroniFe updates done at se&eral sites 7ith conflict resolutionmethods. he materialiFed &ie7s as replicas pro&ide local access to data 7hich other7ise 7ould ha&e to beaccessed from remote sites. :aterialiFed &ie7s are also useful in remote data marts.

    Materialied Eie2s for Mobile Computing! 9ou can also use materialiFed &ie7s to do7nload a subset ofdata from central ser&ers to mobile clients, 7ith periodic refreshes from the central ser&ers and propagation ofupdates by clients bacE to the central ser&ers. his chapter focuses on the use of materialiFed &ie7s in data7arehouses.

    :he eed for Materialied Eie2s! :aterialiFed &ie7s are used in data 7arehouses to increase the speedof Gueries on &ery large databases. 'ueries to large databases often in&ol&e joins bet7een tables or aggregations

    such as S:, or both. hese operations are &ery e3pensi&e in terms of time and processing po7er. he type ofmaterialiFed &ie7 that is created determines ho7 the materialiFed &ie7 can be refreshed and used by Gueryre7rite. :aterialiFed &ie7s can be used in a number of 7ays and almost identical synta3 can be used to performa number of roles. @or e3ample, a materialiFed &ie7 can be used to replicate data, 7hich 7as formerly achie&ed

     by using the C#$A$ SA"SO statement. o7 C#$A$ :A$#IAI^$D 5I$ is a synonym forC#$A$ SA"SO. :aterialiFed &ie7s impro&e Guery performance by precalculating e3pensi&e join andaggregation operations on the database prior to e3ecution time and storing the results in the database. he GueryoptimiFer can use materialiFed &ie7s by automatically recogniFing 7hen an e3isting materialiFed &ie7 can andshould be used to satisfy a reGuest. It then transparently re7rites the reGuest to use the materialiFed &ie7. 'ueriesare then directed to the materialiFed &ie7 and not to the underlying detail tables. In general, re7riting Gueries touse materialiFed &ie7s rather than detail tables results in a significant performance gain.

    Figure 8-1 Transparent Query Rewritehen using Guery re7rite, you 7ant to create materialiFed &ie7s that satisfy the largest number of Gueries. @ore3ample, if you identify / Gueries that are commonly applied to the detail or fact tables, then you might be ableto satisfy them 7ith fi&e or si3 7ell-7ritten materialiFed &ie7s. A materialiFed &ie7 definition can include anynumber of aggregations (S:, CO(3!, CO(

    If a materialiFed &ie7 is to be used by Guery re7rite, it must be stored in the same database as its fact or detailtables. A materialiFed &ie7 can be partitioned, and you can define a materialiFed &ie7 on a partitioned table andone or more inde3es on the materialiFed &ie7. :aterialiFed &ie7s are similar to inde3es in se&eral 7ays4 they

    consume storage space, they must be refreshed 7hen the data in their master tables changes, and, 7hen used forGuery re7rite, they impro&e the performance of S' e3ecution and their e3istence is transparent to S'applications and users. nliEe inde3es, materialiFed &ie7s can be accessed directly using a S$$C statement.Depending on the type of refresh that is reGuired, they can also be accessed directly in an IS$#, "DA$, orD$$$ statement. ote! :aterialiFed &ie7s can also be used by Oracle #eplication. he techniGues sho7n inthis chapter illustrate ho7 to use materialiFed &ie7s in data 7arehouses. See Oracle8i Replication for furtherinformation.

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76959/toc.htmhttp://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76959/toc.htm

  • 8/17/2019 Oracle 24p

    9/25

    Oracle pro&ides a set of ad&isory functions in the DB:S6OA" pacEage to help in designing and e&aluating .materialiFed &ie7s for Guery re7rite.

    Components of Summar ManagementSummary management consists of4

    :echanisms to define materialiFed &ie7s and dimensionsA refresh mechanism to ensure that all materialiFed &ie7s contain the latest dataA Guery re7rite capability to transparently re7rite a Guery to use a materialiFed &ie7

    An ad&isor utility to recommend 7hich materialiFed &ie7s to create, retain, and drop:any large decision support system (DSS! databases ha&e schemas that do not closely resemble a con&entionaldata 7arehouse schema, but that still reGuire joins and aggregates. he use of summary management featuresimposes no schema restrictions, and may enable some e3isting DSS database applications to achie&e large gainsin performance 7ithout reGuiring a redesign of the database or application. his functionality is thus a&ailable toall database users.@igure K- illustrates 7here summary management is used in the 7arehousing cycle. After the data has beentransformed, staged, and loaded into the detail data in the 7arehouse, the summary management process can bein&oEed. his means that summaries can be created, Gueries can be re7ritten, and the ad&isor can be used to plansummary usage and creation.Figure 8-2 Overview of Summary Management 

    nderstanding the summary management process during the earliest stages of data 7arehouse design can yieldlarge di&idends later in the form of higher performance, lo7er summary administration costs, and reduced storagereGuirements.he summary management process begins 7ith the creation of dimensions and hierarchies that describe the

     business relationships and common access patterns in the database. An analysis of the dimensions, combined 7ithan understanding of the typical 7orE load, can then be used to create materialiFed &ie7s. :aterialiFed &ie7simpro&e Guery e3ecution performance by precalculating e3pensi&e join or aggregation operations prior toe3ecution time. 'uery re7rite then automatically recogniFes 7hen an e3isting materialiFed &ie7 can and should

     be used to satisfy a reGuest, and can transparently re7rite a reGuest to use a materialiFed &ie7, thus impro&ing performance.

    :erminolog! Some basic data 7arehousing terms are defined as follo7s4

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#38305http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#38305

  • 8/17/2019 Oracle 24p

    10/25

    •   Dimension tables describe the business entities of an enterprise, 7hich usually represent hierarchical,

    categorical information such as time, departments, locations, and products. Dimension tables aresometimes called lookup or reference tables.Dimension tables usually change slo7ly o&er time and are not modified on a periodic schedule. hey aretypically not large, but they affect the performance of long-running decision support Gueries that consist of 

     joins of fact tables 7ith dimension tables, follo7ed by aggregation to specific le&els of the dimensionhierarchies. Dimensions and dimension tables are discussed in Chapter , MDimensionsM.

    •  Fact tables describe the business transactions of an enterprise. @act tables are sometimes called detail

    tables.he &ast majority of data in a data 7arehouse is stored in a fe7 &ery large fact tables. hey are updated

     periodically 7ith data from one or more operational online transaction processing (O"! databases.

    @act tables include measures such as sales, units, and in&entory.

    o A simple measure is a numeric or character column of one table such as @AC.SA$S.

    o A computed measure is an e3pression in&ol&ing only simple measures of one table, for e3ample,

    @AC.#$5$$S - @AC.$_"$S$S.

    o A multi-table measure is a computed measure defined on multiple tables, for e3ample,

    @AC6A.#$5$$S - @AC6B.$_"$S$S.

    @act tables also contain one or more keys that organiFe the business transactions by the rele&ant businessentities such as time, product, and marEet. In most cases, the fact Eeys are non-null, form a uniGuecompound Eey of the fact table, and join 7ith e3actly one ro7 of a dimension table.

    •   A materialized view is a pre-computed table comprising aggregated and2or joined data from fact and

     possibly dimension tables. Builders of data 7arehouses 7ill Eno7 a materialiFed &ie7 as a summary or

    aggregation.

    Schema Design 4uidelines for Materialied Eie2sA materialiFed &ie7 definition can include any number of aggregates, as 7ell as any number of joins. In se&eral7ays, a materialiFed &ie7 beha&es liEe an inde34

    • he purpose of a materialiFed &ie7 is to increase reGuest e3ecution performance.

    • he e3istence of a materialiFed &ie7 is transparent to S' applications, so a DBA can create or drop

    materialiFed &ie7s at any time 7ithout affecting the &alidity of S' applications.

    • A materialiFed &ie7 consumes storage space.

    • he contents of the materialiFed &ie7 must be updated 7hen the underlying detail tables are modified.

    Before starting to define and use the &arious components of summary management, you should re&ie7 yourschema design to, 7here&er possible, abide by the follo7ing guidelines4

    4uideline

    1!

    9our dimensions should either be denormaliFed (each dimension contained in one table! orthe joins bet7een tables in a normaliFed or partially normaliFed dimension shouldguarantee that each child-side ro7 joins 7ith e3actly one parent-side ro7. he benefits of

    maintaining this condition are described in MCreating a DimensionM.

    If desired, this condition can be enforced by adding @O#$I; Q$9 and O constraints on the child-side join Eey(s! and "#I:A#9 Q$9 constraints on the parent-side

     join Eey(s!. If your materialiFed &ie7 contains only a single detail table, or if it performs no

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/dimensio.htm#11221http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/dimensio.htm#11269http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/dimensio.htm#11221http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/dimensio.htm#11269

  • 8/17/2019 Oracle 24p

    11/25

    aggregation, a preferred alternati&e 7ould be to use Gueries containing outer joins in placeof inner joins. In this case, the Oracle optimiFer can guarantee the integrity of the result7ithout enforced referential integrity constraints.

    4uideline

    &!

    If dimensions are denormaliFed or partially denormaliFed, hierarchical integrity must bemaintained bet7een the Eey columns of the dimension table. $ach child Eey &alue mustuniquely identify its parent Eey &alue, e&en if the dimension table is denormaliFed.ierarchical integrity in a denormaliFed dimension can be &erified by calling the

    5AIDA$6DI:$SIO procedure of the DB:S6OA" pacEage.

    4uideline

    +!

    @act tables and dimension tables should similarly guarantee that each fact table ro7 joins7ith e3actly one dimension table ro7. his condition must be declared, and optionallyenforced, by adding @O#$I; Q$9 and O constraints on the fact Eeycolumn(s! and "#I:A#9 Q$9 constraints on the dimension Eey column(s!, or by usingouter joins as described in ;uideline %. In a data 7arehouse, constraints are typicallyenabled 7ith the O5AIDA$ and #$9 options to a&oid constraint enforcement

     performance o&erhead.

    4uideline

    %!

    Incremental loads of your detail data should be done using the S'

  • 8/17/2019 Oracle 24p

    12/25

    Materialied Eie2s 2ith oins and 5ggregatesIn data 7arehouses, materialiFed &ie7s 7ould normally contain one of the aggregates sho7n in $3ample belo7.@or fast refresh to be possible, the S$$C list must contain all of the ;#O" B9 columns (if present!, and maycontain one or more aggregate functions. he aggregate function must be one of4 S:, CO(3!,CO( s.store6Eey ;#O" B9 s.store6name+

    $3ample % creates a materialiFed &ie7 store"sales"mv that computes the sum of sales by store. It is deri&ed by joining the tables store and fact  on the column store"key. he materialiFed &ie7 does not initially contain anydata because the build method is D$@$##$D. A complete refresh is reGuired for the first refresh of a builddeferred materialiFed &ie7. hen it is refreshed, a complete refresh is performed and, once populated, thismaterialiFed &ie7 can be used by Guery re7rite.Create Materialied Eie2! ?$ample & C#$A$ :A$#IAI^$D 5I$ store6stdcnt6m& "C@#$$ / AB$S"AC$ m&ie7s SO#A;$ (IIIA %0E $_ %0E"CIC#$AS$ /! BID I::$DIA$ #$@#$S @AS $AB$ '$#9 #$#I$ AS S$$C store6name, t.time6Eey,SDD$5(unit6sales! AS stdcnt6unit6sales A5;(unit6sales! AS a&gcnt6unit6sales CO(unit6sales! AS count6daysS:(unit6sales! AS sum6unit6sales @#O: store s, fact f, time t $#$ s.store6Eey > f.store6Eey AD f.time6Eey > t.time6Eey;#O" B9 store6name, t.time6Eey+

    he statement abo&e creates a materialiFed &ie7 store"stdcnt"mv that computes the standard de&iation for thenumber of units sold by a store on a gi&en date# It is deri&ed by joining the tables store$ time$ and fact  on thecolumns store6Eey and time6Eey. he materialiFed &ie7 is populated 7ith data immediately because the buildmethod is immediate and it is a&ailable for use by Guery re7rite. In this e3ample, the default refresh method is

    @AS, 7hich is allo7ed because the CO and S: aggregates ha&e been included to support fast refresh ofthe SDD$5 aggregate.

    SingleG:able 5ggregate Materialied Eie2s! A materialiFed &ie7 that contains one or more aggregates(S:, A5;, 5A#IAC$, SDD$5, CO! and a ;#O" B9 clause may be based on a single table. heaggregate function can in&ol&e an e3pression on the columns such as S:(a

      In this e3ample, a materialiFed &ie7 has been created 7hich contains aggregates on a single table. Because thematerialiFed &ie7 log has been created, the materialiFed &ie7 is fast refreshable. If D: is applied against thefact table, then, 7hen the commit is issued, the changes 7ill be reflected in the materialiFed &ie7.able K-% illustrates the aggregate reGuirements for a single-table aggregate materialiFed &ie7.Table 8-1 Single-Table Aggregate Reuirements

    If aggregate H is present9 aggregate is reJuired and aggregate is

    optional

    H

    CO(e3pr! - -

    S:(e3pr! CO(e3pr! -

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#42223http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#42223

  • 8/17/2019 Oracle 24p

    13/25

    If aggregate H is present9 aggregate is reJuired and aggregate is

    optional

    H

    A5;(e3pr! CO(e3pr! S:(e3pr!

    SDD$5(e3pr! CO(e3pr! S:(e3pr < e3pr!

    5A#IAC$(e3pr! CO(e3pr! S:(e3pr < e3pr!

     ote that CO(

    If you specify #$@#$S @AS, Oracle performs further &erification of the Guery definition to ensure that fastrefresh can be performed if an of the detail tables change. hese additional checEs include4

    % A materialiFed &ie7 log must be present for each detail table.

    % he ro7ids of all the detail tables must appear in the S$$C list of the materialiFed &ie7 Guerydefinition.

    % If there are outer joins, uniGue constraints must e3ist on the join columns of the inner table.@or e3ample, if you are joining the fact and a dimension table and the join is an outer join 7ith the facttable being the outer table, there must e3ist uniGue constraints on the join columns of the dimension table.

    If some of the abo&e restrictions are not met, then the materialiFed &ie7 should be created as #$@#$S @O#C$to taEe ad&antage of incremental refresh 7hen it is possible. If the materialiFed &ie7 is created as O CO::I,Oracle performs all of the fast refresh checEs. If one of the tables did not meet all of the criteria, but the othertables did, the materialiFed &ie7 7ould still be incrementally refreshable 7ith respect to the other tables for 7hichall the criteria are met.In a data 7arehouse star schema, if space is at a premium, you can include the ro7id of the fact table only

     because this is the table that 7ill be most freGuently updated, and the user can specify the @O#C$ option 7henthe materialiFed &ie7 is created.A materialiFed &ie7 log should contain the ro7id of the master table. It is not necessary to add other columns.o speed up refresh, it is recommended that the user create inde3es on the columns of the materialiFed &ie7 that

    stores the ro7ids of the fact table.

    C#$A$ :A$#IAI^$D 5I$ O; O fact I #OID+ C#$A$ :A$#IAI^$D 5I$ O; O time I #OID+C#$A$ :A$#IAI^$D 5I$ O; O store I #OID+

  • 8/17/2019 Oracle 24p

    14/25

     C#$A$ :A$#IAI^$D 5I$ detail6fact6m& "A#A$ BID I::$DIA$ #$@#$S @AS AS S$$C f.ro7idMfact6ridM, t.ro7id Mtime6ridM, s.ro7id Mstore6ridM, s.store6Eey, s.store6name, f.dollar6sales, f.unit6sales, f.time6Eey @#O: factf, time t, store s $#$ f.store6Eey > s.store6Eey(! AD f.time6Eey > t.time6Eey(!+

    In this e3ample, in order to perform a #$@#$S @AS, uniGue constraints should e3ist on  s#store"key andt#time"key. It is also recommended that inde3es be created on the columns fact"rid , time"rid , and store"rid , asillustrated belo7, 7hich 7ill impro&e the performance of refresh.

    C#$A$ ID$_ m&6i36factrid O detail6fact6m&(fact6rid!+

     Alternati&ely, if the e3ample sho7n abo&e did not include the columns time"rid  and store"rid , and if the refreshmethod 7as #$@#$S @O#C$, then this materialiFed &ie7 7ould be fast refreshable only if the  fact  table 7asupdated but not if the tables time or store 7ere updated.

    C#$A$ :A$#IAI^$D 5I$ detail6fact6m& "A#A$ BID I::$DIA$ #$@#$S @O#C$ AS S$$C f.ro7idMfact6ridM, s.store6Eey, s.store6name, f.dollar6sales, f.unit6sales, f.time6Eey @#O: fact f, time t, store s $#$ f.store6Eey >s.store6Eey(! AD f.time6Eey > t.time6Eey(!+

    Creating a Materialied Eie2! A materialiFed &ie7 can be created 7ith the C#$A$ :A$#IAI^$D5I$ statement or using Oracle $nterprise :anager. he follo7ing command creates the materialiFed &ie7

     store"sales"mv.C#$A$ :A$#IAI^$D 5I$ store6sales6m& "C@#$$ / AB$S"AC$ m&ie7s SO#A;$ (IIIA %0E $_ %0E"CIC#$AS$ /! "A#A$ BID I::$DIA$ #$@#$S CO:"$$ $AB$ '$#9 #$#I$ AS S$$Cs.store6name, S:(dollar6sales! AS sum6dollar6sales @#O: store s, fact f $#$ f.store6Eey > s.store6Eey ;#O" B9s.store6name+

    It is not uncommon in a data 7arehouse to ha&e already created summary or aggregation tables, and the DBAmay not 7ish to repeat this 7orE by building a ne7 materialiFed &ie7. In this instance, the table that alreadye3ists in the database can be registered as a prebuilt  materialiFed &ie7. his techniGue is described inM#egistration of an $3isting :aterialiFed 5ie7M.Once you ha&e selected the materialiFed &ie7s you 7ant to create, follo7 the steps belo7 for each materialiFed&ie7.

    % Do the physical design of the materialiFed &ie7 (e3isting user-defined materialiFed &ie7s do not reGuirethis step!. If the materialiFed &ie7 contains many ro7s, then, if appropriate, the materialiFed &ie7 should

     be partitioned by a time attribute (if possible! and should match the partitioning of the largest or mostfreGuently updated detail or fact table (if possible!. #efresh performance generally benefits from a largenumber of partitions because it can taEe ad&antage of the parallel D: capabilities in Oracle.

    % se the C#$A$ :A$#IAI^$D 5I$ statement to create and, optionally, populate the materialiFed&ie7. If a user-defined materialiFed &ie7 already e3ists, then use the "#$BI clause in the C#$A$:A$#IAI^$D 5I$ statement. Other7ise, use the BID I::$DIA$ clause to populate thematerialiFed &ie7 immediately, or the BID D$@$##$D clause to populate the materialiFed &ie7 at a

    more con&enient time. he materialiFed &ie7 is disabled for use by Guery re7rite until the first#$@#$S, after 7hich it 7ill be automatically enabled, pro&ided the $AB$ '$#9 #$#I$clause has been specified.

    aming! he name of a materialiFed &ie7 must conform to standard Oracle naming con&entions. o7e&er, ifthe materialiFed &ie7 is based on a user-defined prebuilt table, then the name of the materialiFed &ie7 muste3actly match that table name.If you already ha&e a naming con&ention for tables and inde3es, you may consider e3tending this naming schemeto the materialiFed &ie7s so that they are easily identifiable. @or e3ample, instead of naming the materialiFed&ie7 sum"of"sales, it could be called sum"of"sales"mv to denote that this is a materialiFed &ie7 and not a tableor &ie7, for instance.

    Storage Characteristics! nless the materialiFed &ie7 is based on a user-defined prebuilt table, it reGuiresand occupies storage space inside the database. herefore, the storage needs for the materialiFed &ie7 should bespecified in terms of the tablespace 7here it is to reside and the siFe of the e3tents.If you do not Eno7 ho7 much space the materialiFed &ie7 7ill reGuire, then the

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32939http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32939

  • 8/17/2019 Oracle 24p

    15/25

    DB:S6OA".$SI:A$6SI^$ pacEage, 7hich is described in Chapter %L, MSummary Ad&isorM, can pro&ide anestimate on the number of bytes reGuired to store this materialiFed &ie7. his information can then assist thedesign team in determining the tablespace in 7hich the materialiFed &ie7 should reside.

    7uild Methods! 7o build methods are a&ailable for creating the materialiFed &ie7, as sho7n in the follo7ingtable. If you select BID I::$DIA$, the materialiFed &ie7 definition is added to the schema objects in thedata dictionary, and then the fact or detail tables are scanned according to the S$$C e3pression and the results

    are stored in the materialiFed &ie7. Depending on the siFe of the tables to be scanned, this build process can taEea considerable amount of time.An alternati&e approach is to use the BID D$@$##$D clause, 7hich creates the materialiFed &ie7 7ithoutdata, thereby enabling it to be populated at a later date using the DB:S6:5I$.#$@#$S pacEage describedin Chapter %1, Moading and #efreshingM. 

    7uild Method Description

    BID D$@$##$D Create the materialiFed &ie7 definition but do not populate it 7ith data.

    BID I::$DIA$ Create the materialiFed &ie7 and then populate it 7ith data.

    6sed for Luer Re2rite! $&en though a materialiFed &ie7 is defined, it 7ill not automatically be used by theGuery re7rite facility. he clause $AB$ '$#9 #$#I$ must be specified if the materialiFed &ie7 is to

     be considered a&ailable for re7riting Gueries.If this clause is omitted or specified as DISAB$ '$#9 #$#I$ 7hen the materialiFed &ie7 is initiallycreated, the materialiFed &ie7 can subseGuently be enabled for Guery re7rite 7ith the A$# :A$#IAI^$D5I$ statement.If you define a materialiFed &ie7 as BID D$@$##$D, it is also not eligible for Guery re7rite until it is

     populated 7ith data.

    Luer Re2rite Restrictions! 'uery re7rite is not possible 7ith all materialiFed &ie7s. If Guery re7rite is notoccurring 7hen e3pected, checE to see if your materialiFed &ie7 satisfies all of the follo7ing conditions.Materialied Eie2 Restrictions

    % here cannot be non-repeatable e3pressions (#O:, S9SDA$, non-repeatable "2S' functions,and so on! any7here in the defining Guery.

    % here cannot be references to #A or O; #A datatypes or object #$@s.

    % he Guery must be a single-blocE Guery, that is, it cannot contain set functions (IO, :IS, and so

    on!. o7e&er, a materialiFed &ie7 can ha&e multiple Guery blocEs (for e3ample, inline &ie7s in the@#O: clause and subselects in the $#$ or A5I; clauses!.

    1 If the materialiFed &ie7 7as registered as "#$BI, the precision of the columns must agree 7ith the precision of the corresponding S$$C e3pressions unless o&erridden by I #$DC$D"#$CISIO.

    Luer Re2rite Restrictions

    % If a Guery has both local and remote tables, only local tables 7ill be considered for potential re7rite.

    % one of the detail tables can be o7ned by S9S, and the materialiFed &ie7 cannot be o7ned by S9S.

    onGSL :e$t Re2rite Restrictions

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/advisor.htm#11221http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/refresh.htm#11221http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/advisor.htm#11221http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/refresh.htm#11221

  • 8/17/2019 Oracle 24p

    16/25

    % S$$C and ;#O" B9 lists, if present, must be the same in the Guery and the materialiFed &ie7 andmust contain straight columns, that is, no e3pressions are allo7ed in the columns.

    % Aggregate operators must occur only as the outermost part of the e3pression+ that is, aggregates such asA5;(A5;(3!! or A5;(3!A5;(3! are not allo7ed.

    % he $#$ clause must contain only inner or outer eGuijoins, and they can be connected only by ADs. o O#s and no selections on single tables are allo7ed in the $#$ clause.

    % A5I; or CO$C B9 clauses are not allo7ed.

    Refresh Options! hen you define a materialiFed &ie7, you can specify its t7o refresh options4 ho7 to refreshand 7hat type of refresh. If unspecified, the defaults are assumed as O D$:AD and @O#C$.he t7o refresh e3ecution modes are4 O CO::I and O D$:AD. he method you select 7ill affect thetype of materialiFed &ie7 that can be defined.

    RefreshMode Description

    O CO::I #efresh occurs automatically 7hen a transaction that modified one of the materialiFed &ie7Rs

    fact tables commits. Can be used 7ith materialiFed &ie7s on single table aggregates andmaterialiFed &ie7s containing joins only.

    OD$:AD

    #efresh occurs 7hen a user manually e3ecutes one of the a&ailable refresh procedures containedin the DB:S6:5I$ pacEage (#$@#$S, #$@#$S6A6:5I$S,#$@#$S6D$"$D$!.

    If you thinE the materialiFed &ie7 did not refresh, checE the alert log or trace file.If a materialiFed &ie7 fails during refresh at CO::I time, the user has to e3plicitly in&oEe the refresh

     procedure using the DB:S6:5I$ pacEage after addressing the errors specified in the trace files. ntil this isdone, the &ie7 7ill no longer be refreshed automatically at commit time.9ou can specify ho7 you 7ant your materialiFed &ie7s to be refreshed from the detail tables by selecting one offour options4 @O#C$, CO:"$$, @AS, and $5$#.

    RefreshOption Description

    CO:"$$ #efreshes by recalculating the materialiFed &ie7Rs defining Guery.

    @AS #efreshes by incrementally adding the ne7 data that has been inserted into the tables. hene7 data is obtained from the direct path log or from the materialiFed &ie7 logs.

    @O#C$ Applies fast refresh if possible+ other7ise, it applies CO:"$$ refresh.

     $5$# Indicates that the materialiFed &ie7 7ill not be refreshed 7ith the Oracle refreshmechanisms.

    hether the fast refresh option is a&ailable 7ill depend upon the type of materialiFed &ie7. @ast refresh is

    a&ailable for three general classes of materialiFed &ie7s4 materialiFed &ie7s 7ith joins only, materialiFed &ie7s7ith joins and aggregates, and materialiFed &ie7s 7ith aggregates on a single table.4eneral Restrictions on Fast Refresh! he materialiFed &ie7Rs defining Guery is restricted as follo7s4

    • he @#O: list must contain base tables only (that is, no &ie7s!.

  • 8/17/2019 Oracle 24p

    17/25

    • It cannot contain references to non-repeating e3pressions liEe S9SDA$ and #O:.

    • It cannot contain references to #A or O; #A data types.

    • It cannot contain A5I; or CO$C B9 clauses.

    • he $#$ clause can contain only joins and they must be eGui-joins (inner or outer! and all join

     predicates must be connected 7ith ADs. o selection predicates on indi&idual tables are allo7ed.

    • It cannot ha&e subGueries, inline &ie7s, or set functions liEe IO or :IS.

    Restrictions on Fast Refresh on Materialied Eie2s 2ith oins Onl

    Defining Gueries for materialiFed &ie7s 7ith joins only and no aggregates ha&e these restrictions on fast refresh4

    • All restrictions from M;eneral #estrictions on @ast #efreshM.

    • hey cannot ha&e ;#O" B9 clauses or aggregates.

    • If the $#$ clause of the Guery contains outer joins, then uniGue constraints must e3ist on the joincolumns of the inner join table.

    • #o7ids of all the tables in the @#O: list must appear in the S$$C list of the Guery.

    • :aterialiFed &ie7 logs must e3ist 7ith ro7ids for all the base tables in the @#O: list of the Guery.

    • :aterialiFed &ie7s from this category are @AS refreshable after D: or Direct oad to the base tables.

    Restrictions on Fast Refresh on Materialied Eie2s 2ith SingleG:able 5ggregates

    Defining Gueries for materialiFed &ie7s 7ith single-table aggregates ha&e these restrictions on fast refresh4

    • All restrictions from M;eneral #estrictions on @ast #efreshM.

    • hey can only ha&e a single table.

    • he S$$C list must contain all ;#O" B9 columns.

    • $3pressions are allo7ed in the ;#O" B9 and S$$C clauses pro&ided they are the same.

    hey cannot ha&e a $#$ clause.

    • CO(

    • hey cannot ha&e a :I or :A_ function.

    • @or a materialiFed &ie7 7ith an aggregate 7ith a single table, a materialiFed &ie7 log must e3ist on the

    table and must contain all columns referenced in the materialiFed &ie7. he log must ha&e been created7ith the ICDI; $ 5A$S clause.

    • If A5;(e3pr! or S:(e3pr! is specified, you must ha&e CO(e3pr!.

    • If 5A#IAC$(e3pr! or SDD$5(e3pr! is specified, you must ha&e CO(e3pr! and S:(e3pr!.

    Restrictions on Fast Refresh on Materialied Eie2s 2ith oins and 5ggregates!

    Defining Gueries for materialiFed &ie7s 7ith joins and aggregates ha&e these restrictions on fast refresh4

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#40960http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#40960http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#40960http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#40960

  • 8/17/2019 Oracle 24p

    18/25

    • All restrictions from M;eneral #estrictions on @ast #efreshM.

    • he $#$ clause can contain inner eGui-joins only (that is, no outer joins!

    • :aterialiFed &ie7s from this category are @AS refreshable after Direct oad to the base tables+ they are

    not @AS refreshable after con&entional D: to the base tables.

    • :aterialiFed &ie7s from this category can ha&e only the O D$:AD option (that is, no O CO::I

    refresh option is allo7ed!.

    ORD?R 74 An O#D$# B9 clause is allo7ed in the C#$A$ :A$#IAI^$D 5I$ statement. It is onlyused during the initial creation of the materialiFed &ie7. It is not used during a full refresh or an incrementalrefresh. o impro&e the performance of Gueries against large materialiFed &ie7s, store the ro7s in thematerialiFed &ie7 in the order specified in the O#D$# B9 clause. his initial ordering pro&ides physicalclustering of the data. If inde3es are built on the columns by 7hich the materialiFed &ie7 is ordered, accessing thero7s of the materialiFed &ie7 using the inde3 7ill significantly reduce the time for disE I2O due to the physicalclustering. he O#D$# B9 clause is not considered part of the materialiFed &ie7 definition. As a result, there isno difference in the manner in 7hich Oracle detects the &arious types of materialiFed &ie7s (for e3ample,materialiFed join &ie7s 7ith no aggregates!. @or the same reason, Guery re7rite is not affected by the O#D$#B9 clause. his feature is similar to the C#$A$ AB$ ... O#D$# B9 ... capability that e3ists in Oracle. @ore3ample4C#$A$ :A$#IAI^$D 5I$ sum6sales #$@#$S @AS O D$:AD AS  S$$C cityid, CO(

    In the abo&e e3ample, 7e 7ould use the MO#D$# B9 cityidM clause only during the creation of the materialiFed&ie7. he materialiFed &ie7 definition is not affected by the O#D$# B9 clause. he definition is4

    S$$C cityid, CO(

    6sing Oracle ?nterprise Manager! A materialiFed &ie7 can also be created using Oracle $nterprise

    :anager by selecting the materialiFed &ie7 object type. here is no difference in the information reGuired if thisapproach is used. o7e&er, there are three property sheets 7hich must be completed and you need to ensure thatthe option M$nable 'uery #e7riteM on the ;eneral sheet is selected.

    ested Materialied Eie2s4 A nested materialiFed &ie7 is a materialiFed &ie7 7hose definition is based onanother materialiFed &ie7. A nested materialiFed &ie7 may reference other relations in the database in addition tomaterialiFed &ie7s.

    8h 6se ested Materialied Eie2s In a data 7arehouse, you typically create many aggregate &ie7s on asingle join (for e3ample, rollups along different dimensions!. Incrementally maintaining these distinctmaterialiFed aggregate &ie7s can taEe a long time because the underlying join has to be performed many times.By using nested materialiFed &ie7s, the join is performed just once (7hile maintaining the materialiFed &ie7

    containing joins only! and incremental maintenance of single-table aggregate materialiFed &ie7s is &ery fast dueto the self-maintenance refresh operations on this class of &ie7s. sing nested materialiFed &ie7s also o&ercomesthe limitation posed by materialiFed aggregate &ie7s, 7here incremental maintenance can only be done 7ithdirect-load insert.

    Rules for 6sing ested Materialied Eie2s9ou should Eeep a couple of points in mind 7hen deciding 7hether to use nested materialiFed &ie7s.

    % If you do not need the @AS #$@#$S clause, then you can define a nested materialiFed &ie7.

    % :aterialiFed &ie7s 7ith joins only and single-table aggregate materialiFed &ie7s can be #$@#$S @ASand nested if all the materialiFed &ie7s that they depend on are either materialiFed join &ie7s or single-table aggregate materialiFed &ie7s.

    Restrictions 2hen 6sing ested Materialied Eie2s! Only nested materialiFed join &ie7s and nestedsingle-table aggregate materialiFed &ie7s can use incremental refresh. If you 7ant complete refresh for all of your materialiFed &ie7s, then you can still nest these materialiFed &ie7s.:aterialiFed join &ie7s and single-table aggregate materialiFed &ie7s can be incrementally refreshed in the

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#40960http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#40960

  • 8/17/2019 Oracle 24p

    19/25

     presence of arbitrary D:. In addition, the O CO::I refresh mode can be used 7ith these types ofmaterialiFed &ie7s. o ma3imiFe performance 7ith materialiFed join &ie7s and single-table aggregatematerialiFed &ie7s, you should first combine the t7o together. hat is, define a single-table aggregatematerialiFed &ie7 on top of a materialiFed join &ie7. Such a composition yields a materialized aggregate view 7ith respect to the base tables. hus, logically4single-table aggregate materialiFed &ie7 (materialiFed join &ie7 (tables)!!

    is eGui&alent to4 materialiFed &ie7 7ith joins and aggregates(tables)!Figure 8-! "este# Materiali$e# %iew &uivalents

    @igure K- is just one of many possible 7ays to nest materialiFed &ie7s, but it is liEely to be the most freGuentand practical. Cyclic dependencies (a materialiFed &ie7 that indirectly references itself! are caught at creation

    time and an error is generated. Some restrictions are placed on the 7ay you can nest materialiFed &ie7s. Oracleallo7s nesting a materialiFed &ie7 only 7hen all the immediate dependencies of the materialiFed &ie7 do notha&e any dependencies amongst themsel&es. hus, in the dependency tree, a materialiFed &ie7 can ne&er be a

     parent as 7ell as a grandparent of an object. @or e3ample, @igure K-1, sho7s an impermissible materialiFed &ie7 because it is both a parent and grandparent of the same object.

    Figure 8-' "este# Materiali$e# %iew Restri(tion

    imitations of ested Materialied Eie2s! ested materialiFed &ie7s incur the space o&erhead ofmaterialiFing the join and ha&ing a materialiFed &ie7 log. his is in contrast to materialiFed aggregate &ie7s7here the space reGuirements of the materialiFed join &ie7 and its log are not demanding, but ha&e relati&ely longrefresh times due to multiple computations of the same join.

     ested materialiFed &ie7s are incrementally refreshable under any type of D: 7hile materialiFed aggregate&ie7s are incrementally refreshable under direct-load insert only.

    ?$ample of a ested Materialied Eie2! 9ou can create a materialiFed join &ie7 or a single-table

    aggregate materialiFed &ie7 on a single-table on top of another materialiFed join &ie7, single-table aggregatematerialiFed &ie7, comple3 materialiFed &ie7 (a materialiFed &ie7 Oracle cannot perform incremental refresh on!or base table. All the underlying objects (be they materialiFed &ie7s or tables! on 7hich the materialiFed &ie7 isdefined on must ha&e a materialiFed &ie7 log. All the underlying objects are treated as if they 7ere tables. All thee3isting options for materialiFed join &ie7s and single-table aggregate materialiFed &ie7s can be used. hus, OCO::I refresh is supported for these types of nested materialiFed &ie7s.he follo7ing presents a retail database 7ith an e3ample schema and some materialiFed &ie7s to illustrate ho7nested materialiFed &ie7s can be created.SO#$ (store6Eey, store6name, store6city, store6state, store6country!

    "#ODC (prod6Eey, prod6name, prod6brand!I:$ (time6Eey, time6day, time67eeE, time6month!@AC (store6Eey, prod6Eey, time6Eey, dollar6sales!

     

    2< create the materialiFed &ie7 logs

  • 8/17/2019 Oracle 24p

    20/25

    C#$A$ :A$#IAI^$D 5I$ O; O product I #OID+

    2multi-table aggregate on the tables fact, time, and store 7hose definition is

    S$$C CO( t.time6Eey AD f.store6Eey > s.store6Eey ;#O" B9 store6name, time6day+

    9ou can no7 define a materialiFed join &ie7 %oin"fact"store"time"prod  as a join bet7een %oin"fact"store"time and table product .

    C#$A$ :A$#IAI^$D 5I$ join6fact6store6time6prod #$@#$S @AS O CO::I AS  S$$C j.ro7id jrid, p.ro7id prid, j.store6name, j.prod6Eey, j.prod6name, j.dollar6sales

    @#O: join6fact6store6time j, product p $#$ j.prod6Eey > p.prod6Eey+

    he abo&e schema can be diagrammatically represented as in @igure K-L.Figure 8-) "este# Materiali$e# %iew S(*ema

    esting Materialied Eie2s 2ith oins and 5ggregates:aterialiFed &ie7s 7ith joins and aggregates can be nested if they are refreshed as CO:"$$ #$@#$S.hus, a user can arbitrarily nest materialiFed &ie7s ha&ing joins and aggregates. o incremental maintenance is

     possible for these materialiFed &ie7s. ote that the O CO::I refresh option is not a&ailable for comple3 materialiFed &ie7s. Because you ha&e toin&oEe the refresh functions manually, ordering has to be taEen into account. his is because the refresh for amaterialiFed &ie7 that is built on other materialiFed &ie7s 7ill use the current state of the other materialiFed&ie7s, 7hether they are fresh or not. 9ou can find the dependent materialiFed &ie7s for a particular object usingthe "2S' function ;$6:56D$"$D$CI$S(! in the DB:S6:5I$ pacEage.

    ested Materialied Eie2 6sage 4uidelinesere are some guidelines on ho7 to use nested materialiFed &ie7s4

    % If incremental refresh is desired 7hen a materialiFed &ie7 contains joins and aggregates and standard fastrefresh cannot be used because D: is occurring on the tables, consider creating a single-table aggregatematerialiFed &ie7 nested on a materialiFed join &ie7.

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#39743http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#39743

  • 8/17/2019 Oracle 24p

    21/25

    % If incremental refresh is desired, you should incrementally refresh all the materialiFed &ie7s along anychain. It maEes little sense to define an incrementally refreshable materialiFed &ie7 on top of amaterialiFed &ie7 that must be refreshed 7ith a complete refresh.

    % hen using materialiFed join &ie7s and single-table aggregate materialiFed &ie7s, you can define them to be O CO::I or O D$:AD. he choice 7ould depend on the application using the materialiFed&ie7s. If one e3pects the materialiFed &ie7s to al7ays remain fresh, then all the materialiFed &ie7s shouldha&e the O CO::I refresh option. If the time 7indo7 for refresh does not permit refreshing all the

    materialiFed &ie7s at commit time, then the appropriate materialiFed &ie7s could be created 7ith (oraltered to ha&e! the O D$:AD refresh option.

    Registration of an ?$isting Materialied Eie2Some data 7arehouses ha&e implemented materialiFed &ie7s in ordinary user tables. Although this solution

     pro&ides the performance benefits of materialiFed &ie7s, it does not4

    •  pro&ide Guery re7rite to all S' applications

    • enable materialiFed &ie7s defined in one application to be transparently accessed in another application

    • generally support fast parallel or fast incremental materialiFed &ie7 refresh

    Because of these problems, and because e3isting materialiFed &ie7s may be e3tremely large and e3pensi&e torebuild, you should register your e3isting materialiFed &ie7 tables 7ith Oracle 7hene&er possible. 9ou canregister a user-defined materialiFed &ie7 7ith the C#$A$ :A$#IAI^$D 5I$ ... O "#$BI AB$statement. Once registered, the materialiFed &ie7 can be used for Guery re7rites or maintained by one of therefresh methods, or both.In some cases, user-defined materialiFed &ie7s are refreshed on a schedule that is longer than the update cycle+for e3ample, a monthly materialiFed &ie7 may be updated only at the end of each month, and the materialiFed&ie7 &alues al7ays refer to complete time periods. #eports 7ritten directly against these materialiFed &ie7s

    implicitly select only data that is not in the current (incomplete! time period. If a user-defined materialiFed &ie7already contains a time dimension4

    • It should be registered and then incrementally refreshed each update cycle.

    • A &ie7 should be created that selects the complete time period of interest.

    @or e3ample, if a materialiFed &ie7 7as formerly refreshed monthly at the end of each month, then the&ie7 7ould contain the selection $#$ time.mont&  C##$6:O(!.

    • he reports should be modified to refer to the &ie7 instead of referring directly to the user-defined

    materialiFed &ie7.

    If the user-defined materialiFed &ie7 does not contain a time dimension, then4

    • A ne7 materialiFed &ie7 should be created that does include the time dimension (if possible!.

    • he &ie7 should aggregate o&er the time column in the ne7 materialiFed &ie7.

    he contents of the table must reflect the materialiFation of the defining Guery at the time you register it as amaterialiFed &ie7, and each column in the defining Guery must correspond to a column in the table that has amatching datatype. o7e&er, you can specify I #$DC$D "#$CISIO to allo7 the precision of columns

    in the defining Guery to be different from that of the table columns.he table and the materialiFed &ie7 must ha&e the same name, but the table retains its identity as a table and cancontain columns that are not referenced in the defining Guery of the materialiFed &ie7. hese e3tra columns areEno7n as unmanaged columns. If ro7s are inserted during a refresh operation, each unmanaged column of thero7 is set to its default &alue. herefore, the unmanaged columns cannot ha&e O constraints unless theyalso ha&e default &alues.

  • 8/17/2019 Oracle 24p

    22/25

    nmanaged columns are not supported by single-table aggregate materialiFed &ie7s or materialiFed &ie7scontaining joins only.:aterialiFed &ie7s based on prebuilt tables are eligible for selection by Guery re7rite pro&ided the parameter'$#96#$#I$6I$;#I9 is set to at least the le&el of #S$D.hen you drop a materialiFed &ie7 that 7as created on a prebuilt table, the table still e3ists--only thematerialiFed &ie7 is dropped.hen a prebuilt table is registered as a materialiFed &ie7 and Guery re7rite is desired, the parameter'$#96#$#I$6I$;#I9 must be set to at least SA$6O$#A$D because, 7hen it is created, the

    materialiFed &ie7 is marEed as unEno7n. herefore, only stale integrity modes can be used.

    C#$A$ AB$ sum6sales6tab "C@#$$ / AB$S"AC$ m&ie7s  SO#A;$ (IIIA %0E $_ %0E "CIC#$AS$ /! AS S$$C f.store6Eey S:(dollar6sales! AS dollar6sales,S:(unit6sales! AS unit6sales, S:(dollar6cost! AS dollar6cost @#O: fact f ;#O" B9 f.store6Eey+

    C#$A$ :A$#IAI^$D 5I$ sum6sales6tab O "#$BI AB$ IO #$DC$D "#$CISIO$AB$ '$#9 #$#I$ AS S$$C f.store6Eey, S:(dollar6sales! AS dollar6sales, S:(unit6sales! AS unit6sales,  S:(dollar6cost! AS dollar6cost @#O: fact f ;#O" B9 f.store6Eey+

    his e3ample illustrates the t7o steps reGuired to register a user-defined table. @irst, the table is created, then thematerialiFed &ie7 is defined using e3actly the same name as the table. his materialiFed &ie7 sum"sales"tab is

    eligible for use in Guery re7rite.Partitioning a Materialied Eie2! Because of the large &olume of data held in a data 7arehouse,

     partitioning is an e3tremely useful option that can be used by the database designer."artitioning the fact tables impro&es scalability, simplifies system administration, and maEes it possible to definelocal inde3es that can be efficiently rebuilt."artitioning a materialiFed &ie7 also has benefits for refresh, since the refresh procedure can use parallel D: tomaintain the materialiFed &ie7. o realiFe these benefits, the materialiFed &ie7 has to be defined as "A#A$and parallel D: must be enabled in the session.hen the data 7arehouse or data mart contains a time dimension, it is often desirable to archi&e the oldestinformation, and then reuse the storage for ne7 information, the rolling 7indo7 scenario. If the fact tables ormaterialiFed &ie7s include a time dimension and are horiFontally partitioned by the time attribute, thenmanagement of rolling materialiFed &ie7s can be reduced to a fe7 fast partition maintenance operations pro&idedthat the unit of data that is rolled out eGuals, or is at least aligned 7ith, the range partitions.If you plan to ha&e rolling materialiFed &ie7s in your 7arehouse, then you should determine ho7 freGuently you

     plan to perform partition maintenance operations, and you should plan to partition fact tables and materialiFed&ie7s to reduce the amount of system administration o&erhead reGuired 7hen old data is aged out.ith the introduction of ne7 partitioning options in OracleKi, you are not restricted to using range partitions. @ore3ample, a composite partition using both a time &alue and, say, a Eey &alue could result in an ideal partitionsolution for your data.An ideal case for using partitions is 7hen a materialiFed &ie7 contains a subset of the data. @or e3ample, this can

     be achie&ed by defining an e3pression of the form $#$ time6Eey R%-OC-%KR in the S$$C e3pression

    for the materialiFed &ie7. o7e&er, if a $#$ clause of this type is included, then Guery re7rite 7ill berestricted to the e'act matc& case, 7hich se&erely restricts 7hen the materialiFed &ie7 is used. o o&ercome this problem, use a partitioned materialiFed &ie7 7ith no $#$ clause and then Guery re7rite 7ill be able to usethe materialiFed &ie7 and it 7ill only search the appropriate partition, thus impro&ing Guery performance.:here are t2o approaches to partitioning a materialied .ie2! %."artitioning the :aterialiFed 5ie7 ."artitioning a "rebuilt able 

    Partitioning the Materialied Eie2! "artitioning a materialiFed &ie7 in&ol&es defining the materialiFed&ie7 7ith the standard Oracle partitioning clauses as illustrated in the e3ample belo7. his e3ample creates amaterialiFed &ie7 called part"sales"mv 7hich uses three partitions, is, by default, fast refreshed, and is eligiblefor Guery re7rite.

    C#$A$ :A$#IAI^$D 5I$ part6sales6m& "A#A$ "A#IIO by #A;$ (time6Eey!  ( "A#IIO time6Eey 5A$S $SS A (O6DA$(R%-%-%JR, RDD-::-9999R!!  "C@#$$ / "CS$D SO#A;$ (IIIA 01E $_ %0E "CIC#$AS$ /! AB$S"AC$ sf%,  "A#IIO month 5A$S $SS A (O6DA$(R%-/%-%KR, RDD-::-9999R!!

    "C@#$$ / "CS$D SO#A;$ IIIA 01E $_ %0E "CIC#$AS$ /! AB$S"AC$ sf, "A#IIO month 5A$S $SS A (O6DA$(R%-/%-%KR, RDD-::-9999R!!  "C@#$$ / "CS$D SO#A;$ (IIIA 01E $_ %0E "CIC#$AS$ /! AB$S"AC$ sf!

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32947http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32948http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32947http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32948

  • 8/17/2019 Oracle 24p

    23/25

    BID D$@$##$D #$@#$S @AS $AB$ '$#9 #$#I$ ASS$$C f.store6Eey, f.time6Eey, S:(f.dollar6sales! AS sum6dol6sales,  S:(f.unit6sales! AS sum6unit6sales @#O: fact f ;#O" B9 f.time6Eey, f.store6Eey+

    Partitioning a Prebuilt :able! Alternati&ely, a materialiFed &ie7 can be registered to a partitioned prebuilttable as illustrated in the follo7ing e3ample4C#$A$ AB$ part6fact6tab( time6Eey, store6Eey, sum6dollar6sales, sum6unit6sale! "A#A$ "A#IIO by #A;$(time6Eey! ( 5A$S $SS A (O6DA$(R%-%-%JR, RDD-::-9999R!!  "C@#$$ / "CS$D SO#A;$ (IIIA 01E $_ %0E "CIC#$AS$ /! AB$S"AC$ sf%,  "A#IIIO month 5A$S $SS A (O6DA$(R%-/%-%KR, RDD-::-9999R!!  "C@#$$ / "CS$D SO#A;$ (IIIA 01E $_ %0E "CIC#$AS$ /! AB$S"AC$ sf, "A#IIO month 5A$S $SS A (O6DA$(R%-/%-%KR, DD-::-9999R!!  "C@#$$ / "CS$D SO#A;$ IIIA 01E $_ %0E "CIC#$AS$ /! AB$S"AC$ sf! ASS$$C f.time6Eey, f.store6Eey, S:(f.dollar6sales! AS sum6dollar6sales,

    S:(f.unit6sales! AS sum6unit6sales @#O: fact f ;#O" B9 f.time6Eey, f.store6Eey+C#$A$ :A$#IAI^$D 5I$ part6fact6tab O "#$BI AB$ $AB$ '$#9 #$#I$ AS S$$C f.time6Eey,f.store6Eey, S:(f.dollar6sales! AS sum6dollar6sales, S:(f.unit6sales! AS sum6unit6sales @#O: fact f ;#O" B9 f.time6Eey, f.store6Eey+

    In this e3ample, the table part"fact"tab has been partitioned o&er three months and then the materialiFed &ie77as registered to use the prebuilt table. his materialiFed &ie7 is eligible for Guery re7rite because the $AB$'$#9 #$#I$ clause has been included.

    Inde$ing Selection for Materialied Eie2s!he t7o main operations on a materialiFed &ie7 are Guery

    e3ecution and incremental refresh, and each operation has different performance reGuirements. 'uery e3ecutionmay need to access any subset of the materialiFed &ie7 Eey columns, and may need to join and aggregate o&er asubset of those columns. ConseGuently, Guery e3ecution usually performs best if there is a single-column bitmapinde3 defined on each materialiFed &ie7 Eey column.In the case of materialiFed &ie7s containing only joins using the fast refresh option, it is highly recommended thatinde3es be created on the columns that contain the ro7ids to impro&e the performance of the refresh operation.If a materialiFed &ie7 using joins and aggregates is fast refreshable, then an inde3 is automatically created andcannot be disabled.

    In.alidating a Materialied Eie2! Dependencies related to materialiFed &ie7s are automaticallymaintained to ensure correct operation. hen a materialiFed &ie7 is created, the materialiFed &ie7 depends on

    the detail tables referenced in its definition. Any DD operation, such as a D#O" or A$#, on any dependencyin the materialiFed &ie7 7ill cause it to become in&alid.A materialiFed &ie7 is automatically re&alidated 7hen it is referenced. In many cases, the materialiFed &ie7 7ill

     be successfully and transparently re&alidated. o7e&er, if a column has been dropped in a table referenced by amaterialiFed &ie7 or the o7ner of the materialiFed &ie7 did not ha&e one of the Guery re7rite pri&ileges and thathas no7 been granted to the o7ner, the command4

    A$# :A$#IAI^$D 5I$ m&ie76name $AB$ '$#9 #$#I$

    should be used to re&alidate the materialiFed &ie7. If there are any problems, an error 7ill be returned.he state of a materialiFed &ie7 can be checEed by Guerying the tables S$#6:5I$S or A6:5I$S. he

    column SA$$SS 7ill sho7 one of the &alues @#$S, SA$, SAB$, QO, orD$@I$D to indicate 7hether the materialiFed &ie7 can be used.

    Securit Issues! o create a materialiFed &ie7, the pri&ilege C#$A$ :A$#IAI^$D 5I$ is reGuired,and to create a materialiFed &ie7 that references a table in another schema, you must ha&e S$$C pri&ileges onthat table. :oreo&er, if you enable Guery re7rite, you must ha&e the '$#9 #$#I$ or ;OBA '$#9#$#I$ pri&ilege to reference tables in your o7n schema. o enable Guery re7rite on a materialiFed &ie7 thatreferences tables outside your schema, you must ha&e the ;OBA '$#9 #$#I$ pri&ilege.If you continue to get a pri&ilege error 7hile trying to create a materialiFed &ie7 and you belie&e that all thereGuired pri&ileges ha&e been granted, then the problem is most liEely due to a pri&ilege not being grantede3plicitly and trying to inherit the pri&ilege from a role instead. he o7ner of the materialiFed &ie7 must ha&ee3plicitly been granted S$$C access to the referenced tables if they are in a different schema.

    4uidelines for 6sing Materialied Eie2s in a Data 8arehouseDetermining 7hat materialiFed &ie7s 7ould be most beneficial for performance gains is aided by the analysistools of the DB:S6OA" pacEage. Specifically, you can call the DB:S6OA".#$CO::$D6:5 procedureto see a list of materialiFed &ie7s that Oracle recommends based on the statistics and the usage of the targetdatabase.

  • 8/17/2019 Oracle 24p

    24/25

    If you are going to 7rite your o7n materialiFed &ie7s 7ithout the aid of Oracle analysis tools, then use theseguidelines to achie&e ma3imum performance4

    % Instead of defining multiple materialiFed &ie7s on the same tables 7ith the same ;#O" B9 columns but7ith different measures, define a single materialiFed &ie7 including all of the different measures.

    % If your materialiFed &ie7 includes the aggregated measure A5;(3!, also include CO(3! to supportincremental refresh. Similarly, if 5A#IAC$(3! or SDD$5(3! is present, then al7ays include

    CO(3! and S:(3! to support incremental refresh.

    5ltering a Materialied Eie2! here are fi&e amendments that can be made to a materialiFed &ie74

    • change its refresh option (@AS2@O#C$2CO:"$$2$5$#!

    • change its refresh mode (O CO::I2 O D$:AD!

    • recompile

    enable2disable its use for Guery re7rite

    • consider fresh

    All other changes are achie&ed by dropping and then recreating the materialiFed &ie7.he CO:"I$ clause of the A$# :A$#IAI^$D 5I$ statement can be used 7hen the materialiFed &ie7has been in&alidated as described in MIn&alidating a :aterialiFed 5ie7M. his compile process is GuicE, andallo7s the materialiFed &ie7 to be used by Guery re7rite again.

    Dropping a Materialied Eie2! se the D#O" :A$#IAI^$D 5I$ statement to drop a materialiFed&ie7. @or e3ample4 D#O" :A$#IAI^$D 5I$ sales6sum6m&+his command drops the materialiFed &ie7 sales6sum6m&. If the materialiFed &ie7 7as prebuilt on a table, then the

    table is not dropped but it can no longer be maintained 7ith the refresh mechanism. Alternati&ely, you can drop amaterialiFed &ie7 using Oracle $nterprise :anager.

    O.er.ie2 of Materialied Eie2 Management :as3she moti&ation for using materialiFed &ie7s is to impro&e performance, but the o&erhead associated 7ithmaterialiFed &ie7 management can become a significant system management problem. :aterialiFed &ie7management acti&ities include4

    • Identifying 7hat materialiFed &ie7s to create initially

    • Inde3ing the materialiFed &ie7s

    • $nsuring that all materialiFed &ie7s and materialiFed &ie7 inde3es are refreshed properly each time the

    database is updated

    • ChecEing 7hich materialiFed &ie7s ha&e been used

    • Determining ho7 effecti&e each materialiFed &ie7 has been on 7orEload performance

    • :easuring the space being used by materialiFed &ie7s

    •Determining 7hich ne7 materialiFed &ie7s should be created

    • Determining 7hich e3isting materialiFed &ie7s should be dropped

    • Archi&ing old detail and materialiFed &ie7 data that is no longer useful

    http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32950http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32950

  • 8/17/2019 Oracle 24p

    25/25

    After the initial effort of creating and populating the data 7arehouse or data mart, the major administrationo&erhead is the update process, 7hich in&ol&es the periodic e3traction of incremental changes from theoperational systems+ transforming the data+ &erification that the incremental changes are correct, consistent, andcomplete+ bulE-loading the data into the 7arehouse+ and refreshing inde3es and materialiFed &ie7s so that theyare consistent 7ith the detail data.he update process must generally be performed 7ithin a limited period of time Eno7n as the update window.he update 7indo7 depends on the update frequency (such as daily or 7eeEly! and the nature of the business. @or a daily update freGuency, an update 7indo7 of t7o to si3 hours might be typical.

    he update 7indo7 usually displays the time for the follo7ing acti&ities4

    % oading the detail data.

    % pdating or rebuilding the inde3es on the detail data.

    % "erforming Guality assurance tests on the data.

    % #efreshing the materialiFed &ie7s.

    % pdating the inde3es on the materialiFed &ie7s.

    A popular and efficient 7ay to load data into a 7arehouse or data mart is to use S' @AS$! until all the materialiFed &ie7s are refreshed, but enabled atthe session le&el for any users 7ho do not reGuire the materialiFed &ie7s to reflect the data from the latestload (7ith A$# S$SSIO S$ '$#96#$#I$6$AB$D > #$!. o7e&er, as long as'$#96#$#I$6I$;#I9 > $@O#C$D or #S$D, this is not necessary because thesystem ensures that only materialiFed &ie7s 7ith updated data participate in a Guery re7rite.