简体   繁体   中英

How to log queries with large number of results

I've been programming a website in Drupal for years now, and sometimes I notice things in the code where I'm querying for only one row, but I forget to use a LIMIT so the result set can get unnecessarily large.

While the best way to avoid this problem is to simply not forget this step for these types of queries, I am still human, so it's unrealistically optimistic for the long-term.

I'd like to reduce as much as possible the amount of data transferred between MySQL and PHP, and to do that I need to know which queries return large result sets so I can find them in the code and make the appropriate fixes.

I know there is a slow query log, but queries with large result sets are not necessarily slow.

Is there any easy way to do this using a Drupal hook or otherwise?

You can use devel module to show the queries being executed on the page.

After enabling the module, go to Administration > Configuration > Development > Devel Settings and make sure that Display query log is on. You should see the query log at the bottom of your pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM