Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
GlossaryNovember 22, 20263 min read

What is a database index?

Why a feed that loaded instantly with 200 rows crawls at 200,000, and the one-line fix. Plus the cost of indexes and how to tell which columns deserve one.

Startbase Team
Editorial ink illustration of an open cookbook with alphabet tabs on its page edge, one pulled-out tab in ember orange

Key takeaways

  • An index is a sorted copy of one or more columns that points back to the rows, so lookups skip the full table scan.
  • Index the columns you filter, join and sort on often; leave rarely queried columns alone, because every index slows writes a little.
  • Small tables do not need extra indexes. The problem appears at tens of thousands of rows, usually on a foreign key or a created_at sort.

Think of a database index as a sorted shortcut the database keeps beside a table, so that a query like "find this user's orders" can jump straight to the matching rows instead of reading every row from top to bottom. It is the single most common fix when an app that felt instant at launch starts to feel slow as data grows.

An everyday example: the back of a cookbook

To find every recipe with lemon in a 600-page cookbook, you could read all 600 pages. Or you could turn to the index at the back, find "lemon" in its alphabetical list and go straight to pages 41, 188 and 502. A database index is that alphabetical list for a column. Without one, the database does a sequential scan: it reads the whole table and checks each row.

With 200 rows that scan takes a fraction of a millisecond, which is why nobody notices during testing. With 500,000 rows, a feed query that scans the whole `posts` table on every page load can take hundreds of milliseconds, and the same query with the right index usually comes back in a few. Exact numbers depend on the data and the machine, but the gap grows with every row you add.

Which columns deserve an index

Look at the questions your app asks most often, then index the columns in their WHERE, JOIN and ORDER BY parts. Typical candidates:

  • Foreign keys you filter on. `orders.customer_id`, `messages.chat_id`, `scores.player_id`. Postgres indexes primary keys automatically but not foreign key columns.
  • Sort columns on long lists. `created_at` on a feed or an activity log.
  • Combined filters. A chat screen that asks for one chat's messages, newest first, is best served by one index on (`chat_id`, `created_at`) rather than two separate ones.
  • Lookups by a natural value. Usernames, slugs or order numbers that people type into a search box. A unique constraint creates an index as a side effect.

What indexes cost

Indexes are not free, which is why databases do not index everything by default. Each one takes disk space, and every insert, update or delete has to update every index on that table too. A table with eight indexes takes noticeably longer to write than one with two. A good starting rule: index for the queries you actually run, and remove an index nobody uses. A column with only a few distinct values, like a true or false `is_archived`, rarely benefits from an index on its own.

Why it matters when building with Startbase

Startbase Cloud gives your project a Postgres database, and the agent manages its schema through SQL migrations, so an index is one more migration rather than something you configure by hand. The Security section in the Backend tab runs security and performance advisors against your live database and flags slow patterns, and each finding has a Fix with AI button that hands it to the agent (see the security docs). You can also run the slow query yourself in the SQL editor to confirm the fix.

The activity feed is getting slow. It loads the 30 newest posts from people the user follows. Check which queries the feed runs, add indexes that match them (including follower and created_at columns), apply it as a migration, and tell me which indexes you added and why.

If the slowness is on the screen rather than in the data, the cause is elsewhere: see how to fix bugs with AI for narrowing it down first.

Common confusions

  • An index is not a backup or a copy you can read. It is internal to the database and only speeds up queries.
  • "Index" in a URL or file name is unrelated. `index.html` is just the default page of a folder.
  • Search engine indexing is a different thing. Google indexing your pages has nothing to do with database indexes.
  • An index does not fix a query that fetches too much. Loading 10,000 rows to show 20 is slow with or without one. Add a limit and paginate.

Frequently asked questions

How do I know if I need a database index?

If a specific screen gets slower as data grows while the rest of the app stays fast, look at that screen's query. Filtering or sorting on an unindexed column of a large table is the most common cause.

Can too many indexes slow down an app?

Yes, on writes. Every insert and update must maintain every index, so write-heavy tables like logs or game events should carry only the indexes their reads truly need.

On this page

  • An everyday example: the back of a cookbook
  • Which columns deserve an index
  • What indexes cost
  • Why it matters when building with Startbase
  • Common confusions

Keep reading

More in Glossary
Editorial ink illustration of a hand-cranked music box drum plucking a metal comb, the crank handle in ember orange
GlossaryNovember 22, 2026

What is a game loop?

Every real-time game runs one repeating cycle: read input, update the world, draw it. Here is what that cycle looks like and why it decides how your game feels.

3 min read
Editorial ink illustration of a brass stopwatch beside a small wind-up toy car, the second hand in ember orange
GlossaryNovember 22, 2026

What is delta time?

Delta time is the number that keeps your game the same speed on every screen. Here is how to use it, where it breaks, and how to spot a game that forgot it.

3 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.