Bug #35318 Wrong number of affected rows in truncate
Submitted: 16 Mar 2008 11:14 Modified: 16 Mar 2008 18:49
Reporter: [ name withheld ] (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.1.23-rc-community OS:Windows
Assigned to: CPU Architecture:Any
Tags: affected rows, truncate

[16 Mar 2008 11:14] [ name withheld ]
Description:
As per the docs (http://dev.mysql.com/doc/refman/5.1/en/truncate.html) truncate doesn't return the number of affected rows, which is fine, but as this shows

mysql> select * from test.agent;
+----+---------------------+
| id | time                |
+----+---------------------+
|  1 | 2008-03-16 11:21:38 |
|  2 | 2008-03-16 11:21:41 |
|  3 | 2008-03-16 11:27:07 |
+----+---------------------+
3 rows in set (0.00 sec)

mysql> truncate test.agent;
Query OK, 1 row affected (0.03 sec)

it reports 1 row affected, shouldn't it report something like NULL or 0?
Any number is really wrong and might be trick an inexperienced users.

How to repeat:
See description

Suggested fix:
Have it at least report 0 rows affected
[16 Mar 2008 18:49] MySQL Verification Team
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

c:\dbs>5.1\bin\mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.24-rc-nt-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select * from test.agent;
+----+---------------------+
| id | time                |
+----+---------------------+
|  1 | 2008-03-16 11:21:38 |
|  2 | 2008-03-16 11:21:41 |
|  3 | 2008-03-16 11:27:07 |
+----+---------------------+
3 rows in set (0.02 sec)

mysql> truncate test.agent;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from test.agent;
Empty set (0.00 sec)

mysql>