Query Exercise Challenge: Why Is This Index Getting Smaller?

9 Comments

This exercise can be done on any version of Postgres, and doesn’t require any other data – just runs by itself.

Let’s start by creating a table with an index:

Load it with a million rows:

Take a look at the data we loaded:

Sample recipes

Vacuum the table to make sure it’s nice and compact, then check the size of the index on last_updated_date:

It’s about 22MB:

First vacuum size

Now update about 1/4 of the rows:

Vacuum the table again, and check the size of the index:

Wait – the new size is – smaller?

Size after updating 25% of rows and vacuuming

And that’s your challenge: figure out why the index’s size dropped in size after we updated about 25% of the rows. Good luck, have fun, leave your answer in the comments, and we’ll circle back next week with the explanation.

 

 

 

 

 

 

 

Previous Post
Smart Postgres News and Techniques 2025 Vol 1
Next Post
Query Exercise Answer: Here’s Why The Index Gets Smaller with Updates.

9 Comments. Leave new

Leave a Reply to Brent Ozar Cancel reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed