Skip to content

Instantly share code, notes, and snippets.

@BenoitDuffez
Created September 22, 2015 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenoitDuffez/8dc23ed48e995d3e3254 to your computer and use it in GitHub Desktop.
Save BenoitDuffez/8dc23ed48e995d3e3254 to your computer and use it in GitHub Desktop.
MySQL bug?
#!/bin/sh
MYSQL="mysql" # add -u xyz -pabcd or export MYSQL_PWD, etc
echo "Init"
$MYSQL -e "drop database if exists test"
$MYSQL -e "create database test"
$MYSQL test -e 'delimiter $$
create function func() returns int(10)
begin
return 1;
end$$'
echo "Create procedure with statement"
$MYSQL test -e 'delimiter $$
create procedure testbug()
begin
drop table if exists src;
drop table if exists result;
create temporary table src (id int);
set @sql = "create temporary table result
select * from (select * from src where id < func()) a";
PREPARE s FROM @sql;
EXECUTE s;
deallocate prepare s;
END$$'
echo "Running script"
$MYSQL test -e 'call testbug(); show columns from result'
echo "Modifying procedure"
$MYSQL test -e 'drop procedure testbug'
$MYSQL test -e 'delimiter $$
create procedure testbug()
begin
drop table if exists src;
drop table if exists result;
create temporary table src (id int);
create temporary table result
select * from (select * from src where id < func()) a;
END$$'
echo "Running script again"
$MYSQL test -e 'call testbug(); show columns from result'
$ ./bug.sh
Init
Create procedure with statement
Running script
ERROR 1146 (42S02) at line 1: Table 'test.src' doesn't exist
Modifying procedure
Running script again
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment