Title: [Plugin: WP SlimStat] Database Insert Warnings
Last modified: August 20, 2016

---

# [Plugin: WP SlimStat] Database Insert Warnings

 *  Resolved [lukewarmmizer](https://wordpress.org/support/users/lukewarmmizer/)
 * (@lukewarmmizer)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/)
 * I noticed a large number of warnings in the mysql slow query log related to wp-
   slimstat. Nearly every request was resulting in:
 * `120728 15:25:58 [Warning] Unsafe statement written to the binary log using statement
   format since BINLOG_FORMAT = STATEMENT. Statements writing to a table with an
   auto-increment column after selecting from another table are unsafe because the
   order in which rows are retrieved determines what (if any) rows will be written.
   This order cannot be predicted and may differ on master and the slave.`

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Jason Crouse](https://wordpress.org/support/users/coolmann/)
 * (@coolmann)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/#post-2926738)
 * Hi there,
 * yes, I know what query your database is complaining about. It’s a query that 
   increments a counter in the same table is being selected. But rest assured that
   even if this is in theory considered “unsafe”, the query itself has been designed
   so that everything will be okay.
 * Please refer to
 * [http://www.dbasquare.com/2012/04/17/why-a-statement-can-be-unsafe-when-it-uses-limit-clause/](http://www.dbasquare.com/2012/04/17/why-a-statement-can-be-unsafe-when-it-uses-limit-clause/)
 * for more information on the problem in general. In my case, I needed an auto_increment
   field that is not the primary key (visit_id), in order to avoid maintaining and
   using a separate table just for that.
 *  Thread Starter [lukewarmmizer](https://wordpress.org/support/users/lukewarmmizer/)
 * (@lukewarmmizer)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/#post-2926770)
 * Thanks for the response – I am actually seeing the message for both the query
   that updates the visit_id as well as the $insert_new_hit_sql :
 *     ```
       $insert_new_hit_sql = "INSERT INTO {$GLOBALS['wpdb']->prefix}slim_stats ( " . implode( ", ", array_keys( $stat ) ) . " )
       			SELECT " . substr(str_repeat('%s,', count($stat)), 0, -1) . "
       			FROM DUAL
       			WHERE NOT EXISTS ( ";
       		$select_sql = "SELECT id
       				FROM {$GLOBALS['wpdb']->prefix}slim_stats
       				WHERE ";
       		foreach ($stat as $a_key => $a_value){
       			if ($a_key == 'dt')
       				$select_sql .= "(TIME_TO_SEC(TIMEDIFF(FROM_UNIXTIME(%s),FROM_UNIXTIME(dt))) < $ignore_interval) AND ";
       			else
       				$select_sql .= "$a_key = %s AND ";
       		}
       		$select_sql = substr($select_sql, 0, -5);
       		$insert_new_hit_sql .= $select_sql.' LIMIT 1)';
       ```
   
 * I can appreciate that it’s not actually an issue for the slimstats code (and 
   really I’m not that worried about being able to restore the slimstats data from
   the binlog), but the problem is that there are so many log messages being generated
   by slimstats that I can’t see if there are other more serious issues by looking
   at my mysql logs.
 * Is it possible to suppress the warnings for these queries?
 *  Plugin Contributor [Jason Crouse](https://wordpress.org/support/users/coolmann/)
 * (@coolmann)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/#post-2926776)
 * Hi there,
 * according to
 * [http://bugs.mysql.com/bug.php?id=46265](http://bugs.mysql.com/bug.php?id=46265)
 * a new option **log_warnings** has been introduced starting from MySQL 5.1.39,
   which does exactly that.
 * log_warnings=0 turns off the warning for the error log
    log_warnings=1 turns 
   on the warning for the error log
 * Cheers,
    Camu
 *  Thread Starter [lukewarmmizer](https://wordpress.org/support/users/lukewarmmizer/)
 * (@lukewarmmizer)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/#post-2926782)
 * I don’t want to disable the warnings globally though – there might be something
   legitimate that warrants further investigation. I tried messing with the code
   to set the log_warnings variable at the session scope but the warnings were still
   showing up in the MySQL log.
 * I came across this post about changing the binlog format to fix the problem –
   after switching to row logging it did go away:
 * [http://www.dbasquare.com/kb/warning-the-statement-is-unsafe-because-it-uses-a-limit-clause/](http://www.dbasquare.com/kb/warning-the-statement-is-unsafe-because-it-uses-a-limit-clause/)
 * In my my.cnf –
 * `binlog-format = ROW`
 * FWIW, I have seen several recommendations to ORDER BY an indexed column when 
   you are using LIMIT, even if you only expect 0 or 1 results.
 * thanks!
 *  Plugin Contributor [Jason Crouse](https://wordpress.org/support/users/coolmann/)
 * (@coolmann)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/#post-2926783)
 * Thank you for your feedback.
 * > FWIW, I have seen several recommendations to ORDER BY an indexed column when
   > you are using LIMIT, even if you only expect 0 or 1 results.
 * This may indeed help, I’ll add it to my todo list.
 * Cheers
    Camu

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[Plugin: WP SlimStat] Database Insert Warnings’ is closed to new replies.

 * ![](https://ps.w.org/wp-slimstat/assets/icon.svg?rev=2832242)
 * [SlimStat Analytics](https://wordpress.org/plugins/wp-slimstat/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-slimstat/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-slimstat/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-slimstat/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-slimstat/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-slimstat/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Jason Crouse](https://wordpress.org/support/users/coolmann/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-wp-slimstat-database-insert-warnings/#post-2926783)
 * Status: resolved