Bug #7185 Stored procedure crash if identifier is AVG
Submitted: 10 Dec 2004 22:06 Modified: 13 Apr 2005 10:06
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.5-beta-debug OS:Linux (SUSE 9.2)
Assigned to: Bugs System CPU Architecture:Any

[10 Dec 2004 22:06] Peter Gulutzan
Description:
The word AVG is not reserved in MySQL. 
So I decide to use AVG as an identifier for a table, a column, and then 
-- in a stored procedure -- a variable name and a cursor name. 
So the server hangs when I say CREATE PROCEDURE. 
 
I fear that there may be other words that aren't reserved, but are used 
as built-in function names or as keywords in dangerous contexts. 
 
I didn't try these statements outside a stored procedure, so the title of this 
bug may be misleading. 
 

How to repeat:
mysql> create table avg (s1 int); 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> insert into avg values (5); 
Query OK, 1 row affected (0.00 sec) 
 
mysql> delimiter // 
mysql> drop table avg// 
Query OK, 0 rows affected (0.01 sec) 
 
mysql> create table avg (avg int)// 
Query OK, 0 rows affected (0.01 sec) 
 
mysql> insert into avg (avg) values (5)// 
Query OK, 1 row affected (0.00 sec) 
 
mysql> create procedure avg (avg int) begin declare avg int; declare avg cursor for select 
avg from avg where avg >= 0 order by avg; open avg; fetch avg into avg; close avg; end;// 
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'avg (avg int) 
begin declare avg int; declare avg cursor for select avg from avg ' at line 1 
 
mysql> create procedure avg1 (avg int) begin declare avg int; declare avg cursor for select 
avg from avg where avg >= 0 order by avg; open avg; fetch avg into avg; close avg; end;//
[11 Dec 2004 11:16] MySQL Verification Team
Thank you for the bug report.
[12 Apr 2005 16:50] Per-Erik Martin
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 bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html
[12 Apr 2005 23:18] Peter Gulutzan
There is still a "hang" if I execute a script which is the same as the problem description except that I do everything twice:

drop database db11;
create database db11;
use db11;
create table avg (s1 int);
insert into avg values (5);
delimiter //
drop table avg//
create table avg (avg int)//
insert into avg (avg) values (5)//
create procedure avg1 (avg int) begin declare avg int; declare
     avg cursor for select
     avg from avg where avg >= 0 order by avg; open avg; fetch avg into avg;
     close avg; end;//
create table avg (s1 int);
     insert into avg values (5);
     delimiter //
drop table avg//
create table avg (avg int)//
insert into avg (avg) values (5)//
create procedure avg1 (avg int) begin declare avg int; declare
     avg cursor for select
     avg from avg where avg >= 0 order by avg; open avg; fetch avg into avg;
     close avg; end;//
drop procedure avg1//
drop table avg//
create table avg (s1 int);
     insert into avg values (5);
delimiter //
[13 Apr 2005 10:06] Per-Erik Martin
The AVG identifier problem is fixed, so this bug should be considered closed.

The problem with the new test script is something else, it's the odd "delimiter"
commands causing problems for the server and/or client.
It can be reduced to this:

mysql> delimiter //
mysql> create table x (s1 int); insert into x values (5); foobar //
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

(... now hanging...)

But this is a different bug.