PlanetScale

Using redundant conditions to unlock indexes in MySQL

Jun 7, 2023Aaron Francis
Using redundant conditions to unlock indexes in MySQL
SummaryAI, from the source post

This post introduces techniques for unlocking MySQL indexes that are otherwise obfuscated by functions or complex expressions. It explains how to use redundant conditions, which are logically superfluous but allow MySQL to utilize existing indexes. Two types of redundant conditions are detailed: logically impossible ones (e.g., `id < 5 AND id < 10`) and domain-specific ones (e.g., `updated_at < X AND created_at < X` where `created_at` is always <= `updated_at`). The post provides `EXPLAIN` output to demonstrate how these techniques enable index usage, improving query performance without requiring database schema changes.

More from the Database Benchmarking Best Practices trail