Secondary Indexes
Secondary Indexes
selecLlon 1he 1eradaLa 8u8MS allows up Lo 32 Sls per Lable 1here are Lwo Lypes of secondary
lndexes
1 unlque Secondary lndexes (uSls)
2 nonunlque Secondary lndexes (nuSls)
1he sysLem malnLalns a separaLe subLable for each secondary lndex SubLables keep base Lable
secondary lndex row hash column values and 8owlu (whlch polnL Lo Lhe row(s)) ln Lhe base
Lable wlLh LhaL value users cannoL access subLables dlrecLly
Secondary lndexes can be deflned for a new Lable uslng C8LA1L 1A8LL or for an exlsLlng Lable
uslng C8LA1L lnuLx
uSl
uSls are always preferable Lo nuSls for access uslng a slngle value 1he usual crlLerlon for
chooslng beLween Lhem ls Lhe lnLended appllcaLlon uaLa Lo be lndexed Lends Lo be elLher
unlque or noL lnherenLly uSls are useful boLh for base Lable access (because uSl access ls aL
worsL a LwoAM operaLlon) and for enforclng daLa lnLegrlLy by applylng a unlqueness
consLralnL on a column seL Llke a unlque prlmary lndex a unlque secondary lndex can be used
Lo guaranLee Lhe unlqueness of each value ln a column seL
uSl ACCLSS
uSl access ls usually a LwoAM operaLlon because a uSl Lyplcally hashes Lo a dlfferenL AM
Lhan Lhe l for Lhe same row lf Lhe uSl subLable row hashes Lo Lhe same AM as Lhe base Lable
row lL polnLs Lo Lhen only one AM ls accessed1he followlng sLages are lnvolved ln a uSl base
Lable row access
- 1he requesLed uSl value ls accessed by hashlng Lo lLs subLable
- 1he polnLer Lo Lhe base Lable row ls read and used Lo access Lhe sLored row dlrecLly
uSl access speclfles a LhreeparL 8?nL1 message LhaL ls ldenLlcal Lo Lhe LhreeparL message
used for prlmary lndex access excepL LhaL Lhe subLable lu ln Lhe message references Lhe uSl
subLable raLher Lhan Lhe base Lable
nuSl
nuSls are parLlcularly useful for range access equallLy and nonequallLy condlLlons Plghly
selecLlve nuSls are useful for reduclng Lhe cosL of frequenLly made selecLlons and [olns
on nonunlque columns and provlde exLremely fasL access for equallLy condlLlons SomeLlmes
however LhaL nuSls wlLh low selecLlvlLy can be less efflclenL Lhan a fullLable scan
nuSls are lmplemenLed on an AMlocal basls Lach AM ls responslble for malnLalnlng only
Lhose nuSl subLable rows LhaL correspond Lo base Lable rows locaLed on LhaL AM Slnce nuSls
allow dupllcaLe lndex values and are based on dlfferenL columns Lhan Lhe l daLa rows
maLchlng Lhe supplled nuSl value could appear on any AM Any AM LhaL does noL have an
lndex row for Lhe nuSl value wlll noL access Lhe base Lable Lo exLracL rows
nuSls are a less preferable secondary lndex cholce for oLher appllcaLlons for several reasons
- nuSl access ls always an allAMs operaLlon
- 8ecause nuSl subLable access ls noL hashed Lhe subLables musL be scanned ln order Lo
locaLe Lhe relevanL polnLers Lo base Lable rows 1hls ls a fasL lookup process when a nuSl ls
speclfled ln an equallLy condlLlon because Lhe nuSl rows are hashordered on each AM
nuSl ACCLSS
nuSl access speclfles a LhreeparL 8?nL1 message LhaL ls ldenLlcal Lo Lhe LhreeparL message
used for prlmary lndex access excepL LhaL Lhe subLable lu ln Lhe message references Lhe nuSl
subLable raLher Lhan Lhe base Lable
8y deflnlLlon Lhere are mulLlple rows per value ln a nuSl lf a nuSl ls noL correlaLed wlLh Lhe
prlmary lndex of lLs base Lable Lhose rows are dlsLrlbuLed among Lhe AMS ln a way LhaL does
noL favor Lhe llkellhood of Lhe CpLlmlzer selecLlng Lhe nuSl Lo access Lhem ln any case when
Lhe number of rows per nuSl value approaches or exceeds Lhe number of AMs ln Lhe sysLem
mulLlple AMs musL be accessed
1he usefulness of a nuSl ls correlaLed wlLh Lhe number of nuSl rows per value Lhe fewer
number of nuSl rows per value Lhe less useful Lhe lndex
Secondary Index Cons|derat|ons
- Sls requlre addlLlonal sLorage Lo hold Lhelr subLables ln Lhe case of a lallback
Lable Lhe Sl subLables are lallback also 1wlce Lhe addlLlonal sLorage space ls
requlred
- Sls requlre addlLlonal l/C Lo malnLaln Lhese subLables
SingIe NUSI Access (Between, Less Than, or Greater Than)
The Teradata RDBMS accesses data Irom a NUSI-deIined column in two ways:
- uLlllze Lhe nuSl and do a lull 1able Scan (l1S) of Lhe nuSl subLable ln Lhls case Lhe 8ow
lus of Lhe quallfylng base Lable rows would be reLrleved lnLo spool 1he 1eradaLa 8u8MS
would use Lhose 8ow lus ln spool Lo access Lhe base Lable rows Lhemselves
- lgnore Lhe nuSl and do an l1S of Lhe base Lable lLself
If the NUSI |s not va|ueordered the system may do a I1S of the NUSI subtab|e
If the NUSI |s ordered by va|ues the NUSI subtab|e |s much more||ke|y be used to |ocate
match|ng base tab|e rows
Dua| NUSI Access
Two NUSIs are created on separate columns oI the table. The Teradata RDBMS decides how to
use these NUSIs based on their selectivity.
AND with EquaIity Conditions:
WII one oI the two indexes is strongly selective, the system uses it alone Ior access.
II both indexes are weakly selective, but together they are strongly selective, the
system does a bit-map intersection.
II both indexes are weakly selective separately and together, the system does an FTS.
# with EquaIity Conditions:
hen accessing data with two NUSI equality conditions joined by the OR, the Teradata RDBMS
may do one oI the Iollowing:
Do a FTS oI the base table.
II each oI the NUSIs is strongly selective, it may use each oI the NUSIs to return the
appropriate rows.
Do an FTS oI the two NUSI subtables and do the Iollowing steps.
Retrieve Rows IDs oI qualiIying base table rows into two separate spools.
Eliminate duplicates Irom the two spools oI Row IDs.
Access the base rows Irom the resulting spool oI Row IDs.