All language subtitles for [SubtitleTools.com] B-tree Indexes - Learning Oracle 12c [Video]

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:01,380 --> 00:00:05,100 In this lesson, we'll be looking at B-tree indexes. 2 00:00:05,100 --> 00:00:08,550 So an index, in general, is used for speeding up 3 00:00:08,550 --> 00:00:11,550 the query performance of certain queries. 4 00:00:11,550 --> 00:00:14,760 That is to say, we're querying on a certain column. 5 00:00:14,760 --> 00:00:20,220 And the way a B-tree index works is by organizing a column value 6 00:00:20,220 --> 00:00:22,450 into a tree structure. 7 00:00:22,450 --> 00:00:26,460 So this goes back to the whole full table scan versus index 8 00:00:26,460 --> 00:00:28,000 scan issue. 9 00:00:28,000 --> 00:00:30,970 So if we have a table with a million rows. 10 00:00:30,970 --> 00:00:34,710 Let's say, it's an employee ID that goes from 1 to 1,000,000. 11 00:00:34,710 --> 00:00:37,830 And we search for the employee ID, 12 00:00:37,830 --> 00:00:41,100 let's say, in the column of 500. 13 00:00:41,100 --> 00:00:42,640 What has to occur? 14 00:00:42,640 --> 00:00:47,460 Well, it starts at the first row and says, does one equal 500? 15 00:00:47,460 --> 00:00:48,600 No, go to the next one. 16 00:00:48,600 --> 00:00:49,770 Does two equal 500? 17 00:00:49,770 --> 00:00:51,300 No, go to the next one. 18 00:00:51,300 --> 00:00:53,930 So on and so forth until it gets to 500. 19 00:00:53,930 --> 00:00:55,920 Does 500 equal 500? 20 00:00:55,920 --> 00:00:56,550 Yes. 21 00:00:56,550 --> 00:00:58,410 And so that row is returned. 22 00:00:58,410 --> 00:01:01,260 But that's not enough, because then it has to go to 501. 23 00:01:01,260 --> 00:01:03,600 Is 501 equal to 500? 24 00:01:03,600 --> 00:01:08,280 No, and continues to go down the entire structure of the table. 25 00:01:08,280 --> 00:01:10,500 So that's a full table scan. 26 00:01:10,500 --> 00:01:14,490 And a full table scan can be very resource intensive 27 00:01:14,490 --> 00:01:15,690 and really time consuming. 28 00:01:15,690 --> 00:01:19,350 Because all of those decisions have to be made as the scan 29 00:01:19,350 --> 00:01:20,700 occurs. 30 00:01:20,700 --> 00:01:24,450 When we structure a table into an index, 31 00:01:24,450 --> 00:01:27,330 or basically create an index on the table, 32 00:01:27,330 --> 00:01:31,590 then what we're doing is saying that this column has values 33 00:01:31,590 --> 00:01:34,380 that we will query on, so we want them structured 34 00:01:34,380 --> 00:01:36,420 in a more efficient manner. 35 00:01:36,420 --> 00:01:41,160 So a B-tree index can be created on one or more columns. 36 00:01:41,160 --> 00:01:44,040 But we can't really understand how a B-tree index works 37 00:01:44,040 --> 00:01:46,560 until we discuss the ROWID. 38 00:01:46,560 --> 00:01:50,580 So the ROWID is what's called a pseudocolumn. 39 00:01:50,580 --> 00:01:52,800 It's present in every table, but you 40 00:01:52,800 --> 00:01:57,150 don't see it, although you can specifically select it. 41 00:01:57,150 --> 00:01:59,400 And the ROWID, for the most part, 42 00:01:59,400 --> 00:02:02,640 is going to be a value that's meaningless to us. 43 00:02:02,640 --> 00:02:06,240 It would just be a series of numbers and letters. 44 00:02:06,240 --> 00:02:10,830 But the ROWID is important, because it uniquely identifies 45 00:02:10,830 --> 00:02:14,140 a row in an entire database. 46 00:02:14,140 --> 00:02:17,220 So whereas a primary key might uniquely 47 00:02:17,220 --> 00:02:20,790 identify a row in a table, a ROWID 48 00:02:20,790 --> 00:02:24,330 is almost like a primary key for every row 49 00:02:24,330 --> 00:02:26,760 in the database in every table. 50 00:02:26,760 --> 00:02:29,520 So the ROWID has important information 51 00:02:29,520 --> 00:02:33,840 about the exact location of that row of data, 52 00:02:33,840 --> 00:02:37,320 what block it's in, what table it's in, what segment it's in, 53 00:02:37,320 --> 00:02:40,140 all the way down to that level. 54 00:02:40,140 --> 00:02:45,840 So the fastest way to find a row would be if you knew its ROWID. 55 00:02:45,840 --> 00:02:49,050 However, ROWIDs can change over time 56 00:02:49,050 --> 00:02:51,360 if data is moved, so on, and so forth. 57 00:02:51,360 --> 00:02:55,420 So let's look at what we mean by a B-tree. 58 00:02:55,420 --> 00:02:59,460 So if we take seven values, the numbers 1 through 7, 59 00:02:59,460 --> 00:03:02,970 and we decide that we want to be able to find 60 00:03:02,970 --> 00:03:06,180 any value between 1 and 7, and that we ask it 61 00:03:06,180 --> 00:03:08,940 be in the most efficient manner possible, 62 00:03:08,940 --> 00:03:11,640 we could structure it into a B-tree. 63 00:03:11,640 --> 00:03:13,320 So how does a B-tree work? 64 00:03:13,320 --> 00:03:15,390 Well, it's a decision-making construct 65 00:03:15,390 --> 00:03:17,640 that we can put data into. 66 00:03:17,640 --> 00:03:20,160 So we've created these seven values 67 00:03:20,160 --> 00:03:22,590 and structured them into a B-tree. 68 00:03:22,590 --> 00:03:25,680 So let's say we're looking for the value 5. 69 00:03:25,680 --> 00:03:27,780 So how does a B-tree operate? 70 00:03:27,780 --> 00:03:30,000 So we start at the top of the tree, what's 71 00:03:30,000 --> 00:03:34,740 actually known as the root, and we say, does four equal five? 72 00:03:34,740 --> 00:03:35,970 No, it does not. 73 00:03:35,970 --> 00:03:39,360 And at this point, it can branch in one direction or the other. 74 00:03:39,360 --> 00:03:43,110 If the value is less than four, it'll branch in this direction. 75 00:03:43,110 --> 00:03:46,000 If it is greater than 4, it'll branch in this direction. 76 00:03:46,000 --> 00:03:49,110 So is five less than four? 77 00:03:49,110 --> 00:03:49,890 No. 78 00:03:49,890 --> 00:03:51,600 Is five greater than four? 79 00:03:51,600 --> 00:03:54,690 Yes, and so it moves down this branch. 80 00:03:54,690 --> 00:03:59,130 So what we've already done is exclude almost half the values 81 00:03:59,130 --> 00:04:01,830 in our seven number series. 82 00:04:01,830 --> 00:04:03,450 And so it goes to six. 83 00:04:03,450 --> 00:04:05,170 Is five equal to six? 84 00:04:05,170 --> 00:04:05,670 No. 85 00:04:05,670 --> 00:04:06,840 Is it less than? 86 00:04:06,840 --> 00:04:07,370 Yes. 87 00:04:07,370 --> 00:04:09,240 And it branches down this direction. 88 00:04:09,240 --> 00:04:11,340 Is five equal to five? 89 00:04:11,340 --> 00:04:14,520 Yes, and then it knows it has found that value. 90 00:04:14,520 --> 00:04:17,100 So it's a way of structuring values 91 00:04:17,100 --> 00:04:19,690 to be able to quickly access them. 92 00:04:19,690 --> 00:04:23,130 So how would this possibly apply to a table? 93 00:04:23,130 --> 00:04:25,110 Well let's take those same seven values 94 00:04:25,110 --> 00:04:27,270 and let's say that they are an employee 95 00:04:27,270 --> 00:04:29,730 ID in an employee table. 96 00:04:29,730 --> 00:04:33,030 Every one of those rows associated with those seven 97 00:04:33,030 --> 00:04:36,110 values has a ROWID. 98 00:04:36,110 --> 00:04:38,910 And that ROWID is the exact location 99 00:04:38,910 --> 00:04:40,810 of that particular row. 100 00:04:40,810 --> 00:04:45,090 So now we want employee ID number five 101 00:04:45,090 --> 00:04:47,520 and with it, it's ROWID. 102 00:04:47,520 --> 00:04:49,410 So we go through the B-tree structure, 103 00:04:49,410 --> 00:04:53,280 because we've created a B-tree index on this table 104 00:04:53,280 --> 00:04:55,090 on that particular column. 105 00:04:55,090 --> 00:04:56,910 So we start with value four. 106 00:04:56,910 --> 00:04:58,260 Is four equal to five? 107 00:04:58,260 --> 00:04:59,070 No. 108 00:04:59,070 --> 00:04:59,580 Less than? 109 00:04:59,580 --> 00:05:00,120 No. 110 00:05:00,120 --> 00:05:01,350 Greater than. 111 00:05:01,350 --> 00:05:02,520 Down to six. 112 00:05:02,520 --> 00:05:03,420 Equal to six? . 113 00:05:03,420 --> 00:05:05,140 No Greater than six? 114 00:05:05,140 --> 00:05:05,640 No. 115 00:05:05,640 --> 00:05:07,440 Less than six, yes. 116 00:05:07,440 --> 00:05:11,280 And so now we have found employee ID number five 117 00:05:11,280 --> 00:05:13,350 and with it, its ROWID. 118 00:05:13,350 --> 00:05:16,650 So now we have the exact location of the row. 119 00:05:16,650 --> 00:05:20,070 We didn't have to take all of the values in the row 120 00:05:20,070 --> 00:05:21,840 and structure them in this way. 121 00:05:21,840 --> 00:05:25,630 We only had to structure the column value. 122 00:05:25,630 --> 00:05:28,920 So a table has the employee ID column, 123 00:05:28,920 --> 00:05:32,770 and we create that index on it. 124 00:05:32,770 --> 00:05:36,150 So let's create some indexes. 125 00:05:36,150 --> 00:05:38,580 So we'll start with a table. 126 00:05:38,580 --> 00:05:40,310 Create table location. 127 00:05:40,310 --> 00:05:48,150 We'll have a location ID, location description, employee 128 00:05:48,150 --> 00:05:51,980 name, and arrival date. 129 00:05:55,390 --> 00:05:57,910 So our table is created. 130 00:05:57,910 --> 00:06:01,690 So let's say that we do a number of queries against this table 131 00:06:01,690 --> 00:06:04,510 based on location ID. 132 00:06:04,510 --> 00:06:07,870 And we want to create an index on the location 133 00:06:07,870 --> 00:06:12,580 table, the location ID column, for faster access. 134 00:06:12,580 --> 00:06:15,000 We type create index. 135 00:06:15,000 --> 00:06:20,490 Then give the index a name, location_id_idx. 136 00:06:20,490 --> 00:06:25,620 On, then the table name, and in parentheses, the column 137 00:06:25,620 --> 00:06:27,000 that we're indexing. 138 00:06:27,000 --> 00:06:28,380 We can stop here. 139 00:06:28,380 --> 00:06:33,450 We can also direct what tablespace to put it into. 140 00:06:33,450 --> 00:06:38,010 And our location ID IDX index has been created. 141 00:06:38,010 --> 00:06:40,770 So we also said that we can do an index 142 00:06:40,770 --> 00:06:42,640 on more than one column. 143 00:06:42,640 --> 00:06:46,650 So let's say that we query the location table, 144 00:06:46,650 --> 00:06:49,830 but we don't always query by location ID. 145 00:06:49,830 --> 00:06:53,160 We might have other queries that query location based 146 00:06:53,160 --> 00:06:55,530 on E name and arrival date. 147 00:06:55,530 --> 00:06:57,810 So we need a different index for those. 148 00:06:57,810 --> 00:07:00,390 So essentially we want to take those values 149 00:07:00,390 --> 00:07:02,610 and structure them separately. 150 00:07:02,610 --> 00:07:04,710 Oracle can use that index, and we 151 00:07:04,710 --> 00:07:07,800 can get the benefit, the performance benefit, when 152 00:07:07,800 --> 00:07:09,990 we use those queries, rather than 153 00:07:09,990 --> 00:07:15,190 the queries that would benefit from an index on location IV. 154 00:07:15,190 --> 00:07:17,820 Again, the same. 155 00:07:17,820 --> 00:07:20,400 Call this comp_idx, because we refer 156 00:07:20,400 --> 00:07:22,200 to this as a composite index. 157 00:07:25,740 --> 00:07:32,020 And we simply say column, comma, second column. 158 00:07:32,020 --> 00:07:34,270 On table, and then if we're querying 159 00:07:34,270 --> 00:07:38,650 on E name and arrival date, we put E name, comma, arrival 160 00:07:38,650 --> 00:07:40,190 date. 161 00:07:40,190 --> 00:07:45,340 And composite B-tree index has been created. 12174

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.