Bug #2687 SP: calling simpleproc sample from Manual twice produces an error
Submitted: 9 Feb 2004 8:32 Modified: 10 Jun 2004 20:40
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:Any (all)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[9 Feb 2004 8:32] Georg Richter
Description:
This bug was reported by Ralf Gebhardt:

When calling simpleproc twice second call ends with error "ERROR 1172 (42000): Result consisted of more than one row".

How to repeat:
mysql> create table t (a int);
Query OK, 0 rows affected (0.08 sec)

mysql> insert into t values (1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> \d |
mysql> CREATE PROCEDURE simpleproc(OUT param1 INT)
    -> BEGIN
    ->   SELECT COUNT(*) INTO param1 FROM t;
    -> END
    -> |
Query OK, 0 rows affected (0.19 sec)

mysql> call simpleproc(@a);|
Query OK, 0 rows affected (0.09 sec)

mysql> select @a|
+------+
| @a   |
+------+
| 2    |
+------+
1 row in set (0.00 sec)

mysql> call simpleproc(@a)|
ERROR 1172 (42000): Result consisted of more than one row
[9 Jun 2004 18:45] Per-Erik Martin
It seems select_dumpvar::send_data() is called twice the second time.
Apparently the do-while loop is iterating twice (at least) in
sql_select.cc:sub_select(), i.e. info->read_record(info) returns more
records than it should.
Most likely a cleanup issue.
[9 Jun 2004 23:12] Oleksandr Byelkin
it looks like general bug in cleanup. Per-Erik was right, it present in 4.0 
 
+ create table t1 (a int); 
+ insert into t1 values (1),(2); 
+ prepare stmt1 from 'SELECT COUNT(*) FROM t1'; 
+ execute stmt1; 
+ COUNT(*) 
+ 2 
+ execute stmt1; 
+ COUNT(*) 
+ 2 
+ 2
[9 Jun 2004 23:13] Oleksandr Byelkin
oops, 4.0 was mistyping
[10 Jun 2004 10:00] Oleksandr Byelkin
ChangeSet 
  1.1912 04/06/10 10:59:55 bell@sanja.is.com.ua +4 -0 
  cleunup() of count() and max()/min() added (BUG#2687)
[10 Jun 2004 20:40] Oleksandr Byelkin
Thank you for bugreport. Bug is fixed, patch is pushe in our internal source 
repository.