Composite index column order should match the query, not the schema
In the TTS Study Assistant
notes table, queries
filter by user_id always and domain often, so the index is declared in that
order:
CREATE INDEX idx_uid_did ON notes(user_id, domain);
A composite index is only fully useful as a left-prefix: this index serves
WHERE user_id = ? and WHERE user_id = ? AND domain = ?, but not
WHERE domain = ? alone. The rule of thumb is to order columns by how the
queries actually filter — most selective / most-always-present first — not by
declaration order in the table, and not alphabetically.