20
18 Partitioned Tables and Indexes This chapter describes partitioned tables and indexes. It covers the following topics: Introduction to Partitioning Overview of Partitioning Methods Overview of Partitioned Indexes Partitioning to Improve Performance Note: This functionality is available only if you purchase the Partitioning option. Introduction to Partitioning Partitioning addresses key issues in supporting very large tables and indexes by letting you decompose them into smaller and more manageable pieces called partitions. SQL queries and DML statements do not need to be modified in order to access partitioned tables. However, after partitions are defined, DDL statements can access and manipulate individuals partitions rather than entire tables or indexes. This is how partitioning can simplify the manageability of large database objects. Also, partitioning is entirely transparent to applications. Each partition of a table or index must have the same logical attributes, such as column names, datatypes, and constraints, but each partition can have separate physical attributes such as pctfree, pctused, and tablespaces. Partitioning is useful for many different types of applications, particularly applications that manage large volumes of data. OLTP systems often benefit from improvements in manageability and availability, while data warehousing systems benefit from performance and manageability. Note: All partitions of a partitioned object must reside in tablespaces of a single block size. See Also:

Document18

Embed Size (px)

DESCRIPTION

18

Citation preview

18 Partitioned Tables and IndexesThis chapter describes partitioned tables and indexes. It covers the following topics: Introducton to Parttonng Overvew of Parttonng Methods Overvew of Parttoned Indexes Parttonng to Improve PerformanceNote:This functionality is available only if you purchase the Partitioning option.Introduction to PartitioningPartitioning addresses key ssues n supportng very arge tabes and ndexes by ettng you decompose them nto smaer and more manageabe peces caed partitions. SOL queres and DML statements do not need to be moded n orderto access parttoned tabes. However, after parttons are dened, DDL statements can access and manpuate ndvduas parttons rather than entre tabes or ndexes. Ths s how parttonng can smpfy the manageabty of arge database ob|ects. Aso, parttonng s entrey transparent to appcatons.Each partton of a tabe or ndex must have the same ogca attrbutes, such as coumn names, datatypes, and constrants, but each partton can have separate physca attrbutes such as pctfree, pctused, and tabespaces.Parttonng s usefu for many dherent types of appcatons, partcuary appcatons that manage arge voumes of data. OLTP systems often benet from mprovements n manageabty and avaabty, whe data warehousng systems benet from performance and manageabty.Note:All partitions of a partitioned object ust reside in tablespaces of a single bloc! si"e.See Also: "Mutpe Bock Szes" Oracle Database Data Warehousing Guide and Oracle Database Administrator's Guide for more nformaton about parttonngParttonng ohers these advantages: Parttonng enabes data management operatons such data oads, ndex creaton and rebudng, and backup/recovery at the partton eve, rather than on the entre tabe. Ths resuts n sgncanty reduced tmes for these operatons. Parttonng mproves query performance. In many cases, the resuts of a query can be acheved by accessng a subset of parttons, rather than the entre tabe. For some queres, ths technque (caed partition pruning) can provde order-of-magntude gans n performance. Parttonng can sgncanty reduce the mpact of schedued downtme for mantenance operatons.Partton ndependence for partton mantenance operatons ets you perform concurrent mantenance operatons on dherent parttons of the same tabe or ndex. You can aso run concurrent SELECT and DML operatons aganst parttons that are unahected by mantenance operatons. Parttonng ncreases the avaabty of msson-crtca databases f crtca tabesand ndexes are dvded nto parttons to reduce the mantenance wndows, recovery tmes, and mpact of faures. Parttonng can be mpemented wthout requrng any modcatons to your appcatons. For exampe, you coud convert a nonparttoned tabe to a parttoned tabe wthout needng to modfy any of the SELECT statements or DMLstatements whch access that tabe. You do not need to rewrte your appcaton code to take advantage of parttonng.Fgure 18-1 ohers a graphca vew of how parttoned tabes dher from nonparttoned tabes.Figure 18-1 A View of Partitioned Tables#escription of $%igure 18&1 A 'iew of Partitioned Tables$Partition (eyEach row n a parttoned tabe s unambguousy assgned to a snge partton. The partton key s a set of one or more coumns that determnes the partton for each row. Orace automatcay drects nsert, update, and deete operatons to the approprate partton through the use of the partton key. A partton key: Conssts of an ordered st of 1 to 16 coumns Cannot contan a LEVEL, ROWID, or MLSLABEL pseudocoumn or a coumn of type ROWID Can contan coumns that are NULLabePartitioned TablesTabes can be parttoned nto up to 1024K-1 separate parttons. Any tabe can be parttoned except those tabes contanng coumns wth LONG or LONGRAW datatypes. You can, however, use tabes contanng coumns wth CLOB or BLOB datatypes.Note:To reduce dis! use and eory use )specifically* the buffer cache+* you can store tables and partitioned tables in a copressed forat inside the database. This often leads to a better scaleup for read&only operations. Table copression can also speed up ,uery execution. There is* however* a slight cost in -P. overhead.See Also:$Table -opression$Partitioned Index&/rgani"ed TablesYou can partton ndex-organzed tabes by range, st, or hash. Parttoned ndex-organzed tabes are very usefu for provdng mproved manageabty, avaabty, and performance for ndex-organzed tabes. In addton, data cartrdges that use ndex-organzed tabes can take advantage of the abty to partton ther stored data. Common exampes of ths are the Image and interMeda cartrdges.For parttonng an ndex-organzed tabe: Partton coumns must be a subset of prmary key coumns Secondary ndexes can be parttoned - ocay and gobay OVERFLOW data segments are aways equparttoned wth the tabe parttons/verview of Partitioning 0ethodsOrace provdes the foowng parttonng methods: Range Parttonng Lst Parttonng Hash Parttonng Composte ParttonngFgure 18-2 ohers a graphca vew of the methods of parttonng.Figure 18-2 List, Range, and Hash Partitioning#escription of $%igure 18&1 2ist* 3ange* and 4ash Partitioning$Composte parttonng s a combnaton of other parttonng methods. Orace supports range-hash and range-st composte parttonng. Fgure 18-3ohers a graphca vew of range-hash and range-st composte parttonng.Figure 18-3 o!"osite Partitioning#escription of $%igure 18&5 -oposite Partitioning$3ange PartitioningRange parttonng maps data to parttons based on ranges of partton key vaues that you estabsh for each partton. It s the most common type of parttonng and s often used wth dates. For exampe, you mght want to partton saes data nto monthy parttons.When usng range parttonng, consder the foowng rues: Each partton has a VALUES LESS THAN cause, whch speces a nonncusve upper bound for the parttons. Any vaues of the partton key equa to or hgher than ths tera are added to the next hgher partton. A parttons, except the rst, have an mpct ower bound speced by the VALUES LESS THAN cause on the prevous partton. A MAXVALUE tera can be dened for the hghest partton. MAXVALUE represents a vrtua nnte vaue that sorts hgher than any other possbe vaue for the partton key, ncudng the nu vaue.A typca exampe s gven n the foowng secton. The statement creates a tabe (sales_range) that s range parttoned on the sales_date ed.3ange Partitioning 6xapleCREATE TABLE sales_range (salesman_idNUMBER(5), salesman_name VARCHAR2(30), sales_am!n"NUMBER(#0), sales_da"e$ATE)%ART&T&'N B( RAN)E(sales_da"e) (%ART&T&'N sales_*an2000 VALUE+ LE++ THAN(T'_$ATE(,02-0#-2000,,,MM-$$-((((,)),%ART&T&'N sales_.e/2000 VALUE+ LE++ THAN(T'_$ATE(,03-0#-2000,,,MM-$$-((((,)),%ART&T&'N sales_mar2000 VALUE+ LE++ THAN(T'_$ATE(,00-0#-2000,,,MM-$$-((((,)),%ART&T&'N sales_a1r2000 VALUE+ LE++ THAN(T'_$ATE(,05-0#-2000,,,MM-$$-((((,)))22ist PartitioningLst parttonng enabes you to expcty contro how rows map to parttons. You do ths by specfyng a st of dscrete vaues for the parttonng key n the descrpton for each partton. Ths s dherent from range parttonng, where a range of vaues s assocated wth a partton and from hash parttonng, where a hash functon contros the row-to-partton mappng. The advantage of st parttonng s that you can group and organze unordered and unreated sets of data n a natura way.The detas of st parttonng can best be descrbed wth an exampe. In ths case, et's say you want to partton a saes tabe by regon. That means groupng states together accordng to ther geographca ocaton as n the foowng exampe.2ist Partitioning 6xapleCREATE TABLE sales_lis"(salesman_idNUMBER(5), salesman_name VARCHAR2(30),sales_s"a"e VARCHAR2(20),sales_am!n"NUMBER(#0), sales_da"e$ATE)%ART&T&'N B( L&+T(sales_s"a"e)(%ART&T&'N sales_3es" VALUE+(,Cali.rnia,, ,Ha3aii,),%ART&T&'N sales_eas" VALUE+ (,Ne3 (r4,, ,Virginia,, ,5lrida,),%ART&T&'N sales_6en"ral VALUE+(,Te7as,, ,&llinis,),%ART&T&'N sales_"8er VALUE+($E5AULT))2A row s mapped to a partton by checkng whether the vaue of the parttonng coumnfor a row fas wthn the set of vaues that descrbes the partton. For exampe, the rowsare nserted as foows: (1, !"#nes!, !Ha$a%%!, 1, !&'"AN'(!) maps to partton sales_$est ((1, !S)%t*!, !Fl#r%da!, 1&, !1&'"AN'(!) maps to partton sales_east (+(, !Lee!, !C#l#rad#!, 1+, !(1'"AN'(!) maps to partton sales_#t*erUnke range and hash parttonng, mutcoumn partton keys are not supported for st parttonng. If a tabe s parttoned by st, the parttonng key can ony consst of a snge coumn of the tabe.The DEFAULT partton enabes you to avod specfyng a possbe vaues for a st-parttoned tabe by usng a defaut partton, so that a rows that do not map to any other partton do not generate an error.4ash PartitioningHash parttonng enabes easy parttonng of data that does not end tsef to range or st parttonng. It does ths wth a smpe syntax and s easy to mpement. It s a better choce than range parttonng when: You do not know beforehand how much data maps nto a gven range The szes of range parttons woud dher qute substantay or woud be dmcut to baance manuay Range parttonng woud cause the data to be undesraby custered Performance features such as parae DML, partton prunng, and partton-wse |ons are mportantThe concepts of spttng, droppng or mergng parttons do not appy to hash parttons.Instead, hash parttons can be added and coaesced.See Also:Oracle Database Administrator's Guide for ore inforation about partition tas!s such as splitting partitions4ash Partitioning 6xapleCREATE TABLE sales_8as8(salesman_idNUMBER(5), salesman_name VARCHAR2(30), sales_am!n"NUMBER(#0), 3ee4_n NUMBER(2)) %ART&T&'N B( HA+H(salesman_id) %ART&T&'N+ 0 +T'RE &N ("s#, "s2, "s3, "s0)2The precedng statement creates a tabe sales_*as*, whch s hash parttoned on sales)an_%d ed. The tabespace names are ts1, ts(, ts+, andts,. Wth ths syntax, we ensure that we create the parttons n a round-robn manner across the speced tabespaces.-oposite PartitioningComposte parttonng parttons data usng the range method, and wthn each partton, subparttons t usng the hash or st method. Composte range-hash parttonng provdes the mproved manageabty of range parttonng and the data pacement, strpng, and paraesm advantages of hash parttonng. Composte range-st parttonng provdes the manageabty of range parttonng and the expct contro of st parttonng for the subparttons.Composte parttonng supports hstorca operatons, such as addng new range parttons, but aso provdes hgher degrees of paraesm for DML operatons and ner granuarty of data pacement through subparttonng.-oposite Partitioning 3ange&4ash 6xapleCREATE TABLE sales_6m1si"e (salesman_idNUMBER(5), salesman_name VARCHAR2(30), sales_am!n"NUMBER(#0), sales_da"e$ATE)%ART&T&'N B( RAN)E(sales_da"e) +UB%ART&T&'N B( HA+H(salesman_id)+UB%ART&T&'N TEM%LATE(+UB%ART&T&'N s1# TABLE+%ACE "s#,+UB%ART&T&'N s12 TABLE+%ACE "s2,+UB%ART&T&'N s13 TABLE+%ACE "s3,+UB%ART&T&'N s10 TABLE+%ACE "s0)(%ART&T&'N sales_*an2000 VALUE+ LE++ THAN(T'_$ATE(,02-0#-2000,,,MM-$$-((((,)) %ART&T&'N sales_.e/2000 VALUE+ LE++ THAN(T'_$ATE(,03-0#-2000,,,MM-$$-((((,)) %ART&T&'N sales_mar2000 VALUE+ LE++ THAN(T'_$ATE(,00-0#-2000,,,MM-$$-((((,)) %ART&T&'N sales_a1r2000 VALUE+ LE++ THAN(T'_$ATE(,05-0#-2000,,,MM-$$-((((,)) %ART&T&'N sales_ma92000 VALUE+ LE++ THAN(T'_$ATE(,0:-0#-2000,,,MM-$$-((((,)))2Ths statement creates a tabe sales_-#).#s%te that s range parttoned on the sales_date ed and hash subparttoned on sales)an_%d. When you use a tempate, Orace names the subparttons by concatenatng the partton name, an underscore, and the subpartton name from the tempate. Orace paces ths subpartton n the tabespace speced n the tempate. In the prevous statement, sales_/an(_s.1 s created and paced n tabespace ts1 whe sales_/an(_s., s created and paced n tabespace ts,. In the same manner, sales_a.r(_s.1 s created and paced n tabespace ts1 whe sales_a.r(_s., s created and paced n tabespace ts,. Fgure18-4 ohers a graphca vew of the prevous exampe.Figure 18-# o!"osite Range-Hash Partitioning#escription of $%igure 18&7 -oposite 3ange&4ash Partitioning$-oposite Partitioning 3ange&2ist 6xapleCREATE TABLE /imn"8l9_reginal_sales(de1"n NUMBER, i"em_n VARCHAR2(20), "7n_da"e $ATE, "7n_am!n" NUMBER, s"a"e VARCHAR2(2))%ART&T&'N B( RAN)E ("7n_da"e)+UB%ART&T&'N B( L&+T (s"a"e)+UB%ART&T&'N TEM%LATE(+UB%ART&T&'N eas" VALUE+(,N(,, ,VA,, ,5L,) TABLE+%ACE "s#,+UB%ART&T&'N 3es" VALUE+(,CA,, ,'R,, ,H&,) TABLE+%ACE "s2,+UB%ART&T&'N 6en"ral VALUE+(,&L,, ,T;,, ,M',) TABLE+%ACE "s3)(%ART&T&'N *an.e/_2000 VALUE+ LE++ THAN (T'_$ATE(,#