

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Back
ctrl+,
Next
ctrl+.
An index is an in-memory structure that ensures that queries we run on a database are performant, that is to say, they run quickly. If you can remember back to the data structures course, most database indexes are just binary trees or B-trees! The binary tree can be stored in RAM as well as on disk, and it makes it easy to look up the location of an entire row.
PRIMARY KEY columns are indexed by default, ensuring you can look up a row by its id very quickly. However, if you have other columns that you want to be able to do quick lookups on, you'll need to index them.
CREATE INDEX index_name ON table_name (column_name);
It's fairly common to name an index after the column it's created on with a suffix of _idx.
As it turns out, the front-end frequently finds itself in a state where it knows a user's email but not their id. Let's add an index to the email field called email_idx.
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution