Knowledgebase

Understanding and Adding Indexes Print

  • databasesphpmyadmin, databases, performance, database, phpmyadmin, troubleshooting, support, guide
  • 0

The most effective database fix.

WHAT AN INDEX IS

A structure allowing the database to find matching rows without reading every row.

Like an index in a book: without it you read every page.

WHEN ONE HELPS

A query filtering or sorting on a column that has no index, on a table with many rows.

This is the single most common cause of a database that has become slow.

FINDING WHERE ONE IS NEEDED

Run EXPLAIN on the slow query. If it reports scanning the whole table, an index on the filtered column will help.

ADDING ONE

In phpMyAdmin, the Structure tab lists columns with an index option beside each.

Back up before changing structure.

THE COST

Indexes make reads faster and writes slightly slower, and they consume space.

On a table read far more often than written, which is most of them, the trade is heavily worthwhile.

WHAT NOT TO DO

Index every column. That slows writes and wastes space without helping.

Index what queries actually filter on.

IF YOU ARE UNSURE

Open a ticket with the slow query. We can advise.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot