Loading workspace environment...
Master B-Tree indexes, composite covering indexes, EXPLAIN / EXPLAIN QUERY PLAN analysis, and avoiding performance bottlenecks like full-table scans.
CREATE INDEX idx_users_email ON users(email);Creates a single-column B-Tree index.EXPLAIN QUERY PLAN SELECT * FROM users WHERE email = ?;Inspects execution plan and index utilization.CREATE TABLE orders_ledger (
id INTEGER PRIMARY KEY,
account_id INTEGER NOT NULL,
status TEXT NOT NULL,
amount REAL NOT NULL
);
-- Seed rows
INSERT INTO orders_ledger VALUES (1, 501, 'completed', 100.0);
INSERT INTO orders_ledger VALUES (2, 502, 'pending', 50.0);
INSERT INTO orders_ledger VALUES (3, 501, 'completed', 250.0);
-- Create composite covering index for account filtering
CREATE INDEX idx_orders_acc_status ON orders_ledger(account_id, status);
-- Inspect query execution plan
EXPLAIN QUERY PLAN
SELECT account_id, status, amount
FROM orders_ledger
WHERE account_id = 501 AND status = 'completed';id | parent | notused | detail
---+--------+---------+-------------------------------------------------------------
2 | 0 | 0 | SEARCH orders_ledger USING INDEX idx_orders_acc_status (account_id=? AND status=?)SELECT * FROM users WHERE YEAR(created_at) = 2026; -- Function invalidates indexSELECT * FROM users WHERE created_at >= "2026-01-01" AND created_at < "2027-01-01";Architectural Explanation: Wrapping columns in functions prevents the query planner from using standard B-Tree index range scans.
Create a composite index on an `invoices` table that covers filtering by `client_id` and sorting by `invoice_date DESC`.