CREATE INDEX idx_orders_status_created_at ON orders (status, created_at DESC);Descending indexes can help mixed sort-order workloads and order-sensitive queries in modern MySQL.
Composite indexes, invisible indexes, descending indexes, generated-column indexing, and EXPLAIN workflows in MySQL.
Common MySQL DDL and tuning workflows.
CREATE INDEX idx_orders_status_created_at ON orders (status, created_at DESC);Descending indexes can help mixed sort-order workloads and order-sensitive queries in modern MySQL.
Practical route for function-based searches.
ALTER TABLE users
ADD COLUMN email_lc VARCHAR(255) GENERATED ALWAYS AS (LOWER(email)) STORED,
ADD INDEX idx_users_email_lc (email_lc);A generated column can make case-normalized lookups indexable in MySQL.
Test an index without making it visible to the optimizer by default.
CREATE INDEX idx_orders_coupon_code ON orders (coupon_code) INVISIBLE;Invisible indexes are useful for experiments and staged rollouts.
ALTER TABLE orders ALTER INDEX idx_orders_coupon_code VISIBLE;This lets you test optimizer behavior before committing to a drop.
Use EXPLAIN and related patterns before and after adding an index.
EXPLAIN SELECT id, total_amount
FROM orders
WHERE status = 'paid'
ORDER BY created_at DESC
LIMIT 50;Look at the chosen key, access method, estimated rows, and extra information.
Help the optimizer make better choices after major data changes.
ANALYZE TABLE orders;Stale statistics can cause unexpected plans even when a good index exists.
SELECT id
FROM orders FORCE INDEX (idx_orders_status_created_at)
WHERE status = 'paid'
ORDER BY created_at DESC
LIMIT 50;Useful for testing, but avoid relying on it as the first fix for poor design.