List:Commits« Previous MessageNext Message »
From:Roy Lyseng Date:October 7 2011 1:00pm
Subject:bzr push into mysql-trunk branch (roy.lyseng:3457 to 3458) Bug#12711441
View as plain text  
 3458 Roy Lyseng	2011-10-07
      Bug#12711441: crash in item_ident::fix_after_pullout on subquery...
      
      The problem occurs during semi-join transformation of
      a query involving the following query blocks (select_lex objects):
      
      +-------+
      | Outer |
      +-------+ 
          |       +--------+
          +------>| Middle |
                  +--------+
                      |       +--------+
                      +------>| Inner  |
                              +--------+
      
      The Middle query block is part of an IN predicate and is merged
      into the Outer query block. The Inner query block is part of a
      >= SOME quantified comparison predicate which cannot be transformed.
      
      When attempting to apply the function fix_after_pullout() on a field
      of type Item_direct_view_ref which is also an outer reference, the
      program crashes. The field is referenced in the Inner query block and
      it originates from a view that is referenced in the Middle query block.
      
      The reason for the crash is that the Item_direct_view_ref object
      representing the view field v1.col_varchar_key is created with wrong
      name resolution context information. It is created with a context
      representing the Middle query block, but an equivalent table field
      would have been created with a context representing the Inner query
      block. dependent_from is then set to the same query block as the
      name resolution context points to, which is an illegal situation
      that Item_ident::fix_after_pullout() is not trained to handle.
      
      The solution seems to be to add proper name resolution context
      information to the Item_direct_view_ref constructor.
      
      Notice that the inner ref object of Item_direct_view_ref object
      references the query block where the view is referenced in the FROM
      clause, hence looking in the inner object will fail to get a proper
      name resolution context for the view field.
      
      mysql-test/include/subquery_sj.inc
        Added test case for bug#12711441
      
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
        Added test case results for bug#12711441
      
      sql/item.cc
        Added an invariant check to Item_ident::fix_after_pullout.
        Added Name_resolution_context argument to Item_ref constructor.
        Deleted redundant Item_ident and Item_ref constructors.
      
      sql/item.h
        Added Name_resolution_context arguments to constructors for
        Item_ident, Item_ref, Item_direct_ref and Item_direct_view_ref
        Deleted redundant Item_ident, Item_ref, Item_direct_ref and
        Item_direct_view_ref constructors.
      
      sql/table.cc
        Added Name_resolution_context argument when constructing
        Item_direct_view_ref objects.
      
      sql/table.h
        Deleted function declaration after declaring function static.

    modified:
      mysql-test/include/subquery_sj.inc
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
      sql/item.cc
      sql/item.h
      sql/table.cc
      sql/table.h
 3457 Roy Lyseng	2011-10-06
      Bug#12867557: Valgrind: conditional jump/move at key_cmp
      
      This problem may occur when starting a JOIN execution for the second
      and subsequent time, such as when a subquery is evaluated in the
      context of an UPDATE statement to evaluate whether a row qualifies
      to be updated. The problem may also appear only in the case of a
      loosescan semi-join strategy. When the previous execution had
      qualifying rows, the found_match flag may be left with value TRUE,
      so that we erroneously assume that there is a row in loosescan_buf
      that we may compare the current row with.
      
      The problem is fixed by clearing the found_match flag when entering a
      new join_tab level within sub_select().
      
      mysql-test/include/subquery_sj.inc
        Added test case for bug#12867557.
      
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
        Added test case results for bug#12867557.
      
      sql/sql_select.cc
        In sub_select(), added initialization of loosescan match flag when
        entering a new join_tab level.

    modified:
      mysql-test/include/subquery_sj.inc
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
      sql/sql_select.cc
=== modified file 'mysql-test/include/subquery_sj.inc'
--- a/mysql-test/include/subquery_sj.inc	2011-10-06 10:58:30 +0000
+++ b/mysql-test/include/subquery_sj.inc	2011-10-07 12:44:17 +0000
@@ -4169,4 +4169,76 @@ DROP TABLE t0, t1, t2;
 
 --echo # End of test for bug#12867557
 
+--echo #
+--echo # Bug#12711441: crash in fix_after_pullout
+--echo #
+
+CREATE TABLE t1 (
+  pk int NOT NULL,
+  col_int_nokey int DEFAULT NULL,
+  col_int_key int DEFAULT NULL,
+  col_time_key time DEFAULT NULL,
+  col_varchar_key varchar(1) DEFAULT NULL,
+  PRIMARY KEY (pk)
+);
+
+CREATE VIEW v1 AS SELECT * FROM t1;
+
+CREATE TABLE t2 (
+  col_int_key int DEFAULT NULL,
+  col_varchar_key varchar(1) DEFAULT NULL,
+  col_varchar_nokey varchar(1) DEFAULT NULL,
+  KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+
+CREATE TABLE t3 (
+  pk int NOT NULL,
+  col_int_key INT DEFAULT NULL,
+  PRIMARY KEY (pk)
+);
+
+CREATE TABLE t4 (
+  col_int_nokey INT DEFAULT NULL,
+  col_varchar_key varchar(1) DEFAULT NULL,
+  col_varchar_nokey varchar(1) DEFAULT NULL,
+  KEY col_varchar_key(col_varchar_key)
+);
+
+CREATE TABLE ts
+  SELECT alias1.col_time_key AS field1
+  FROM v1 AS alias1
+       RIGHT JOIN t3 AS alias2
+       ON alias2.col_int_key = alias1.col_int_nokey
+  WHERE alias1.pk >= SOME(
+    SELECT SQ1_alias1.pk AS SQ1_field1
+    FROM t3 AS SQ1_alias1
+         INNER JOIN (t2 AS SQ1_alias2
+           INNER JOIN t4 AS SQ1_alias3
+           ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+         ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+    WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+      AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+
+SELECT * FROM ts WHERE field1 IN (
+  SELECT alias1.col_time_key AS field1
+  FROM v1 AS alias1
+       RIGHT JOIN t3 AS alias2
+       ON alias2.col_int_key = alias1.col_int_nokey
+  WHERE alias1.pk >= SOME(
+    SELECT SQ1_alias1.pk AS SQ1_field1
+    FROM t3 AS SQ1_alias1
+         INNER JOIN (t2 AS SQ1_alias2
+           INNER JOIN t4 AS SQ1_alias3
+           ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+          ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+    WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+      AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+
+--echo # End of test for bug#12711441.
+
 --echo # End of 5.6 tests

=== modified file 'mysql-test/r/subquery_sj_all.result'
--- a/mysql-test/r/subquery_sj_all.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_all.result	2011-10-07 12:44:17 +0000
@@ -6839,5 +6839,68 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_all_bka.result'
--- a/mysql-test/r/subquery_sj_all_bka.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_all_bka.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_all_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_all_bka_nixbnl.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_all_bka_nixbnl.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_all_bkaunique.result'
--- a/mysql-test/r/subquery_sj_all_bkaunique.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_all_bkaunique.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed.result'
--- a/mysql-test/r/subquery_sj_dupsweed.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed.result	2011-10-07 12:44:17 +0000
@@ -6839,5 +6839,68 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed_bka.result'
--- a/mysql-test/r/subquery_sj_dupsweed_bka.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed_bka.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_dupsweed_bkaunique.result'
--- a/mysql-test/r/subquery_sj_dupsweed_bkaunique.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_dupsweed_bkaunique.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_firstmatch.result'
--- a/mysql-test/r/subquery_sj_firstmatch.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_firstmatch_bka.result'
--- a/mysql-test/r/subquery_sj_firstmatch_bka.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch_bka.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_firstmatch_bkaunique.result'
--- a/mysql-test/r/subquery_sj_firstmatch_bkaunique.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_firstmatch_bkaunique.result	2011-10-07 12:44:17 +0000
@@ -6842,6 +6842,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 #
 # Bug#51457 Firstmatch semijoin strategy gives wrong results for

=== modified file 'mysql-test/r/subquery_sj_loosescan.result'
--- a/mysql-test/r/subquery_sj_loosescan.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_loosescan.result	2011-10-07 12:44:17 +0000
@@ -6840,5 +6840,68 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_loosescan_bka.result'
--- a/mysql-test/r/subquery_sj_loosescan_bka.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_loosescan_bka.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_loosescan_bkaunique.result'
--- a/mysql-test/r/subquery_sj_loosescan_bkaunique.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_loosescan_bkaunique.result	2011-10-07 12:44:17 +0000
@@ -6842,6 +6842,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat.result'
--- a/mysql-test/r/subquery_sj_mat.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_mat.result	2011-10-07 12:44:17 +0000
@@ -6839,5 +6839,68 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_bka.result'
--- a/mysql-test/r/subquery_sj_mat_bka.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_mat_bka.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_mat_bka_nixbnl.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_mat_bka_nixbnl.result	2011-10-07 12:44:17 +0000
@@ -6840,6 +6840,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_bkaunique.result'
--- a/mysql-test/r/subquery_sj_mat_bkaunique.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_mat_bkaunique.result	2011-10-07 12:44:17 +0000
@@ -6841,6 +6841,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_mat_nosj.result'
--- a/mysql-test/r/subquery_sj_mat_nosj.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_mat_nosj.result	2011-10-07 12:44:17 +0000
@@ -6916,5 +6916,68 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none.result'
--- a/mysql-test/r/subquery_sj_none.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_none.result	2011-10-07 12:44:17 +0000
@@ -6851,5 +6851,68 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none_bka.result'
--- a/mysql-test/r/subquery_sj_none_bka.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_none_bka.result	2011-10-07 12:44:17 +0000
@@ -6852,6 +6852,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none_bka_nixbnl.result'
--- a/mysql-test/r/subquery_sj_none_bka_nixbnl.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_none_bka_nixbnl.result	2011-10-07 12:44:17 +0000
@@ -6852,6 +6852,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'mysql-test/r/subquery_sj_none_bkaunique.result'
--- a/mysql-test/r/subquery_sj_none_bkaunique.result	2011-10-06 10:58:30 +0000
+++ b/mysql-test/r/subquery_sj_none_bkaunique.result	2011-10-07 12:44:17 +0000
@@ -6853,6 +6853,69 @@ FROM t1 AS parent1)
 AND grandparent1.pk > 9);
 DROP TABLE t0, t1, t2;
 # End of test for bug#12867557
+#
+# Bug#12711441: crash in fix_after_pullout
+#
+CREATE TABLE t1 (
+pk int NOT NULL,
+col_int_nokey int DEFAULT NULL,
+col_int_key int DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TABLE t2 (
+col_int_key int DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key, col_int_key)
+);
+CREATE TABLE t3 (
+pk int NOT NULL,
+col_int_key INT DEFAULT NULL,
+PRIMARY KEY (pk)
+);
+CREATE TABLE t4 (
+col_int_nokey INT DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+col_varchar_nokey varchar(1) DEFAULT NULL,
+KEY col_varchar_key(col_varchar_key)
+);
+CREATE TABLE ts
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+;
+SELECT * FROM ts WHERE field1 IN (
+SELECT alias1.col_time_key AS field1
+FROM v1 AS alias1
+RIGHT JOIN t3 AS alias2
+ON alias2.col_int_key = alias1.col_int_nokey
+WHERE alias1.pk >= SOME(
+SELECT SQ1_alias1.pk AS SQ1_field1
+FROM t3 AS SQ1_alias1
+INNER JOIN (t2 AS SQ1_alias2
+INNER JOIN t4 AS SQ1_alias3
+ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
+ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
+WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
+AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
+);
+field1
+DROP TABLE t1, t2, t3, t4, ts;
+DROP VIEW v1;
+# End of test for bug#12711441.
 # End of 5.6 tests
 set optimizer_switch=default;
 set optimizer_switch=default;

=== modified file 'sql/item.cc'
--- a/sql/item.cc	2011-09-07 12:41:53 +0000
+++ b/sql/item.cc	2011-10-07 12:44:17 +0000
@@ -600,18 +600,6 @@ Item_ident::Item_ident(Name_resolution_c
 }
 
 
-Item_ident::Item_ident(TABLE_LIST *view_arg, const char *field_name_arg)
-  :orig_db_name(NullS), orig_table_name(view_arg->table_name),
-   orig_field_name(field_name_arg), context(&view_arg->view->select_lex.context),
-   db_name(NullS), table_name(view_arg->alias),
-   field_name(field_name_arg),
-   alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
-   cached_table(NULL), depended_from(NULL)
-{
-  name = (char*) field_name_arg;
-}
-
-
 /**
   Constructor used by Item_field & Item_*_ref (see Item comment)
 */
@@ -2379,6 +2367,9 @@ void Item_ident::fix_after_pullout(st_se
                                    st_select_lex *removed_select,
                                    Item **ref)
 {
+  DBUG_ASSERT(context->select_lex == NULL ||
+              context->select_lex != depended_from);
+
   if (context->select_lex == removed_select ||
       context->select_lex == parent_select)
   {
@@ -6294,20 +6285,6 @@ Item_ref::Item_ref(Name_resolution_conte
 }
 
 
-Item_ref::Item_ref(TABLE_LIST *view_arg, Item **item,
-                   const char *field_name_arg, bool alias_name_used_arg)
-  :Item_ident(view_arg, field_name_arg),
-   result_field(NULL), ref(item)
-{
-  alias_name_used= alias_name_used_arg;
-  /*
-    This constructor is used to create some internal references over fixed items
-  */
-  if (ref && *ref && (*ref)->fixed)
-    set_properties();
-}
-
-
 /**
   Resolve the name of a reference to a column reference.
 

=== modified file 'sql/item.h'
--- a/sql/item.h	2011-09-07 12:41:53 +0000
+++ b/sql/item.h	2011-10-07 12:44:17 +0000
@@ -1704,7 +1704,6 @@ public:
              const char *db_name_arg, const char *table_name_arg,
              const char *field_name_arg);
   Item_ident(THD *thd, Item_ident *item);
-  Item_ident(TABLE_LIST *view_arg, const char *field_name_arg);
   /*
     Return used table information for the level on which this table is resolved.
   */
@@ -2594,8 +2593,6 @@ public:
   Item_ref(Name_resolution_context *context_arg, Item **item,
            const char *table_name_arg, const char *field_name_arg,
            bool alias_name_used_arg= FALSE);
-  Item_ref(TABLE_LIST *view_arg, Item **item,
-           const char *field_name_arg, bool alias_name_used_arg= FALSE);
 
   /* Constructor need to process subselect with temporary tables (see Item) */
   Item_ref(THD *thd, Item_ref *item)
@@ -2737,12 +2734,6 @@ public:
   {}
   /* Constructor need to process subselect with temporary tables (see Item) */
   Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
-  Item_direct_ref(TABLE_LIST *view_arg, Item **item,
-                  const char *field_name_arg,
-                  bool alias_name_used_arg= FALSE)
-    :Item_ref(view_arg, item, field_name_arg,
-              alias_name_used_arg)
-  {}
 
   double val_real();
   longlong val_int();
@@ -2761,17 +2752,19 @@ public:
 class Item_direct_view_ref :public Item_direct_ref
 {
 public:
-  Item_direct_view_ref(Name_resolution_context *context_arg, Item **item,
-                  const char *table_name_arg,
-                  const char *field_name_arg)
-    :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
+  Item_direct_view_ref(Name_resolution_context *context_arg,
+                       Item **item,
+                       const char *alias_name_arg,
+                       const char *table_name_arg,
+                       const char *field_name_arg)
+    : Item_direct_ref(context_arg, item, alias_name_arg, field_name_arg)
+  {
+    orig_table_name= table_name_arg;
+  }
+
   /* Constructor need to process subselect with temporary tables (see Item) */
   Item_direct_view_ref(THD *thd, Item_direct_ref *item)
     :Item_direct_ref(thd, item) {}
-  Item_direct_view_ref(TABLE_LIST *view_arg, Item **item,
-                       const char *field_name_arg)
-    :Item_direct_ref(view_arg, item, field_name_arg)
-  {}
 
   bool fix_fields(THD *, Item **);
   bool eq(const Item *item, bool binary_cmp) const;

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2011-09-26 13:48:06 +0000
+++ b/sql/table.cc	2011-10-07 12:44:17 +0000
@@ -73,6 +73,10 @@ static void fix_type_pointers(const char
 			      uint types, char **names);
 static uint find_field(Field **fields, uchar *record, uint start, uint length);
 
+static Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
+                               const char *name,
+                               Name_resolution_context *context);
+
 inline bool is_system_table_name(const char *name, uint length);
 
 static ulong get_form_pos(File file, uchar *head);
@@ -4431,8 +4435,9 @@ Item *Natural_join_column::create_item(T
   if (view_field)
   {
     DBUG_ASSERT(table_field == NULL);
+    SELECT_LEX *select= thd->lex->current_select;
     return create_view_field(thd, table_ref, &view_field->item,
-                             view_field->name);
+                             view_field->name, &select->context);
   }
   return table_field;
 }
@@ -4522,11 +4527,14 @@ const char *Field_iterator_view::name()
 
 Item *Field_iterator_view::create_item(THD *thd)
 {
-  return create_view_field(thd, view, &ptr->item, ptr->name);
+  SELECT_LEX *select= thd->lex->current_select;
+  return create_view_field(thd, view, &ptr->item, ptr->name,
+                           &select->context);
 }
 
-Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
-                        const char *name)
+static Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
+                               const char *name,
+                               Name_resolution_context *context)
 {
   bool save_wrapper= thd->lex->select_lex.no_wrap_view_item;
   Item *field= *field_ref;
@@ -4559,7 +4567,8 @@ Item *create_view_field(THD *thd, TABLE_
   {
     DBUG_RETURN(field);
   }
-  Item *item= new Item_direct_view_ref(view, field_ref, name);
+  Item *item= new Item_direct_view_ref(context, field_ref,
+                                       view->alias, view->table_name, name);
   DBUG_RETURN(item);
 }
 

=== modified file 'sql/table.h'
--- a/sql/table.h	2011-09-16 10:12:49 +0000
+++ b/sql/table.h	2011-10-07 12:44:17 +0000
@@ -1337,9 +1337,6 @@ enum enum_derived_type {
 class select_union;
 class TMP_TABLE_PARAM;
 
-Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
-                        const char *name);
-
 struct Field_translator
 {
   Item *item;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (roy.lyseng:3457 to 3458) Bug#12711441Roy Lyseng7 Oct