Home >Database >Mysql Tutorial >How can I leverage indexes in MySQL view queries to improve performance?
Using Indexes in MySQL View Queries
Issue:
You're encountering performance issues with a MySQL view because the index on a underlying table is not used in view-based queries.
原因:
MySQL does not push filter predicates (e.g., WHERE happened_in = 2006) from outer queries into view queries. Instead, it materializes the view results as an intermediate temporary table and applies the predicate to this table. As a result, indexes on the original table cannot be used effectively.
Solution:
To leverage indexes in view queries, you need to create a suitable index that can be used by the view query. In this case, a covering index that includes all columns referenced in the view query is recommended.
Optimum Index:
CREATE INDEX highscores_IX3 ON highscores (player, happened_in, score)
Why it Works:
Additional Considerations:
The above is the detailed content of How can I leverage indexes in MySQL view queries to improve performance?. For more information, please follow other related articles on the PHP Chinese website!