In partnership with

Imagine there's a bookshelf in front of you. It's filled with all 1,180 chapters of One Piece manga.

You want to reread chapter 153…

Unfortunately, the order is completely messed up.

How would you find the 153?

There really isn’t a “smart” strategy because the positions are just random.

Your best bet is probably to scan every row.

This method is known as linear search.

Now imagine another scenario.

This time, the manga are sorted by chapter. Chapter one is in the top-left, and the last chapter is in the bottom right.

If you try to find chapter 153 again, does it become easier or harder?

It's much easier because you know exactly where to look.

This method is called a binary search, which is much faster than the previous approach (O(logn) vs O(n)).

But why do you need to know all that?

Well, this is why database indexes exist.

What are database indexes?

When you run a select query with a where clause…

SELECT * FROM ONE_PIECE_MANGA 
WHERE CHAPTER=153

The database is doing the same thing as searching a bookshelf.

  • If the table is not sorted, the database has to scan every row. The search is slower.

  • But if it's sorted, the database can use binary search, which is faster.

Indexing a table is essentially creating a sorted version of it1.

How to index a table

To do that, run CREATE INDEX.

CREATE INDEX

We need to index a specific column(s).

We want to sort by chapter, right? So, let's create an index for the column “chapter”.

This creates a pseudo table that's sorted by chapters.

When you run a query with the chapter filter,2

SELECT * FROM ONE_PIECE_MANGA 
WHERE CHAPTER=153 --filter

the database can use the pseudo table and return the result much faster.

Ship Docs Your Team Is Actually Proud Of

Mintlify helps you create fast, beautiful docs that developers actually enjoy using. Write in markdown, sync with your repo, and deploy in minutes. Built-in components handle search, navigation, API references, and interactive examples out of the box, so you can focus on clear content instead of custom infrastructure.

Automatic versioning, analytics, and AI powered search make it easy to scale as your product grows. Your docs stay accurate automatically with AI-powered workflows with every pull request.

Whether you're a dev, technical writer, part of devrel, and beyond, Mintlify fits into the way you already work and helps your documentation keep pace with your product.

1 The index (pseudo-table) is not exactly a table, but often a B-tree.

2 An index only speeds up queries that filter by its column. To speed up other columns, index them separately or create a multi-column index. Just keep in mind: the more indexes you add, the slower writes become, since every insert or update to the table must update the indexes too.

To recap:

  • Indexing makes queries faster by creating a sorted version of a table

  • Indexing columns that are commonly used as a filter is a good idea

  • Creating too many indexes could slow down table writes

Fee from Anime Coders

PS: Anime art of the week (Since I’ve been rewatching One Piece recently)

How did you like today's email?

Login or Subscribe to participate

Keep Reading