Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: "LIMIT 5" causes warnings

I've been executing the following query in MySQL console:

INSERT INTO pixel_window 
   SELECT id 
      FROM pixels 
         WHERE pixel_id='type2' 
            ORDER BY id DESC 
               LIMIT 5;

And got:

Query OK, 5 rows affected, 1 warning (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
  Level: Note
   Code: 1592
Message: Statement may not be safe to log in statement format.
1 row in set (0.00 sec)

I've played a little with the query, and found out that when LIMIT is omitted the warning disappears.

What does this warning mean? Why is LIMIT a problem in this subquery?

like image 564
Adam Matan Avatar asked Jul 09 '12 13:07

Adam Matan


1 Answers

It's considered a bug.

A warning can be thrown when you don't define 'order by' clause in your update. In your case, it is considered safe since you order by ID (asuming id is a unique id?)

Read more on the bugreport here: http://bugs.mysql.com/bug.php?id=42415

like image 99
PoeHaH Avatar answered Sep 21 '22 14:09

PoeHaH