One of the common ways to debug DB queries in WordPress is to enable
SAVEQUERIES, which keeps track of all the DB queries that are executed in WordPress, together with other information like how long it took for the query to execute, what are the functions that called it etc and stores in the global array variable
While this is a great way to debug DB queries, this could be a huge issue on production sites.
Recently I was running a backend script in my development environment to selectively delete some posts from WordPress. Even though the code was simple and very less data was handled in each iteration, the script was running out of memory after about 100 queries.
After a couple of hours of debugging I found that
SAVEQUEIRES was the culprit. Since it was enabled, WordPress was storing information about each query that got executed which quickly added up, which let to PHP running out of memory. And that’s when I realized that having
SAVEQUERIES enabled could be a major performance issue.
So the tl;dr version is
Don’t ever enable
SAVEQUEIRES in production sites. Also if you are doing any kind of data import/export in your development environment then disabling
SAVEQUERIES, could really speed up things.
If you are using WP_Query you can find the SQL query generated by WordPress, instead of enabling it.
Also, remember that
SAVEQUERIES is enabled by default in vip quickstart and by debugging plugins like Debug Bar.
- WordPress Developer tools to increase productivity in WordCamp Mumbai
- Email Log WordPress plugin v1.9.1 released
- Email Log WordPress plugin v1.9 released
- How to find if you are on the last page of a multi-page post in WordPress
- Easy Retweet WordPress plugin v3.1 Released
- Creating custom tables with correct Character Set and Collation in WordPress
Leave a Reply