[Commits] bda8829: MDEV-10141 & MDEV-10140 : Postpostreview changes

Oleksandr Byelkin sanja at mariadb.com
Mon Mar 13 13:06:14 EET 2017


revision-id: bda882968ae3799f4841d443d8c60c14696c019e (mariadb-10.2.2-170-gbda8829)
parent(s): 4c31280c5bfdfc3a1fec177de563c61559efe9c0
committer: Oleksandr Byelkin
timestamp: 2017-03-13 12:06:14 +0100
message:

MDEV-10141 & MDEV-10140 : Postpostreview changes

---
 include/m_string.h            |  6 ++++++
 mysql-test/r/intersect.result | 16 ++++++++++++++++
 mysql-test/t/intersect.test   |  6 ++++++
 sql/sql_explain.cc            | 14 ++++++--------
 sql/sql_lex.cc                |  2 +-
 sql/sql_union.cc              | 10 +++-------
 6 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/include/m_string.h b/include/m_string.h
index 0f3cd36..8cd9d3a 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -230,6 +230,12 @@ static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
   lex_str->str= (char *) c_str;
   lex_str->length= strlen(c_str);
 }
+static inline void lex_string_set3(LEX_STRING *lex_str, const char *c_str,
+                                   size_t len)
+{
+  lex_str->str= (char *) c_str;
+  lex_str->length= len;
+}
 
 #ifdef __cplusplus
 static inline char *safe_str(char *str)
diff --git a/mysql-test/r/intersect.result b/mysql-test/r/intersect.result
index 52bb564..5dfb7fb 100644
--- a/mysql-test/r/intersect.result
+++ b/mysql-test/r/intersect.result
@@ -607,6 +607,22 @@ NULL	INTERSECT RESULT	<intersect2,4>	ALL	NULL	NULL	NULL	NULL	NULL	NULL
 NULL	UNION RESULT	<union1,3,5>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
 Warnings:
 Note	1003	(/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`)
+(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
+e	f
+3	3
+4	4
+5	5
+6	6
+explain extended
+(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	INTERSECT	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
+3	UNION	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+4	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+NULL	UNIT RESULT	<unit1,2,3,4>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
+Warnings:
+Note	1003	(/* select#1 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`) intersect (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) union (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union (/* select#4 */ select 4 AS `4`,4 AS `4`)
 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`);
 a	b
 3	3
diff --git a/mysql-test/t/intersect.test b/mysql-test/t/intersect.test
index d7abf41..86fa534 100644
--- a/mysql-test/t/intersect.test
+++ b/mysql-test/t/intersect.test
@@ -148,6 +148,12 @@ insert into t3 values (1,1),(3,3);
 explain extended
 (select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
 
+# test result of linear mix operation 
+--sorted_result
+(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
+explain extended
+(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
+
 --sorted_result
 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`);
 
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 693235c..87b86f7 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -424,27 +424,25 @@ uint Explain_union::make_union_table_name(char *buf)
 {
   uint childno= 0;
   uint len, lastop= 0;
+  LEX_STRING type;
   switch (operation)
   {
     case OP_MIX:
-      len= 5;
-      memcpy(buf, STRING_WITH_LEN("<unit"));
+      lex_string_set3(&type, STRING_WITH_LEN("<unit"));
       break;
     case OP_UNION:
-      len= 6;
-      memcpy(buf, STRING_WITH_LEN("<union"));
+      lex_string_set3(&type, STRING_WITH_LEN("<union"));
       break;
     case OP_INTERSECT:
-      len= 10;
-      memcpy(buf, STRING_WITH_LEN("<intersect"));
+      lex_string_set3(&type, STRING_WITH_LEN("<intersect"));
       break;
     case OP_EXCEPT:
-      len= 7;
-      memcpy(buf, STRING_WITH_LEN("<except"));
+      lex_string_set3(&type, STRING_WITH_LEN("<except"));
       break;
     default:
       DBUG_ASSERT(0);
   }
+  memcpy(buf, type.str, (len= type.length));
 
   for (; childno < union_members.elements() && len + lastop + 5 < NAME_LEN;
        childno++)
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index cc6e332..24c08f1 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -4766,7 +4766,7 @@ unit_common_op st_select_lex_unit::common_op()
       if (first_op)
       {
         operation= op;
-        first_op= TRUE;
+        first_op= FALSE;
       }
       else
       {
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 3d9949a..f644bf4 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -55,7 +55,7 @@ int select_unit::prepare(List<Item> &list, SELECT_LEX_UNIT *u)
 }
 
 /**
-  This called by SELECT_LEX_UNIT::exec when select chenged
+  This called by SELECT_LEX_UNIT::exec when select changed
 */
 
 void select_unit::change_select()
@@ -71,6 +71,8 @@ void select_unit::change_select()
   switch (thd->lex->current_select->linkage)
   {
   case INTERSECT_TYPE:
+    intersect_mark->value= prev_step= curr_step;
+    curr_step= current_select_number;
   case EXCEPT_TYPE:
     step= thd->lex->current_select->linkage;
     break;
@@ -78,12 +80,6 @@ void select_unit::change_select()
     step= UNION_TYPE;
     break;
   }
-
-  if (step == INTERSECT_TYPE)
-  {
-    intersect_mark->value= prev_step= curr_step;
-    curr_step= current_select_number;
-  }
   DBUG_VOID_RETURN;
 }
 /**


More information about the commits mailing list