School DB Lab
What actually speeds up a query

Index Lab

An index is a separate, sorted lookup structure MySQL maintains alongside a table. It can make matching rows much faster to find — at a real cost in storage and write speed.

انڈیکس (Index) ایک علیحدہ، ترتیب شدہ لُک اپ ڈھانچہ (Lookup Structure) ہے جو MySQL ٹیبل کے ساتھ ساتھ برقرار رکھتا ہے۔ یہ مطلوبہ ریکارڈز کو تلاش کرنے کی رفتار کو کئی گنا تیز کر سکتا ہے — تاہم اس کے بدلے اسٹوریج (Storage) اور ڈیٹا لکھنے (Write) کی رفتار پر اضافی بوجھ پڑتا ہے۔

Same query, before and after adding an index

Query: SELECT * FROM fee_invoices WHERE status = 'Overdue'

Without idx_invoices_status

idselect_typetabletypepossible_keyskeykey_lenrefrowsExtra
1SIMPLEfee_invoicesALLNULLNULLNULLNULL40Using where

With idx_invoices_status

idselect_typetabletypepossible_keyskeykey_lenrefrowsExtra
1SIMPLEfee_invoicesrefidx_invoices_statusidx_invoices_status1const1Using index condition

Look at the type and key columns: without the index, MySQL's plan uses type = ALL (a full table scan — it must check every row). With the index, key names idx_invoices_status and MySQL can jump straight to matching rows instead of scanning the whole table.

This table is small (only 40 rows) so the real time difference is invisible here — but the same full-scan-vs-lookup difference on a table with millions of rows is the entire reason indexes matter in production. An index doesn't make every query faster; it only helps queries that filter, join, or sort on the indexed column(s).
Explain this page
What is EXPLAIN?
A command that asks MySQL "how would you run this query?" without actually running it for real — it returns the query plan: which index (if any) it would use, and roughly how many rows it expects to examine.
EXPLAIN کیا ہے؟
ایک کمانڈ جو MySQL سے پوچھتی ہے "تم یہ کیوری کیسے چلاؤ گے؟" — اسے اصل میں چلائے بغیر۔ یہ کیوری پلان (Query Plan) واپس کرتی ہے: کون سا انڈیکس (Index) استعمال ہوگا (اگر کوئی ہو)، اور تقریباً کتنی قطاریں جانچی جائیں گی۔