This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Description
See: https://jacobbednarz.com/posts/tracking-sql-queries
Add a comment method to query builder to prepend comments to queries so that they show up in the logs. Example:
db_select('users', 'u')
->comment('module:my_custom_module,function:some_slow_function')
->fields('u', array('mail', 'status'))
->execute()
# => /* module:my_custom_module,function:some_slow_function */ SELECT u.mail AS mail, u.status AS status FROM users u
Now should the query pop up in your slow query logs, it will be annotated with some helpful debugging information on it’s caller.
# Time: 150517 6:26:05
# User@Host: mysql_user[mysql_user] @ db1.example.com [10.0.0.60]
# Thread_id: 4038366 Schema: example_table Last_errno: 0 Killed: 0
# Query_time: 2.388451 Lock_time: 0.000041 Rows_sent: 0 Rows_examined: 1302 Rows_affected: 1302 Rows_read: 1302
# Bytes_sent: 13 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0
# InnoDB_trx_id: 2D57FA24A
use example_table;
/* module:my_custom_module,function:some_slow_function */
SELECT *
FROM users