What kind of queries are bad for MySQL?

July 19, 2013
Author
Vadim Tkachenko
Share this Post:

In writing a recommendation for our Web development team on how to use MySQL, I came up with the following list, which I want to share: What kind of queries are bad for MySQL?

  • Any query is bad. Send a query only if you must. (Hint: use caching like memcache or redis)
  • Queries that examine many rows are bad. Try instead to use…

    . Or at least

    . If it is still not possible, try to make the query examine the least amount of rows possible (zero is ideal, as we come to the first case here)
  • Queries with JOINS are bad. Try to denormalize the table to avoid JOINS. Example: original query

    . This can be denormalized by copying the column orderdate from table t1 to table t2, so the query will look like:

    . I know that fans of 3NF will hit me hard for this, but this is needed for performance
  • Aggregation queries are bad. If you have SUM, AVG, MIN, MAX over many rows, try to pre-calculate these value in roll-up tables, or at least minimize amount of rows to handle. You can have daily, weekly, monthly, you name it, summary tables. Actually INSERT .. ON DUPLICATE KEY UPDATE ... is very useful here.

Do you have more examples?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved