summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorram@gw.mysql.r18.ru <>2004-09-03 19:59:29 +0500
committerram@gw.mysql.r18.ru <>2004-09-03 19:59:29 +0500
commitf91ca0bd660bd1d2449a3d5b3141b1a4d7dfb443 (patch)
tree2d229ece9ab6e399ce768d24026efbcd64481ad8
parentf7bc60e0fc0848b441103a0303237031c56949cc (diff)
downloadmariadb-git-f91ca0bd660bd1d2449a3d5b3141b1a4d7dfb443.tar.gz
A fix (Bug #4980: union statement with () union () order by produces wrong explain).
-rw-r--r--mysql-test/r/union.result9
-rw-r--r--mysql-test/t/union.test9
-rw-r--r--sql/sql_union.cc4
3 files changed, 21 insertions, 1 deletions
diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result
index 4b9555c334b..8f33bc4c316 100644
--- a/mysql-test/r/union.result
+++ b/mysql-test/r/union.result
@@ -88,7 +88,6 @@ explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a l
table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 4
t2 ALL NULL NULL NULL NULL 4 Using filesort
-t1 ALL NULL NULL NULL NULL 4
(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2;
a b
1 a
@@ -424,8 +423,16 @@ create table t1 select a from t1 union select a from t2;
INSERT TABLE 't1' isn't allowed in FROM table list
select a from t1 union select a from t2 order by t2.a;
Unknown column 't2.a' in 'ORDER BY'
+drop table t1;
drop table t1,t2;
select length(version()) > 1 as `*` UNION select 2;
*
1
2
+create table t1 (a int);
+insert into t1 values (0), (3), (1), (2);
+explain (select * from t1) union (select * from t1) order by a;
+table type possible_keys key key_len ref rows Extra
+t1 ALL NULL NULL NULL NULL 4
+t1 ALL NULL NULL NULL NULL 4
+drop table t1;
diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test
index c978aef9ce0..65b062d663f 100644
--- a/mysql-test/t/union.test
+++ b/mysql-test/t/union.test
@@ -228,6 +228,7 @@ create temporary table t1 select a from t1 union select a from t2;
create table t1 select a from t1 union select a from t2;
--error 1054
select a from t1 union select a from t2 order by t2.a;
+drop table t1; # Drop temporary table
drop table t1,t2;
#
@@ -236,3 +237,11 @@ drop table t1,t2;
select length(version()) > 1 as `*` UNION select 2;
+#
+# Bug #4980: problem with explain
+#
+
+create table t1 (a int);
+insert into t1 values (0), (3), (1), (2);
+explain (select * from t1) union (select * from t1) order by a;
+drop table t1;
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 8088737c0de..f79ff7967db 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -148,6 +148,10 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
{
ha_rows records_at_start;
lex->select=sl;
+#if MYSQL_VERSION_ID < 40100
+ if (describe && sl->linkage == NOT_A_SELECT)
+ break; // Skip extra item in case of 'explain'
+#endif
/* Don't use offset for the last union if there is no braces */
if (sl != lex_sl)
{