Showing entries 1 to 6
Displaying posts with tag: mysql queries (reset)
Indexing 101: Optimizing MySQL queries on a single table

I have recently seen several cases when performance for MySQL queries on a single table was terrible. The reason was simple: the wrong indexes were added and so the execution plan was poor. Here are guidelines to help you optimize various kinds of single-table queries.

Disclaimer: I will be presenting general guidelines and I do not intend to cover all scenarios. I am pretty confident that you can find examples where what I am writing does not work, but I am also confident that it will help you most of the time. Also I will not discuss features you can find in MySQL 5.6+ like Index Condition Pushdown to keep things simple. Be aware that such features can actually make a significant difference in query response time (for good or for bad).

What an index can do for you

An index can perform up to 3 actions: filter, sort/group and cover. While the first 2 actions are self-explanatory, not everyone may know what …

[Read more]
Profiling MySQL queries from Performance Schema

When optimizing queries and investigating performance issues, MySQL comes with built in support for profiling queries aka

SET profiling = 1;

 . This is already awesome and simple to use, but why the PERFORMANCE_SCHEMA alternative?

Because profiling will be removed soon (already deprecated on MySQL 5.6 ad 5.7); the built-in profiling capability can only be enabled per session. This means that you cannot capture profiling information for queries running from other connections. If you are using Percona Server, the profiling option for log_slow_verbosity is a nice alternative, unfortunately, not everyone is using Percona Server.

Now, for a quick demo: I execute a …

[Read more]
How to log all MySQL queries in Drupal

In order to benchmark a Drupal site performance you need to see all the database queries related to your Drupal site. In case you don’t have access to the my.cnf file If you don’t have access to the my.cnf file, you can log the queries from the Drupal code itself: cp includes/database.mysql-common.inc includes/database.mysql-common.inc.backup.orig vim includes/database.mysql-common.inc […]

5 Ways to Boost MySQL Scalability

There are a lot of scalability challenges we see with clients over and over. The list could easily include 20, 50 or even 100 items, but we shortened it down to the biggest five issues we see.

1. Tune those queries

By far the biggest bang for your buck is query optimization. Queries can be functionally correct and meet business requirements without being stress tested for high traffic and high load. This is why we often see clients with growing pains, and scalability challenges as their site becomes more popular. This also makes sense. It wouldn't necessarily be a good use of time to tune a query for some page off in a remote corner of your site, that didn't receive real-world traffic. So some amount of reactive tuning is common and appropriate.

Enable the slow query log and watch it. Use …

[Read more]
MySQL Challenge: Limit Rows Accessed - Continued

Yesterday I blogged about the MySQL Challenge to limit rows accessed. Sheeri had some great comments about the subject, but didn't know either why the first 4 rows were not counted in my original solution:



mysql> explain select actor_id from actor where actor_id % 5 = 0 and actor_id < 26;

*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: actor
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 2
ref: NULL
rows: 20
Extra: Using where; Using index

mysql>


I've been thinking about this some more, and wondered what would happen if I tried this query:



mysql> select actor_id from actor where actor_id …
[Read more]
MySQL Challenge: Limit Rows Accessed - Continued

Yesterday I blogged about the MySQL Challenge to limit rows accessed. Sheeri had some great comments about the subject, but didn't know either why the first 4 rows were not counted in my original solution:



mysql> explain select actor_id from actor where actor_id % 5 = 0 and actor_id < 26;

*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: actor
type: range
possible_keys: PRIMARY
key: PRIMARY
key_len: 2
ref: NULL
rows: 20
Extra: Using where; Using index

mysql>


I've been thinking about this some more, and wondered what would happen if I tried this query:



mysql> select actor_id from actor where actor_id …
[Read more]
Showing entries 1 to 6