[Commits] 2b7e080: MDEV-19363 Assertion `select_lex' failed in LEX::pop_select

IgorBabaev igor at mariadb.com
Thu May 2 04:20:06 EEST 2019


revision-id: 2b7e080faece853f463f6f546066d54e1cbc330b (mariadb-10.4.4-61-g2b7e080)
parent(s): ea679c88c323dc2c79d9b5c05d4dba9671ad62bc
author: Igor Babaev
committer: Igor Babaev
timestamp: 2019-05-01 18:20:06 -0700
message:

MDEV-19363 Assertion `select_lex' failed in LEX::pop_select

This patch corrects the patch for MDEV-19324. The latter did not
work properly in the cases when the transformation
  (SELECT ... ORDER BY ...) LIMIT ... =>
   SELECT ... ORDER BY ... LIMIT ...
was applied to the operands of a set operation.

---
 mysql-test/main/brackets.result | 59 +++++++++++++++++++++++++++++++++++++++++
 mysql-test/main/brackets.test   | 15 +++++++++++
 sql/sql_lex.cc                  |  8 +++---
 3 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/mysql-test/main/brackets.result b/mysql-test/main/brackets.result
index 3cf3468..869afe5 100644
--- a/mysql-test/main/brackets.result
+++ b/mysql-test/main/brackets.result
@@ -393,4 +393,63 @@ EXPLAIN
   }
 }
 drop table t1;
+#
+# MDEV-19363: ((SELECT ...) ORDER BY col ) LIMIT n UNION ...
+#
+create table t1 (pk int);
+insert into t1 values (5),(4),(1),(2),(3);
+((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
+pk
+1
+2
+5
+explain extended ((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using filesort
+2	UNION	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
+Warnings:
+Note	1003	(/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` order by `test`.`t1`.`pk` limit 2) union (/* select#2 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where `test`.`t1`.`pk` > 4)
+explain format=json ((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
+EXPLAIN
+{
+  "query_block": {
+    "union_result": {
+      "table_name": "<union1,2>",
+      "access_type": "ALL",
+      "query_specifications": [
+        {
+          "query_block": {
+            "select_id": 1,
+            "read_sorted_file": {
+              "filesort": {
+                "sort_key": "t1.pk",
+                "table": {
+                  "table_name": "t1",
+                  "access_type": "ALL",
+                  "rows": 5,
+                  "filtered": 100
+                }
+              }
+            }
+          }
+        },
+        {
+          "query_block": {
+            "select_id": 2,
+            "operation": "UNION",
+            "table": {
+              "table_name": "t1",
+              "access_type": "ALL",
+              "rows": 5,
+              "filtered": 100,
+              "attached_condition": "t1.pk > 4"
+            }
+          }
+        }
+      ]
+    }
+  }
+}
+drop table t1;
 # End of 10.4 tests
diff --git a/mysql-test/main/brackets.test b/mysql-test/main/brackets.test
index 54f7d27..cf1dcc5 100644
--- a/mysql-test/main/brackets.test
+++ b/mysql-test/main/brackets.test
@@ -139,5 +139,20 @@ eval explain format=json $q2;
 
 drop table t1;
 
+--echo #
+--echo # MDEV-19363: ((SELECT ...) ORDER BY col ) LIMIT n UNION ...
+--echo #
+
+create table t1 (pk int);
+insert into t1 values (5),(4),(1),(2),(3);
+
+let $q=
+((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
+eval $q;
+eval explain extended $q;
+eval explain format=json $q;
+
+drop table t1;
+
 --echo # End of 10.4 tests
 
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 66ac69f..e1a6420 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -9147,13 +9147,15 @@ SELECT_LEX *LEX::parsed_select(SELECT_LEX *sel, Lex_order_limit_lock * l)
     }
     else
     {
-      SELECT_LEX_UNIT *unit= create_unit(sel);
-      if (!unit)
-        return NULL;
       if (!l->order_list && !sel->explicit_limit)
         l->order_list= &sel->order_list;
       else
+      {
+        SELECT_LEX_UNIT *unit= create_unit(sel);
+        if (!unit)
+          return NULL;
         sel= wrap_unit_into_derived(unit);
+      }
       if (!sel)
         return NULL;
       l->set_to(sel);


More information about the commits mailing list