Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,430 --> 00:00:04,900
In this lesson we
discuss bitmap indexes.
2
00:00:04,900 --> 00:00:08,240
So bitmap indexes are
different or distinct
3
00:00:08,240 --> 00:00:10,880
from B-tree indexes,
which we might
4
00:00:10,880 --> 00:00:15,740
consider regular indexes or the
standard index that is used.
5
00:00:15,740 --> 00:00:19,070
Bitmap indexes were designed
because Oracle realized
6
00:00:19,070 --> 00:00:21,650
that certain situations
called for an index,
7
00:00:21,650 --> 00:00:24,200
say, as a large table.
8
00:00:24,200 --> 00:00:29,450
But structuring those values
into a B-tree structure
9
00:00:29,450 --> 00:00:32,810
was not the most efficient
way to do so and really
10
00:00:32,810 --> 00:00:35,060
gave you very little benefit.
11
00:00:35,060 --> 00:00:37,460
So a bitmap index
is a special type
12
00:00:37,460 --> 00:00:41,240
of index for very
specific situations.
13
00:00:41,240 --> 00:00:43,520
So in order to understand
a bitmap index,
14
00:00:43,520 --> 00:00:46,730
you have to understand the
concept of cardinality.
15
00:00:46,730 --> 00:00:52,140
So cardinality is the number
of distinct values in a set.
16
00:00:52,140 --> 00:00:55,820
So if we looked at cardinality
in terms of a table
17
00:00:55,820 --> 00:00:58,600
and the column
values that it has,
18
00:00:58,600 --> 00:01:03,530
let's look at an employee
table that has employee ID.
19
00:01:03,530 --> 00:01:06,260
So the employee ID,
let's say, is different,
20
00:01:06,260 --> 00:01:09,050
is distinct for every employee.
21
00:01:09,050 --> 00:01:12,440
Every employee has a
different employee ID.
22
00:01:12,440 --> 00:01:15,680
So in a million row
table of employees,
23
00:01:15,680 --> 00:01:18,590
there would be a
million different values
24
00:01:18,590 --> 00:01:20,420
for employee ID.
25
00:01:20,420 --> 00:01:24,740
So we refer to that as high
cardinality, a large number
26
00:01:24,740 --> 00:01:26,090
of distinct values.
27
00:01:26,090 --> 00:01:30,290
So high cardinality would
be lots of distinct values.
28
00:01:30,290 --> 00:01:32,390
But what if we had a
column in that table,
29
00:01:32,390 --> 00:01:35,450
in the employee
table, called gender?
30
00:01:35,450 --> 00:01:38,990
So gender, typically going
to have an M for male or F
31
00:01:38,990 --> 00:01:40,610
for female.
32
00:01:40,610 --> 00:01:44,540
So we would refer to that as
a very low cardinality column.
33
00:01:44,540 --> 00:01:48,440
What if we tried to create
a B-tree index on gender,
34
00:01:48,440 --> 00:01:50,250
on the gender column?
35
00:01:50,250 --> 00:01:52,040
Well, if it was
structured, it would simply
36
00:01:52,040 --> 00:01:57,470
have an M and an F, and then
all of the different row IDs
37
00:01:57,470 --> 00:01:59,690
that were possible
underneath it.
38
00:01:59,690 --> 00:02:02,630
So you haven't really
gotten any benefit
39
00:02:02,630 --> 00:02:05,370
from the structure of the data.
40
00:02:05,370 --> 00:02:09,110
You still have to scan through
a large number of values.
41
00:02:09,110 --> 00:02:11,690
So if you looked at
it as 50/50, just
42
00:02:11,690 --> 00:02:14,870
by kind of the numeric
odds, then you've
43
00:02:14,870 --> 00:02:17,090
reduced your one
million row scan
44
00:02:17,090 --> 00:02:20,280
to 500,000 distinct values.
45
00:02:20,280 --> 00:02:22,040
But that's not the
same kind of benefit
46
00:02:22,040 --> 00:02:24,620
that you get from
a B-tree index.
47
00:02:24,620 --> 00:02:28,580
And so a bitmap index
is used when the column
48
00:02:28,580 --> 00:02:31,100
values are low in cardinality.
49
00:02:31,100 --> 00:02:33,740
That is to say, they
have a small number
50
00:02:33,740 --> 00:02:35,780
of distinct values.
51
00:02:35,780 --> 00:02:38,340
Now, we said this is only
for certain situations.
52
00:02:38,340 --> 00:02:43,010
So rule number 1 is low
cardinality in the column.
53
00:02:43,010 --> 00:02:46,190
And what constitutes
low cardinality?
54
00:02:46,190 --> 00:02:48,620
Well, that is
somewhat debatable.
55
00:02:48,620 --> 00:02:51,200
I think generally
Oracle advises that,
56
00:02:51,200 --> 00:02:55,820
if the cardinality of
the column is about 10%--
57
00:02:55,820 --> 00:03:00,020
so about 10% of the
rows in the table
58
00:03:00,020 --> 00:03:02,780
are distinct in those
number of values--
59
00:03:02,780 --> 00:03:05,030
then a bitmap index
can be helpful.
60
00:03:05,030 --> 00:03:09,770
But it is best really to just
test it and try it, and run
61
00:03:09,770 --> 00:03:12,800
explain plans and get
the execution plan,
62
00:03:12,800 --> 00:03:17,360
and see things like the cost,
test how long the query runs,
63
00:03:17,360 --> 00:03:18,970
those types of things.
64
00:03:18,970 --> 00:03:21,560
The other thing that is
important in a bitmap index
65
00:03:21,560 --> 00:03:26,300
is that you have few or
no updates on that column.
66
00:03:26,300 --> 00:03:29,210
Because of the way a
bitmap index is structured,
67
00:03:29,210 --> 00:03:32,780
updates are going to
be a very high resource
68
00:03:32,780 --> 00:03:34,620
intensive operation.
69
00:03:34,620 --> 00:03:38,210
So, if you create a table and
put a lot of bitmap indexes
70
00:03:38,210 --> 00:03:41,150
on it, you're going to find
that your updates of that table,
71
00:03:41,150 --> 00:03:44,360
if they're updating that
value, are going to be slower.
72
00:03:44,360 --> 00:03:48,870
So it's best if you are not
doing updates to the table.
73
00:03:48,870 --> 00:03:51,890
So, if we were to look at the
structure of a bitmap index,
74
00:03:51,890 --> 00:03:54,950
it's quite different
than a B-tree index.
75
00:03:54,950 --> 00:03:59,180
And so what we have are a
value and then its row ID.
76
00:03:59,180 --> 00:04:03,680
And let's say it was the gender
column and we have M and F.
77
00:04:03,680 --> 00:04:07,880
And so our first row
ID would be this value,
78
00:04:07,880 --> 00:04:13,160
and it would be an M. So
our value is M for male
79
00:04:13,160 --> 00:04:14,810
and associated with this row ID.
80
00:04:14,810 --> 00:04:17,960
Then the next is female,
associated with this row ID,
81
00:04:17,960 --> 00:04:19,250
so on and so forth.
82
00:04:19,250 --> 00:04:23,390
So, now, if we do a query
against the employee table
83
00:04:23,390 --> 00:04:27,200
where gender equals
M, the scan simply
84
00:04:27,200 --> 00:04:31,850
has to look for where this
value is essentially marked.
85
00:04:31,850 --> 00:04:34,610
Here, gathers the
row ID, no, no.
86
00:04:34,610 --> 00:04:36,410
Here, gathers the row ID.
87
00:04:36,410 --> 00:04:37,250
So on and so forth.
88
00:04:37,250 --> 00:04:39,530
And it'd be sort of the
opposite for female.
89
00:04:39,530 --> 00:04:41,870
No, yes, get the row ID.
90
00:04:41,870 --> 00:04:43,250
Yes, get the row ID.
91
00:04:43,250 --> 00:04:44,780
And then no.
92
00:04:44,780 --> 00:04:47,540
So let's look at how to
create a bitmap index that's
93
00:04:47,540 --> 00:04:50,110
very similar to a B-tree.
94
00:04:50,110 --> 00:04:55,680
We simply say
create bitmap index.
95
00:04:55,680 --> 00:05:01,280
And we're going to do
it on the job table
96
00:05:01,280 --> 00:05:08,020
on Scott emp in the job column.
97
00:05:08,020 --> 00:05:10,900
So, if we look at
that table and decide
98
00:05:10,900 --> 00:05:16,250
whether it's a
good candidate, we
99
00:05:16,250 --> 00:05:21,350
see that the job column as
clerk and salesman and manager,
100
00:05:21,350 --> 00:05:24,890
but there's a fairly low
number of distinct values.
101
00:05:24,890 --> 00:05:28,850
Whereas this emp now, they're
entirely unique and distinct.
102
00:05:28,850 --> 00:05:30,800
Not a good candidate
for a bitmap index.
103
00:05:30,800 --> 00:05:35,090
But job is certain categories
that people have a job in.
104
00:05:35,090 --> 00:05:37,790
We could say that that's
a low cardinality column.
105
00:05:37,790 --> 00:05:41,510
We create a bitmap
index in order
106
00:05:41,510 --> 00:05:44,420
to be able to select data
from that table in the most
107
00:05:44,420 --> 00:05:46,460
efficient way
possible when we're
108
00:05:46,460 --> 00:05:49,330
querying on the job column.
8728
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.