How to find the view/page/module that's generating a SQL statement I have newrelic performance monitoring with my Pantheon hosting account. It shows "slow SQL" reports but I can't tell which page, view or module is generating a SQL statement.

For example:


  SELECT node.nid AS nid, node.title AS node_title, users_node.name AS
  users_node_name, users_node.uid AS users_node_uid, node.created AS
  node_created, '?' AS field_data_field_photo_node_entity_type FROM node
  node INNER JOIN users users_node ON node.uid = users_node.uid LEFT
  JOIN field_data_field_photo_topic field_data_field_photo_topic ON
  node.nid = field_data_field_photo_topic.entity_id AND
  field_data_field_photo_topic.field_photo_topic_tid =
  :views_join_condition_? WHERE (( (node.status =
  :db_condition_placeholder_?) AND (users_node.uid = :users_uid? )
  )AND(( (node.type IN (:db_condition_placeholder_?)) AND
  (field_data_field_photo_topic.field_photo_topic_tid IS NULL ) )))
  ORDER BY node_created DESC LIMIT ? OFFSET ?


How could I get that info?
I suspect your logs are are the output from the MySQL Slow Query Log.  What ends up here varies based on server configuration, but they general culprits are


Queries that take a long time
Queries that don't use indexes


My suggestion is to try to match up the timestamps (start time) to the Apache access_log to get a page.  Then, use the Devel module and enable "Display query log" from admin/config/development/devel.  This will record queries and log them along with execution times.



It looks like that bad query is tied to a view.  For these, enable "Add Views signature to all SQL queries" on the Advanced settings page.  When you do this you can identify which view is slow.

To resolve the "slowness", copy the query and hand edit to add in the parameters.  Then open a MySQL tool, and use the EXPLAIN statement.  Look at what it tells you and go from there.