Lesson 22 of the SQL Optimization Course: Scenarios for Multi-Valued Indexes

For relational databases, the design of tables and SQL is written are particularly crucial. It wouldn’t be an exaggeration to say that they account for 90% of performance. So this time, specifically targeting these two major knowledge areas, we’ll conduct a detailed analysis for you, peeling back the layers.
This Series uses plain and understandable language and selects a large number of examples to elaborate on the subtleties for you.
🧑💻 Target audience:
We will use MySQL as the demonstration database.
Multi-valued indexes and composite indexes serve fundamentally different purposes:
(r1, r2, r3)
), optimized for queries filtering on all specified columns.Introduced in MySQL 8.0.17, multi-valued indexes solve MySQL’s hard limit of 64 indexes per table while simplifying schema designs.
|
|
Querying for a value across 6 columns:
|
|
Execution Time: 210 ms Index Strategy: 6 single-column indexes with INDEX_MERGE.
|
|
|
|
Execution Time: 200 ms Plan: Uses idx_r_com directly.
A table with 500 columns (t2) would require 500 single-column indexes to optimize OR queries—exceeding MySQL’s 64-index limit.
|
|
|
|
Execution Time: 11.31 sec (vs. impractical 500-column index approach)
👋 See you in the next lesson.
SQLFlash is your AI-powered SQL Optimization Partner.
Based on AI models, we accurately identify SQL performance bottlenecks and optimize query performance, freeing you from the cumbersome SQL tuning process so you can fully focus on developing and implementing business logic.
Join us and experience the power of SQLFlash today!.