-
Title:
Indexes - Web Development
-
Description:
-
So far, we've been doing--in our Phyton IDE--
-
we've been doing what are called sequential scans.
-
And a sequential scan is where you have a list of something.
-
In our case, links.
-
We have this list of links
-
that have these IDs--link 1, link 2, link 3.
-
And we've been doing things like find the link with the ID of 2,
-
so in which case we write a loop to
-
go over the list and find the one who has ID 2.
-
Or you just eyeball it by hand
-
and answer your quiz just by writing in the answer by hand,
-
which is actually totally fine because you went through the same process.
-
You had to look through this whole list of links by hand.
-
Now, that works fine if you have 25 links,
-
but if you have a million links or a billion links,
-
iterating over that entire list is going to take some time,
-
and we want to make our websites fast,
-
or at least reasonably responsive.
-
So that's going to be troublesome.
-
So I'd like to introduce you to a new concept called Indexes.
-
And index is just like an index in a book.
-
They make lookups faster.
-
One index you're probably familiar with already is the hashtable.
-
So in Python you can have a dictionary
-
that looks something like this--
-
that is a mapping--a key--to a value.
-
Let's assign this to a variable.
-
We'll call this just index.
-
Now, you can do very fast lookups in your code
-
by writing something that looks like this,
-
which we'll refer to the index key 2 of this hash table.
-
And when you do a hashtable lookup--
-
you learned this in CS 101--
-
we hash this value, we find it in the hashtable,
-
and then we return the key--
-
or we return the value.
-
We don't have to scan over every element in the list and see if it matches our constraint.
-
We can jump immediately to that element.
-
And that makes queries run much faster.
-
Okay, so let's play around with this in the IDE a little bit
-
and see what we can do.