[Commits] Rev 3732: MDEV-5353: server crash on subselect if WHERE applied to some result field in file:///home/bell/maria/bzr/work-maria-5.3-MDEV-5353/

sanja at askmonty.org sanja at askmonty.org
Wed Dec 4 16:54:58 EET 2013


At file:///home/bell/maria/bzr/work-maria-5.3-MDEV-5353/

------------------------------------------------------------
revno: 3732
revision-id: sanja at askmonty.org-20131204145433-i54vkc1iwbgw41oz
parent: bar at mnogosearch.org-20131203110843-1bsdu0hcrpzhie8w
committer: sanja at askmonty.org
branch nick: work-maria-5.3-MDEV-5353
timestamp: Wed 2013-12-04 16:54:33 +0200
message:
  MDEV-5353: server crash on subselect if WHERE applied to some result field
  
  Correct processing of view/derived with no tables added.
-------------- next part --------------
=== modified file 'mysql-test/r/derived.result'
--- a/mysql-test/r/derived.result	2013-10-21 10:45:49 +0000
+++ b/mysql-test/r/derived.result	2013-12-04 14:54:33 +0000
@@ -465,5 +465,19 @@ t1.val=t3.val
 ;
 ERROR 42S22: Unknown column 'v.val' in 'field list'
 drop table t1, t2;
+#
+# MDEV-5353: server crash on subselect if WHERE applied to some
+# result field
+#
+SELECT * FROM 
+( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
+WHERE tmp.b;
+a	b
+100	200
+SELECT * FROM 
+( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
+WHERE tmp.a;
+a	b
+100	200
 # End of 5.3 tests
 set optimizer_switch=@save_derived_optimizer_switch;

=== modified file 'mysql-test/t/derived.test'
--- a/mysql-test/t/derived.test	2013-10-21 10:45:49 +0000
+++ b/mysql-test/t/derived.test	2013-12-04 14:54:33 +0000
@@ -383,7 +383,17 @@ set
 
 drop table t1, t2;
 
+--echo #
+--echo # MDEV-5353: server crash on subselect if WHERE applied to some
+--echo # result field
+--echo #
 
+SELECT * FROM 
+( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
+WHERE tmp.b;
+SELECT * FROM 
+( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
+WHERE tmp.a;
 --echo # End of 5.3 tests
 
 set optimizer_switch=@save_derived_optimizer_switch;

=== modified file 'sql/item.h'
--- a/sql/item.h	2013-11-21 07:46:36 +0000
+++ b/sql/item.h	2013-12-04 14:54:33 +0000
@@ -2963,13 +2963,16 @@ class Item_direct_view_ref :public Item_
   TABLE_LIST *view;
   TABLE *null_ref_table;
 
+#define NO_NULL_TABLE (reinterpret_cast<TABLE *>(0x1))
+
   bool check_null_ref()
   {
     if (null_ref_table == NULL)
     {
-      null_ref_table= view->get_real_join_table();
+      if (!(null_ref_table= view->get_real_join_table()))
+        null_ref_table= NO_NULL_TABLE;
     }
-    if (null_ref_table->null_row)
+    if (null_ref_table != NO_NULL_TABLE && null_ref_table->null_row)
     {
       null_value= 1;
       return TRUE;

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2013-08-15 21:04:20 +0000
+++ b/sql/table.cc	2013-12-04 14:54:33 +0000
@@ -4487,10 +4487,8 @@ TABLE *TABLE_LIST::get_real_join_table()
           */
           for (TABLE_LIST *t= ti++; t; t= ti++)
             tbl= t;
-          /*
-            It is impossible that the list is empty
-            so tbl can't be NULL after above loop.
-          */
+          if (!tbl)
+            return NULL; // view/derived with no tables
           if (!tbl->nested_join)
             break;
           /* go deeper if we've found nested join */



More information about the commits mailing list