S
Seoffix.com
Sign In Get Pro Membership

SQL & MariaDB

SQL: Composite Indexing for Sub-Millisecond Queries

Advanced SQL 25 XP

B-Tree Composite Indexes and the Leftmost Prefix Rule

When querying tables with millions of rows:

SELECT * FROM sfx_links WHERE target_domain = 'seoffix.com' AND status_code = 200 ORDER BY created_at DESC;

Creating separate indexes on target_domain, status_code, and created_at forces the MySQL query optimizer to perform index merge passes or filesort memory buffers.

A Composite Index on (target_domain, status_code, created_at) allows the engine to locate matching rows in a single B-Tree descent and stream rows pre-sorted with 0 filesort penalty.

Hints

  1. Place exact-match equality filters first: target_domain, status_code
  2. Place the range or ORDER BY column last: created_at DESC
  3. This satisfies the Leftmost Prefix B-Tree traversal rule

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 25 XP. Finish every lesson in the track to earn its certificate.
Sign in to earn XP