Tackling Slow "SELECT COUNT(*)" Queries on MySQL
Your query on the change_event table, counting rows that exceed a specific change_event_id, is experiencing significant delays. But why? Let's delve into possible causes.
Unveiling InnoDB's Behavior
MySQL's InnoDB engine utilizes clustered primary keys, meaning that the primary key is stored alongside row data in data pages, rather than separate index pages. As a result, range scans, such as yours, require scanning through all potentially wide rows in data pages. This factor is exacerbated by the table's xml_diff column, a TEXT data type that further slows down processing.
Optimization Strategies
To accelerate the query, two approaches are worth considering:
Additional Tip:
To enhance performance further, consider altering the change_event_id column to bigint unsigned. This step prevents negative values and can also streamline processing.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3