---
title: "Discussion on \"How database indexing actually works internally?\" | Hashnode"
description: "Discussion on \"How database indexing actually works internally?\". Let's start with a simple example showing why you would need indexing in a database.\nSuppose we have a table called costing with three columns company_id, unit, unit_cost which is completely unordered.\n\nIf we run the below query -\nSELECT\n    company_..."
url: "https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How database indexing actually works internally?](https://pankajtanwar.hashnode.dev/how-database-indexing-actually-works-internally?utm_source=hashnode&utm_medium=feed)

Let's start with a simple example showing why you would need indexing in a database. Suppose we have a table called costing with three columns company\_id, unit, unit\_cost which is completely unordered. If we run the below query - SELECT company\_...

Mar 31, 2021 · 5 min read · pankajtanwar.hashnode.dev  
Updated Aug 25, 2021  
Read the article

-   [#databases](https://hashnode.com/tag/databases)
-   [#mysql](https://hashnode.com/tag/mysql)
-   [#system-architecture](https://hashnode.com/tag/system-architecture)

## Written by

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

@pankajtanwar · Rajasthan.

  
[View profile](https://hashnode.com/@pankajtanwar)

I write about System Design & Web Tech. Curious about how things work!

## Responses 7

Markdown supported · ⌘↵ to post

[Michael Nielson](https://hashnode.com/@safetytrick)

[Aug 21, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/6120dc71e404793819ca9144)

This is misleading:

But, It will still do a full table scan because we are using "amount" column to calculate the total. So, we need to put an index on "amount" column too.

Two indexes don't add together (you might look up covering index).

There are also very legitimate reasons why the database will ignore an index that could be applied and do a full table scan anyway.

You've explained a few behaviors of indexes but not really how they work.

[Idris Olubisi](https://hashnode.com/@olanetsoft)

[Apr 12, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/607441c3318eed1a2fe7718c)

This is great. Bookmarked

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

[Apr 12, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/607441c3318eed1a2fe7718c#reply-607471d3308cd51e1477f6dd)

Thank you [Olubisi Idris Ayinde](https://hashnode.com/@olanetsoft)

[Victoria Lo](https://hashnode.com/@victoria)

[Apr 12, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/60743ca4318eed1a2fe77111)

Wonderfully explained! :) Bookmarked!

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

[Apr 12, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/60743ca4318eed1a2fe77111#reply-6074720e308cd51e1477f6e4)

Many thanks [Victoria Lo](https://hashnode.com/@victoria)!

[Shad Mirza](https://hashnode.com/@iamshadmirza)

[Apr 12, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/607433fc318eed1a2fe77082)

This was a great read. Followed you. And bookmarked this.

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

[Apr 12, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/607433fc318eed1a2fe77082#reply-6074723085f3a21e3926bebf)

Thanks for your support [Mohd Shad Mirza](https://hashnode.com/@iamshadmirza). It means a lot.

[Yeswanth kumar Bandaru](https://hashnode.com/@Ybandaru)

[Apr 2, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/6066e39b602838220343ea54)

Good article Pankaj. Can you throw some more light on last section indexing pitfalls. Especially why do we need index over amount also

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

[Apr 4, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/6066e39b602838220343ea54#reply-60695a82b17dc439b747ac78)

Thank Yeswanth. Check out this [great talk](https://www.youtube.com/watch?v=HubezKbFL7E) by Kai Sassnowski.

[Maxi Contieri](https://hashnode.com/@mcsee)

[Apr 1, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/6065e849602838220343dc6a)

nice article and nice graphics !

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

[Apr 4, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/6065e849602838220343dc6a#reply-606959d61ed1783ab0633967)

Thanks.

[Rahul Singh](https://hashnode.com/@rahuladream)

[Apr 1, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/606559c2574933157db93b59)

so well explained 👏️

[Pankaj Tanwar](https://hashnode.com/@pankajtanwar)

[Apr 1, 2021](https://hashnode.com/posts/how-database-indexing-actually-works-internally/60641370f7e8f90bd1d5eb96/comment/606559c2574933157db93b59#reply-6065e53c602838220343dc43)

Thank you [Rahul Singh](https://hashnode.com/@rahuladream)
