[Commits] 6936857: Fixed a bug with select numbering.

IgorBabaev igor at mariadb.com
Fri Apr 6 03:12:11 EEST 2018


revision-id: 6936857654df02555fec95259c46ab07e7591413 (mariadb-10.3.5-106-g6936857)
parent(s): 9751b597780f025636e85987cbbe279e3fce772d
author: Igor Babaev
committer: Igor Babaev
timestamp: 2018-04-05 17:12:11 -0700
message:

Fixed a bug with select numbering.
Fixed a bug in LEX::pop_new_select_and_wrap()
that caused constructing invalid unit trees.

---
 mysql-test/main/cte_nonrecursive.result | 32 ++++++++++++++++----------------
 sql/sql_lex.cc                          |  3 +--
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/mysql-test/main/cte_nonrecursive.result b/mysql-test/main/cte_nonrecursive.result
index a1c4dca..89ffd94 100644
--- a/mysql-test/main/cte_nonrecursive.result
+++ b/mysql-test/main/cte_nonrecursive.result
@@ -151,8 +151,8 @@ with t as (select a from t1 where a<5)
 select * from t2 where c in (select a from t);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	4	
-1	PRIMARY	<subquery2>	eq_ref	distinct_key	distinct_key	4	func	1	
-2	MATERIALIZED	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
+1	PRIMARY	<subquery3>	eq_ref	distinct_key	distinct_key	4	func	1	
+3	MATERIALIZED	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
 explain
 select * from t2 
 where c in (select a from (select a from t1 where a<5) as t);
@@ -332,8 +332,8 @@ union
 select * from t where a >= 4;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
-2	UNION	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
-NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
+3	UNION	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
+NULL	UNION RESULT	<union1,3>	ALL	NULL	NULL	NULL	NULL	NULL	
 explain
 select * from (select a from t1 where b >= 'c') as t
 where t.a < 2
@@ -461,10 +461,10 @@ t.c in (with t as (select * from t1 where t1.a<5)
 select t2.c from t2,t where t2.c=t.a);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
-1	PRIMARY	<subquery3>	eq_ref	distinct_key	distinct_key	4	func	1	
+1	PRIMARY	<subquery4>	eq_ref	distinct_key	distinct_key	4	func	1	
 1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using join buffer (flat, BNL join)
-3	MATERIALIZED	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
-3	MATERIALIZED	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using join buffer (flat, BNL join)
+4	MATERIALIZED	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+4	MATERIALIZED	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using join buffer (flat, BNL join)
 explain
 select t1.a,t1.b from t1, (select c from t2 where c >= 4) as t
 where t1.a=t.c and
@@ -597,8 +597,8 @@ explain
 select * from v2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
-1	PRIMARY	<derived3>	ref	key0	key0	5	test.t2.c	2	
-3	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using temporary; Using filesort
+1	PRIMARY	<derived2>	ref	key0	key0	5	test.t2.c	2	
+2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using temporary; Using filesort
 # with clause in the specification of a view that whose definition
 # table alias for a with table
 create view v3 as
@@ -1116,17 +1116,17 @@ select * from cte_e as cte_e1 where a > 1
 union
 select * from cte_e as cte_e2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
-1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	14	100.00	Using where
-2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	7	100.00	Using where
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	14	100.00	Using where
+4	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	7	100.00	Using where
 5	UNION	t1	ALL	NULL	NULL	NULL	NULL	7	100.00	Using where
-NULL	UNION RESULT	<union2,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
-6	UNION	<derived9>	ALL	NULL	NULL	NULL	NULL	14	100.00	
-9	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	7	100.00	Using where
+NULL	UNION RESULT	<union4,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
+6	UNION	<derived11>	ALL	NULL	NULL	NULL	NULL	14	100.00	
+11	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	7	100.00	Using where
 12	UNION	t1	ALL	NULL	NULL	NULL	NULL	7	100.00	Using where
-NULL	UNION RESULT	<union9,12>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
+NULL	UNION RESULT	<union11,12>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
 NULL	UNION RESULT	<union1,6>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
 Warnings:
-Note	1003	with cte_e as (with cte_o as (with cte_i as (/* select#4 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 7)/* select#3 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1)/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 3 and `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7 and `test`.`t1`.`a` > 1 union /* select#5 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4 and `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7 and `test`.`t1`.`a` > 1)/* select#1 */ select `cte_e1`.`a` AS `a` from `cte_e` `cte_e1` where `cte_e1`.`a` > 1 union /* select#6 */ select `cte_e2`.`a` AS `a` from (with cte_o as (with cte_i as (/* select#11 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 7)/* select#10 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1)/* select#9 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a`
  < 3 and
  `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7 union /* select#12 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4 and `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7) `cte_e2`
+Note	1003	with cte_e as (with cte_o as (with cte_i as (select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 7)select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1)select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 3 and `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7 and `test`.`t1`.`a` > 1 union select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4 and `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7 and `test`.`t1`.`a` > 1)select `cte_e1`.`a` AS `a` from `cte_e` `cte_e1` where `cte_e1`.`a` > 1 union select `cte_e2`.`a` AS `a` from (with cte_o as (with cte_i as (select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 7)select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 1)select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` < 3 and `test`.`t1`.`a` > 1 and `test`.`t1`.`a` < 7 union select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4 and `
 test`.`t
 1`.`a` > 1 and `test`.`t1`.`a` < 7) `cte_e2`
 drop table t1;
 #
 # MDEV-13753: embedded CTE in a VIEW created in prepared statement
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index e037f05..cc7cc8d 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3687,8 +3687,6 @@ void LEX::fix_first_select_number()
     {
       if (sel->select_number < num)
         sel->select_number++;
-      if (sel->select_number > num)
-        sel->select_number--;
     }
     first->select_number= 1;
   }
@@ -5556,6 +5554,7 @@ SELECT_LEX *LEX::pop_new_select_and_wrap()
       DBUG_RETURN(NULL);
   last->link_neighbour(sel);
   sel->set_linkage_and_distinct(op, ds);
+  sel->set_master_unit(last->master_unit());
   DBUG_RETURN(sel);
 }
 


More information about the commits mailing list