summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/subselect.result3
-rw-r--r--mysql-test/t/subselect.test2
-rw-r--r--sql/sql_lex.cc2
-rw-r--r--sql/sql_lex.h5
-rw-r--r--sql/sql_union.cc8
5 files changed, 14 insertions, 6 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 5c5b8984102..b1bf134fdde 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -5,6 +5,9 @@ SELECT (SELECT 1) UNION SELECT (SELECT 2);
(SELECT 1)
1
2
+SELECT (SELECT (SELECT 0 UNION SELECT 0));
+(SELECT (SELECT 0 UNION SELECT 0))
+0
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
create table t1 (a int);
create table t2 (a int, b int);
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index c74922d3d9e..841e98dd96c 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1,6 +1,6 @@
-
select (select 2);
SELECT (SELECT 1) UNION SELECT (SELECT 2);
+SELECT (SELECT (SELECT 0 UNION SELECT 0));
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
create table t1 (a int);
create table t2 (a int, b int);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index b68316a1e4a..52f1be6bddf 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -945,7 +945,7 @@ void st_select_lex_unit::init_query()
select_limit_cnt= HA_POS_ERROR;
offset_limit_cnt= 0;
union_option= 0;
- prepared= optimized= 0;
+ prepared= optimized= executed= 0;
item= 0;
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 070eecb1797..fa886f9d60a 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -227,8 +227,9 @@ protected:
select_result *result;
int res;
bool describe, found_rows_for_union,
- prepared, //prepare phase already performed for UNION (unit)
- optimized; // optimize phase already performed for UNION (unit)
+ prepared, // prepare phase already performed for UNION (unit)
+ optimized, // optimize phase already performed for UNION (unit)
+ executed; // already executed
public:
/*
Pointer to 'last' select or pointer to unit where stored
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index f1c80bf8546..899dceab9bc 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -199,8 +199,12 @@ int st_select_lex_unit::exec()
{
DBUG_ENTER("st_select_lex_unit::exec");
SELECT_LEX *lex_select_save= thd->lex.select;
-
- if(depended || !item || !item->assigned())
+
+ if (executed && !depended)
+ DBUG_RETURN(0);
+ executed= 1;
+
+ if (depended || !item || !item->assigned())
{
if (optimized && item && item->assigned())
item->assigned(0); // We will reinit & rexecute unit