Support » Plugin: Query Recorder » Recording SELECT queries

  • Hi, I like the idea behind this plugin, very useful for debugging.
    I am wondering, why SELECT queries cannot be recorded with the plugin?
    It is not an option in the settings page (where INSERT, UPDATE, DELETE, DROP, CREATE are the possible options).

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello

    1. class/query-recorder.php, find: function page_options().
    Replace old line with new one:

    $recordable_queries = apply_filters( ‘query_recorder_recordable_queries’, array( ‘INSERT’, ‘UPDATE’, ‘DELETE’, ‘DROP’, ‘CREATE’, ‘SELECT’ ) );

    Save options.

    2. class/query-recorder.php, find: function record_query( $sql )
    Scroll down to the line

    $save_sql = substr( rtrim( $sql ), -1 ) == ‘;’ ? $sql : $sql . ‘ ;’;

    Under it insert additional lines:

    $db = debug_backtrace() ;
    $length = count($db);
    $r = array();

    for ($i = 0; $i < $length; $i++) {
    $r[] = $db[$i][‘file’].’ ‘.$db[$i][‘line’].”: “.$db[$i][‘function’] ;

    $save_sql .= “\r\n”.implode( “\r\n”, $r ).”\r\n\r\n” ;

    Check if the recorder is working as it should. You’ll get additional information about source of the queries.

    Take care now, bye bye then 😉

    Hi, thank you for your response.
    Appreciate your comments, and I can see the SELECT can be added via code. Any plans to support this in a future release of the plugin, without needing to add custom code?

    I could just fork it and upload as my own version. Original author didn’t change a thing in this plugin since 2013/2014, so I don’t think that he would be mad about it. It’s GPL anyway.

    Hi @januzi_pl, first of all sorry for the confusion. I thought you was the author plugin. 🙂

    No problem mate 😉

    What do you think about the new name: Pro Query Pro Recorder Pro? 😛 But seriously thou, I’d add some new settings and explain to queries, but I’m not sure if that’s good idea to run explain against queries when wordpress+themes+plugins are being know for generating 100+ queries per page.

    Hi, funny to hear about Pro Query Pro Recorder Pro as a name. Maybe something like Pro Query Pro Recorder Reloaded? 🙂

    Regarding explain queries, I am not sure to understand the idea behind it. Can please clarify? However, something that could help, while debugging the hundreds of queries that are being logged per page, could be to add a prefix […] with a hint about what is being recorded for.

    Mysql has got feature that allows you to check how good the query is. This feature is activated with the word “explain” at the beginning of the query. In that case mysql will check it’s indexes and try to figure out if the query will use them. If the query is using indexes then everything is ok. If not, then it should be rewritten (or the mysql table should be changed).

    So, the plugin would execute additional queries to get “explain info”. 100 normal queries would lead to 200 total queries.

    As for prefix, good idea.

    This seems to be the only plugin I can find that records queries to a file, so you can monitor queries during POST requests (when there is no page returned for showing the debug bar). But only DML – no SQL! What a strange omission.

    I’ll hack those code changes in to my install. Thanks.

    I’ve put the amended plugin here if it is any use to anyone:

    I have noticed however that not all queries are caught. I’m debugging a WooCommerce query that updates taxonomy counts after updating a product, and that cannot be seen in the list even though I know it runs (by logging the query explicitly before it executes). It’s the query in _wc_terms_recount and that uses $wpdb->get_var($sql_query) so I would not expect it to bypass any logging.

    Anyway – take it as a starting point and feel free to submit PRs to improve it. I’ve not changed any of the author details – just what I needed to use it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Recording SELECT queries’ is closed to new replies.