List:Commits« Previous MessageNext Message »
From:Guilhem Bichot Date:August 31 2011 4:49pm
Subject:bzr push into mysql-trunk branch (guilhem.bichot:3403 to 3404) Bug#12905521
Bug#12905758
View as plain text  
 3404 Guilhem Bichot	2011-08-31
      1) fix for BUG#12905521 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON SELECT DISTINCT/MIN/JOIN/SUBQ QUERY
      (bug when evaluating subq in GROUP BY)
      and BUG#12905758 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON SELECT/SUBQ/SUM QUERY
      (bug when evaluating subq in ORDER BY)
      2) to avoid such bugs in the future, we don't crash anymore in case of json syntax error;
      instead, we now always produce valid syntax, by omitting a superfluous key, or
      autogenerating a needed key.
     @ mysql-test/suite/opt_trace/include/subquery.inc
        sorry the SELECT is in lowercase, it's because it originally had table names in uppercase,
        which makes a non-repeatable test output (uppercase on Unix, lowercase on Windows),
        so I changed everything to lowercase.
        Need to disable semijoin, so that tracing does not depend on whether
        the build supports semijoin or not.
     @ mysql-test/suite/opt_trace/r/subquery_no_prot.result
        see the "clause_processing" for the two new tests: it evaluates the subq.
     @ sql/opt_trace.cc
        * make_unknown_key() produces a dummy key when a key is needed,
        this key has a growing numeric suffix for uniqueness
        * Opt_trace_stmt::open_struct() had code similar to
        that of Opt_trace_stmt::add(); the first now calls the second
        * thus, the check_key() calls can all be moved into
        Opt_trace_stmt::add().
        * syntax_error() not needed anymore as we don't emit syntax
        errors now.
     @ sql/opt_trace.h
        syntax_error() is removed so its informative comment moves to check_key()
     @ sql/sql_select.cc
        When GROUP BY or ORDER BY contains a subquery which is constant, it is evaluated
        in remove_const(); so subq tracing was emitted: this starts as an anonymous
        object (with no key), alas it is inside an object which requires keys
        (like "item", "uses_only_constant_tables").
        The fix is to open a wrapper array around subq evaluation.
        This place of code is found similar to other existing ones, so they get
        the same name: "subselect_evaluation". The old names like
        "subselect_equality_propagation" were:
        - maybe incorrect (looking in result files, "subselect_equality_propagation"
        seems to evaluate the subq, not only propagate equalities into it)
        - unnecessarily precise ("subselect_equality_propagation" is inside
        a wrapper object which already says "equality_propagation").
        After all they are all about evaluating a subq.
     @ unittest/gunit/opt_trace-t.cc
        * no more assert on syntax error
        * trace is json-compliant now

    modified:
      mysql-test/suite/opt_trace/include/subquery.inc
      mysql-test/suite/opt_trace/r/bugs_no_prot_all.result
      mysql-test/suite/opt_trace/r/bugs_no_prot_none.result
      mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result
      mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result
      mysql-test/suite/opt_trace/r/general2_no_prot.result
      mysql-test/suite/opt_trace/r/general2_ps_prot.result
      mysql-test/suite/opt_trace/r/general_no_prot_all.result
      mysql-test/suite/opt_trace/r/general_no_prot_none.result
      mysql-test/suite/opt_trace/r/general_ps_prot_all.result
      mysql-test/suite/opt_trace/r/general_ps_prot_none.result
      mysql-test/suite/opt_trace/r/range_no_prot.result
      mysql-test/suite/opt_trace/r/range_ps_prot.result
      mysql-test/suite/opt_trace/r/subquery_no_prot.result
      mysql-test/suite/opt_trace/r/subquery_ps_prot.result
      sql/opt_trace.cc
      sql/opt_trace.h
      sql/sql_select.cc
      unittest/gunit/opt_trace-t.cc
 3403 Jonathan Perkin	2011-08-30
      Bump milestone.

    modified:
      VERSION
=== modified file 'mysql-test/suite/opt_trace/include/subquery.inc'
--- a/mysql-test/suite/opt_trace/include/subquery.inc	2011-07-20 13:10:44 +0000
+++ b/mysql-test/suite/opt_trace/include/subquery.inc	2011-08-31 16:48:23 +0000
@@ -49,3 +49,163 @@ SELECT * FROM information_schema.OPTIMIZ
 --echo
 
 DROP TABLE t1,t2;
+
+--echo #
+--echo # BUG#12905521 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON SELECT
+--echo # DISTINCT/MIN/JOIN/SUBQ QUERY
+--echo #
+
+CREATE TABLE t1 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t2 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t3 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_time_key TIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t4 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t4 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,7,'2008-10-02','2008-10-02','04:07:22.028954','04:07:22.028954','2001-10-08 00:00:00','2001-10-08 00:00:00','g','g');
+CREATE TABLE t5 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t5 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,NULL,'2000-12-03','2000-12-03','22:55:23.019225','22:55:23.019225','2005-07-20 00:00:00','2005-07-20 00:00:00','x','x'),
+(7,8,'2008-05-03','2008-05-03','10:19:31.050677','10:19:31.050677','2007-10-06 17:56:40.056051','2007-10-06 17:56:40.056051','d','d'),
+(8,6,'2000-09-20','2000-09-20','14:11:27.044095','14:11:27.044095','2003-06-13 23:19:49.018300','2003-06-13 23:19:49.018300','c','c');
+
+set @old_opt_switch=@@optimizer_switch;
+if (`select locate('semijoin', @@optimizer_switch) > 0`)
+{
+--disable_query_log
+  set optimizer_switch="semijoin=off";
+--enable_query_log
+}
+
+select distinct
+alias1.`col_varchar_key` as field1 ,alias1.`col_date_key` as
+field2 ,( select min( sq1_alias1.`col_varchar_nokey` ) as sq1_field1 from ( t1
+as sq1_alias1 inner join ( t5 as sq1_alias2 left join t5 as sq1_alias3 on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) where
+exists ( select distinct c_sq1_alias2.`col_int_nokey` as c_sq1_field1 from (
+t3 as c_sq1_alias1 right join t4 as c_sq1_alias2 on (c_sq1_alias2.`col_int_nokey` = c_sq1_alias1.`pk` ) ) where
+c_sq1_alias2.`col_varchar_key` = sq1_alias2.`col_varchar_nokey` ) ) as field3
+,( select max( sq2_alias1.`pk` ) as sq2_field1 from t5 as sq2_alias1 ) as
+field4 ,alias2.`col_varchar_nokey` as field5 ,alias2.`col_varchar_nokey` as
+field6 from ( t5 as alias1 right outer join ( ( ( select sq3_alias2.* from ( t5 as sq3_alias1 ,t4 as sq3_alias2 ) ) as alias2 right join t4
+as alias3 on (alias3.`col_varchar_key` = alias2.`col_varchar_key` ) ) ) on
+(alias3.`col_int_key` = alias2.`pk` ) ) where ( alias1.`col_varchar_nokey` in
+( select sq4_alias1.`col_varchar_key` as sq4_field1 from ( t3 as sq4_alias1
+inner join ( t2 as sq4_alias2 right outer join t3 as sq4_alias3 on
+(sq4_alias3.`pk` = sq4_alias2.`col_int_key` ) ) on
+(sq4_alias3.`col_varchar_nokey` = sq4_alias2.`col_varchar_key` ) ) where
+sq4_alias2.`col_int_key` < alias1.`col_int_nokey` and
+sq4_alias3.`col_varchar_nokey` <> alias1.`col_varchar_key` ) ) and
+alias1.`col_int_key` not in (214) group by field1,field2,field3,
+field4,field5,field6; 
+
+select * from information_schema.optimizer_trace;
+set optimizer_switch=@old_opt_switch;
+drop table t1,t2,t3,t4,t5;
+
+--echo #
+--echo # BUG#12905758 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON
+--echo # SELECT/SUBQ/SUM QUERY
+--echo #
+
+CREATE TABLE t1 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t1 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,NULL,'2000-12-03','2000-12-03','22:55:23.019225','22:55:23.019225','2005-07-20 00:00:00','2005-07-20 00:00:00','x','x'),
+(8,6,'2000-09-20','2000-09-20','14:11:27.044095','14:11:27.044095','2003-06-13 23:19:49.018300','2003-06-13 23:19:49.018300','c','c');
+CREATE TABLE t2 (I INTEGER);
+
+select ( select sum( subquery1_t1.`col_int_nokey` ) as subquery1_field1 from
+t1 as subquery1_t1 ) as field1 from ( t1 as table1 straight_join t1 as table2
+on (table2.`col_varchar_key` = table1.`col_varchar_key` ) ) where (
+table2.`col_int_nokey` <> any ( select 5 from t2 ) ) and table1.`pk` in
+(192,18) order by field1 desc; 
+
+select * from information_schema.optimizer_trace;
+drop table t1,t2;

=== modified file 'mysql-test/suite/opt_trace/r/bugs_no_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/bugs_no_prot_all.result	2011-07-20 13:10:44 +0000
+++ b/mysql-test/suite/opt_trace/r/bugs_no_prot_all.result	2011-08-31 16:48:23 +0000
@@ -225,20 +225,20 @@ WHERE sq2_alias1.col_varchar_nokey <= al
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (`test`.`alias2`.`col_varchar_key` in (/* select#4 */ select `test`.`sq2_alias1`.`col_varchar_nokey` AS `sq2_field1` from `test`.`t3` `sq2_alias1` where (`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`)) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_1937!
 9`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (`test`.`alias2`.`col_varchar_key` in (/* select#4 */ select `test`.`sq2_alias1`.`col_varchar_nokey` AS `sq2_field1` from `test`.`t3` `sq2_alias1` where (`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`)) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_1937!
 9`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (`test`.`alias2`.`col_varchar_key` in (/* select#4 */ select `test`.`sq2_alias1`.`col_varchar_nokey` AS `sq2_field1` from `test`.`t3` `sq2_alias1` where (`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`)) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_1937!
 9`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`alias1`.`col_varchar_nokey`), true))))))"
                 }
               ] /* steps */
@@ -432,8 +432,8 @@ FROM t1
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(1 and multiple equal(7, `test`.`where_subselect_19033`.`field1`))"
                 },
                 {
@@ -780,19 +780,19 @@ ON table2 .col_int_key = table1 .col_int
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(1 and ((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`where_subselect_20070`.`field1`, `test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(1 and ((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`where_subselect_20070`.`field1`, `test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
+                  "subselect_evaluation": [
                     {
                       "subselect_execution": {
                         "select#": 2,
@@ -947,7 +947,7 @@ ON table2 .col_int_key = table1 .col_int
                         ] /* steps */
                       } /* subselect_execution */
                     }
-                  ] /* subselect_cond_removal */,
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "multiple equal(`test`.`where_subselect_20070`.`field1`, `test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`)"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/bugs_no_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/bugs_no_prot_none.result	2011-07-22 09:53:44 +0000
+++ b/mysql-test/suite/opt_trace/r/bugs_no_prot_none.result	2011-08-31 16:48:23 +0000
@@ -242,20 +242,20 @@ WHERE sq2_alias1.col_varchar_nokey <= al
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (<in_optimizer>(`test`.`alias2`.`col_varchar_key`,<exists>(/* select#4 */ select 1 from `test`.`t3` `sq2_alias1` where ((`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias2`.`col_varchar_key`) = `test`.`sq2_alias1`.`col_varchar_nokey`)))) and trigcond_if(out!
 er_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.!
 `alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (<in_optimizer>(`test`.`alias2`.`col_varchar_key`,<exists>(/* select#4 */ select 1 from `test`.`t3` `sq2_alias1` where ((`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias2`.`col_varchar_key`) = `test`.`sq2_alias1`.`col_varchar_nokey`)))) and trigcond_if(out!
 er_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.!
 `alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (<in_optimizer>(`test`.`alias2`.`col_varchar_key`,<exists>(/* select#4 */ select 1 from `test`.`t3` `sq2_alias1` where ((`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias2`.`col_varchar_key`) = `test`.`sq2_alias1`.`col_varchar_nokey`)))) and trigcond_if(out!
 er_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.!
 `alias1`.`col_varchar_nokey`), true))))))"
                 }
               ] /* steps */
@@ -405,20 +405,20 @@ FROM t1
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`where_subselect_19033`.`field1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`where_subselect_19033`.`field1`) = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`where_subselect_19033`.`field1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`where_subselect_19033`.`field1`) = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`where_subselect_19033`.`field1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`where_subselect_19033`.`field1`) = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))))"
                 }
               ] /* steps */
@@ -454,20 +454,20 @@ FROM t1
                           "steps": [
                             {
                               "transformation": "equality_propagation",
-                              "subselect_equality_propagation": [
-                              ] /* subselect_equality_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "(<cache>('7') = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))"
                             },
                             {
                               "transformation": "constant_propagation",
-                              "subselect_constant_propagation": [
-                              ] /* subselect_constant_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "(<cache>('7') = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))"
                             },
                             {
                               "transformation": "trivial_condition_removal",
-                              "subselect_cond_removal": [
-                              ] /* subselect_cond_removal */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "(<cache>('7') = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))"
                             }
                           ] /* steps */
@@ -809,20 +809,20 @@ ON table2 .col_int_key = table1 .col_int
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`where_subselect_20070`.`field1`,(/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)),<exists>(/* select#3 */ select `test`.`table2`.`col_int_key` AS `field1`,(/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) from (`test`.`t1` `table1` join `test`.`t1` `table2` on((`test`.`table2`.`col_int_key` = `test`.`table1`.`col_int_key`))) where ((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`where_subselect_20070`.`field1`,(/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)),<exists>(/* select#3 */ select `test`.`table2`.`col_int_key` AS `field1`,(/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) from (`test`.`t1` `table1` join `test`.`t1` `table2` on((`test`.`table2`.`col_int_key` = `test`.`table1`.`col_int_key`))) where ((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`where_subselect_20070`.`field1`,(/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)),<exists>(/* select#3 */ select `test`.`table2`.`col_int_key` AS `field1`,(/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) from (`test`.`t1` `table1` join `test`.`t1` `table2` on((`test`.`table2`.`col_int_key` = `test`.`table1`.`col_int_key`))) where ((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)))))"
                 }
               ] /* steps */
@@ -994,19 +994,19 @@ ON table2 .col_int_key = table1 .col_int
                           "steps": [
                             {
                               "transformation": "equality_propagation",
-                              "subselect_equality_propagation": [
-                              ] /* subselect_equality_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                             },
                             {
                               "transformation": "constant_propagation",
-                              "subselect_constant_propagation": [
-                              ] /* subselect_constant_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                             },
                             {
                               "transformation": "trivial_condition_removal",
-                              "subselect_cond_removal": [
+                              "subselect_evaluation": [
                                 {
                                   "subselect_execution": {
                                     "select#": 4,
@@ -1084,7 +1084,7 @@ ON table2 .col_int_key = table1 .col_int
                                     ] /* steps */
                                   } /* subselect_execution */
                                 }
-                              ] /* subselect_cond_removal */,
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and multiple equal(`test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                             }
                           ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result	2011-07-20 13:10:44 +0000
+++ b/mysql-test/suite/opt_trace/r/bugs_ps_prot_all.result	2011-08-31 16:48:23 +0000
@@ -225,20 +225,20 @@ WHERE sq2_alias1.col_varchar_nokey <= al
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (`test`.`alias2`.`col_varchar_key` in (/* select#4 */ select `test`.`sq2_alias1`.`col_varchar_nokey` AS `sq2_field1` from `test`.`t3` `sq2_alias1` where (`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`)) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_1937!
 9`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (`test`.`alias2`.`col_varchar_key` in (/* select#4 */ select `test`.`sq2_alias1`.`col_varchar_nokey` AS `sq2_field1` from `test`.`t3` `sq2_alias1` where (`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`)) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_1937!
 9`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (`test`.`alias2`.`col_varchar_key` in (/* select#4 */ select `test`.`sq2_alias1`.`col_varchar_nokey` AS `sq2_field1` from `test`.`t3` `sq2_alias1` where (`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`)) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_1937!
 9`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`alias1`.`col_varchar_nokey`), true))))))"
                 }
               ] /* steps */
@@ -432,8 +432,8 @@ FROM t1
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(1 and multiple equal(7, `test`.`where_subselect_19033`.`field1`))"
                 },
                 {
@@ -780,19 +780,19 @@ ON table2 .col_int_key = table1 .col_int
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(1 and ((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`where_subselect_20070`.`field1`, `test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(1 and ((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`where_subselect_20070`.`field1`, `test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
+                  "subselect_evaluation": [
                     {
                       "subselect_execution": {
                         "select#": 2,
@@ -947,7 +947,7 @@ ON table2 .col_int_key = table1 .col_int
                         ] /* steps */
                       } /* subselect_execution */
                     }
-                  ] /* subselect_cond_removal */,
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "multiple equal(`test`.`where_subselect_20070`.`field1`, `test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`)"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result	2011-07-22 09:53:44 +0000
+++ b/mysql-test/suite/opt_trace/r/bugs_ps_prot_none.result	2011-08-31 16:48:23 +0000
@@ -242,20 +242,20 @@ WHERE sq2_alias1.col_varchar_nokey <= al
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (<in_optimizer>(`test`.`alias2`.`col_varchar_key`,<exists>(/* select#4 */ select 1 from `test`.`t3` `sq2_alias1` where ((`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias2`.`col_varchar_key`) = `test`.`sq2_alias1`.`col_varchar_nokey`)))) and trigcond_if(out!
 er_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.!
 `alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (<in_optimizer>(`test`.`alias2`.`col_varchar_key`,<exists>(/* select#4 */ select 1 from `test`.`t3` `sq2_alias1` where ((`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias2`.`col_varchar_key`) = `test`.`sq2_alias1`.`col_varchar_nokey`)))) and trigcond_if(out!
 er_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.!
 `alias1`.`col_varchar_nokey`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`where_subselect_19379`.`field1`,`test`.`where_subselect_19379`.`field2`),<exists>(/* select#2 */ select (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))) AS `field1`,`test`.`alias1`.`col_varchar_nokey` AS `field2` from (`test`.`t2` `alias1` left join (`test`.`t2` `alias2` left join `test`.`t2` `alias3` on((`test`.`alias3`.`col_varchar_nokey` = `test`.`alias2`.`col_varchar_key`))) on((`test`.`alias3`.`col_varchar_key` = `test`.`alias2`.`col_varchar_key`))) where (<in_optimizer>(`test`.`alias2`.`col_varchar_key`,<exists>(/* select#4 */ select 1 from `test`.`t3` `sq2_alias1` where ((`test`.`sq2_alias1`.`col_varchar_nokey` <= `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias2`.`col_varchar_key`) = `test`.`sq2_alias1`.`col_varchar_nokey`)))) and trigcond_if(out!
 er_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field1`) = (/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))) or isnull((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`)))))), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`where_subselect_19379`.`field2`) = `test`.`alias1`.`col_varchar_nokey`) or isnull(`test`.`alias1`.`col_varchar_nokey`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>((/* select#3 */ select sum(`test`.`t4`.`pk`) AS `sq1_field1` from ((`test`.`t4`) join `test`.`t1` `sq1_alias2` on((`test`.`sq1_alias2`.`col_varchar_key` = `test`.`t4`.`col_varchar_key`))))), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.!
 `alias1`.`col_varchar_nokey`), true))))))"
                 }
               ] /* steps */
@@ -395,20 +395,20 @@ FROM t1
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`where_subselect_19033`.`field1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`where_subselect_19033`.`field1`) = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`where_subselect_19033`.`field1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`where_subselect_19033`.`field1`) = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`where_subselect_19033`.`field1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`where_subselect_19033`.`field1`) = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))))"
                 }
               ] /* steps */
@@ -444,20 +444,20 @@ FROM t1
                           "steps": [
                             {
                               "transformation": "equality_propagation",
-                              "subselect_equality_propagation": [
-                              ] /* subselect_equality_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "(<cache>('7') = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))"
                             },
                             {
                               "transformation": "constant_propagation",
-                              "subselect_constant_propagation": [
-                              ] /* subselect_constant_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "(<cache>('7') = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))"
                             },
                             {
                               "transformation": "trivial_condition_removal",
-                              "subselect_cond_removal": [
-                              ] /* subselect_cond_removal */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "(<cache>('7') = (/* select#3 */ select `test`.`t2`.`col_int_key` from `test`.`t2`))"
                             }
                           ] /* steps */
@@ -789,20 +789,20 @@ ON table2 .col_int_key = table1 .col_int
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`where_subselect_20070`.`field1`,(/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)),<exists>(/* select#3 */ select `test`.`table2`.`col_int_key` AS `field1`,(/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) from (`test`.`t1` `table1` join `test`.`t1` `table2` on((`test`.`table2`.`col_int_key` = `test`.`table1`.`col_int_key`))) where ((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`where_subselect_20070`.`field1`,(/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)),<exists>(/* select#3 */ select `test`.`table2`.`col_int_key` AS `field1`,(/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) from (`test`.`t1` `table1` join `test`.`t1` `table2` on((`test`.`table2`.`col_int_key` = `test`.`table1`.`col_int_key`))) where ((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`where_subselect_20070`.`field1`,(/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)),<exists>(/* select#3 */ select `test`.`table2`.`col_int_key` AS `field1`,(/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`) from (`test`.`t1` `table1` join `test`.`t1` `table2` on((`test`.`table2`.`col_int_key` = `test`.`table1`.`col_int_key`))) where ((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)))))"
                 }
               ] /* steps */
@@ -974,19 +974,19 @@ ON table2 .col_int_key = table1 .col_int
                           "steps": [
                             {
                               "transformation": "equality_propagation",
-                              "subselect_equality_propagation": [
-                              ] /* subselect_equality_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                             },
                             {
                               "transformation": "constant_propagation",
-                              "subselect_constant_propagation": [
-                              ] /* subselect_constant_propagation */,
+                              "subselect_evaluation": [
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and (<cache>((/* select#2 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) = (/* select#4 */ select count(`test`.`t1`.`col_int_key`) from `test`.`t1`)) and multiple equal(`test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                             },
                             {
                               "transformation": "trivial_condition_removal",
-                              "subselect_cond_removal": [
+                              "subselect_evaluation": [
                                 {
                                   "subselect_execution": {
                                     "select#": 4,
@@ -1064,7 +1064,7 @@ ON table2 .col_int_key = table1 .col_int
                                     ] /* steps */
                                   } /* subselect_execution */
                                 }
-                              ] /* subselect_cond_removal */,
+                              ] /* subselect_evaluation */,
                               "resulting_condition": "((<cache>(`test`.`where_subselect_20070`.`field1`) = `test`.`table2`.`col_int_key`) and multiple equal(`test`.`table2`.`col_int_key`, `test`.`table1`.`col_int_key`))"
                             }
                           ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/general2_no_prot.result'
--- a/mysql-test/suite/opt_trace/r/general2_no_prot.result	2011-08-19 10:27:23 +0000
+++ b/mysql-test/suite/opt_trace/r/general2_no_prot.result	2011-08-31 16:48:23 +0000
@@ -705,14 +705,14 @@ TRACE
               "steps": [
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `test`.`t1`.`f2`,min(`test`.`t1`.`f2`) from `test`.`t1` having (((<cache>('v') = `test`.`t1`.`f2`) or isnull(`test`.`t1`.`f2`)) and ((<cache>('i') = min(`test`.`t1`.`f2`)) or isnull(min(`test`.`t1`.`f2`))) and <is_not_null_test>(`test`.`t1`.`f2`) and <is_not_null_test>(min(`test`.`t1`.`f2`)))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `test`.`t1`.`f2`,min(`test`.`t1`.`f2`) from `test`.`t1` having (((<cache>('v') = `test`.`t1`.`f2`) or isnull(`test`.`t1`.`f2`)) and ((<cache>('i') = min(`test`.`t1`.`f2`)) or isnull(min(`test`.`t1`.`f2`))) and <is_not_null_test>(`test`.`t1`.`f2`) and <is_not_null_test>(min(`test`.`t1`.`f2`)))))))"
                 }
               ] /* steps */
@@ -2357,20 +2357,20 @@ from t0 where a in
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from (`test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)))) where (<cache>(`test`.`t0`.`a`) = (`test`.`t2`.`a` + `test`.`t3`.`a`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from (`test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)))) where (<cache>(`test`.`t0`.`a`) = (`test`.`t2`.`a` + `test`.`t3`.`a`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from (`test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)))) where (<cache>(`test`.`t0`.`a`) = (`test`.`t2`.`a` + `test`.`t3`.`a`))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/general2_ps_prot.result'
--- a/mysql-test/suite/opt_trace/r/general2_ps_prot.result	2011-08-19 10:27:23 +0000
+++ b/mysql-test/suite/opt_trace/r/general2_ps_prot.result	2011-08-31 16:48:23 +0000
@@ -723,14 +723,14 @@ TRACE
               "steps": [
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `test`.`t1`.`f2`,min(`test`.`t1`.`f2`) from `test`.`t1` having (((<cache>('v') = `test`.`t1`.`f2`) or isnull(`test`.`t1`.`f2`)) and ((<cache>('i') = min(`test`.`t1`.`f2`)) or isnull(min(`test`.`t1`.`f2`))) and <is_not_null_test>(`test`.`t1`.`f2`) and <is_not_null_test>(min(`test`.`t1`.`f2`)))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>(('v','i'),<exists>(/* select#2 */ select `test`.`t1`.`f2`,min(`test`.`t1`.`f2`) from `test`.`t1` having (((<cache>('v') = `test`.`t1`.`f2`) or isnull(`test`.`t1`.`f2`)) and ((<cache>('i') = min(`test`.`t1`.`f2`)) or isnull(min(`test`.`t1`.`f2`))) and <is_not_null_test>(`test`.`t1`.`f2`) and <is_not_null_test>(min(`test`.`t1`.`f2`)))))))"
                 }
               ] /* steps */
@@ -2410,20 +2410,20 @@ from t0 where a in
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from (`test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)))) where (<cache>(`test`.`t0`.`a`) = (`test`.`t2`.`a` + `test`.`t3`.`a`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from (`test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)))) where (<cache>(`test`.`t0`.`a`) = (`test`.`t2`.`a` + `test`.`t3`.`a`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t0`.`a`,<exists>(/* select#2 */ select 1 from (`test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(((`test`.`t2`.`a` = `test`.`t1`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`a`)))) where (<cache>(`test`.`t0`.`a`) = (`test`.`t2`.`a` + `test`.`t3`.`a`))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/general_no_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/general_no_prot_all.result	2011-08-17 10:30:04 +0000
+++ b/mysql-test/suite/opt_trace/r/general_no_prot_all.result	2011-08-31 16:48:23 +0000
@@ -942,20 +942,20 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 }
               ] /* steps */
@@ -1173,7 +1173,7 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-13332
+13288
 set optimizer_trace_max_mem_size=12800;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
@@ -1182,7 +1182,7 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
 c
 select (@missing_bytes:=missing_bytes_beyond_max_mem_size) from information_schema.OPTIMIZER_TRACE;
 (@missing_bytes:=missing_bytes_beyond_max_mem_size)
-659
+600
 select (@query2:=QUERY)+NULL,(@trace2:=TRACE)+NULL from information_schema.OPTIMIZER_TRACE;
 (@query2:=QUERY)+NULL	(@trace2:=TRACE)+NULL
 NULL	NULL
@@ -1190,7 +1190,7 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-12673	1	1
+12688	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-200) and (@@optimizer_trace_max_mem_size+200);
 length(@query2) + length(@trace2)
@@ -1541,20 +1541,20 @@ explain SELECT c FROM t5 where c+1 in (s
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),(`test`.`t5`.`c` + 1) in (/* select#2 */ select (`test`.`t6`.`d` + 1) from `test`.`t6` where isnull(`test`.`t6`.`d`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),(`test`.`t5`.`c` + 1) in (/* select#2 */ select (`test`.`t6`.`d` + 1) from `test`.`t6` where isnull(`test`.`t6`.`d`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),(`test`.`t5`.`c` + 1) in (/* select#2 */ select (`test`.`t6`.`d` + 1) from `test`.`t6` where isnull(`test`.`t6`.`d`)))"
                 }
               ] /* steps */
@@ -1811,20 +1811,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2021,20 +2021,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2249,20 +2249,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 }
               ] /* steps */
@@ -2501,20 +2501,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 }
               ] /* steps */
@@ -3051,20 +3051,20 @@ where a1 in (select b1 from t2_16 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 }
               ] /* steps */
@@ -3313,20 +3313,20 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 }
               ] /* steps */
@@ -3978,20 +3978,20 @@ concat(c1,'y') IN
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),concat(`test`.`t1`.`c1`,'x') in (/* select#2 */ select left(`test`.`t2`.`c2`,8) from `test`.`t2`)) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),concat(`test`.`t1`.`c1`,'y') in (/* select#3 */ select left(`test`.`t2`.`c2`,9) from `test`.`t2`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),concat(`test`.`t1`.`c1`,'x') in (/* select#2 */ select left(`test`.`t2`.`c2`,8) from `test`.`t2`)) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),concat(`test`.`t1`.`c1`,'y') in (/* select#3 */ select left(`test`.`t2`.`c2`,9) from `test`.`t2`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),concat(`test`.`t1`.`c1`,'x') in (/* select#2 */ select left(`test`.`t2`.`c2`,8) from `test`.`t2`)) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),concat(`test`.`t1`.`c1`,'y') in (/* select#3 */ select left(`test`.`t2`.`c2`,9) from `test`.`t2`)))"
                 }
               ] /* steps */
@@ -5308,20 +5308,20 @@ select * from t1 where (t1.a,t1.b) not i
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/general_no_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/general_no_prot_none.result	2011-08-19 11:39:15 +0000
+++ b/mysql-test/suite/opt_trace/r/general_no_prot_none.result	2011-08-31 16:48:23 +0000
@@ -941,20 +941,20 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 }
               ] /* steps */
@@ -1172,7 +1172,7 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-13332
+13288
 set optimizer_trace_max_mem_size=12800;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
@@ -1181,7 +1181,7 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
 c
 select (@missing_bytes:=missing_bytes_beyond_max_mem_size) from information_schema.OPTIMIZER_TRACE;
 (@missing_bytes:=missing_bytes_beyond_max_mem_size)
-659
+600
 select (@query2:=QUERY)+NULL,(@trace2:=TRACE)+NULL from information_schema.OPTIMIZER_TRACE;
 (@query2:=QUERY)+NULL	(@trace2:=TRACE)+NULL
 NULL	NULL
@@ -1189,7 +1189,7 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-12673	1	1
+12688	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-200) and (@@optimizer_trace_max_mem_size+200);
 length(@query2) + length(@trace2)
@@ -1278,20 +1278,20 @@ explain SELECT c FROM t5 where c+1 in (s
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 }
               ] /* steps */
@@ -1543,20 +1543,20 @@ explain SELECT c FROM t5 where c+1 in (s
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 }
               ] /* steps */
@@ -1795,20 +1795,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2005,20 +2005,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2233,20 +2233,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 }
               ] /* steps */
@@ -2485,20 +2485,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 }
               ] /* steps */
@@ -3034,20 +3034,20 @@ where a1 in (select b1 from t2_16 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 }
               ] /* steps */
@@ -3295,20 +3295,20 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 }
               ] /* steps */
@@ -3980,20 +3980,20 @@ concat(c1,'y') IN
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'x')) = left(`test`.`t2`.`c2`,8)))) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),<exists>(/* select#3 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'y')) = left(`test`.`t2`.`c2`,9)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'x')) = left(`test`.`t2`.`c2`,8)))) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),<exists>(/* select#3 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'y')) = left(`test`.`t2`.`c2`,9)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'x')) = left(`test`.`t2`.`c2`,8)))) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),<exists>(/* select#3 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'y')) = left(`test`.`t2`.`c2`,9)))))"
                 }
               ] /* steps */
@@ -4438,20 +4438,20 @@ trace
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 }
               ] /* steps */
@@ -4540,20 +4540,20 @@ trace
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 }
               ] /* steps */
@@ -4815,20 +4815,20 @@ select * from t1 where (t1.a,t1.b) not i
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 }
               ] /* steps */
@@ -6668,20 +6668,20 @@ select d into res from t6 where d in (se
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 }
               ] /* steps */
@@ -8275,20 +8275,20 @@ select d into res from t6 where d in (se
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/general_ps_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/general_ps_prot_all.result	2011-08-17 10:30:04 +0000
+++ b/mysql-test/suite/opt_trace/r/general_ps_prot_all.result	2011-08-31 16:48:23 +0000
@@ -922,20 +922,20 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 }
               ] /* steps */
@@ -1153,7 +1153,7 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-12554
+12510
 set optimizer_trace_max_mem_size=12800;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
@@ -1170,7 +1170,7 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-12554	1	1
+12510	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-200) and (@@optimizer_trace_max_mem_size+200);
 length(@query2) + length(@trace2)
@@ -1521,20 +1521,20 @@ explain SELECT c FROM t5 where c+1 in (s
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),(`test`.`t5`.`c` + 1) in (/* select#2 */ select (`test`.`t6`.`d` + 1) from `test`.`t6` where isnull(`test`.`t6`.`d`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),(`test`.`t5`.`c` + 1) in (/* select#2 */ select (`test`.`t6`.`d` + 1) from `test`.`t6` where isnull(`test`.`t6`.`d`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),(`test`.`t5`.`c` + 1) in (/* select#2 */ select (`test`.`t6`.`d` + 1) from `test`.`t6` where isnull(`test`.`t6`.`d`)))"
                 }
               ] /* steps */
@@ -1791,20 +1791,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2001,20 +2001,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2229,20 +2229,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 }
               ] /* steps */
@@ -2481,20 +2481,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 }
               ] /* steps */
@@ -3031,20 +3031,20 @@ where a1 in (select b1 from t2_16 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 }
               ] /* steps */
@@ -3293,20 +3293,20 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 }
               ] /* steps */
@@ -3958,20 +3958,20 @@ concat(c1,'y') IN
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),concat(`test`.`t1`.`c1`,'x') in (/* select#2 */ select left(`test`.`t2`.`c2`,8) from `test`.`t2`)) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),concat(`test`.`t1`.`c1`,'y') in (/* select#3 */ select left(`test`.`t2`.`c2`,9) from `test`.`t2`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),concat(`test`.`t1`.`c1`,'x') in (/* select#2 */ select left(`test`.`t2`.`c2`,8) from `test`.`t2`)) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),concat(`test`.`t1`.`c1`,'y') in (/* select#3 */ select left(`test`.`t2`.`c2`,9) from `test`.`t2`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),concat(`test`.`t1`.`c1`,'x') in (/* select#2 */ select left(`test`.`t2`.`c2`,8) from `test`.`t2`)) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),concat(`test`.`t1`.`c1`,'y') in (/* select#3 */ select left(`test`.`t2`.`c2`,9) from `test`.`t2`)))"
                 }
               ] /* steps */
@@ -5276,20 +5276,20 @@ select * from t1 where (t1.a,t1.b) not i
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/general_ps_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/general_ps_prot_none.result	2011-08-19 11:39:15 +0000
+++ b/mysql-test/suite/opt_trace/r/general_ps_prot_none.result	2011-08-31 16:48:23 +0000
@@ -921,20 +921,20 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(5,<exists>(/* select#2 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 1)) union /* select#3 */ select 1 from `test`.`t6` where ((`test`.`t6`.`d` = ifnull(`test`.`t5`.`c`,NULL)) and (<cache>(5) = 2))))"
                 }
               ] /* steps */
@@ -1152,7 +1152,7 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-12554
+12510
 set optimizer_trace_max_mem_size=12800;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
@@ -1169,7 +1169,7 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-12554	1	1
+12510	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-200) and (@@optimizer_trace_max_mem_size+200);
 length(@query2) + length(@trace2)
@@ -1258,20 +1258,20 @@ explain SELECT c FROM t5 where c+1 in (s
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 }
               ] /* steps */
@@ -1523,20 +1523,20 @@ explain SELECT c FROM t5 where c+1 in (s
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t5`.`c` + 1),<exists>(/* select#2 */ select 1 from `test`.`t6` where (isnull(`test`.`t6`.`d`) and (<cache>((`test`.`t5`.`c` + 1)) = (`test`.`t6`.`d` + 1)))))"
                 }
               ] /* steps */
@@ -1775,20 +1775,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -1985,20 +1985,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* steps */
@@ -2213,20 +2213,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
                 }
               ] /* steps */
@@ -2465,20 +2465,20 @@ explain extended select * from t1 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t1`.`s1`,`test`.`t1`.`s2`),<exists>(/* select#2 */ select `test`.`t1`.`s2`,`test`.`t1`.`s1` from `test`.`t1` where ((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))))"
                 }
               ] /* steps */
@@ -3014,20 +3014,20 @@ where a1 in (select b1 from t2_16 where 
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select 1 from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))"
                 }
               ] /* steps */
@@ -3265,20 +3265,20 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(`test`.`t2`.`c2`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t2`.`c2`) = `test`.`t2`.`c2`)))) and multiple equal(`test`.`t1`.`c1`, `test`.`t2`.`c2`))"
                 }
               ] /* steps */
@@ -3950,20 +3950,20 @@ concat(c1,'y') IN
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'x')) = left(`test`.`t2`.`c2`,8)))) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),<exists>(/* select#3 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'y')) = left(`test`.`t2`.`c2`,9)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'x')) = left(`test`.`t2`.`c2`,8)))) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),<exists>(/* select#3 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'y')) = left(`test`.`t2`.`c2`,9)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(<in_optimizer>(concat(`test`.`t1`.`c1`,'x'),<exists>(/* select#2 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'x')) = left(`test`.`t2`.`c2`,8)))) and <in_optimizer>(concat(`test`.`t1`.`c1`,'y'),<exists>(/* select#3 */ select 1 from `test`.`t2` where (<cache>(concat(`test`.`t1`.`c1`,'y')) = left(`test`.`t2`.`c2`,9)))))"
                 }
               ] /* steps */
@@ -4408,20 +4408,20 @@ trace
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 }
               ] /* steps */
@@ -4510,20 +4510,20 @@ trace
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>((`test`.`t3`.`a`,`test`.`t3`.`a`,`test`.`t3`.`b`),<exists>(/* select#2 */ select `test`.`t1`.`a`,`test`.`t2`.`a`,`test`.`t4`.`a` from `test`.`t1` join `test`.`t2` join `test`.`t4` where ((<cache>(`test`.`t3`.`a`) = `test`.`t1`.`a`) and (<cache>(`test`.`t3`.`a`) = `test`.`t2`.`a`) and (<cache>(`test`.`t3`.`b`) = `test`.`t4`.`a`))))"
                 }
               ] /* steps */
@@ -4773,20 +4773,20 @@ select * from t1 where (t1.a,t1.b) not i
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(/* select#2 */ select `test`.`t2`.`c`,`test`.`t2`.`d` from `test`.`t2` where ((`test`.`t2`.`c` > 0) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`) or isnull(`test`.`t2`.`c`)), true) and trigcond_if(outer_field_is_not_null, ((<cache>(`test`.`t1`.`b`) = `test`.`t2`.`d`) or isnull(`test`.`t2`.`d`)), true)) having (trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`c`), true) and trigcond_if(outer_field_is_not_null, <is_not_null_test>(`test`.`t2`.`d`), true))))))"
                 }
               ] /* steps */
@@ -6588,20 +6588,20 @@ select d into res from t6 where d in (se
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 }
               ] /* steps */
@@ -8209,20 +8209,20 @@ select d into res from t6 where d in (se
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<in_optimizer>(`test`.`t6`.`d`,<exists>(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`s` = arg@0) and (<cache>(`test`.`t6`.`d`) = `f1`()))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/range_no_prot.result'
--- a/mysql-test/suite/opt_trace/r/range_no_prot.result	2011-08-19 10:27:23 +0000
+++ b/mysql-test/suite/opt_trace/r/range_no_prot.result	2011-08-31 16:48:23 +0000
@@ -4131,20 +4131,20 @@ SELECT * from t1 where topic = all (SELE
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<not>(<in_optimizer>(`test`.`t1`.`topic`,<exists>(/* select#2 */ select `test`.`t1`.`topic` from `test`.`t1` group by `test`.`t1`.`topic` having (<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<not>(<in_optimizer>(`test`.`t1`.`topic`,<exists>(/* select#2 */ select `test`.`t1`.`topic` from `test`.`t1` group by `test`.`t1`.`topic` having (<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<not>(<in_optimizer>(`test`.`t1`.`topic`,<exists>(/* select#2 */ select `test`.`t1`.`topic` from `test`.`t1` group by `test`.`t1`.`topic` having (<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`)))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/range_ps_prot.result'
--- a/mysql-test/suite/opt_trace/r/range_ps_prot.result	2011-08-19 10:27:23 +0000
+++ b/mysql-test/suite/opt_trace/r/range_ps_prot.result	2011-08-31 16:48:23 +0000
@@ -4121,20 +4121,20 @@ SELECT * from t1 where topic = all (SELE
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<not>(<in_optimizer>(`test`.`t1`.`topic`,<exists>(/* select#2 */ select `test`.`t1`.`topic` from `test`.`t1` group by `test`.`t1`.`topic` having (<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<not>(<in_optimizer>(`test`.`t1`.`topic`,<exists>(/* select#2 */ select `test`.`t1`.`topic` from `test`.`t1` group by `test`.`t1`.`topic` having (<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "<not>(<in_optimizer>(`test`.`t1`.`topic`,<exists>(/* select#2 */ select `test`.`t1`.`topic` from `test`.`t1` group by `test`.`t1`.`topic` having (<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`)))))"
                 }
               ] /* steps */

=== modified file 'mysql-test/suite/opt_trace/r/subquery_no_prot.result'
--- a/mysql-test/suite/opt_trace/r/subquery_no_prot.result	2011-07-20 13:10:44 +0000
+++ b/mysql-test/suite/opt_trace/r/subquery_no_prot.result	2011-08-31 16:48:23 +0000
@@ -386,7 +386,7 @@ t1.a= (SELECT a FROM t2 LIMIT 1)	{
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
+                  "subselect_evaluation": [
                     {
                       "subselect_execution": {
                         "select#": 2,
@@ -429,19 +429,19 @@ t1.a= (SELECT a FROM t2 LIMIT 1)	{
                         ] /* steps */
                       } /* subselect_execution */
                     }
-                  ] /* subselect_equality_propagation */,
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "((NULL <> (/* select#3 */ select `test`.`t2`.`a` from `test`.`t2` limit 1)) and multiple equal((/* select#2 */ select NULL from `test`.`t2` limit 1), `test`.`t1`.`a`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "((NULL <> (/* select#3 */ select `test`.`t2`.`a` from `test`.`t2` limit 1)) and multiple equal((/* select#2 */ select NULL from `test`.`t2` limit 1), `test`.`t1`.`a`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": null
                 }
               ] /* steps */
@@ -506,19 +506,19 @@ WHERE NOT EXISTS
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(exists(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`a` = 50) and (`test`.`t2`.`b` = 3)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(exists(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`a` = 50) and (`test`.`t2`.`b` = 3)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
+                  "subselect_evaluation": [
                     {
                       "subselect_execution": {
                         "select#": 2,
@@ -578,7 +578,7 @@ WHERE NOT EXISTS
                         ] /* steps */
                       } /* subselect_execution */
                     }
-                  ] /* subselect_cond_removal */,
+                  ] /* subselect_evaluation */,
                   "resulting_condition": null
                 }
               ] /* steps */
@@ -598,3 +598,1229 @@ WHERE NOT EXISTS
 }	0	0
 
 DROP TABLE t1,t2;
+#
+# BUG#12905521 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON SELECT
+# DISTINCT/MIN/JOIN/SUBQ QUERY
+#
+CREATE TABLE t1 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t2 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t3 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_time_key TIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t4 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t4 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,7,'2008-10-02','2008-10-02','04:07:22.028954','04:07:22.028954','2001-10-08 00:00:00','2001-10-08 00:00:00','g','g');
+CREATE TABLE t5 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t5 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,NULL,'2000-12-03','2000-12-03','22:55:23.019225','22:55:23.019225','2005-07-20 00:00:00','2005-07-20 00:00:00','x','x'),
+(7,8,'2008-05-03','2008-05-03','10:19:31.050677','10:19:31.050677','2007-10-06 17:56:40.056051','2007-10-06 17:56:40.056051','d','d'),
+(8,6,'2000-09-20','2000-09-20','14:11:27.044095','14:11:27.044095','2003-06-13 23:19:49.018300','2003-06-13 23:19:49.018300','c','c');
+set @old_opt_switch=@@optimizer_switch;
+select distinct
+alias1.`col_varchar_key` as field1 ,alias1.`col_date_key` as
+field2 ,( select min( sq1_alias1.`col_varchar_nokey` ) as sq1_field1 from ( t1
+as sq1_alias1 inner join ( t5 as sq1_alias2 left join t5 as sq1_alias3 on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) where
+exists ( select distinct c_sq1_alias2.`col_int_nokey` as c_sq1_field1 from (
+t3 as c_sq1_alias1 right join t4 as c_sq1_alias2 on (c_sq1_alias2.`col_int_nokey` = c_sq1_alias1.`pk` ) ) where
+c_sq1_alias2.`col_varchar_key` = sq1_alias2.`col_varchar_nokey` ) ) as field3
+,( select max( sq2_alias1.`pk` ) as sq2_field1 from t5 as sq2_alias1 ) as
+field4 ,alias2.`col_varchar_nokey` as field5 ,alias2.`col_varchar_nokey` as
+field6 from ( t5 as alias1 right outer join ( ( ( select sq3_alias2.* from ( t5 as sq3_alias1 ,t4 as sq3_alias2 ) ) as alias2 right join t4
+as alias3 on (alias3.`col_varchar_key` = alias2.`col_varchar_key` ) ) ) on
+(alias3.`col_int_key` = alias2.`pk` ) ) where ( alias1.`col_varchar_nokey` in
+( select sq4_alias1.`col_varchar_key` as sq4_field1 from ( t3 as sq4_alias1
+inner join ( t2 as sq4_alias2 right outer join t3 as sq4_alias3 on
+(sq4_alias3.`pk` = sq4_alias2.`col_int_key` ) ) on
+(sq4_alias3.`col_varchar_nokey` = sq4_alias2.`col_varchar_key` ) ) where
+sq4_alias2.`col_int_key` < alias1.`col_int_nokey` and
+sq4_alias3.`col_varchar_nokey` <> alias1.`col_varchar_key` ) ) and
+alias1.`col_int_key` not in (214) group by field1,field2,field3,
+field4,field5,field6;
+field1	field2	field3	field4	field5	field6
+select * from information_schema.optimizer_trace;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	INSUFFICIENT_PRIVILEGES
+select distinct
+alias1.`col_varchar_key` as field1 ,alias1.`col_date_key` as
+field2 ,( select min( sq1_alias1.`col_varchar_nokey` ) as sq1_field1 from ( t1
+as sq1_alias1 inner join ( t5 as sq1_alias2 left join t5 as sq1_alias3 on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) where
+exists ( select distinct c_sq1_alias2.`col_int_nokey` as c_sq1_field1 from (
+t3 as c_sq1_alias1 right join t4 as c_sq1_alias2 on (c_sq1_alias2.`col_int_nokey` = c_sq1_alias1.`pk` ) ) where
+c_sq1_alias2.`col_varchar_key` = sq1_alias2.`col_varchar_nokey` ) ) as field3
+,( select max( sq2_alias1.`pk` ) as sq2_field1 from t5 as sq2_alias1 ) as
+field4 ,alias2.`col_varchar_nokey` as field5 ,alias2.`col_varchar_nokey` as
+field6 from ( t5 as alias1 right outer join ( ( ( select sq3_alias2.* from ( t5 as sq3_alias1 ,t4 as sq3_alias2 ) ) as alias2 right join t4
+as alias3 on (alias3.`col_varchar_key` = alias2.`col_varchar_key` ) ) ) on
+(alias3.`col_int_key` = alias2.`pk` ) ) where ( alias1.`col_varchar_nokey` in
+( select sq4_alias1.`col_varchar_key` as sq4_field1 from ( t3 as sq4_alias1
+inner join ( t2 as sq4_alias2 right outer join t3 as sq4_alias3 on
+(sq4_alias3.`pk` = sq4_alias2.`col_int_key` ) ) on
+(sq4_alias3.`col_varchar_nokey` = sq4_alias2.`col_varchar_key` ) ) where
+sq4_alias2.`col_int_key` < alias1.`col_int_nokey` and
+sq4_alias3.`col_varchar_nokey` <> alias1.`col_varchar_key` ) ) and
+alias1.`col_int_key` not in (214) group by field1,field2,field3,
+field4,field5,field6	{
+  "steps": [
+    {
+      "join_preparation": {
+        "select#": 5,
+        "steps": [
+          {
+            "expanded_query": "/* select#5 */ select `test`.`sq3_alias2`.`pk` AS `pk`,`test`.`sq3_alias2`.`col_int_nokey` AS `col_int_nokey`,`test`.`sq3_alias2`.`col_int_key` AS `col_int_key`,`test`.`sq3_alias2`.`col_date_key` AS `col_date_key`,`test`.`sq3_alias2`.`col_date_nokey` AS `col_date_nokey`,`test`.`sq3_alias2`.`col_time_key` AS `col_time_key`,`test`.`sq3_alias2`.`col_time_nokey` AS `col_time_nokey`,`test`.`sq3_alias2`.`col_datetime_key` AS `col_datetime_key`,`test`.`sq3_alias2`.`col_datetime_nokey` AS `col_datetime_nokey`,`test`.`sq3_alias2`.`col_varchar_key` AS `col_varchar_key`,`test`.`sq3_alias2`.`col_varchar_nokey` AS `col_varchar_nokey` from (`test`.`t5` `sq3_alias1` join `test`.`t4` `sq3_alias2`)"
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_preparation": {
+                    "select#": 3,
+                    "steps": [
+                      {
+                        "expanded_query": "/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)"
+                      }
+                    ] /* steps */
+                  } /* join_preparation */
+                },
+                {
+                  "expanded_query": "/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "join_preparation": {
+              "select#": 4,
+              "steps": [
+                {
+                  "expanded_query": "/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "join_preparation": {
+              "select#": 6,
+              "steps": [
+                {
+                  "expanded_query": "/* select#6 */ select `test`.`sq4_alias1`.`col_varchar_key` AS `sq4_field1` from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": {
+                    "select#": 6,
+                    "from": "IN (SELECT)",
+                    "to": "semijoin",
+                    "chosen": false
+                  } /* transformation */
+                },
+                {
+                  "transformation": {
+                    "select#": 6,
+                    "from": "IN (SELECT)",
+                    "to": "materialization",
+                    "chosen": false
+                  } /* transformation */
+                },
+                {
+                  "transformation": {
+                    "select#": 6,
+                    "from": "IN (SELECT)",
+                    "to": "EXISTS (CORRELATED SELECT)",
+                    "chosen": true,
+                    "evaluating_constant_where_conditions": [
+                    ] /* evaluating_constant_where_conditions */
+                  } /* transformation */
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "expanded_query": "/* select#1 */ select distinct `test`.`alias1`.`col_varchar_key` AS `field1`,`test`.`alias1`.`col_date_key` AS `field2`,(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))) AS `field3`,(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`) AS `field4`,`alias2`.`col_varchar_!
 nokey` AS `field5`,`alias2`.`col_varchar_nokey` AS `field6` from ((`test`.`t4` `alias3` left join ((/* select#5 */ select `test`.`sq3_alias2`.`pk` AS `pk`,`test`.`sq3_alias2`.`col_int_nokey` AS `col_int_nokey`,`test`.`sq3_alias2`.`col_int_key` AS `col_int_key`,`test`.`sq3_alias2`.`col_date_key` AS `col_date_key`,`test`.`sq3_alias2`.`col_date_nokey` AS `col_date_nokey`,`test`.`sq3_alias2`.`col_time_key` AS `col_time_key`,`test`.`sq3_alias2`.`col_time_nokey` AS `col_time_nokey`,`test`.`sq3_alias2`.`col_datetime_key` AS `col_datetime_key`,`test`.`sq3_alias2`.`col_datetime_nokey` AS `col_datetime_nokey`,`test`.`sq3_alias2`.`col_varchar_key` AS `col_varchar_key`,`test`.`sq3_alias2`.`col_varchar_nokey` AS `col_varchar_nokey` from (`test`.`t5` `sq3_alias1` join `test`.`t4` `sq3_alias2`))) `alias2` on((`test`.`alias3`.`col_varchar_key` = `alias2`.`col_varchar_key`))) left join `test`.`t5` `alias1` on((`test`.`alias3`.`col_int_key` = `alias2`.`pk`))) where (<in_optimizer>(`test`.`al!
 ias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test
`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214)) group by `test`.`alias1`.`col_varchar_key`,`test`.`alias1`.`col_date_key`,(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* selec!
 t#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))),(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`),`alias2`.`col_varchar_nokey`,`alias2`.`col_varchar_nokey`"
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_optimization": {
+              "select#": 5,
+              "steps": [
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "sq3_alias1",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    },
+                    {
+                      "database": "test",
+                      "table": "sq3_alias2",
+                      "records": 1,
+                      "cost": 1,
+                      "table_type": "system"
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "sq3_alias1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "records": 3,
+                            "cost": 2.0371,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.6371,
+                      "records_for_plan": 3,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions_computation": [
+                    ] /* attached_conditions_computation */,
+                    "attached_conditions_summary": [
+                      {
+                        "database": "test",
+                        "table": "sq3_alias1",
+                        "attached": null
+                      }
+                    ] /* attached_conditions_summary */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "sq3_alias1",
+                      "scan_type": "index"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and (`test`.`alias3`.`col_int_key` = `alias2`.`pk`) and (`test`.`alias3`.`col_varchar_key` = `alias2`.`col_varchar_key`))",
+              "steps": [
+                {
+                  "transformation": "equality_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and multiple equal(`test`.`alias3`.`col_int_key`, `alias2`.`pk`) and multiple equal(`test`.`alias3`.`col_varchar_key`, `alias2`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "constant_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and multiple equal(`test`.`alias3`.`col_int_key`, `alias2`.`pk`) and multiple equal(`test`.`alias3`.`col_varchar_key`, `alias2`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "trivial_condition_removal",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and multiple equal(`test`.`alias3`.`col_int_key`, `alias2`.`pk`) and multiple equal(`test`.`alias3`.`col_varchar_key`, `alias2`.`col_varchar_key`))"
+                }
+              ] /* steps */
+            } /* condition_processing */
+          },
+          {
+            "ref_optimizer_key_uses": [
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "pk",
+                "equals": "`test`.`alias3`.`col_int_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "col_varchar_key",
+                "equals": "`test`.`alias3`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "pk",
+                "equals": "`test`.`alias3`.`col_int_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "col_varchar_key",
+                "equals": "`test`.`alias3`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "test",
+                "table": "alias3",
+                "field": "col_varchar_key",
+                "equals": "`alias2`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "test",
+                "table": "alias3",
+                "field": "col_int_key",
+                "equals": "`alias2`.`pk`",
+                "null_rejecting": true
+              }
+            ] /* ref_optimizer_key_uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "alias1",
+                "range_analysis": {
+                  "table_scan": {
+                    "records": 3,
+                    "cost": 4.7371
+                  } /* table_scan */,
+                  "potential_range_indices": [
+                    {
+                      "index": "PRIMARY",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    },
+                    {
+                      "index": "col_int_key",
+                      "usable": true,
+                      "key_parts": [
+                        "col_int_key"
+                      ] /* key_parts */
+                    },
+                    {
+                      "index": "col_varchar_key",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    }
+                  ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
+                  "group_index_range": {
+                    "chosen": false,
+                    "cause": "not_single_table"
+                  } /* group_index_range */,
+                  "analyzing_range_alternatives": {
+                    "range_scan_alternatives": [
+                      {
+                        "index": "col_int_key",
+                        "ranges": [
+                          "NULL < col_int_key < 214",
+                          "214 < col_int_key"
+                        ] /* ranges */,
+                        "index_only": false,
+                        "records": 3,
+                        "cost": 5.61,
+                        "rowid_ordered": false,
+                        "chosen": false,
+                        "cause": "cost"
+                      }
+                    ] /* range_scan_alternatives */,
+                    "analyzing_roworder_intersect": {
+                      "usable": false,
+                      "cause": "too_few_roworder_scans"
+                    } /* analyzing_roworder_intersect */
+                  } /* analyzing_range_alternatives */
+                } /* range_analysis */
+              },
+              {
+                "database": "",
+                "table": "alias2"
+              },
+              {
+                "database": "test",
+                "table": "alias3",
+                "records": 1,
+                "cost": 1,
+                "table_type": "system"
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": [
+              {
+                "database": "test",
+                "table": "alias1",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "scan",
+                      "records": 3,
+                      "cost": 2.0371,
+                      "chosen": true
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 2.6371,
+                "records_for_plan": 3,
+                "rest_of_plan": [
+                  {
+                    "database": "",
+                    "table": "alias2",
+                    "best_access_path": {
+                      "considered_access_paths": [
+                        {
+                          "access_type": "ref",
+                          "index": "auto_key0",
+                          "records": 0.3,
+                          "cost": 0.96,
+                          "chosen": true
+                        },
+                        {
+                          "access_type": "ref",
+                          "index": "auto_key1",
+                          "records": 0.3,
+                          "cost": 0.96,
+                          "chosen": false
+                        },
+                        {
+                          "access_type": "scan",
+                          "cost": 10,
+                          "records": 3,
+                          "cause": "cost",
+                          "chosen": false
+                        }
+                      ] /* considered_access_paths */
+                    } /* best_access_path */,
+                    "cost_for_plan": 3.7171,
+                    "records_for_plan": 0.9,
+                    "chosen": true
+                  }
+                ] /* rest_of_plan */
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "ref",
+                      "index": "auto_key0",
+                      "records": 0.3,
+                      "cost": 0.36,
+                      "chosen": true
+                    },
+                    {
+                      "access_type": "ref",
+                      "index": "auto_key1",
+                      "records": 0.3,
+                      "cost": 0.36,
+                      "chosen": false
+                    },
+                    {
+                      "access_type": "scan",
+                      "cost": 10,
+                      "records": 3,
+                      "cause": "cost",
+                      "chosen": false
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 0.36,
+                "records_for_plan": 0.3,
+                "rest_of_plan": [
+                  {
+                    "database": "test",
+                    "table": "alias1",
+                    "best_access_path": {
+                      "considered_access_paths": [
+                        {
+                          "access_type": "scan",
+                          "using_join_cache": true,
+                          "records": 3,
+                          "cost": 2.0373,
+                          "chosen": true
+                        }
+                      ] /* considered_access_paths */
+                    } /* best_access_path */,
+                    "cost_for_plan": 2.5773,
+                    "records_for_plan": 0.9,
+                    "chosen": true
+                  }
+                ] /* rest_of_plan */
+              }
+            ] /* considered_execution_plans */
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": "((`alias2`.`col_varchar_key` = 'g') and (`alias2`.`pk` = '8') and <in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214))",
+              "attached_conditions_computation": [
+              ] /* attached_conditions_computation */,
+              "attached_conditions_summary": [
+                {
+                  "database": "",
+                  "table": "alias2",
+                  "attached": null
+                },
+                {
+                  "database": "test",
+                  "table": "alias1",
+                  "attached": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214))"
+                }
+              ] /* attached_conditions_summary */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "clause_processing": {
+              "clause": "GROUP BY",
+              "original_clause": "`test`.`alias1`.`col_varchar_key`,`test`.`alias1`.`col_date_key`,(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))),(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`),`alias2`.`col_varchar_nokey`,`alias2`.`col_varchar_nokey`",
+              "items": [
+                {
+                  "item": "`test`.`alias1`.`col_varchar_key`"
+                },
+                {
+                  "item": "`test`.`alias1`.`col_date_key`"
+                },
+                {
+                  "item": "(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)))",
+                  "subselect_evaluation": [
+                    {
+                      "subselect_execution": {
+                        "select#": 2,
+                        "steps": [
+                          {
+                            "join_optimization": {
+                              "select#": 2,
+                              "steps": [
+                                {
+                                  "condition_processing": {
+                                    "condition": "WHERE",
+                                    "original_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and (`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`) and (`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))",
+                                    "steps": [
+                                      {
+                                        "transformation": "equality_propagation",
+                                        "subselect_evaluation": [
+                                        ] /* subselect_evaluation */,
+                                        "resulting_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and multiple equal(`test`.`sq1_alias3`.`col_varchar_nokey`, `test`.`sq1_alias2`.`col_varchar_key`))"
+                                      },
+                                      {
+                                        "transformation": "constant_propagation",
+                                        "subselect_evaluation": [
+                                        ] /* subselect_evaluation */,
+                                        "resulting_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and multiple equal(`test`.`sq1_alias3`.`col_varchar_nokey`, `test`.`sq1_alias2`.`col_varchar_key`))"
+                                      },
+                                      {
+                                        "transformation": "trivial_condition_removal",
+                                        "subselect_evaluation": [
+                                        ] /* subselect_evaluation */,
+                                        "resulting_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and multiple equal(`test`.`sq1_alias3`.`col_varchar_nokey`, `test`.`sq1_alias2`.`col_varchar_key`))"
+                                      }
+                                    ] /* steps */
+                                  } /* condition_processing */
+                                },
+                                {
+                                  "ref_optimizer_key_uses": [
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias2",
+                                      "field": "col_varchar_key",
+                                      "equals": "`test`.`sq1_alias3`.`col_varchar_nokey`",
+                                      "null_rejecting": true
+                                    }
+                                  ] /* ref_optimizer_key_uses */
+                                },
+                                {
+                                  "records_estimation": [
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias1",
+                                      "records": 1,
+                                      "cost": 1,
+                                      "table_type": "system"
+                                    },
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias2",
+                                      "table_scan": {
+                                        "records": 3,
+                                        "cost": 2
+                                      } /* table_scan */
+                                    },
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias3",
+                                      "table_scan": {
+                                        "records": 3,
+                                        "cost": 2
+                                      } /* table_scan */
+                                    }
+                                  ] /* records_estimation */
+                                },
+                                {
+                                  "considered_execution_plans": [
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias2",
+                                      "best_access_path": {
+                                        "considered_access_paths": [
+                                          {
+                                            "access_type": "ref",
+                                            "index": "col_varchar_key",
+                                            "usable": false,
+                                            "chosen": false
+                                          },
+                                          {
+                                            "access_type": "scan",
+                                            "records": 3,
+                                            "cost": 2.0371,
+                                            "chosen": true
+                                          }
+                                        ] /* considered_access_paths */
+                                      } /* best_access_path */,
+                                      "cost_for_plan": 2.6371,
+                                      "records_for_plan": 3,
+                                      "rest_of_plan": [
+                                        {
+                                          "database": "test",
+                                          "table": "sq1_alias3",
+                                          "best_access_path": {
+                                            "considered_access_paths": [
+                                              {
+                                                "access_type": "scan",
+                                                "using_join_cache": true,
+                                                "records": 3,
+                                                "cost": 2.0374,
+                                                "chosen": true
+                                              }
+                                            ] /* considered_access_paths */
+                                          } /* best_access_path */,
+                                          "cost_for_plan": 6.4745,
+                                          "records_for_plan": 9,
+                                          "chosen": true
+                                        }
+                                      ] /* rest_of_plan */
+                                    },
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias3",
+                                      "best_access_path": {
+                                        "considered_access_paths": [
+                                          {
+                                            "access_type": "scan",
+                                            "records": 3,
+                                            "cost": 2.0371,
+                                            "chosen": true
+                                          }
+                                        ] /* considered_access_paths */
+                                      } /* best_access_path */,
+                                      "cost_for_plan": 2.6371,
+                                      "records_for_plan": 3,
+                                      "rest_of_plan": [
+                                        {
+                                          "database": "test",
+                                          "table": "sq1_alias2",
+                                          "best_access_path": {
+                                            "considered_access_paths": [
+                                              {
+                                                "access_type": "ref",
+                                                "index": "col_varchar_key",
+                                                "records": 1,
+                                                "cost": 4.1,
+                                                "chosen": true
+                                              },
+                                              {
+                                                "access_type": "scan",
+                                                "using_join_cache": true,
+                                                "records": 3,
+                                                "cost": 2.0373,
+                                                "chosen": true
+                                              }
+                                            ] /* considered_access_paths */
+                                          } /* best_access_path */,
+                                          "cost_for_plan": 6.4745,
+                                          "records_for_plan": 9,
+                                          "pruned_by_cost": true
+                                        }
+                                      ] /* rest_of_plan */
+                                    }
+                                  ] /* considered_execution_plans */
+                                }
+                              ] /* steps */,
+                              "empty_result": {
+                                "cause": "no matching row in const table"
+                              } /* empty_result */
+                            } /* join_optimization */
+                          },
+                          {
+                            "join_execution": {
+                              "select#": 2,
+                              "steps": [
+                              ] /* steps */
+                            } /* join_execution */
+                          }
+                        ] /* steps */
+                      } /* subselect_execution */
+                    }
+                  ] /* subselect_evaluation */,
+                  "uses_only_constant_tables": true
+                },
+                {
+                  "item": "(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`)",
+                  "subselect_evaluation": [
+                    {
+                      "subselect_execution": {
+                        "select#": 4,
+                        "steps": [
+                          {
+                            "join_optimization": {
+                              "select#": 4,
+                              "steps": [
+                              ] /* steps */,
+                              "empty_result": {
+                                "cause": "Select tables optimized away"
+                              } /* empty_result */
+                            } /* join_optimization */
+                          },
+                          {
+                            "join_execution": {
+                              "select#": 4,
+                              "steps": [
+                              ] /* steps */
+                            } /* join_execution */
+                          }
+                        ] /* steps */
+                      } /* subselect_execution */
+                    }
+                  ] /* subselect_evaluation */,
+                  "uses_only_constant_tables": true
+                },
+                {
+                  "item": "`alias2`.`col_varchar_nokey`"
+                },
+                {
+                  "item": "`alias2`.`col_varchar_nokey`"
+                }
+              ] /* items */,
+              "resulting_clause_is_simple": false,
+              "resulting_clause": "`test`.`alias1`.`col_varchar_key`,`test`.`alias1`.`col_date_key`,`alias2`.`col_varchar_nokey`,`alias2`.`col_varchar_nokey`"
+            } /* clause_processing */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "",
+                "table": "alias2"
+              },
+              {
+                "database": "test",
+                "table": "alias1",
+                "scan_type": "table"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_execution": {
+              "select#": 5,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+set optimizer_switch=@old_opt_switch;
+drop table t1,t2,t3,t4,t5;
+#
+# BUG#12905758 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON
+# SELECT/SUBQ/SUM QUERY
+#
+CREATE TABLE t1 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t1 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,NULL,'2000-12-03','2000-12-03','22:55:23.019225','22:55:23.019225','2005-07-20 00:00:00','2005-07-20 00:00:00','x','x'),
+(8,6,'2000-09-20','2000-09-20','14:11:27.044095','14:11:27.044095','2003-06-13 23:19:49.018300','2003-06-13 23:19:49.018300','c','c');
+CREATE TABLE t2 (I INTEGER);
+select ( select sum( subquery1_t1.`col_int_nokey` ) as subquery1_field1 from
+t1 as subquery1_t1 ) as field1 from ( t1 as table1 straight_join t1 as table2
+on (table2.`col_varchar_key` = table1.`col_varchar_key` ) ) where (
+table2.`col_int_nokey` <> any ( select 5 from t2 ) ) and table1.`pk` in
+(192,18) order by field1 desc;
+field1
+select * from information_schema.optimizer_trace;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	INSUFFICIENT_PRIVILEGES
+select ( select sum( subquery1_t1.`col_int_nokey` ) as subquery1_field1 from
+t1 as subquery1_t1 ) as field1 from ( t1 as table1 straight_join t1 as table2
+on (table2.`col_varchar_key` = table1.`col_varchar_key` ) ) where (
+table2.`col_int_nokey` <> any ( select 5 from t2 ) ) and table1.`pk` in
+(192,18) order by field1 desc	{
+  "steps": [
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+                {
+                  "expanded_query": "/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "join_preparation": {
+              "select#": 3,
+              "steps": [
+                {
+                  "expanded_query": "/* select#3 */ select 5 from `test`.`t2`"
+                },
+                {
+                  "transformation": {
+                    "select#": 3,
+                    "from": "IN (SELECT)",
+                    "to": "EXISTS (CORRELATED SELECT)",
+                    "chosen": true,
+                    "evaluating_constant_where_conditions": [
+                    ] /* evaluating_constant_where_conditions */
+                  } /* transformation */
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "expanded_query": "/* select#1 */ select (/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`) AS `field1` from (`test`.`t1` `table1` straight_join `test`.`t1` `table2` on((`test`.`table2`.`col_varchar_key` = `test`.`table1`.`col_varchar_key`))) where (<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18))) order by (/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`) desc"
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and (`test`.`table2`.`col_varchar_key` = `test`.`table1`.`col_varchar_key`))",
+              "steps": [
+                {
+                  "transformation": "equality_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and multiple equal(`test`.`table2`.`col_varchar_key`, `test`.`table1`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "constant_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and multiple equal(`test`.`table2`.`col_varchar_key`, `test`.`table1`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "trivial_condition_removal",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and multiple equal(`test`.`table2`.`col_varchar_key`, `test`.`table1`.`col_varchar_key`))"
+                }
+              ] /* steps */
+            } /* condition_processing */
+          },
+          {
+            "ref_optimizer_key_uses": [
+              {
+                "database": "test",
+                "table": "table1",
+                "field": "col_varchar_key",
+                "equals": "`test`.`table2`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "test",
+                "table": "table2",
+                "field": "col_varchar_key",
+                "equals": "`test`.`table1`.`col_varchar_key`",
+                "null_rejecting": true
+              }
+            ] /* ref_optimizer_key_uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "table1",
+                "range_analysis": {
+                  "table_scan": {
+                    "records": 2,
+                    "cost": 4.5244
+                  } /* table_scan */,
+                  "potential_range_indices": [
+                    {
+                      "index": "PRIMARY",
+                      "usable": true,
+                      "key_parts": [
+                        "pk"
+                      ] /* key_parts */
+                    },
+                    {
+                      "index": "col_varchar_key",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    }
+                  ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
+                  "group_index_range": {
+                    "chosen": false,
+                    "cause": "not_single_table"
+                  } /* group_index_range */,
+                  "analyzing_range_alternatives": {
+                    "range_scan_alternatives": [
+                      {
+                        "index": "PRIMARY",
+                        "ranges": [
+                          "18 <= pk <= 18",
+                          "192 <= pk <= 192"
+                        ] /* ranges */,
+                        "index_only": false,
+                        "records": 2,
+                        "cost": 4.41,
+                        "rowid_ordered": false,
+                        "chosen": true
+                      }
+                    ] /* range_scan_alternatives */,
+                    "analyzing_roworder_intersect": {
+                      "usable": false,
+                      "cause": "too_few_roworder_scans"
+                    } /* analyzing_roworder_intersect */
+                  } /* analyzing_range_alternatives */,
+                  "chosen_range_access_summary": {
+                    "range_access_plan": {
+                      "type": "range_scan",
+                      "index": "PRIMARY",
+                      "records": 2,
+                      "ranges": [
+                        "18 <= pk <= 18",
+                        "192 <= pk <= 192"
+                      ] /* ranges */
+                    } /* range_access_plan */,
+                    "records_for_plan": 2,
+                    "cost_for_plan": 4.41,
+                    "chosen": true
+                  } /* chosen_range_access_summary */
+                } /* range_analysis */
+              },
+              {
+                "database": "test",
+                "table": "table2",
+                "table_scan": {
+                  "records": 2,
+                  "cost": 2
+                } /* table_scan */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": [
+              {
+                "database": "test",
+                "table": "table1",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "ref",
+                      "index": "col_varchar_key",
+                      "usable": false,
+                      "chosen": false
+                    },
+                    {
+                      "access_type": "range",
+                      "records": 2,
+                      "cost": 4.41,
+                      "chosen": true
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 4.81,
+                "records_for_plan": 2,
+                "rest_of_plan": [
+                  {
+                    "database": "test",
+                    "table": "table2",
+                    "best_access_path": {
+                      "considered_access_paths": [
+                        {
+                          "access_type": "ref",
+                          "index": "col_varchar_key",
+                          "records": 1,
+                          "cost": 2.6,
+                          "chosen": true
+                        },
+                        {
+                          "access_type": "scan",
+                          "using_join_cache": true,
+                          "records": 2,
+                          "cost": 2.0247,
+                          "chosen": false
+                        }
+                      ] /* considered_access_paths */
+                    } /* best_access_path */,
+                    "cost_for_plan": 7.61,
+                    "records_for_plan": 2,
+                    "chosen": true
+                  }
+                ] /* rest_of_plan */
+              }
+            ] /* considered_execution_plans */
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": "((`test`.`table2`.`col_varchar_key` = `test`.`table1`.`col_varchar_key`) and <nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)))",
+              "attached_conditions_computation": [
+              ] /* attached_conditions_computation */,
+              "attached_conditions_summary": [
+                {
+                  "database": "test",
+                  "table": "table1",
+                  "attached": "((`test`.`table1`.`pk` in (192,18)) and (`test`.`table1`.`col_varchar_key` is not null))"
+                },
+                {
+                  "database": "test",
+                  "table": "table2",
+                  "attached": "<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true))))"
+                }
+              ] /* attached_conditions_summary */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "clause_processing": {
+              "clause": "ORDER BY",
+              "original_clause": "(/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`) desc",
+              "items": [
+                {
+                  "item": "(/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`)",
+                  "subselect_evaluation": [
+                    {
+                      "subselect_execution": {
+                        "select#": 2,
+                        "steps": [
+                          {
+                            "join_optimization": {
+                              "select#": 2,
+                              "steps": [
+                                {
+                                  "records_estimation": [
+                                    {
+                                      "database": "test",
+                                      "table": "subquery1_t1",
+                                      "table_scan": {
+                                        "records": 2,
+                                        "cost": 2
+                                      } /* table_scan */
+                                    }
+                                  ] /* records_estimation */
+                                },
+                                {
+                                  "considered_execution_plans": [
+                                    {
+                                      "database": "test",
+                                      "table": "subquery1_t1",
+                                      "best_access_path": {
+                                        "considered_access_paths": [
+                                          {
+                                            "access_type": "scan",
+                                            "records": 2,
+                                            "cost": 2.0244,
+                                            "chosen": true
+                                          }
+                                        ] /* considered_access_paths */
+                                      } /* best_access_path */,
+                                      "cost_for_plan": 2.4244,
+                                      "records_for_plan": 2,
+                                      "chosen": true
+                                    }
+                                  ] /* considered_execution_plans */
+                                },
+                                {
+                                  "attaching_conditions_to_tables": {
+                                    "original_condition": null,
+                                    "attached_conditions_computation": [
+                                    ] /* attached_conditions_computation */,
+                                    "attached_conditions_summary": [
+                                      {
+                                        "database": "test",
+                                        "table": "subquery1_t1",
+                                        "attached": null
+                                      }
+                                    ] /* attached_conditions_summary */
+                                  } /* attaching_conditions_to_tables */
+                                },
+                                {
+                                  "refine_plan": [
+                                    {
+                                      "database": "test",
+                                      "table": "subquery1_t1",
+                                      "scan_type": "table"
+                                    }
+                                  ] /* refine_plan */
+                                }
+                              ] /* steps */
+                            } /* join_optimization */
+                          },
+                          {
+                            "join_execution": {
+                              "select#": 2,
+                              "steps": [
+                              ] /* steps */
+                            } /* join_execution */
+                          }
+                        ] /* steps */
+                      } /* subselect_execution */
+                    }
+                  ] /* subselect_evaluation */,
+                  "uses_only_constant_tables": true
+                }
+              ] /* items */,
+              "resulting_clause_is_simple": true,
+              "resulting_clause": ""
+            } /* clause_processing */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "table1",
+                "scan_type": "table"
+              },
+              {
+                "database": "test",
+                "table": "table2"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+drop table t1,t2;

=== modified file 'mysql-test/suite/opt_trace/r/subquery_ps_prot.result'
--- a/mysql-test/suite/opt_trace/r/subquery_ps_prot.result	2011-07-20 13:10:44 +0000
+++ b/mysql-test/suite/opt_trace/r/subquery_ps_prot.result	2011-08-31 16:48:23 +0000
@@ -386,7 +386,7 @@ t1.a= (SELECT a FROM t2 LIMIT 1)	{
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
+                  "subselect_evaluation": [
                     {
                       "subselect_execution": {
                         "select#": 2,
@@ -429,19 +429,19 @@ t1.a= (SELECT a FROM t2 LIMIT 1)	{
                         ] /* steps */
                       } /* subselect_execution */
                     }
-                  ] /* subselect_equality_propagation */,
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "((NULL <> (/* select#3 */ select `test`.`t2`.`a` from `test`.`t2` limit 1)) and multiple equal((/* select#2 */ select NULL from `test`.`t2` limit 1), `test`.`t1`.`a`))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "((NULL <> (/* select#3 */ select `test`.`t2`.`a` from `test`.`t2` limit 1)) and multiple equal((/* select#2 */ select NULL from `test`.`t2` limit 1), `test`.`t1`.`a`))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
-                  ] /* subselect_cond_removal */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": null
                 }
               ] /* steps */
@@ -506,19 +506,19 @@ WHERE NOT EXISTS
               "steps": [
                 {
                   "transformation": "equality_propagation",
-                  "subselect_equality_propagation": [
-                  ] /* subselect_equality_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(exists(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`a` = 50) and (`test`.`t2`.`b` = 3)))))"
                 },
                 {
                   "transformation": "constant_propagation",
-                  "subselect_constant_propagation": [
-                  ] /* subselect_constant_propagation */,
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
                   "resulting_condition": "(not(exists(/* select#2 */ select 1 from `test`.`t2` where ((`test`.`t2`.`a` = 50) and (`test`.`t2`.`b` = 3)))))"
                 },
                 {
                   "transformation": "trivial_condition_removal",
-                  "subselect_cond_removal": [
+                  "subselect_evaluation": [
                     {
                       "subselect_execution": {
                         "select#": 2,
@@ -578,7 +578,7 @@ WHERE NOT EXISTS
                         ] /* steps */
                       } /* subselect_execution */
                     }
-                  ] /* subselect_cond_removal */,
+                  ] /* subselect_evaluation */,
                   "resulting_condition": null
                 }
               ] /* steps */
@@ -598,3 +598,1209 @@ WHERE NOT EXISTS
 }	0	0
 
 DROP TABLE t1,t2;
+#
+# BUG#12905521 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON SELECT
+# DISTINCT/MIN/JOIN/SUBQ QUERY
+#
+CREATE TABLE t1 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t2 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t3 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_time_key TIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+CREATE TABLE t4 (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t4 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,7,'2008-10-02','2008-10-02','04:07:22.028954','04:07:22.028954','2001-10-08 00:00:00','2001-10-08 00:00:00','g','g');
+CREATE TABLE t5 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t5 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,NULL,'2000-12-03','2000-12-03','22:55:23.019225','22:55:23.019225','2005-07-20 00:00:00','2005-07-20 00:00:00','x','x'),
+(7,8,'2008-05-03','2008-05-03','10:19:31.050677','10:19:31.050677','2007-10-06 17:56:40.056051','2007-10-06 17:56:40.056051','d','d'),
+(8,6,'2000-09-20','2000-09-20','14:11:27.044095','14:11:27.044095','2003-06-13 23:19:49.018300','2003-06-13 23:19:49.018300','c','c');
+set @old_opt_switch=@@optimizer_switch;
+select distinct
+alias1.`col_varchar_key` as field1 ,alias1.`col_date_key` as
+field2 ,( select min( sq1_alias1.`col_varchar_nokey` ) as sq1_field1 from ( t1
+as sq1_alias1 inner join ( t5 as sq1_alias2 left join t5 as sq1_alias3 on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) where
+exists ( select distinct c_sq1_alias2.`col_int_nokey` as c_sq1_field1 from (
+t3 as c_sq1_alias1 right join t4 as c_sq1_alias2 on (c_sq1_alias2.`col_int_nokey` = c_sq1_alias1.`pk` ) ) where
+c_sq1_alias2.`col_varchar_key` = sq1_alias2.`col_varchar_nokey` ) ) as field3
+,( select max( sq2_alias1.`pk` ) as sq2_field1 from t5 as sq2_alias1 ) as
+field4 ,alias2.`col_varchar_nokey` as field5 ,alias2.`col_varchar_nokey` as
+field6 from ( t5 as alias1 right outer join ( ( ( select sq3_alias2.* from ( t5 as sq3_alias1 ,t4 as sq3_alias2 ) ) as alias2 right join t4
+as alias3 on (alias3.`col_varchar_key` = alias2.`col_varchar_key` ) ) ) on
+(alias3.`col_int_key` = alias2.`pk` ) ) where ( alias1.`col_varchar_nokey` in
+( select sq4_alias1.`col_varchar_key` as sq4_field1 from ( t3 as sq4_alias1
+inner join ( t2 as sq4_alias2 right outer join t3 as sq4_alias3 on
+(sq4_alias3.`pk` = sq4_alias2.`col_int_key` ) ) on
+(sq4_alias3.`col_varchar_nokey` = sq4_alias2.`col_varchar_key` ) ) where
+sq4_alias2.`col_int_key` < alias1.`col_int_nokey` and
+sq4_alias3.`col_varchar_nokey` <> alias1.`col_varchar_key` ) ) and
+alias1.`col_int_key` not in (214) group by field1,field2,field3,
+field4,field5,field6;
+field1	field2	field3	field4	field5	field6
+select * from information_schema.optimizer_trace;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	INSUFFICIENT_PRIVILEGES
+select distinct
+alias1.`col_varchar_key` as field1 ,alias1.`col_date_key` as
+field2 ,( select min( sq1_alias1.`col_varchar_nokey` ) as sq1_field1 from ( t1
+as sq1_alias1 inner join ( t5 as sq1_alias2 left join t5 as sq1_alias3 on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) on
+(sq1_alias3.`col_varchar_nokey` = sq1_alias2.`col_varchar_key` ) ) where
+exists ( select distinct c_sq1_alias2.`col_int_nokey` as c_sq1_field1 from (
+t3 as c_sq1_alias1 right join t4 as c_sq1_alias2 on (c_sq1_alias2.`col_int_nokey` = c_sq1_alias1.`pk` ) ) where
+c_sq1_alias2.`col_varchar_key` = sq1_alias2.`col_varchar_nokey` ) ) as field3
+,( select max( sq2_alias1.`pk` ) as sq2_field1 from t5 as sq2_alias1 ) as
+field4 ,alias2.`col_varchar_nokey` as field5 ,alias2.`col_varchar_nokey` as
+field6 from ( t5 as alias1 right outer join ( ( ( select sq3_alias2.* from ( t5 as sq3_alias1 ,t4 as sq3_alias2 ) ) as alias2 right join t4
+as alias3 on (alias3.`col_varchar_key` = alias2.`col_varchar_key` ) ) ) on
+(alias3.`col_int_key` = alias2.`pk` ) ) where ( alias1.`col_varchar_nokey` in
+( select sq4_alias1.`col_varchar_key` as sq4_field1 from ( t3 as sq4_alias1
+inner join ( t2 as sq4_alias2 right outer join t3 as sq4_alias3 on
+(sq4_alias3.`pk` = sq4_alias2.`col_int_key` ) ) on
+(sq4_alias3.`col_varchar_nokey` = sq4_alias2.`col_varchar_key` ) ) where
+sq4_alias2.`col_int_key` < alias1.`col_int_nokey` and
+sq4_alias3.`col_varchar_nokey` <> alias1.`col_varchar_key` ) ) and
+alias1.`col_int_key` not in (214) group by field1,field2,field3,
+field4,field5,field6	{
+  "steps": [
+    {
+      "join_preparation": {
+        "select#": 5,
+        "steps": [
+          {
+            "expanded_query": "/* select#5 */ select `test`.`sq3_alias2`.`pk` AS `pk`,`test`.`sq3_alias2`.`col_int_nokey` AS `col_int_nokey`,`test`.`sq3_alias2`.`col_int_key` AS `col_int_key`,`test`.`sq3_alias2`.`col_date_key` AS `col_date_key`,`test`.`sq3_alias2`.`col_date_nokey` AS `col_date_nokey`,`test`.`sq3_alias2`.`col_time_key` AS `col_time_key`,`test`.`sq3_alias2`.`col_time_nokey` AS `col_time_nokey`,`test`.`sq3_alias2`.`col_datetime_key` AS `col_datetime_key`,`test`.`sq3_alias2`.`col_datetime_nokey` AS `col_datetime_nokey`,`test`.`sq3_alias2`.`col_varchar_key` AS `col_varchar_key`,`test`.`sq3_alias2`.`col_varchar_nokey` AS `col_varchar_nokey` from (`test`.`t5` `sq3_alias1` join `test`.`t4` `sq3_alias2`)"
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_preparation": {
+                    "select#": 3,
+                    "steps": [
+                      {
+                        "expanded_query": "/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)"
+                      }
+                    ] /* steps */
+                  } /* join_preparation */
+                },
+                {
+                  "expanded_query": "/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "join_preparation": {
+              "select#": 4,
+              "steps": [
+                {
+                  "expanded_query": "/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "join_preparation": {
+              "select#": 6,
+              "steps": [
+                {
+                  "expanded_query": "/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": {
+                    "select#": 6,
+                    "from": "IN (SELECT)",
+                    "to": "semijoin",
+                    "chosen": false
+                  } /* transformation */
+                },
+                {
+                  "transformation": {
+                    "select#": 6,
+                    "from": "IN (SELECT)",
+                    "to": "materialization",
+                    "chosen": false
+                  } /* transformation */
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "expanded_query": "/* select#1 */ select distinct `test`.`alias1`.`col_varchar_key` AS `field1`,`test`.`alias1`.`col_date_key` AS `field2`,(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))) AS `field3`,(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`) AS `field4`,`alias2`.`col_varchar_!
 nokey` AS `field5`,`alias2`.`col_varchar_nokey` AS `field6` from ((`test`.`t4` `alias3` left join ((/* select#5 */ select `test`.`sq3_alias2`.`pk` AS `pk`,`test`.`sq3_alias2`.`col_int_nokey` AS `col_int_nokey`,`test`.`sq3_alias2`.`col_int_key` AS `col_int_key`,`test`.`sq3_alias2`.`col_date_key` AS `col_date_key`,`test`.`sq3_alias2`.`col_date_nokey` AS `col_date_nokey`,`test`.`sq3_alias2`.`col_time_key` AS `col_time_key`,`test`.`sq3_alias2`.`col_time_nokey` AS `col_time_nokey`,`test`.`sq3_alias2`.`col_datetime_key` AS `col_datetime_key`,`test`.`sq3_alias2`.`col_datetime_nokey` AS `col_datetime_nokey`,`test`.`sq3_alias2`.`col_varchar_key` AS `col_varchar_key`,`test`.`sq3_alias2`.`col_varchar_nokey` AS `col_varchar_nokey` from (`test`.`t5` `sq3_alias1` join `test`.`t4` `sq3_alias2`))) `alias2` on((`test`.`alias3`.`col_varchar_key` = `alias2`.`col_varchar_key`))) left join `test`.`t5` `alias1` on((`test`.`alias3`.`col_int_key` = `alias2`.`pk`))) where (<in_optimizer>(`test`.`al!
 ias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test
`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214)) group by `test`.`alias1`.`col_varchar_key`,`test`.`alias1`.`col_date_key`,(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* selec!
 t#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))),(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`),`alias2`.`col_varchar_nokey`,`alias2`.`col_varchar_nokey`"
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_optimization": {
+              "select#": 5,
+              "steps": [
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "sq3_alias1",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    },
+                    {
+                      "database": "test",
+                      "table": "sq3_alias2",
+                      "records": 1,
+                      "cost": 1,
+                      "table_type": "system"
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "sq3_alias1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "records": 3,
+                            "cost": 2.0371,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.6371,
+                      "records_for_plan": 3,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions_computation": [
+                    ] /* attached_conditions_computation */,
+                    "attached_conditions_summary": [
+                      {
+                        "database": "test",
+                        "table": "sq3_alias1",
+                        "attached": null
+                      }
+                    ] /* attached_conditions_summary */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "sq3_alias1",
+                      "scan_type": "index"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and (`test`.`alias3`.`col_int_key` = `alias2`.`pk`) and (`test`.`alias3`.`col_varchar_key` = `alias2`.`col_varchar_key`))",
+              "steps": [
+                {
+                  "transformation": "equality_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and multiple equal(`test`.`alias3`.`col_int_key`, `alias2`.`pk`) and multiple equal(`test`.`alias3`.`col_varchar_key`, `alias2`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "constant_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and multiple equal(`test`.`alias3`.`col_int_key`, `alias2`.`pk`) and multiple equal(`test`.`alias3`.`col_varchar_key`, `alias2`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "trivial_condition_removal",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214) and multiple equal(`test`.`alias3`.`col_int_key`, `alias2`.`pk`) and multiple equal(`test`.`alias3`.`col_varchar_key`, `alias2`.`col_varchar_key`))"
+                }
+              ] /* steps */
+            } /* condition_processing */
+          },
+          {
+            "ref_optimizer_key_uses": [
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "pk",
+                "equals": "`test`.`alias3`.`col_int_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "col_varchar_key",
+                "equals": "`test`.`alias3`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "pk",
+                "equals": "`test`.`alias3`.`col_int_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "field": "col_varchar_key",
+                "equals": "`test`.`alias3`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "test",
+                "table": "alias3",
+                "field": "col_varchar_key",
+                "equals": "`alias2`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "test",
+                "table": "alias3",
+                "field": "col_int_key",
+                "equals": "`alias2`.`pk`",
+                "null_rejecting": true
+              }
+            ] /* ref_optimizer_key_uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "alias1",
+                "range_analysis": {
+                  "table_scan": {
+                    "records": 3,
+                    "cost": 4.7371
+                  } /* table_scan */,
+                  "potential_range_indices": [
+                    {
+                      "index": "PRIMARY",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    },
+                    {
+                      "index": "col_int_key",
+                      "usable": true,
+                      "key_parts": [
+                        "col_int_key"
+                      ] /* key_parts */
+                    },
+                    {
+                      "index": "col_varchar_key",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    }
+                  ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
+                  "group_index_range": {
+                    "chosen": false,
+                    "cause": "not_single_table"
+                  } /* group_index_range */,
+                  "analyzing_range_alternatives": {
+                    "range_scan_alternatives": [
+                      {
+                        "index": "col_int_key",
+                        "ranges": [
+                          "NULL < col_int_key < 214",
+                          "214 < col_int_key"
+                        ] /* ranges */,
+                        "index_only": false,
+                        "records": 3,
+                        "cost": 5.61,
+                        "rowid_ordered": false,
+                        "chosen": false,
+                        "cause": "cost"
+                      }
+                    ] /* range_scan_alternatives */,
+                    "analyzing_roworder_intersect": {
+                      "usable": false,
+                      "cause": "too_few_roworder_scans"
+                    } /* analyzing_roworder_intersect */
+                  } /* analyzing_range_alternatives */
+                } /* range_analysis */
+              },
+              {
+                "database": "",
+                "table": "alias2"
+              },
+              {
+                "database": "test",
+                "table": "alias3",
+                "records": 1,
+                "cost": 1,
+                "table_type": "system"
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": [
+              {
+                "database": "test",
+                "table": "alias1",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "scan",
+                      "records": 3,
+                      "cost": 2.0371,
+                      "chosen": true
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 2.6371,
+                "records_for_plan": 3,
+                "rest_of_plan": [
+                  {
+                    "database": "",
+                    "table": "alias2",
+                    "best_access_path": {
+                      "considered_access_paths": [
+                        {
+                          "access_type": "ref",
+                          "index": "auto_key0",
+                          "records": 0.3,
+                          "cost": 0.96,
+                          "chosen": true
+                        },
+                        {
+                          "access_type": "ref",
+                          "index": "auto_key1",
+                          "records": 0.3,
+                          "cost": 0.96,
+                          "chosen": false
+                        },
+                        {
+                          "access_type": "scan",
+                          "cost": 10,
+                          "records": 3,
+                          "cause": "cost",
+                          "chosen": false
+                        }
+                      ] /* considered_access_paths */
+                    } /* best_access_path */,
+                    "cost_for_plan": 3.7171,
+                    "records_for_plan": 0.9,
+                    "chosen": true
+                  }
+                ] /* rest_of_plan */
+              },
+              {
+                "database": "",
+                "table": "alias2",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "ref",
+                      "index": "auto_key0",
+                      "records": 0.3,
+                      "cost": 0.36,
+                      "chosen": true
+                    },
+                    {
+                      "access_type": "ref",
+                      "index": "auto_key1",
+                      "records": 0.3,
+                      "cost": 0.36,
+                      "chosen": false
+                    },
+                    {
+                      "access_type": "scan",
+                      "cost": 10,
+                      "records": 3,
+                      "cause": "cost",
+                      "chosen": false
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 0.36,
+                "records_for_plan": 0.3,
+                "rest_of_plan": [
+                  {
+                    "database": "test",
+                    "table": "alias1",
+                    "best_access_path": {
+                      "considered_access_paths": [
+                        {
+                          "access_type": "scan",
+                          "using_join_cache": true,
+                          "records": 3,
+                          "cost": 2.0373,
+                          "chosen": true
+                        }
+                      ] /* considered_access_paths */
+                    } /* best_access_path */,
+                    "cost_for_plan": 2.5773,
+                    "records_for_plan": 0.9,
+                    "chosen": true
+                  }
+                ] /* rest_of_plan */
+              }
+            ] /* considered_execution_plans */
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": "((`alias2`.`col_varchar_key` = 'g') and (`alias2`.`pk` = '8') and <in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214))",
+              "attached_conditions_computation": [
+              ] /* attached_conditions_computation */,
+              "attached_conditions_summary": [
+                {
+                  "database": "",
+                  "table": "alias2",
+                  "attached": null
+                },
+                {
+                  "database": "test",
+                  "table": "alias1",
+                  "attached": "(<in_optimizer>(`test`.`alias1`.`col_varchar_nokey`,<exists>(/* select#6 */ select 1 from (`test`.`t3` `sq4_alias1` join (`test`.`t3` `sq4_alias3` left join `test`.`t2` `sq4_alias2` on((`test`.`sq4_alias3`.`pk` = `test`.`sq4_alias2`.`col_int_key`))) on((`test`.`sq4_alias3`.`col_varchar_nokey` = `test`.`sq4_alias2`.`col_varchar_key`))) where ((`test`.`sq4_alias2`.`col_int_key` < `test`.`alias1`.`col_int_nokey`) and (`test`.`sq4_alias3`.`col_varchar_nokey` <> `test`.`alias1`.`col_varchar_key`) and (<cache>(`test`.`alias1`.`col_varchar_nokey`) = `test`.`sq4_alias1`.`col_varchar_key`)))) and (`test`.`alias1`.`col_int_key` <> 214))"
+                }
+              ] /* attached_conditions_summary */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "clause_processing": {
+              "clause": "GROUP BY",
+              "original_clause": "`test`.`alias1`.`col_varchar_key`,`test`.`alias1`.`col_date_key`,(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`))),(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`),`alias2`.`col_varchar_nokey`,`alias2`.`col_varchar_nokey`",
+              "items": [
+                {
+                  "item": "`test`.`alias1`.`col_varchar_key`"
+                },
+                {
+                  "item": "`test`.`alias1`.`col_date_key`"
+                },
+                {
+                  "item": "(/* select#2 */ select min(`test`.`sq1_alias1`.`col_varchar_nokey`) AS `sq1_field1` from (`test`.`t1` `sq1_alias1` join (`test`.`t5` `sq1_alias2` left join `test`.`t5` `sq1_alias3` on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) on((`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))) where exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)))",
+                  "subselect_evaluation": [
+                    {
+                      "subselect_execution": {
+                        "select#": 2,
+                        "steps": [
+                          {
+                            "join_optimization": {
+                              "select#": 2,
+                              "steps": [
+                                {
+                                  "condition_processing": {
+                                    "condition": "WHERE",
+                                    "original_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and (`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`) and (`test`.`sq1_alias3`.`col_varchar_nokey` = `test`.`sq1_alias2`.`col_varchar_key`))",
+                                    "steps": [
+                                      {
+                                        "transformation": "equality_propagation",
+                                        "subselect_evaluation": [
+                                        ] /* subselect_evaluation */,
+                                        "resulting_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and multiple equal(`test`.`sq1_alias3`.`col_varchar_nokey`, `test`.`sq1_alias2`.`col_varchar_key`))"
+                                      },
+                                      {
+                                        "transformation": "constant_propagation",
+                                        "subselect_evaluation": [
+                                        ] /* subselect_evaluation */,
+                                        "resulting_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and multiple equal(`test`.`sq1_alias3`.`col_varchar_nokey`, `test`.`sq1_alias2`.`col_varchar_key`))"
+                                      },
+                                      {
+                                        "transformation": "trivial_condition_removal",
+                                        "subselect_evaluation": [
+                                        ] /* subselect_evaluation */,
+                                        "resulting_condition": "(exists(/* select#3 */ select distinct `test`.`c_sq1_alias2`.`col_int_nokey` AS `c_sq1_field1` from (`test`.`t4` `c_sq1_alias2` left join `test`.`t3` `c_sq1_alias1` on((`test`.`c_sq1_alias2`.`col_int_nokey` = `test`.`c_sq1_alias1`.`pk`))) where (`test`.`c_sq1_alias2`.`col_varchar_key` = `test`.`sq1_alias2`.`col_varchar_nokey`)) and multiple equal(`test`.`sq1_alias3`.`col_varchar_nokey`, `test`.`sq1_alias2`.`col_varchar_key`))"
+                                      }
+                                    ] /* steps */
+                                  } /* condition_processing */
+                                },
+                                {
+                                  "ref_optimizer_key_uses": [
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias2",
+                                      "field": "col_varchar_key",
+                                      "equals": "`test`.`sq1_alias3`.`col_varchar_nokey`",
+                                      "null_rejecting": true
+                                    }
+                                  ] /* ref_optimizer_key_uses */
+                                },
+                                {
+                                  "records_estimation": [
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias1",
+                                      "records": 1,
+                                      "cost": 1,
+                                      "table_type": "system"
+                                    },
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias2",
+                                      "table_scan": {
+                                        "records": 3,
+                                        "cost": 2
+                                      } /* table_scan */
+                                    },
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias3",
+                                      "table_scan": {
+                                        "records": 3,
+                                        "cost": 2
+                                      } /* table_scan */
+                                    }
+                                  ] /* records_estimation */
+                                },
+                                {
+                                  "considered_execution_plans": [
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias2",
+                                      "best_access_path": {
+                                        "considered_access_paths": [
+                                          {
+                                            "access_type": "ref",
+                                            "index": "col_varchar_key",
+                                            "usable": false,
+                                            "chosen": false
+                                          },
+                                          {
+                                            "access_type": "scan",
+                                            "records": 3,
+                                            "cost": 2.0371,
+                                            "chosen": true
+                                          }
+                                        ] /* considered_access_paths */
+                                      } /* best_access_path */,
+                                      "cost_for_plan": 2.6371,
+                                      "records_for_plan": 3,
+                                      "rest_of_plan": [
+                                        {
+                                          "database": "test",
+                                          "table": "sq1_alias3",
+                                          "best_access_path": {
+                                            "considered_access_paths": [
+                                              {
+                                                "access_type": "scan",
+                                                "using_join_cache": true,
+                                                "records": 3,
+                                                "cost": 2.0374,
+                                                "chosen": true
+                                              }
+                                            ] /* considered_access_paths */
+                                          } /* best_access_path */,
+                                          "cost_for_plan": 6.4745,
+                                          "records_for_plan": 9,
+                                          "chosen": true
+                                        }
+                                      ] /* rest_of_plan */
+                                    },
+                                    {
+                                      "database": "test",
+                                      "table": "sq1_alias3",
+                                      "best_access_path": {
+                                        "considered_access_paths": [
+                                          {
+                                            "access_type": "scan",
+                                            "records": 3,
+                                            "cost": 2.0371,
+                                            "chosen": true
+                                          }
+                                        ] /* considered_access_paths */
+                                      } /* best_access_path */,
+                                      "cost_for_plan": 2.6371,
+                                      "records_for_plan": 3,
+                                      "rest_of_plan": [
+                                        {
+                                          "database": "test",
+                                          "table": "sq1_alias2",
+                                          "best_access_path": {
+                                            "considered_access_paths": [
+                                              {
+                                                "access_type": "ref",
+                                                "index": "col_varchar_key",
+                                                "records": 1,
+                                                "cost": 4.1,
+                                                "chosen": true
+                                              },
+                                              {
+                                                "access_type": "scan",
+                                                "using_join_cache": true,
+                                                "records": 3,
+                                                "cost": 2.0373,
+                                                "chosen": true
+                                              }
+                                            ] /* considered_access_paths */
+                                          } /* best_access_path */,
+                                          "cost_for_plan": 6.4745,
+                                          "records_for_plan": 9,
+                                          "pruned_by_cost": true
+                                        }
+                                      ] /* rest_of_plan */
+                                    }
+                                  ] /* considered_execution_plans */
+                                }
+                              ] /* steps */,
+                              "empty_result": {
+                                "cause": "no matching row in const table"
+                              } /* empty_result */
+                            } /* join_optimization */
+                          },
+                          {
+                            "join_execution": {
+                              "select#": 2,
+                              "steps": [
+                              ] /* steps */
+                            } /* join_execution */
+                          }
+                        ] /* steps */
+                      } /* subselect_execution */
+                    }
+                  ] /* subselect_evaluation */,
+                  "uses_only_constant_tables": true
+                },
+                {
+                  "item": "(/* select#4 */ select max(`test`.`sq2_alias1`.`pk`) AS `sq2_field1` from `test`.`t5` `sq2_alias1`)",
+                  "subselect_evaluation": [
+                    {
+                      "subselect_execution": {
+                        "select#": 4,
+                        "steps": [
+                          {
+                            "join_optimization": {
+                              "select#": 4,
+                              "steps": [
+                              ] /* steps */,
+                              "empty_result": {
+                                "cause": "Select tables optimized away"
+                              } /* empty_result */
+                            } /* join_optimization */
+                          },
+                          {
+                            "join_execution": {
+                              "select#": 4,
+                              "steps": [
+                              ] /* steps */
+                            } /* join_execution */
+                          }
+                        ] /* steps */
+                      } /* subselect_execution */
+                    }
+                  ] /* subselect_evaluation */,
+                  "uses_only_constant_tables": true
+                },
+                {
+                  "item": "`alias2`.`col_varchar_nokey`"
+                },
+                {
+                  "item": "`alias2`.`col_varchar_nokey`"
+                }
+              ] /* items */,
+              "resulting_clause_is_simple": false,
+              "resulting_clause": "`test`.`alias1`.`col_varchar_key`,`test`.`alias1`.`col_date_key`,`alias2`.`col_varchar_nokey`,`alias2`.`col_varchar_nokey`"
+            } /* clause_processing */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "",
+                "table": "alias2"
+              },
+              {
+                "database": "test",
+                "table": "alias1",
+                "scan_type": "table"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_execution": {
+              "select#": 5,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+set optimizer_switch=@old_opt_switch;
+drop table t1,t2,t3,t4,t5;
+#
+# BUG#12905758 - ASSERT IN OPT_TRACE_STMT::SYNTAX_ERROR ON
+# SELECT/SUBQ/SUM QUERY
+#
+CREATE TABLE t1 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER,
+col_date_key DATE,
+col_date_nokey DATE,
+col_time_key TIME,
+col_time_nokey TIME,
+col_datetime_key DATETIME,
+col_datetime_nokey DATETIME,
+col_varchar_key VARCHAR(1),
+col_varchar_nokey VARCHAR(1),
+PRIMARY KEY (pk),
+KEY (col_varchar_key,col_int_key)
+) ENGINE=MYISAM;
+INSERT INTO t1 (
+col_int_key,col_int_nokey,
+col_date_key,col_date_nokey,
+col_time_key,col_time_nokey,
+col_datetime_key,col_datetime_nokey,
+col_varchar_key,col_varchar_nokey
+) VALUES
+(8,NULL,'2000-12-03','2000-12-03','22:55:23.019225','22:55:23.019225','2005-07-20 00:00:00','2005-07-20 00:00:00','x','x'),
+(8,6,'2000-09-20','2000-09-20','14:11:27.044095','14:11:27.044095','2003-06-13 23:19:49.018300','2003-06-13 23:19:49.018300','c','c');
+CREATE TABLE t2 (I INTEGER);
+select ( select sum( subquery1_t1.`col_int_nokey` ) as subquery1_field1 from
+t1 as subquery1_t1 ) as field1 from ( t1 as table1 straight_join t1 as table2
+on (table2.`col_varchar_key` = table1.`col_varchar_key` ) ) where (
+table2.`col_int_nokey` <> any ( select 5 from t2 ) ) and table1.`pk` in
+(192,18) order by field1 desc;
+field1
+select * from information_schema.optimizer_trace;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	INSUFFICIENT_PRIVILEGES
+select ( select sum( subquery1_t1.`col_int_nokey` ) as subquery1_field1 from
+t1 as subquery1_t1 ) as field1 from ( t1 as table1 straight_join t1 as table2
+on (table2.`col_varchar_key` = table1.`col_varchar_key` ) ) where (
+table2.`col_int_nokey` <> any ( select 5 from t2 ) ) and table1.`pk` in
+(192,18) order by field1 desc	{
+  "steps": [
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+                {
+                  "expanded_query": "/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "join_preparation": {
+              "select#": 3,
+              "steps": [
+                {
+                  "expanded_query": "/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)"
+                }
+              ] /* steps */
+            } /* join_preparation */
+          },
+          {
+            "expanded_query": "/* select#1 */ select (/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`) AS `field1` from (`test`.`t1` `table1` straight_join `test`.`t1` `table2` on((`test`.`table2`.`col_varchar_key` = `test`.`table1`.`col_varchar_key`))) where (<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18))) order by (/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`) desc"
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and (`test`.`table2`.`col_varchar_key` = `test`.`table1`.`col_varchar_key`))",
+              "steps": [
+                {
+                  "transformation": "equality_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and multiple equal(`test`.`table2`.`col_varchar_key`, `test`.`table1`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "constant_propagation",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and multiple equal(`test`.`table2`.`col_varchar_key`, `test`.`table1`.`col_varchar_key`))"
+                },
+                {
+                  "transformation": "trivial_condition_removal",
+                  "subselect_evaluation": [
+                  ] /* subselect_evaluation */,
+                  "resulting_condition": "(<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)) and multiple equal(`test`.`table2`.`col_varchar_key`, `test`.`table1`.`col_varchar_key`))"
+                }
+              ] /* steps */
+            } /* condition_processing */
+          },
+          {
+            "ref_optimizer_key_uses": [
+              {
+                "database": "test",
+                "table": "table1",
+                "field": "col_varchar_key",
+                "equals": "`test`.`table2`.`col_varchar_key`",
+                "null_rejecting": true
+              },
+              {
+                "database": "test",
+                "table": "table2",
+                "field": "col_varchar_key",
+                "equals": "`test`.`table1`.`col_varchar_key`",
+                "null_rejecting": true
+              }
+            ] /* ref_optimizer_key_uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "table1",
+                "range_analysis": {
+                  "table_scan": {
+                    "records": 2,
+                    "cost": 4.5244
+                  } /* table_scan */,
+                  "potential_range_indices": [
+                    {
+                      "index": "PRIMARY",
+                      "usable": true,
+                      "key_parts": [
+                        "pk"
+                      ] /* key_parts */
+                    },
+                    {
+                      "index": "col_varchar_key",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    }
+                  ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
+                  "group_index_range": {
+                    "chosen": false,
+                    "cause": "not_single_table"
+                  } /* group_index_range */,
+                  "analyzing_range_alternatives": {
+                    "range_scan_alternatives": [
+                      {
+                        "index": "PRIMARY",
+                        "ranges": [
+                          "18 <= pk <= 18",
+                          "192 <= pk <= 192"
+                        ] /* ranges */,
+                        "index_only": false,
+                        "records": 2,
+                        "cost": 4.41,
+                        "rowid_ordered": false,
+                        "chosen": true
+                      }
+                    ] /* range_scan_alternatives */,
+                    "analyzing_roworder_intersect": {
+                      "usable": false,
+                      "cause": "too_few_roworder_scans"
+                    } /* analyzing_roworder_intersect */
+                  } /* analyzing_range_alternatives */,
+                  "chosen_range_access_summary": {
+                    "range_access_plan": {
+                      "type": "range_scan",
+                      "index": "PRIMARY",
+                      "records": 2,
+                      "ranges": [
+                        "18 <= pk <= 18",
+                        "192 <= pk <= 192"
+                      ] /* ranges */
+                    } /* range_access_plan */,
+                    "records_for_plan": 2,
+                    "cost_for_plan": 4.41,
+                    "chosen": true
+                  } /* chosen_range_access_summary */
+                } /* range_analysis */
+              },
+              {
+                "database": "test",
+                "table": "table2",
+                "table_scan": {
+                  "records": 2,
+                  "cost": 2
+                } /* table_scan */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": [
+              {
+                "database": "test",
+                "table": "table1",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "ref",
+                      "index": "col_varchar_key",
+                      "usable": false,
+                      "chosen": false
+                    },
+                    {
+                      "access_type": "range",
+                      "records": 2,
+                      "cost": 4.41,
+                      "chosen": true
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 4.81,
+                "records_for_plan": 2,
+                "rest_of_plan": [
+                  {
+                    "database": "test",
+                    "table": "table2",
+                    "best_access_path": {
+                      "considered_access_paths": [
+                        {
+                          "access_type": "ref",
+                          "index": "col_varchar_key",
+                          "records": 1,
+                          "cost": 2.6,
+                          "chosen": true
+                        },
+                        {
+                          "access_type": "scan",
+                          "using_join_cache": true,
+                          "records": 2,
+                          "cost": 2.0247,
+                          "chosen": false
+                        }
+                      ] /* considered_access_paths */
+                    } /* best_access_path */,
+                    "cost_for_plan": 7.61,
+                    "records_for_plan": 2,
+                    "chosen": true
+                  }
+                ] /* rest_of_plan */
+              }
+            ] /* considered_execution_plans */
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": "((`test`.`table2`.`col_varchar_key` = `test`.`table1`.`col_varchar_key`) and <nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true)))) and (`test`.`table1`.`pk` in (192,18)))",
+              "attached_conditions_computation": [
+              ] /* attached_conditions_computation */,
+              "attached_conditions_summary": [
+                {
+                  "database": "test",
+                  "table": "table1",
+                  "attached": "((`test`.`table1`.`pk` in (192,18)) and (`test`.`table1`.`col_varchar_key` is not null))"
+                },
+                {
+                  "database": "test",
+                  "table": "table2",
+                  "attached": "<nop>(<in_optimizer>(`test`.`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 1 from `test`.`t2` where trigcond_if(outer_field_is_not_null, (<cache>(`test`.`table2`.`col_int_nokey`) <> 5), true))))"
+                }
+              ] /* attached_conditions_summary */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "clause_processing": {
+              "clause": "ORDER BY",
+              "original_clause": "(/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`) desc",
+              "items": [
+                {
+                  "item": "(/* select#2 */ select sum(`test`.`subquery1_t1`.`col_int_nokey`) AS `subquery1_field1` from `test`.`t1` `subquery1_t1`)",
+                  "subselect_evaluation": [
+                    {
+                      "subselect_execution": {
+                        "select#": 2,
+                        "steps": [
+                          {
+                            "join_optimization": {
+                              "select#": 2,
+                              "steps": [
+                                {
+                                  "records_estimation": [
+                                    {
+                                      "database": "test",
+                                      "table": "subquery1_t1",
+                                      "table_scan": {
+                                        "records": 2,
+                                        "cost": 2
+                                      } /* table_scan */
+                                    }
+                                  ] /* records_estimation */
+                                },
+                                {
+                                  "considered_execution_plans": [
+                                    {
+                                      "database": "test",
+                                      "table": "subquery1_t1",
+                                      "best_access_path": {
+                                        "considered_access_paths": [
+                                          {
+                                            "access_type": "scan",
+                                            "records": 2,
+                                            "cost": 2.0244,
+                                            "chosen": true
+                                          }
+                                        ] /* considered_access_paths */
+                                      } /* best_access_path */,
+                                      "cost_for_plan": 2.4244,
+                                      "records_for_plan": 2,
+                                      "chosen": true
+                                    }
+                                  ] /* considered_execution_plans */
+                                },
+                                {
+                                  "attaching_conditions_to_tables": {
+                                    "original_condition": null,
+                                    "attached_conditions_computation": [
+                                    ] /* attached_conditions_computation */,
+                                    "attached_conditions_summary": [
+                                      {
+                                        "database": "test",
+                                        "table": "subquery1_t1",
+                                        "attached": null
+                                      }
+                                    ] /* attached_conditions_summary */
+                                  } /* attaching_conditions_to_tables */
+                                },
+                                {
+                                  "refine_plan": [
+                                    {
+                                      "database": "test",
+                                      "table": "subquery1_t1",
+                                      "scan_type": "table"
+                                    }
+                                  ] /* refine_plan */
+                                }
+                              ] /* steps */
+                            } /* join_optimization */
+                          },
+                          {
+                            "join_execution": {
+                              "select#": 2,
+                              "steps": [
+                              ] /* steps */
+                            } /* join_execution */
+                          }
+                        ] /* steps */
+                      } /* subselect_execution */
+                    }
+                  ] /* subselect_evaluation */,
+                  "uses_only_constant_tables": true
+                }
+              ] /* items */,
+              "resulting_clause_is_simple": true,
+              "resulting_clause": ""
+            } /* clause_processing */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "table1",
+                "scan_type": "table"
+              },
+              {
+                "database": "test",
+                "table": "table2"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+drop table t1,t2;

=== modified file 'sql/opt_trace.cc'
--- a/sql/opt_trace.cc	2011-07-19 15:11:15 +0000
+++ b/sql/opt_trace.cc	2011-08-31 16:48:23 +0000
@@ -161,41 +161,6 @@ public:
   void add(const char *key, const char *val, size_t val_length,
            bool quotes, bool escape);
 
-  /**
-     Emits a JSON syntax error into the trace.
-     @param key  key involved in the error, NULL if there is no key.
-
-     When adding a value (or array or object) to an array, or a key/value pair
-     to an object, we need to know this outer array or object.
-
-     It would be possible, when trying to add a key to an array, which is wrong
-     in JSON, or similarly when trying to add a value without any key to an
-     object, to catch it at compilation time, if the adder received, as
-     function parameter, the type of the structure (like @c
-     Opt_trace_array*). Then the @c add(key,val) call would not compile as
-     Opt_trace_array wouldn't feature it.
-
-     But as explained in comment of class Opt_trace_context we
-     cannot pass down the object, have to maintain a "current object or
-     array" in the Opt_trace_context context (pointer to an instance of
-     Opt_trace_struct), and the adder grabs it from the context.
-
-     As this current structure is of type "object or array", we cannot do
-     compile-time checks that only suitable functions are used. A call to @c
-     add(key,value) is necessarily legal for the compiler as the structure may
-     be an object, though it will be wrong in case the structure is actually
-     an array at run-time. Thus we have the risk of an untested particular
-     situation where the current structure is not an object (but an array)
-     though the code expected it to be one. We catch that at run-time:
-     our functions detect wrong usage, like adding a value to an object
-     without specifying a key, and then call syntax_error() which:
-     @li in debug build, asserts
-     @li in release builds, emits a warning string in the trace and should not
-     crash. The trace is invalid JSON but still human-readable (our best
-     effort).
-  */
-  void syntax_error(const char *key);
-
   /* Below, functions to request information from this instance */
 
   /// Fills user-level information @sa Opt_trace_iterator
@@ -225,6 +190,13 @@ public:
   */
   void restore_I_S() { --I_S_disabled; }
 
+  /**
+     Generate a dummy unique key, and return pointer to it. The pointed data
+     has the lifetime of Opt_trace_stmt, and is overwritten by the next call
+     to this function.
+  */
+  const char *make_unknown_key();
+
 private:
 
   bool ended;           ///< Whether @c end() has been called on this instance
@@ -253,6 +225,15 @@ private:
 
   Buffer trace_buffer;                    ///< Where the trace is accumulated
   Buffer query_buffer;                    ///< Where the original query is put
+
+  /**
+    Counter which serves to have unique autogenerated keys, needed if we
+    autogenerate more than one key in a single object.
+    @see Opt_trace_struct::check_key() and @see Opt_trace_stmt::add() .
+  */
+  uint unknown_key_count;
+  /// Space for last autogenerated key
+  char unknown_key[24];
 };
 
 
@@ -316,7 +297,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
 {
   DBUG_ASSERT(started);
   DBUG_PRINT("opt", ("%s: \"%.*s\"", key, (int)val_length, val));
-  stmt->add(check_key(key), val, val_length, true, escape);
+  stmt->add(key, val, val_length, true, escape);
   return *this;
 }
 
@@ -331,7 +312,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
   DBUG_ASSERT(started);
   DBUG_PRINT("opt", ("%s: %d", key, (int)val));
   const LEX_CSTRING *text= &bool_as_text[val];
-  stmt->add(check_key(key), text->str, text->length, false, false);
+  stmt->add(key, text->str, text->length, false, false);
   return *this;
 }
 
@@ -342,7 +323,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
   char buf[22];                     // 22 is enough for digits of a 64-bit int
   llstr(val, buf);
   DBUG_PRINT("opt", ("%s: %s", key, buf));
-  stmt->add(check_key(key), buf, strlen(buf), false, false);
+  stmt->add(key, buf, strlen(buf), false, false);
   return *this;
 }
 
@@ -353,7 +334,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
   char buf[22];
   ullstr(val, buf);
   DBUG_PRINT("opt", ("%s: %s", key, buf));
-  stmt->add(check_key(key), buf, strlen(buf), false, false);
+  stmt->add(key, buf, strlen(buf), false, false);
   return *this;
 }
 
@@ -364,7 +345,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
   char buf[32];                         // 32 is enough for digits of a double
   my_snprintf(buf, sizeof(buf), "%g", val);
   DBUG_PRINT("opt", ("%s: %s", key, buf));
-  stmt->add(check_key(key), buf, strlen(buf), false, false);
+  stmt->add(key, buf, strlen(buf), false, false);
   return *this;
 }
 
@@ -373,7 +354,7 @@ Opt_trace_struct& Opt_trace_struct::do_a
 {
   DBUG_ASSERT(started);
   DBUG_PRINT("opt", ("%s: null", key));
-  stmt->add(check_key(key), STRING_WITH_LEN("null"), false, false);
+  stmt->add(key, STRING_WITH_LEN("null"), false, false);
   return *this;
 }
 
@@ -412,8 +393,8 @@ const char *Opt_trace_struct::check_key(
   bool has_key= key != NULL;
   if (unlikely(has_key != requires_key))
   {
-    stmt->syntax_error(key);
-    key= has_key ? NULL : "?";
+    // fix the key to produce correct JSON syntax:
+    key= has_key ? NULL : stmt->make_unknown_key();
     has_key= !has_key;
   }
   if (has_key)
@@ -436,7 +417,7 @@ const char *Opt_trace_struct::check_key(
 
 Opt_trace_stmt::Opt_trace_stmt(Opt_trace_context *ctx_arg) :
   ended(false), I_S_disabled(0), missing_priv(false), ctx(ctx_arg),
-  current_struct(NULL)
+  current_struct(NULL), unknown_key_count(0)
 {
   // Trace is always in UTF8. This is the only charset which JSON accepts.
   trace_buffer.set_charset(system_charset_info);
@@ -538,17 +519,8 @@ bool Opt_trace_stmt::open_struct(const c
     }
     else
     {
-      if (current_struct != NULL)
-        key= current_struct->check_key(key);
       trace_buffer.prealloc();
-      separator();
-      if (key != NULL)
-      {
-        trace_buffer.append('"');
-        trace_buffer.append(key);
-        trace_buffer.append(STRING_WITH_LEN("\": "));
-      }
-      trace_buffer.append(opening_bracket);
+      add(key, &opening_bracket, 1, false, false);
     }
   }
   if (wants_disable_I_S)
@@ -637,12 +609,22 @@ void Opt_trace_stmt::next_line()
 }
 
 
+const char *Opt_trace_stmt::make_unknown_key()
+{
+  my_snprintf(unknown_key, sizeof(unknown_key),
+              "unknown_key_%u", ++unknown_key_count);
+  return unknown_key;
+}
+
+
 void Opt_trace_stmt::add(const char *key, const char *val, size_t val_length,
                          bool quotes, bool escape)
 {
   if (!support_I_S())
     return;
   separator();
+  if (current_struct != NULL)
+    key= current_struct->check_key(key);
   if (key != NULL)
   {
     trace_buffer.append('"');
@@ -665,33 +647,6 @@ void Opt_trace_stmt::add(const char *key
 }
 
 
-void Opt_trace_stmt::syntax_error(const char *key)
-{
-  DBUG_PRINT("opt", ("syntax error key: %s", key));
-  DBUG_ASSERT(support_I_S());
-#ifndef DBUG_OFF
-  bool no_assert_on_syntax_error= false;
-  DBUG_EXECUTE_IF("opt_trace_no_assert_on_syntax_error",
-                  no_assert_on_syntax_error= true;);
-  DBUG_ASSERT(no_assert_on_syntax_error);
-#endif
-  /*
-    Inserting some warning text into the trace below helps locating where
-    things went wrong.
-  */
-  if (key != NULL)
-  {
-    trace_buffer.append(STRING_WITH_LEN("** invalid JSON"
-                                        " (unexpected key \""));
-    trace_buffer.append(key);
-    trace_buffer.append(STRING_WITH_LEN("\") ** "));
-  }
-  else
-    trace_buffer.append(STRING_WITH_LEN("** invalid JSON"
-                                        " (missing key) ** "));
-}
-
-
 void Opt_trace_stmt::fill_info(Opt_trace_info *info) const
 {
   if (unlikely(info->missing_priv= missing_priv))

=== modified file 'sql/opt_trace.h'
--- a/sql/opt_trace.h	2011-07-20 13:10:44 +0000
+++ b/sql/opt_trace.h	2011-08-31 16:48:23 +0000
@@ -724,6 +724,35 @@ public:
   /**
     Validates the key about to be added.
     @note this is reserved for use by Opt_trace_stmt.
+
+    When adding a value (or array or object) to an array, or a key/value pair
+    to an object, we need to know this outer array or object.
+
+    It would be possible, when trying to add a key to an array, which is wrong
+    in JSON, or similarly when trying to add a value without any key to an
+    object, to catch it at compilation time, if the adder received, as
+    function parameter, the type of the structure (like @c
+    Opt_trace_array*). Then the @c add(key,val) call would not compile as
+    Opt_trace_array wouldn't feature it.
+
+    But as explained in comment of class Opt_trace_context we
+    cannot pass down the object, have to maintain a "current object or
+    array" in the Opt_trace_context context (pointer to an instance of
+    Opt_trace_struct), and the adder grabs it from the context.
+
+    As this current structure is of type "object or array", we cannot do
+    compile-time checks that only suitable functions are used. A call to @c
+    add(key,value) is necessarily legal for the compiler as the structure may
+    be an object, though it will be wrong in case the structure is actually
+    an array at run-time. Thus we have the risk of an untested particular
+    situation where the current structure is not an object (but an array)
+    though the code expected it to be one. This happens in practice, because
+    subqueries are evaluated in many possible places of code, not all of them
+    being known. Same happens, to a lesser extent, with calls to the range
+    optimizer.
+    So at run-time, in check_key(), we detect wrong usage, like adding a value
+    to an object without specifying a key, and then remove the unnecessary
+    key, or add an autogenerated key.
   */
   const char *check_key(const char *key);
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-08-19 11:39:15 +0000
+++ b/sql/sql_select.cc	2011-08-31 16:48:23 +0000
@@ -13031,7 +13031,10 @@ remove_const(JOIN *join,ORDER *first_ord
     {
       if (order->item[0]->has_subquery() && 
           !(join->select_lex->options & SELECT_DESCRIBE))
+      {
+        Opt_trace_array trace_subselect(trace, "subselect_evaluation");
         order->item[0]->val_str(&order->item[0]->str_value);
+      }
       trace_one_item.add("uses_only_constant_tables", true);
       continue;					// skip const item
     }
@@ -15808,7 +15811,7 @@ optimize_cond(JOIN *join, Item *conds, L
         Opt_trace_disable_I_S
           disable_trace_wrapper(trace, !conds->has_subquery());
         Opt_trace_array
-          trace_subselect(trace, "subselect_equality_propagation");
+          trace_subselect(trace, "subselect_evaluation");
         conds= build_equal_items(join->thd, conds, NULL, join_list,
                                  &join->cond_equal);
       }
@@ -15823,7 +15826,7 @@ optimize_cond(JOIN *join, Item *conds, L
         Opt_trace_disable_I_S
           disable_trace_wrapper(trace, !conds->has_subquery());
         Opt_trace_array
-          trace_subselect(trace, "subselect_constant_propagation");
+          trace_subselect(trace, "subselect_evaluation");
         propagate_cond_constants(thd, (I_List<COND_CMP> *) 0, conds, conds);
       }
       step_wrapper.add("resulting_condition", conds);
@@ -15840,7 +15843,7 @@ optimize_cond(JOIN *join, Item *conds, L
       {
         Opt_trace_disable_I_S
           disable_trace_wrapper(trace, !conds->has_subquery());
-        Opt_trace_array trace_subselect(trace, "subselect_cond_removal");
+        Opt_trace_array trace_subselect(trace, "subselect_evaluation");
         conds= remove_eq_conds(thd, conds, cond_value) ;
       }
       step_wrapper.add("resulting_condition", conds);

=== modified file 'unittest/gunit/opt_trace-t.cc'
--- a/unittest/gunit/opt_trace-t.cc	2011-07-22 07:21:40 +0000
+++ b/unittest/gunit/opt_trace-t.cc	2011-08-31 16:48:23 +0000
@@ -290,9 +290,9 @@ TEST_F(TraceContentTest, BuggyObject)
       ota.add(200.4);
       {
         Opt_trace_object oto1(&trace);
-        DBUG_SET("+d,opt_trace_no_assert_on_syntax_error");
         oto1.add_alnum("one value"); // no key, which is wrong
-        DBUG_SET("-d,opt_trace_no_assert_on_syntax_error");
+        oto1.add(326); // same
+        Opt_trace_object oto2(&trace); // same
       }
       ota.add_alnum("one string element");
       ota.add(true);
@@ -312,8 +312,11 @@ TEST_F(TraceContentTest, BuggyObject)
     "{\n"
     "  \"one array\": [\n"
     "    200.4,\n"
-    "    {** invalid JSON (missing key) ** \n"
-    "      \"?\": \"one value\"\n"
+    "    {\n"
+    "      \"unknown_key_1\": \"one value\",\n"
+    "      \"unknown_key_2\": 326,\n"
+    "      \"unknown_key_3\": {\n"
+    "      }\n"
     "    },\n"
     "    \"one string element\",\n"
     "    true\n"
@@ -328,6 +331,7 @@ TEST_F(TraceContentTest, BuggyObject)
     "}";
   EXPECT_STREQ(expected, info.trace_ptr);
   EXPECT_EQ(sizeof(expected) - 1, info.trace_length);
+  check_json_compliance(info.trace_ptr, info.trace_length);
   EXPECT_EQ(0U, info.missing_bytes);
   EXPECT_FALSE(info.missing_priv);
   EXPECT_FALSE(oom);
@@ -345,9 +349,9 @@ TEST_F(TraceContentTest, BuggyArray)
     Opt_trace_object oto(&trace);
     {
       Opt_trace_array ota(&trace, "one array");
-      DBUG_SET("+d,opt_trace_no_assert_on_syntax_error");
       ota.add("superfluous key", 200.4); // key, which is wrong
-      DBUG_SET("-d,opt_trace_no_assert_on_syntax_error");
+      ota.add("not necessary", 326); // same
+      Opt_trace_object oto2(&trace, "not needed"); // same
     }
     oto.add("yet another key", -1000LL);
     {
@@ -362,8 +366,11 @@ TEST_F(TraceContentTest, BuggyArray)
   it.get_value(&info);
   const char expected[]=
     "{\n"
-    "  \"one array\": [** invalid JSON (unexpected key \"superfluous key\") ** \n"
-    "    200.4\n"
+    "  \"one array\": [\n"
+    "    200.4,\n"
+    "    326,\n"
+    "    {\n"
+    "    } /* not needed */\n"
     "  ] /* one array */,\n"
     "  \"yet another key\": -1000,\n"
     "  \"another array\": [\n"
@@ -375,6 +382,7 @@ TEST_F(TraceContentTest, BuggyArray)
     "}";
   EXPECT_STREQ(expected, info.trace_ptr);
   EXPECT_EQ(sizeof(expected) - 1, info.trace_length);
+  check_json_compliance(info.trace_ptr, info.trace_length);
   EXPECT_EQ(0U, info.missing_bytes);
   EXPECT_FALSE(info.missing_priv);
   EXPECT_FALSE(oom);

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (guilhem.bichot:3403 to 3404) Bug#12905521Bug#12905758Guilhem Bichot31 Aug