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) کی رفتار پر اضافی بوجھ پڑتا ہے۔
Composite Index: attendance (class_id, attendance_date)
A composite index is one index built across multiple columns, in a specific order. Column order is not cosmetic — it determines which queries the index can actually help.
| Seq in index | Column |
|---|---|
| 1 | class_id |
| 2 | attendance_date |
✓ This index helps:
SELECT * FROM attendance WHERE class_id = 3 AND attendance_date = '2025-09-01';Filters on
class_id first (the index's leading column), then narrows by date.
✗ This index can't help:
SELECT * FROM attendance WHERE attendance_date = '2025-09-01';Filters only on the second column. MySQL cannot use a
(class_id, attendance_date) index to jump to a date without knowing the class
first — same idea as a phone book sorted by (last name, first name): you can't jump to
"everyone named John" without scanning the whole book.
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) استعمال ہوگا (اگر کوئی ہو)، اور تقریباً کتنی قطاریں جانچی جائیں گی۔