summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-05-28 19:43:06 +0200
committerunknown <pem@mysql.comhem.se>2004-05-28 19:43:06 +0200
commitb0921b1f5a1f610b04641a83d0d7b21e3fe46d84 (patch)
treeacfbe5dd51eab312289261b3f572fa68ce012884
parent72139b18aac3d799afea1c0ffe8a4dee92d2420d (diff)
downloadmariadb-git-b0921b1f5a1f610b04641a83d0d7b21e3fe46d84.tar.gz
Fixed BUG#2460: Crash wih Stored Procedure and UNION.
mysql-test/r/sp.result: Added test case for BUG#2460. mysql-test/t/sp.test: Added test case for BUG#2460. sql/sql_union.cc: When called from stored procedures, tabs might be reset already.
-rw-r--r--mysql-test/r/sp.result45
-rw-r--r--mysql-test/t/sp.test46
-rw-r--r--sql/sql_union.cc4
3 files changed, 94 insertions, 1 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index d0a37c742a4..8595f1ecebd 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -1273,6 +1273,51 @@ select @a|
@a
5
drop procedure bug3863|
+drop table if exists t3|
+create table t3 (
+id int(10) unsigned not null default 0,
+rid int(10) unsigned not null default 0,
+msg text not null,
+primary key (id),
+unique key rid (rid, id)
+)|
+create procedure bug2460_1(in v int)
+begin
+( select n0.id from t3 as n0 where n0.id = v )
+union
+( select n0.id from t3 as n0, t3 as n1
+where n0.id = n1.rid and n1.id = v )
+union
+( select n0.id from t3 as n0, t3 as n1, t3 as n2
+where n0.id = n1.rid and n1.id = n2.rid and n2.id = v );
+end|
+call bug2460_1(2)|
+id
+call bug2460_1(2)|
+id
+insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')|
+call bug2460_1(2)|
+id
+2
+1
+call bug2460_1(2)|
+id
+2
+1
+create procedure bug2460_2()
+begin
+drop table if exists t3;
+create table t3 (s1 int);
+insert into t3 select 1 union select 1;
+end|
+call bug2460_2()|
+call bug2460_2()|
+select * from t3|
+s1
+1
+drop procedure bug2460_1|
+drop procedure bug2460_2|
+drop table t3|
drop table if exists fac|
create table fac (n int unsigned not null primary key, f bigint unsigned)|
create procedure ifac(n int unsigned)
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index bd6606332b9..05847ba220c 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -1471,6 +1471,52 @@ select @a|
drop procedure bug3863|
+#
+# BUG#2460
+#
+--disable_warnings
+drop table if exists t3|
+--enable_warnings
+create table t3 (
+ id int(10) unsigned not null default 0,
+ rid int(10) unsigned not null default 0,
+ msg text not null,
+ primary key (id),
+ unique key rid (rid, id)
+)|
+
+create procedure bug2460_1(in v int)
+begin
+ ( select n0.id from t3 as n0 where n0.id = v )
+ union
+ ( select n0.id from t3 as n0, t3 as n1
+ where n0.id = n1.rid and n1.id = v )
+ union
+ ( select n0.id from t3 as n0, t3 as n1, t3 as n2
+ where n0.id = n1.rid and n1.id = n2.rid and n2.id = v );
+end|
+
+call bug2460_1(2)|
+call bug2460_1(2)|
+insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')|
+call bug2460_1(2)|
+call bug2460_1(2)|
+
+create procedure bug2460_2()
+begin
+ drop table if exists t3;
+ create table t3 (s1 int);
+ insert into t3 select 1 union select 1;
+end|
+
+call bug2460_2()|
+call bug2460_2()|
+select * from t3|
+
+drop procedure bug2460_1|
+drop procedure bug2460_2|
+drop table t3|
+
#
# Some "real" examples
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 794fbc74c73..81f64400400 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -457,7 +457,9 @@ int st_select_lex_unit::exec()
else
{
JOIN_TAB *tab,*end;
- for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
+ for (tab=join->join_tab, end=tab+join->tables ;
+ tab && tab != end ;
+ tab++)
{
delete tab->select;
delete tab->quick;