List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:December 13 2010 2:03pm
Subject:bzr commit into mysql-next-mr-bugfixing branch (jorgen.loland:3242) WL#4800
View as plain text  
#At file:///export/home/jl208045/mysql/wl4800/mysql-next-mr-opt-backporting-wl4800-range-subselect/ based on revid:jorgen.loland@stripped

 3242 Jorgen Loland	2010-12-13
      WL#4800: Optimizer trace/debugger
      
      Fix tracepoints so that all mtr test cases can be traced without 
      JSON syntax errors.
      
      Added DYNAMIC_RANGE and REPEATED_SUBSELECT tracing features to
      avoid repeated tracing of range analysis and execution, 
      respectivley, of subselects.
     @ sql/item_subselect.cc
        Added Item_subselect::executed_before used to avoid tracing of 
        subquery execution when this happens repeatedly for each record
        in outer select.
     @ sql/item_subselect.h
        Added Item_subselect::executed_before used to avoid tracing of 
        subquery execution when this happens repeatedly for each record
        in outer select.
     @ sql/opt_range.cc
        Add tracepoints to range optimizer
     @ sql/sql_select.cc
        Add tracepoints to range optimizer

    added:
      mysql-test/r/optimizer_trace_subquery.result
      mysql-test/t/optimizer_trace_subquery.test
    modified:
      mysql-test/r/optimizer_trace_charset.result
      mysql-test/r/optimizer_trace_no_prot.result
      mysql-test/r/optimizer_trace_ps_prot.result
      mysql-test/r/optimizer_trace_range.result
      mysql-test/suite/sys_vars/r/optimizer_trace_features_basic.result
      mysql-test/t/optimizer_trace_range.test
      sql/item_subselect.cc
      sql/item_subselect.h
      sql/opt_range.cc
      sql/opt_trace.cc
      sql/opt_trace.h
      sql/sql_select.cc
=== modified file 'mysql-test/r/optimizer_trace_charset.result'
--- a/mysql-test/r/optimizer_trace_charset.result	2010-11-24 18:54:26 +0000
+++ b/mysql-test/r/optimizer_trace_charset.result	2010-12-13 14:03:16 +0000
@@ -52,6 +52,13 @@ explain extended select '��� from t1 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -98,6 +105,13 @@ explain extended select 'ÁÂÃÄÅ' fro
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -162,6 +176,13 @@ select * from v1 where v1.col = 'ÁÂÃ�       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_preparation": {
         "select#": 1,
         "steps": [
@@ -209,6 +230,13 @@ select * from v1 where v1.col = 'ÁÂÃ�           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -280,6 +308,8 @@ select * from t1 where c < 'ÁÂÃÄÅ'	
                     "cost": 1.4213,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -353,6 +383,13 @@ select * from t1 where c < 'ÁÂÃÄÅ'	
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -441,6 +478,8 @@ select `col
                     "cost": 1.4233,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -514,6 +553,13 @@ select `col
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }

=== modified file 'mysql-test/r/optimizer_trace_no_prot.result'
--- a/mysql-test/r/optimizer_trace_no_prot.result	2010-11-26 16:16:31 +0000
+++ b/mysql-test/r/optimizer_trace_no_prot.result	2010-12-13 14:03:16 +0000
@@ -62,66 +62,91 @@ SELECT (SELECT 1 FROM t6 WHERE d = c) AS
       }
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = NULL)",
-              "after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
-              "after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
-              "after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"
-            }
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= NULL",
-                "null_rejecting": true
-              }
-            ]
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  },
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ]
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = NULL)",
+                          "after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
+                          "after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
+                          "after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"
+                        }
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= NULL",
+                            "null_rejecting": true
+                          }
+                        ]
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              },
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ]
+                                }
+                              ],
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              },
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  }
+                                }
+                              ],
+                              "impossible_range": true
+                            },
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ]
+                      }
+                    ],
+                    "empty_result": {
+                      "cause": "no matching row in const table"
                     }
-                  ],
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  },
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  },
-                  "impossible_range": true
+                  }
                 },
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ]
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ]
+                  }
+                }
+              ]
+            }
           }
-        ],
-        "empty_result": {
-          "cause": "no matching row in const table"
-        }
+        ]
       }
     }
   ]
@@ -129,18 +154,18 @@ SELECT (SELECT 1 FROM t6 WHERE d = c) AS
 select (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
 from information_schema.OPTIMIZER_TRACE;
 (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
-50.1007
+61.4266
 set optimizer_trace="one_line=on";
 SELECT (SELECT 1 FROM t6 WHERE d = c) AS RESULT FROM t5 ;
 RESULT
 NULL
 select * from information_schema.OPTIMIZER_TRACE;
 QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
-SELECT (SELECT 1 FROM t6 WHERE d = c) AS RESULT FROM t5	{"steps": [{"expanded_query": "/* select#1 */ select (/* select#2 */ select 1 from `test`.`t6` where (`d` = `c`)) AS `RESULT` from `test`.`t5`"},{"join_preparation": {"select#": 1,"steps": [{"join_preparation": {"select#": 2,"steps": []}}]}},{"join_optimization": {"select#": 1,"steps": [{"records_estimation": [{"database": "test","table": "t5","records": 1,"cost": 1,"table_type": "system"}]},{"attaching_conditions_to_tables": {"original_condition": null,"attached_conditions": []}},{"refine_plan": []}]}},{"join_optimization": {"select#": 2,"steps": [{"condition_processing": {"condition": "WHERE","original_condition": "(`test`.`t6`.`d` = NULL)","after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"}},{"ref-optimizer-key-uses": [{"condition": "t6.d= NULL","null_rejecting": true}]},{"records_estimation": [{"database": "test","table": "t6","range_analysis": {"table_scan": {"records": 2,"cost": 4.5034},"potential_range_indices": [{"index": "d","usable": true,"key_parts": ["d"]}],"best_covering_index_scan": {"index": "d","cost": 1.4233,"chosen": true},"impossible_condition": {"table": "t6","field": "d","cause": "comparison_with_null_always_false"},"impossible_range": true},"records": 0,"cause": "impossible_where_condition"}]}],"empty_result": {"cause": "no matching row in const table"}}}]}	0	0
+SELECT (SELECT 1 FROM t6 WHERE d = c) AS RESULT FROM t5	{"steps": [{"expanded_query": "/* select#1 */ select (/* select#2 */ select 1 from `test`.`t6` where (`d` = `c`)) AS `RESULT` from `test`.`t5`"},{"join_preparation": {"select#": 1,"steps": [{"join_preparation": {"select#": 2,"steps": []}}]}},{"join_optimization": {"select#": 1,"steps": [{"records_estimation": [{"database": "test","table": "t5","records": 1,"cost": 1,"table_type": "system"}]},{"attaching_conditions_to_tables": {"original_condition": null,"attached_conditions": []}},{"refine_plan": []}]}},{"join_execution": {"select#": 1,"steps": [{"subselect_exec": {"select#": 2,"steps": [{"join_optimization": {"select#": 2,"steps": [{"condition_processing": {"condition": "WHERE","original_condition": "(`test`.`t6`.`d` = NULL)","after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"}},{"ref-optimizer-key-uses": [{"condition": "t6.d= NULL","null_rejecting": true}]},{"records_estimation": [{"database": "test","table": "t6","range_analysis": {"table_scan": {"records": 2,"cost": 4.5034},"potential_range_indices": [{"index": "d","usable": true,"key_parts": ["d"]}],"best_covering_index_scan": {"index": "d","cost": 1.4233,"chosen": true},"setup_range_conditions": [{"impossible_condition": {"table": "t6","field": "d","cause": "comparison_with_null_always_false"}}],"impossible_range": true},"records": 0,"cause": "impossible_where_condition"}]}],"empty_result": {"cause": "no matching row in const table"}}},{"join_execution": {"select#": 2,"steps": []}}]}}]}}]}	0	0
 select (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
 from information_schema.OPTIMIZER_TRACE;
 (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
-6.0792
+6.0625
 set optimizer_trace="one_line=off,end_marker=on";
 EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d = ifnull(c,null)) AS RESULT FROM t5 ;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -197,67 +222,85 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                    "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                    "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                    "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
                     {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
+                      "condition": "t6.d= ifnull(NULL,NULL)",
+                      "null_rejecting": false
                     }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t6",
+                      "range_analysis": {
+                        "table_scan": {
+                          "records": 2,
+                          "cost": 4.5034
+                        } /* table_scan */,
+                        "potential_range_indices": [
+                          {
+                            "index": "d",
+                            "usable": true,
+                            "key_parts": [
+                              "d"
+                            ] /* key_parts */
+                          }
+                        ] /* potential_range_indices */,
+                        "best_covering_index_scan": {
+                          "index": "d",
+                          "cost": 1.4233,
+                          "chosen": true
+                        } /* best_covering_index_scan */,
+                        "setup_range_conditions": [
+                          {
+                            "impossible_condition": {
+                              "table": "t6",
+                              "field": "d",
+                              "cause": "comparison_with_null_always_false"
+                            } /* impossible_condition */
+                          }
+                        ] /* setup_range_conditions */,
+                        "impossible_range": true
+                      } /* range_analysis */,
+                      "records": 0,
+                      "cause": "impossible_where_condition"
+                    }
+                  ] /* records_estimation */
+                }
+              ] /* steps */,
+              "empty_result": {
+                "cause": "Impossible WHERE noticed after reading const tables"
+              } /* empty_result */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "Impossible WHERE noticed after reading const tables"
-        } /* empty_result */
-      } /* join_optimization */
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -315,67 +358,92 @@ SELECT /* should be last */ (SELECT 1 FR
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
-                    }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= ifnull(NULL,NULL)",
+                            "null_rejecting": false
+                          }
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  } /* impossible_condition */
+                                }
+                              ] /* setup_range_conditions */,
+                              "impossible_range": true
+                            } /* range_analysis */,
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ] /* records_estimation */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "no matching row in const table"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
           }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "no matching row in const table"
-        } /* empty_result */
-      } /* join_optimization */
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -448,199 +516,242 @@ SELECT (SELECT 1 FROM t6 WHERE d = ifnul
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
-                    }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
-          }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "no matching row in const table"
-        } /* empty_result */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 3,
-        "steps": [
-          {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
-                    }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
-          }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "no matching row in const table"
-        } /* empty_result */
-      } /* join_optimization */
-    },
-    {
-      "join_preparation": {
-        "select#": "fake",
-        "steps": [
-        ] /* steps */
-      } /* join_preparation */
-    },
-    {
-      "join_optimization": {
-        "select#": "fake",
-        "steps": [
-          {
-            "records_estimation": [
-              {
-                "database": "",
-                "table": "",
-                "table_scan": {
-                  "records": 0,
-                  "cost": 10
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "",
-                "table": "",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 0,
-                      "cost": 10,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 10,
-                "records_for_plan": 0,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
                 {
-                  "database": "",
-                  "table": "",
-                  "attached": null
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= ifnull(NULL,NULL)",
+                            "null_rejecting": false
+                          }
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  } /* impossible_condition */
+                                }
+                              ] /* setup_range_conditions */,
+                              "impossible_range": true
+                            } /* range_analysis */,
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ] /* records_estimation */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "no matching row in const table"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
+                {
+                  "join_optimization": {
+                    "select#": 3,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= ifnull(NULL,NULL)",
+                            "null_rejecting": false
+                          }
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  } /* impossible_condition */
+                                }
+                              ] /* setup_range_conditions */,
+                              "impossible_range": true
+                            } /* range_analysis */,
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ] /* records_estimation */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "no matching row in const table"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 3,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
+                {
+                  "join_preparation": {
+                    "select#": "fake",
+                    "steps": [
+                    ] /* steps */
+                  } /* join_preparation */
+                },
+                {
+                  "join_optimization": {
+                    "select#": "fake",
+                    "steps": [
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "table_scan": {
+                              "records": 0,
+                              "cost": 10
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 0,
+                                  "cost": 10,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 10,
+                            "records_for_plan": 0,
+                            "chosen": true
+                          }
+                        ] /* considered_execution_plans */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": null,
+                          "attached_conditions": [
+                            {
+                              "database": "",
+                              "table": "",
+                              "attached": null
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": "fake",
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "",
-                "table": "",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* subselect_exec */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -730,8 +841,14 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
             "condition_processing": {
               "condition": "WHERE",
               "original_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))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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))))"
             } /* condition_processing */
           },
@@ -751,133 +868,168 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
             ] /* records_estimation */
           },
           {
-            "join_optimization": {
+            "subselect_exec": {
               "select#": 2,
               "steps": [
                 {
-                  "condition_processing": {
-                    "condition": "WHERE",
-                    "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
-                    "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
-                    "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 1))",
-                    "after_trivial_conditions_removal": null
-                  } /* condition_processing */
-                }
-              ] /* steps */,
-              "empty_result": {
-                "cause": "Impossible WHERE"
-              } /* empty_result */
-            } /* join_optimization */
-          },
-          {
-            "join_optimization": {
-              "select#": 3,
-              "steps": [
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
+                          "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
+                          "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 1))",
+                          "after_trivial_conditions_removal": null
+                        } /* condition_processing */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "Impossible WHERE"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
                 {
-                  "condition_processing": {
-                    "condition": "WHERE",
-                    "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
-                    "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
-                    "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 2))",
-                    "after_trivial_conditions_removal": null
-                  } /* condition_processing */
-                }
-              ] /* steps */,
-              "empty_result": {
-                "cause": "Impossible WHERE"
-              } /* empty_result */
-            } /* join_optimization */
-          },
-          {
-            "join_preparation": {
-              "select#": "fake",
-              "steps": [
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
                 {
-                  "transformation": {
-                    "select#": "fake",
-                    "from": "IN (SELECT)",
-                    "to": "semijoin",
-                    "chosen": false
-                  } /* transformation */
+                  "join_optimization": {
+                    "select#": 3,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
+                          "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
+                          "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 2))",
+                          "after_trivial_conditions_removal": null
+                        } /* condition_processing */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "Impossible WHERE"
+                    } /* empty_result */
+                  } /* join_optimization */
                 },
                 {
-                  "transformation": {
-                    "select#": "fake",
-                    "from": "IN (SELECT)",
-                    "to": "materialization",
-                    "chosen": false
-                  } /* transformation */
-                }
-              ] /* steps */
-            } /* join_preparation */
-          },
-          {
-            "join_optimization": {
-              "select#": "fake",
-              "steps": [
+                  "join_execution": {
+                    "select#": 3,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
                 {
-                  "records_estimation": [
-                    {
-                      "database": "",
-                      "table": "",
-                      "table_scan": {
-                        "records": 0,
-                        "cost": 10
-                      } /* table_scan */
-                    }
-                  ] /* records_estimation */
+                  "join_preparation": {
+                    "select#": "fake",
+                    "steps": [
+                      {
+                        "transformation": {
+                          "select#": "fake",
+                          "from": "IN (SELECT)",
+                          "to": "semijoin",
+                          "chosen": false
+                        } /* transformation */
+                      },
+                      {
+                        "transformation": {
+                          "select#": "fake",
+                          "from": "IN (SELECT)",
+                          "to": "materialization",
+                          "chosen": false
+                        } /* transformation */
+                      }
+                    ] /* steps */
+                  } /* join_preparation */
                 },
                 {
-                  "considered_execution_plans": [
-                    {
-                      "database": "",
-                      "table": "",
-                      "best_access_path": {
-                        "considered_access_paths": [
+                  "join_optimization": {
+                    "select#": "fake",
+                    "steps": [
+                      {
+                        "records_estimation": [
                           {
-                            "access_type": "scan",
-                            "using_join_cache": true,
-                            "records": 0,
-                            "cost": 10,
+                            "database": "",
+                            "table": "",
+                            "table_scan": {
+                              "records": 0,
+                              "cost": 10
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 0,
+                                  "cost": 10,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 10,
+                            "records_for_plan": 0,
                             "chosen": true
                           }
-                        ] /* considered_access_paths */
-                      } /* best_access_path */,
-                      "cost_for_plan": 10,
-                      "records_for_plan": 0,
-                      "chosen": true
-                    }
-                  ] /* considered_execution_plans */
-                },
-                {
-                  "attaching_conditions_to_tables": {
-                    "original_condition": null,
-                    "attached_conditions": [
+                        ] /* considered_execution_plans */
+                      },
                       {
-                        "database": "",
-                        "table": "",
-                        "attached": null
+                        "attaching_conditions_to_tables": {
+                          "original_condition": null,
+                          "attached_conditions": [
+                            {
+                              "database": "",
+                              "table": "",
+                              "attached": null
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
                       }
-                    ] /* attached_conditions */
-                  } /* attaching_conditions_to_tables */
+                    ] /* steps */
+                  } /* join_optimization */
                 },
                 {
-                  "refine_plan": [
-                    {
-                      "database": "",
-                      "table": "",
-                      "scan_type": "table"
-                    }
-                  ] /* refine_plan */
+                  "join_execution": {
+                    "select#": "fake",
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
               ] /* steps */
-            } /* join_optimization */
+            } /* subselect_exec */
           }
         ] /* steps */,
         "empty_result": {
           "cause": "Impossible WHERE noticed after reading const tables"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -886,7 +1038,7 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-9086
+11083
 set optimizer_trace_max_mem_size=9000;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
@@ -895,7 +1047,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)
-208
+2209
 select (@query2:=QUERY)+NULL,(@trace2:=TRACE)+NULL from information_schema.OPTIMIZER_TRACE;
 (@query2:=QUERY)+NULL	(@trace2:=TRACE)+NULL
 NULL	NULL
@@ -903,7 +1055,7 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-8878	1	1
+8874	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-100) and (@@optimizer_trace_max_mem_size+100);
 length(@query2) + length(@trace2)
@@ -918,14 +1070,14 @@ select 1;
 1
 select * from information_schema.OPTIMIZER_TRACE;
 QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
-select 1		373	0
+select 1		504	0
 set optimizer_trace_max_mem_size=0;
 select 1;
 1
 1
 select * from information_schema.OPTIMIZER_TRACE;
 QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
-		381	0
+		512	0
 set optimizer_trace_max_mem_size=1048576;
 explain SELECT c FROM t5 where c+1 in (select d+1 from t6 where d is null);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1020,6 +1172,8 @@ explain SELECT c FROM t5 where c+1 in (s
                     "cost": 1.4233,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -1185,6 +1339,13 @@ explain SELECT c FROM t5 where c+1 in (s
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1238,8 +1399,14 @@ explain SELECT c FROM t5 where c+1 in (s
             "condition_processing": {
               "condition": "WHERE",
               "original_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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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`)))"
             } /* condition_processing */
           },
@@ -1281,129 +1448,145 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "isnull(`test`.`t6`.`d`)",
-              "after_equality_propagation": "isnull(`test`.`t6`.`d`)",
-              "after_constant_propagation": "isnull(`test`.`t6`.`d`)",
-              "after_trivial_conditions_removal": "isnull(`test`.`t6`.`d`)"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= NULL",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "isnull(`test`.`t6`.`d`)",
+                    "after_equality_propagation": "isnull(`test`.`t6`.`d`)",
+                    "after_constant_propagation": "isnull(`test`.`t6`.`d`)",
+                    "after_trivial_conditions_removal": "isnull(`test`.`t6`.`d`)"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
                     {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
+                      "condition": "t6.d= NULL",
+                      "null_rejecting": false
                     }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "group_index_range": {
-                    "chosen": false,
-                    "cause": "not_group_by_or_distinct"
-                  } /* group_index_range */,
-                  "analyzing_range_alternatives": {
-                    "range_scan_alternatives": [
-                      {
-                        "index": "d",
-                        "ranges": [
-                          "NULL <= d <= NULL"
-                        ] /* ranges */,
-                        "index_only": true,
-                        "records": 1,
-                        "cost": 2.21,
-                        "rowid_ordered": true,
-                        "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 */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t6",
-                "best_access_path": {
-                  "considered_access_paths": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "ref",
-                      "index": "d",
-                      "records": 1,
-                      "cost": 1,
-                      "chosen": true
-                    },
+                      "database": "test",
+                      "table": "t6",
+                      "range_analysis": {
+                        "table_scan": {
+                          "records": 2,
+                          "cost": 4.5034
+                        } /* table_scan */,
+                        "potential_range_indices": [
+                          {
+                            "index": "d",
+                            "usable": true,
+                            "key_parts": [
+                              "d"
+                            ] /* key_parts */
+                          }
+                        ] /* potential_range_indices */,
+                        "best_covering_index_scan": {
+                          "index": "d",
+                          "cost": 1.4233,
+                          "chosen": true
+                        } /* best_covering_index_scan */,
+                        "setup_range_conditions": [
+                        ] /* setup_range_conditions */,
+                        "group_index_range": {
+                          "chosen": false,
+                          "cause": "not_group_by_or_distinct"
+                        } /* group_index_range */,
+                        "analyzing_range_alternatives": {
+                          "range_scan_alternatives": [
+                            {
+                              "index": "d",
+                              "ranges": [
+                                "NULL <= d <= NULL"
+                              ] /* ranges */,
+                              "index_only": true,
+                              "records": 1,
+                              "cost": 2.21,
+                              "rowid_ordered": true,
+                              "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 */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
                     {
-                      "access_type": "scan",
-                      "cost": 2,
-                      "records": 2,
-                      "cause": "cost",
-                      "chosen": false
+                      "database": "test",
+                      "table": "t6",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "ref",
+                            "index": "d",
+                            "records": 1,
+                            "cost": 1,
+                            "chosen": true
+                          },
+                          {
+                            "access_type": "scan",
+                            "cost": 2,
+                            "records": 2,
+                            "cause": "cost",
+                            "chosen": false
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 1,
+                      "records_for_plan": 1,
+                      "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 1,
-                "records_for_plan": 1,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "isnull(`test`.`t6`.`d`)",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t6",
-                  "attached": "isnull(`test`.`t6`.`d`)"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "isnull(`test`.`t6`.`d`)",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t6",
+                        "attached": "isnull(`test`.`t6`.`d`)"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t6"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t6"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1452,79 +1635,23 @@ explain extended select * from t1 where 
         "steps": [
           {
             "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "after_equality_propagation": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "after_constant_propagation": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "after_trivial_conditions_removal": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "attached_conditions": [
-                {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
-                }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
-          }
-        ] /* steps */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 2,
-        "steps": [
+              "condition": "WHERE",
+              "original_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_equality_propagation": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_constant_propagation": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_trivial_conditions_removal": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
+            } /* condition_processing */
+          },
+          {
+            "ref-optimizer-key-uses": [
+            ] /* ref-optimizer-key-uses */
+          },
           {
             "records_estimation": [
               {
@@ -1561,12 +1688,12 @@ explain extended select * from t1 where 
           },
           {
             "attaching_conditions_to_tables": {
-              "original_condition": null,
+              "original_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
               "attached_conditions": [
                 {
                   "database": "test",
                   "table": "t1",
-                  "attached": null
+                  "attached": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* attached_conditions */
             } /* attaching_conditions_to_tables */
@@ -1582,6 +1709,82 @@ explain extended select * from t1 where 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1628,8 +1831,14 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
             } /* condition_processing */
           },
@@ -1696,66 +1905,80 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": null
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1819,8 +2042,14 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
             } /* condition_processing */
           },
@@ -1887,79 +2116,93 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "after_equality_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "after_constant_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "after_trivial_conditions_removal": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "after_equality_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "after_constant_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "after_trivial_conditions_removal": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2022,8 +2265,14 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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`))))"
             } /* condition_processing */
           },
@@ -2090,79 +2339,93 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "after_equality_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "after_constant_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "after_equality_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "after_constant_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2326,12 +2589,19 @@ explain select * from t1,t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
 select @@optimizer_trace_features;
 @@optimizer_trace_features
-greedy_search=on,range_optimizer=on
+greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 set @@optimizer_trace_features="greedy_search=off";
 explain select * from t1,t2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -2411,6 +2681,13 @@ explain select * from t1,t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2508,8 +2785,14 @@ where a1 in (select b1 from t2_16 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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`))))"
             } /* condition_processing */
           },
@@ -2576,79 +2859,93 @@ where a1 in (select b1 from t2_16 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "after_equality_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "after_constant_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "after_trivial_conditions_removal": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2_16",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2_16",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "after_equality_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "after_constant_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "after_trivial_conditions_removal": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0293,
+                      "database": "test",
+                      "table": "t2_16",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t2_16",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 3,
+                            "cost": 2.0293,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0293,
+                      "records_for_plan": 3,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0293,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t2_16",
-                  "attached": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t2_16",
+                        "attached": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t2_16",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2_16",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2721,8 +3018,14 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
             "condition_processing": {
               "condition": "WHERE",
               "original_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 (`test`.`t1`.`c1` = `test`.`t2`.`c2`))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "(<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`))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "(<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`))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "(<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`))"
             } /* condition_processing */
           },
@@ -2844,79 +3147,100 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c2`))",
-              "after_equality_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
-              "after_constant_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
-              "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0051,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0051,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))",
-              "attached_conditions": [
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
                 {
-                  "database": "test",
-                  "table": "t2",
-                  "attached": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))"
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c2`))",
+                          "after_equality_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
+                          "after_constant_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
+                          "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "table_scan": {
+                              "records": 3,
+                              "cost": 2
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 3,
+                                  "cost": 2.0051,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 2.0051,
+                            "records_for_plan": 3,
+                            "chosen": true
+                          }
+                        ] /* considered_execution_plans */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))",
+                          "attached_conditions": [
+                            {
+                              "database": "test",
+                              "table": "t2",
+                              "attached": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))"
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* subselect_exec */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3020,6 +3344,13 @@ SELECT * FROM t1 WHERE c1=5 UNION SELECT
       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_optimization": {
         "select#": 2,
         "steps": [
@@ -3095,6 +3426,13 @@ SELECT * FROM t1 WHERE c1=5 UNION SELECT
       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_preparation": {
         "select#": "fake",
         "steps": [
@@ -3162,6 +3500,13 @@ SELECT * FROM t1 WHERE c1=5 UNION SELECT
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": "fake",
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3251,160 +3596,26 @@ concat(c1,'y') IN
             "condition_processing": {
               "condition": "WHERE",
               "original_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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "(<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "(<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "(<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`)))"
             } /* condition_processing */
           },
           {
             "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0051,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0051,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_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`)))",
-              "attached_conditions": [
-                {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "(<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`)))"
-                }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
-          },
-          {
-            "transformation": {
-              "select#": 3,
-              "from": "IN (SELECT)",
-              "to": "materialization",
-              "chosen": true
-            } /* transformation */
-          },
-          {
-            "transformation": {
-              "select#": 2,
-              "from": "IN (SELECT)",
-              "to": "materialization",
-              "chosen": true
-            } /* transformation */
-          }
-        ] /* steps */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 3,
-        "steps": [
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0051,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0051,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
-                {
-                  "database": "test",
-                  "table": "t2",
-                  "attached": null
-                }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
-          }
-        ] /* steps */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 2,
-        "steps": [
+            ] /* ref-optimizer-key-uses */
+          },
           {
             "records_estimation": [
               {
                 "database": "test",
-                "table": "t2",
+                "table": "t1",
                 "table_scan": {
                   "records": 3,
                   "cost": 2
@@ -3416,7 +3627,7 @@ concat(c1,'y') IN
             "considered_execution_plans": [
               {
                 "database": "test",
-                "table": "t2",
+                "table": "t1",
                 "best_access_path": {
                   "considered_access_paths": [
                     {
@@ -3436,12 +3647,12 @@ concat(c1,'y') IN
           },
           {
             "attaching_conditions_to_tables": {
-              "original_condition": null,
+              "original_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`)))",
               "attached_conditions": [
                 {
                   "database": "test",
-                  "table": "t2",
-                  "attached": null
+                  "table": "t1",
+                  "attached": "(<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`)))"
                 }
               ] /* attached_conditions */
             } /* attaching_conditions_to_tables */
@@ -3450,13 +3661,174 @@ concat(c1,'y') IN
             "refine_plan": [
               {
                 "database": "test",
-                "table": "t2",
+                "table": "t1",
                 "scan_type": "table"
               }
             ] /* refine_plan */
+          },
+          {
+            "transformation": {
+              "select#": 3,
+              "from": "IN (SELECT)",
+              "to": "materialization",
+              "chosen": true
+            } /* transformation */
+          },
+          {
+            "transformation": {
+              "select#": 2,
+              "from": "IN (SELECT)",
+              "to": "materialization",
+              "chosen": true
+            } /* transformation */
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_optimization": {
+              "select#": 3,
+              "steps": [
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 3,
+                            "cost": 2.0051,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0051,
+                      "records_for_plan": 3,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t2",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 3,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          },
+          {
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 3,
+                            "cost": 2.0051,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0051,
+                      "records_for_plan": 3,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t2",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3518,6 +3890,13 @@ select * from t1,t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3702,6 +4081,13 @@ trace
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -3809,6 +4195,13 @@ trace
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -3945,6 +4338,13 @@ select * from t1 left join t2 on t2.a=50
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3976,124 +4376,47 @@ select * from t1 where (t1.a,t1.b) not i
                     "from": "IN (SELECT)",
                     "to": "semijoin",
                     "chosen": false
-                  } /* transformation */
-                },
-                {
-                  "transformation": {
-                    "select#": 2,
-                    "from": "IN (SELECT)",
-                    "to": "materialization",
-                    "chosen": false
-                  } /* transformation */
-                },
-                {
-                  "transformation": {
-                    "select#": 2,
-                    "from": "IN (SELECT)",
-                    "to": "EXISTS (CORRELATED SELECT)",
-                    "chosen": true
-                  } /* transformation */
-                }
-              ] /* steps */
-            } /* join_preparation */
-          }
-        ] /* steps */
-      } /* join_preparation */
-    },
-    {
-      "join_optimization": {
-        "select#": 1,
-        "steps": [
-          {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_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))))))",
-              "after_equality_propagation": "(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))))))",
-              "after_constant_propagation": "(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))))))",
-              "after_trivial_conditions_removal": "(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))))))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0044,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0044,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_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))))))",
-              "attached_conditions": [
+                  } /* transformation */
+                },
                 {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "(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": {
+                    "select#": 2,
+                    "from": "IN (SELECT)",
+                    "to": "materialization",
+                    "chosen": false
+                  } /* transformation */
+                },
+                {
+                  "transformation": {
+                    "select#": 2,
+                    "from": "IN (SELECT)",
+                    "to": "EXISTS (CORRELATED SELECT)",
+                    "chosen": true
+                  } /* transformation */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* join_preparation */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_preparation */
     },
     {
       "join_optimization": {
-        "select#": 2,
+        "select#": 1,
         "steps": [
           {
             "condition_processing": {
               "condition": "WHERE",
-              "original_condition": "((`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))",
-              "after_equality_propagation": "((`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))",
-              "after_constant_propagation": "((`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))",
-              "after_trivial_conditions_removal": "((`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))"
-            } /* condition_processing */
-          },
-          {
-            "condition_processing": {
-              "condition": "HAVING",
-              "original_condition": "(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))",
-              "after_constant_propagation": "(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))",
-              "after_trivial_conditions_removal": "(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))"
+              "original_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))))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_equality_propagation": "(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))))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_constant_propagation": "(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))))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_trivial_conditions_removal": "(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))))))"
             } /* condition_processing */
           },
           {
@@ -4104,7 +4427,7 @@ select * from t1 where (t1.a,t1.b) not i
             "records_estimation": [
               {
                 "database": "test",
-                "table": "t2",
+                "table": "t1",
                 "table_scan": {
                   "records": 2,
                   "cost": 2
@@ -4116,7 +4439,7 @@ select * from t1 where (t1.a,t1.b) not i
             "considered_execution_plans": [
               {
                 "database": "test",
-                "table": "t2",
+                "table": "t1",
                 "best_access_path": {
                   "considered_access_paths": [
                     {
@@ -4136,12 +4459,12 @@ select * from t1 where (t1.a,t1.b) not i
           },
           {
             "attaching_conditions_to_tables": {
-              "original_condition": "((`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))",
+              "original_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))))))",
               "attached_conditions": [
                 {
                   "database": "test",
-                  "table": "t2",
-                  "attached": "((`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))"
+                  "table": "t1",
+                  "attached": "(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))))))"
                 }
               ] /* attached_conditions */
             } /* attaching_conditions_to_tables */
@@ -4150,13 +4473,117 @@ select * from t1 where (t1.a,t1.b) not i
             "refine_plan": [
               {
                 "database": "test",
-                "table": "t2",
+                "table": "t1",
                 "scan_type": "table"
               }
             ] /* refine_plan */
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`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))",
+                          "after_equality_propagation": "((`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))",
+                          "after_constant_propagation": "((`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))",
+                          "after_trivial_conditions_removal": "((`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))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "condition_processing": {
+                          "condition": "HAVING",
+                          "original_condition": "(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))",
+                          "after_constant_propagation": "(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))",
+                          "after_trivial_conditions_removal": "(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))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "table_scan": {
+                              "records": 2,
+                              "cost": 2
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 2,
+                                  "cost": 2.0044,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 2.0044,
+                            "records_for_plan": 2,
+                            "chosen": true
+                          }
+                        ] /* considered_execution_plans */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": "((`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))",
+                          "attached_conditions": [
+                            {
+                              "database": "test",
+                              "table": "t2",
+                              "attached": "((`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))"
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4317,6 +4744,13 @@ trace
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -4363,6 +4797,13 @@ trace
           "cause": "Impossible HAVING"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -4392,6 +4833,8 @@ update t6 set d=5 where d is NULL	{
             ] /* key_parts */
           }
         ] /* potential_range_indices */,
+        "setup_range_conditions": [
+        ] /* setup_range_conditions */,
         "group_index_range": {
           "chosen": false,
           "cause": "no_join"
@@ -4457,6 +4900,8 @@ delete from t6 where d=5	{
             ] /* key_parts */
           }
         ] /* potential_range_indices */,
+        "setup_range_conditions": [
+        ] /* setup_range_conditions */,
         "group_index_range": {
           "chosen": false,
           "cause": "no_join"
@@ -4559,6 +5004,8 @@ insert into t6 select * from t6 where d>
                     "cost": 1.6465,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -4632,6 +5079,13 @@ insert into t6 select * from t6 where d>
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4693,6 +5147,8 @@ update t5, t6 set t6.d=t6.d+t5.c+4-t5.c-
                       ] /* key_parts */
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -4777,6 +5233,13 @@ update t5, t6 set t6.d=t6.d+t5.c+4-t5.c-
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4843,6 +5306,8 @@ delete t6 from t5, t6 where d>7000	{
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -4916,6 +5381,13 @@ delete t6 from t5, t6 where d>7000	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4957,6 +5429,13 @@ select 3	{
         "steps": [
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4978,6 +5457,13 @@ select 4	{
         "steps": [
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5019,6 +5505,13 @@ select 4	{
         "steps": [
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5040,6 +5533,13 @@ select 5	{
         "steps": [
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5143,6 +5643,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5226,6 +5733,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5306,6 +5820,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5397,6 +5918,8 @@ select * from t6 where d in (select f1()
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -5663,6 +6186,13 @@ select * from t6 where d in (select f1()
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5763,6 +6293,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5863,6 +6400,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5957,11 +6501,15 @@ select d+1 into res from t6 where d= NAM
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
+                  "setup_range_conditions": [
+                    {
+                      "impossible_condition": {
+                        "table": "t6",
+                        "field": "d",
+                        "cause": "comparison_with_null_always_false"
+                      } /* impossible_condition */
+                    }
+                  ] /* setup_range_conditions */,
                   "impossible_range": true
                 } /* range_analysis */,
                 "records": 0,
@@ -5974,6 +6522,13 @@ select d+1 into res from t6 where d= NAM
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6057,6 +6612,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6137,11 +6699,15 @@ select @trace;
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
+                  "setup_range_conditions": [
+                    {
+                      "impossible_condition": {
+                        "table": "t6",
+                        "field": "d",
+                        "cause": "comparison_with_null_always_false"
+                      } /* impossible_condition */
+                    }
+                  ] /* setup_range_conditions */,
                   "impossible_range": true
                 } /* range_analysis */,
                 "records": 0,
@@ -6154,6 +6720,13 @@ select @trace;
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -6264,6 +6837,8 @@ select d into res from t6 where d in (se
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -6495,6 +7070,13 @@ select d into res from t6 where d in (se
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6595,6 +7177,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6695,6 +7284,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6806,6 +7402,13 @@ explain select * from v1 where id="b"	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6959,6 +7562,13 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_preparation": {
         "select#": 1,
         "steps": [
@@ -7039,6 +7649,20 @@ explain select * from v1 where id="b"	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -7136,6 +7760,13 @@ VARIABLE_NAME="optimizer_trace"	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -7172,6 +7803,13 @@ select TRACE into dumpfile 'MYSQLTEST_VA
       }
     },
     {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ]
+      }
+    },
+    {
       "join_optimization": {
         "select#": 2,
         "steps": [
@@ -7179,6 +7817,13 @@ select TRACE into dumpfile 'MYSQLTEST_VA
       }
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ]
+      }
+    },
+    {
       "join_preparation": {
         "select#": "fake",
         "steps": [
@@ -7246,6 +7891,13 @@ select TRACE into dumpfile 'MYSQLTEST_VA
           }
         ]
       }
+    },
+    {
+      "join_execution": {
+        "select#": "fake",
+        "steps": [
+        ]
+      }
     }
   ]
 }set optimizer_switch='default,index_merge=on,index_merge=off,default';
@@ -7273,6 +7925,13 @@ select "abc11111111111111111111111111111
         "steps": [
         ]
       }
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ]
+      }
     }
   ]
 }	0	0

=== modified file 'mysql-test/r/optimizer_trace_ps_prot.result'
--- a/mysql-test/r/optimizer_trace_ps_prot.result	2010-11-26 16:16:31 +0000
+++ b/mysql-test/r/optimizer_trace_ps_prot.result	2010-12-13 14:03:16 +0000
@@ -62,66 +62,91 @@ SELECT (SELECT 1 FROM t6 WHERE d = c) AS
       }
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = NULL)",
-              "after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
-              "after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
-              "after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"
-            }
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= NULL",
-                "null_rejecting": true
-              }
-            ]
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  },
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ]
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = NULL)",
+                          "after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
+                          "after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)",
+                          "after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"
+                        }
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= NULL",
+                            "null_rejecting": true
+                          }
+                        ]
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              },
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ]
+                                }
+                              ],
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              },
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  }
+                                }
+                              ],
+                              "impossible_range": true
+                            },
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ]
+                      }
+                    ],
+                    "empty_result": {
+                      "cause": "no matching row in const table"
                     }
-                  ],
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  },
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  },
-                  "impossible_range": true
+                  }
                 },
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ]
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ]
+                  }
+                }
+              ]
+            }
           }
-        ],
-        "empty_result": {
-          "cause": "no matching row in const table"
-        }
+        ]
       }
     }
   ]
@@ -129,18 +154,18 @@ SELECT (SELECT 1 FROM t6 WHERE d = c) AS
 select (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
 from information_schema.OPTIMIZER_TRACE;
 (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
-50.1007
+61.4266
 set optimizer_trace="one_line=on";
 SELECT (SELECT 1 FROM t6 WHERE d = c) AS RESULT FROM t5 ;
 RESULT
 NULL
 select * from information_schema.OPTIMIZER_TRACE;
 QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
-SELECT (SELECT 1 FROM t6 WHERE d = c) AS RESULT FROM t5	{"steps": [{"expanded_query": "/* select#1 */ select (/* select#2 */ select 1 from `test`.`t6` where (`d` = `c`)) AS `RESULT` from `test`.`t5`"},{"join_preparation": {"select#": 1,"steps": [{"join_preparation": {"select#": 2,"steps": []}}]}},{"join_optimization": {"select#": 1,"steps": [{"records_estimation": [{"database": "test","table": "t5","records": 1,"cost": 1,"table_type": "system"}]},{"attaching_conditions_to_tables": {"original_condition": null,"attached_conditions": []}},{"refine_plan": []}]}},{"join_optimization": {"select#": 2,"steps": [{"condition_processing": {"condition": "WHERE","original_condition": "(`test`.`t6`.`d` = NULL)","after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"}},{"ref-optimizer-key-uses": [{"condition": "t6.d= NULL","null_rejecting": true}]},{"records_estimation": [{"database": "test","table": "t6","range_analysis": {"table_scan": {"records": 2,"cost": 4.5034},"potential_range_indices": [{"index": "d","usable": true,"key_parts": ["d"]}],"best_covering_index_scan": {"index": "d","cost": 1.4233,"chosen": true},"impossible_condition": {"table": "t6","field": "d","cause": "comparison_with_null_always_false"},"impossible_range": true},"records": 0,"cause": "impossible_where_condition"}]}],"empty_result": {"cause": "no matching row in const table"}}}]}	0	0
+SELECT (SELECT 1 FROM t6 WHERE d = c) AS RESULT FROM t5	{"steps": [{"expanded_query": "/* select#1 */ select (/* select#2 */ select 1 from `test`.`t6` where (`d` = `c`)) AS `RESULT` from `test`.`t5`"},{"join_preparation": {"select#": 1,"steps": [{"join_preparation": {"select#": 2,"steps": []}}]}},{"join_optimization": {"select#": 1,"steps": [{"records_estimation": [{"database": "test","table": "t5","records": 1,"cost": 1,"table_type": "system"}]},{"attaching_conditions_to_tables": {"original_condition": null,"attached_conditions": []}},{"refine_plan": []}]}},{"join_execution": {"select#": 1,"steps": [{"subselect_exec": {"select#": 2,"steps": [{"join_optimization": {"select#": 2,"steps": [{"condition_processing": {"condition": "WHERE","original_condition": "(`test`.`t6`.`d` = NULL)","after_equality_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_constant_propagation": "multiple equal(NULL, `test`.`t6`.`d`)","after_trivial_conditions_removal": "multiple equal(NULL, `test`.`t6`.`d`)"}},{"ref-optimizer-key-uses": [{"condition": "t6.d= NULL","null_rejecting": true}]},{"records_estimation": [{"database": "test","table": "t6","range_analysis": {"table_scan": {"records": 2,"cost": 4.5034},"potential_range_indices": [{"index": "d","usable": true,"key_parts": ["d"]}],"best_covering_index_scan": {"index": "d","cost": 1.4233,"chosen": true},"setup_range_conditions": [{"impossible_condition": {"table": "t6","field": "d","cause": "comparison_with_null_always_false"}}],"impossible_range": true},"records": 0,"cause": "impossible_where_condition"}]}],"empty_result": {"cause": "no matching row in const table"}}},{"join_execution": {"select#": 2,"steps": []}}]}}]}}]}	0	0
 select (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
 from information_schema.OPTIMIZER_TRACE;
 (1-length(replace(TRACE, " ", ""))/length(TRACE))*100
-6.0792
+6.0625
 set optimizer_trace="one_line=off,end_marker=on";
 EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d = ifnull(c,null)) AS RESULT FROM t5 ;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -197,67 +222,85 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                    "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                    "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                    "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
                     {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
+                      "condition": "t6.d= ifnull(NULL,NULL)",
+                      "null_rejecting": false
                     }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t6",
+                      "range_analysis": {
+                        "table_scan": {
+                          "records": 2,
+                          "cost": 4.5034
+                        } /* table_scan */,
+                        "potential_range_indices": [
+                          {
+                            "index": "d",
+                            "usable": true,
+                            "key_parts": [
+                              "d"
+                            ] /* key_parts */
+                          }
+                        ] /* potential_range_indices */,
+                        "best_covering_index_scan": {
+                          "index": "d",
+                          "cost": 1.4233,
+                          "chosen": true
+                        } /* best_covering_index_scan */,
+                        "setup_range_conditions": [
+                          {
+                            "impossible_condition": {
+                              "table": "t6",
+                              "field": "d",
+                              "cause": "comparison_with_null_always_false"
+                            } /* impossible_condition */
+                          }
+                        ] /* setup_range_conditions */,
+                        "impossible_range": true
+                      } /* range_analysis */,
+                      "records": 0,
+                      "cause": "impossible_where_condition"
+                    }
+                  ] /* records_estimation */
+                }
+              ] /* steps */,
+              "empty_result": {
+                "cause": "Impossible WHERE noticed after reading const tables"
+              } /* empty_result */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "Impossible WHERE noticed after reading const tables"
-        } /* empty_result */
-      } /* join_optimization */
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -315,67 +358,92 @@ SELECT /* should be last */ (SELECT 1 FR
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
-                    }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= ifnull(NULL,NULL)",
+                            "null_rejecting": false
+                          }
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  } /* impossible_condition */
+                                }
+                              ] /* setup_range_conditions */,
+                              "impossible_range": true
+                            } /* range_analysis */,
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ] /* records_estimation */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "no matching row in const table"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
           }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "no matching row in const table"
-        } /* empty_result */
-      } /* join_optimization */
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -448,199 +516,242 @@ SELECT (SELECT 1 FROM t6 WHERE d = ifnul
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
-                    }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
-          }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "no matching row in const table"
-        } /* empty_result */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 3,
-        "steps": [
-          {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
-              "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= ifnull(NULL,NULL)",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
-                    {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
-                    }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
-                  "impossible_range": true
-                } /* range_analysis */,
-                "records": 0,
-                "cause": "impossible_where_condition"
-              }
-            ] /* records_estimation */
-          }
-        ] /* steps */,
-        "empty_result": {
-          "cause": "no matching row in const table"
-        } /* empty_result */
-      } /* join_optimization */
-    },
-    {
-      "join_preparation": {
-        "select#": "fake",
-        "steps": [
-        ] /* steps */
-      } /* join_preparation */
-    },
-    {
-      "join_optimization": {
-        "select#": "fake",
-        "steps": [
-          {
-            "records_estimation": [
-              {
-                "database": "",
-                "table": "",
-                "table_scan": {
-                  "records": 0,
-                  "cost": 10
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "",
-                "table": "",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 0,
-                      "cost": 10,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 10,
-                "records_for_plan": 0,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
                 {
-                  "database": "",
-                  "table": "",
-                  "attached": null
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= ifnull(NULL,NULL)",
+                            "null_rejecting": false
+                          }
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  } /* impossible_condition */
+                                }
+                              ] /* setup_range_conditions */,
+                              "impossible_range": true
+                            } /* range_analysis */,
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ] /* records_estimation */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "no matching row in const table"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
+                {
+                  "join_optimization": {
+                    "select#": 3,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_equality_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_constant_propagation": "(`test`.`t6`.`d` = ifnull(NULL,NULL))",
+                          "after_trivial_conditions_removal": "(`test`.`t6`.`d` = ifnull(NULL,NULL))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                          {
+                            "condition": "t6.d= ifnull(NULL,NULL)",
+                            "null_rejecting": false
+                          }
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t6",
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5034
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "d",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "d"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "d",
+                                "cost": 1.4233,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "setup_range_conditions": [
+                                {
+                                  "impossible_condition": {
+                                    "table": "t6",
+                                    "field": "d",
+                                    "cause": "comparison_with_null_always_false"
+                                  } /* impossible_condition */
+                                }
+                              ] /* setup_range_conditions */,
+                              "impossible_range": true
+                            } /* range_analysis */,
+                            "records": 0,
+                            "cause": "impossible_where_condition"
+                          }
+                        ] /* records_estimation */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "no matching row in const table"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 3,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
+                {
+                  "join_preparation": {
+                    "select#": "fake",
+                    "steps": [
+                    ] /* steps */
+                  } /* join_preparation */
+                },
+                {
+                  "join_optimization": {
+                    "select#": "fake",
+                    "steps": [
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "table_scan": {
+                              "records": 0,
+                              "cost": 10
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 0,
+                                  "cost": 10,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 10,
+                            "records_for_plan": 0,
+                            "chosen": true
+                          }
+                        ] /* considered_execution_plans */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": null,
+                          "attached_conditions": [
+                            {
+                              "database": "",
+                              "table": "",
+                              "attached": null
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": "fake",
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "",
-                "table": "",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* subselect_exec */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -714,8 +825,14 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
             "condition_processing": {
               "condition": "WHERE",
               "original_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))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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))))"
             } /* condition_processing */
           },
@@ -735,133 +852,168 @@ SELECT * FROM t5 WHERE 5 IN (SELECT 1 FR
             ] /* records_estimation */
           },
           {
-            "join_optimization": {
+            "subselect_exec": {
               "select#": 2,
               "steps": [
                 {
-                  "condition_processing": {
-                    "condition": "WHERE",
-                    "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
-                    "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
-                    "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 1))",
-                    "after_trivial_conditions_removal": null
-                  } /* condition_processing */
-                }
-              ] /* steps */,
-              "empty_result": {
-                "cause": "Impossible WHERE"
-              } /* empty_result */
-            } /* join_optimization */
-          },
-          {
-            "join_optimization": {
-              "select#": 3,
-              "steps": [
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
+                          "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 1))",
+                          "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 1))",
+                          "after_trivial_conditions_removal": null
+                        } /* condition_processing */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "Impossible WHERE"
+                    } /* empty_result */
+                  } /* join_optimization */
+                },
                 {
-                  "condition_processing": {
-                    "condition": "WHERE",
-                    "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
-                    "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
-                    "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 2))",
-                    "after_trivial_conditions_removal": null
-                  } /* condition_processing */
-                }
-              ] /* steps */,
-              "empty_result": {
-                "cause": "Impossible WHERE"
-              } /* empty_result */
-            } /* join_optimization */
-          },
-          {
-            "join_preparation": {
-              "select#": "fake",
-              "steps": [
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
                 {
-                  "transformation": {
-                    "select#": "fake",
-                    "from": "IN (SELECT)",
-                    "to": "semijoin",
-                    "chosen": false
-                  } /* transformation */
+                  "join_optimization": {
+                    "select#": 3,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
+                          "after_equality_propagation": "((`test`.`t6`.`d` = ifnull(NULL,NULL)) and (<cache>(5) = 2))",
+                          "after_constant_propagation": "((`test`.`t6`.`d` = NULL) and (<cache>(5) = 2))",
+                          "after_trivial_conditions_removal": null
+                        } /* condition_processing */
+                      }
+                    ] /* steps */,
+                    "empty_result": {
+                      "cause": "Impossible WHERE"
+                    } /* empty_result */
+                  } /* join_optimization */
                 },
                 {
-                  "transformation": {
-                    "select#": "fake",
-                    "from": "IN (SELECT)",
-                    "to": "materialization",
-                    "chosen": false
-                  } /* transformation */
-                }
-              ] /* steps */
-            } /* join_preparation */
-          },
-          {
-            "join_optimization": {
-              "select#": "fake",
-              "steps": [
+                  "join_execution": {
+                    "select#": 3,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                },
                 {
-                  "records_estimation": [
-                    {
-                      "database": "",
-                      "table": "",
-                      "table_scan": {
-                        "records": 0,
-                        "cost": 10
-                      } /* table_scan */
-                    }
-                  ] /* records_estimation */
+                  "join_preparation": {
+                    "select#": "fake",
+                    "steps": [
+                      {
+                        "transformation": {
+                          "select#": "fake",
+                          "from": "IN (SELECT)",
+                          "to": "semijoin",
+                          "chosen": false
+                        } /* transformation */
+                      },
+                      {
+                        "transformation": {
+                          "select#": "fake",
+                          "from": "IN (SELECT)",
+                          "to": "materialization",
+                          "chosen": false
+                        } /* transformation */
+                      }
+                    ] /* steps */
+                  } /* join_preparation */
                 },
                 {
-                  "considered_execution_plans": [
-                    {
-                      "database": "",
-                      "table": "",
-                      "best_access_path": {
-                        "considered_access_paths": [
+                  "join_optimization": {
+                    "select#": "fake",
+                    "steps": [
+                      {
+                        "records_estimation": [
                           {
-                            "access_type": "scan",
-                            "using_join_cache": true,
-                            "records": 0,
-                            "cost": 10,
+                            "database": "",
+                            "table": "",
+                            "table_scan": {
+                              "records": 0,
+                              "cost": 10
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 0,
+                                  "cost": 10,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 10,
+                            "records_for_plan": 0,
                             "chosen": true
                           }
-                        ] /* considered_access_paths */
-                      } /* best_access_path */,
-                      "cost_for_plan": 10,
-                      "records_for_plan": 0,
-                      "chosen": true
-                    }
-                  ] /* considered_execution_plans */
-                },
-                {
-                  "attaching_conditions_to_tables": {
-                    "original_condition": null,
-                    "attached_conditions": [
+                        ] /* considered_execution_plans */
+                      },
                       {
-                        "database": "",
-                        "table": "",
-                        "attached": null
+                        "attaching_conditions_to_tables": {
+                          "original_condition": null,
+                          "attached_conditions": [
+                            {
+                              "database": "",
+                              "table": "",
+                              "attached": null
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "",
+                            "table": "",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
                       }
-                    ] /* attached_conditions */
-                  } /* attaching_conditions_to_tables */
+                    ] /* steps */
+                  } /* join_optimization */
                 },
                 {
-                  "refine_plan": [
-                    {
-                      "database": "",
-                      "table": "",
-                      "scan_type": "table"
-                    }
-                  ] /* refine_plan */
+                  "join_execution": {
+                    "select#": "fake",
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
               ] /* steps */
-            } /* join_optimization */
+            } /* subselect_exec */
           }
         ] /* steps */,
         "empty_result": {
           "cause": "Impossible WHERE noticed after reading const tables"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -870,16 +1022,16 @@ select (@query:=QUERY)+NULL, (@trace:=TR
 NULL	NULL
 select length(@trace);
 length(@trace)
-8631
+10628
 set optimizer_trace_max_mem_size=9000;
 select length(@query)+length(@trace) > @@optimizer_trace_max_mem_size;
 length(@query)+length(@trace) > @@optimizer_trace_max_mem_size
-0
+1
 SELECT * FROM t5 WHERE 5 IN (SELECT 1 FROM t6 WHERE d = ifnull(c,null) UNION SELECT 2 FROM t6 WHERE d = ifnull(c,null));
 c
 select (@missing_bytes:=missing_bytes_beyond_max_mem_size) from information_schema.OPTIMIZER_TRACE;
 (@missing_bytes:=missing_bytes_beyond_max_mem_size)
-0
+1756
 select (@query2:=QUERY)+NULL,(@trace2:=TRACE)+NULL from information_schema.OPTIMIZER_TRACE;
 (@query2:=QUERY)+NULL	(@trace2:=TRACE)+NULL
 NULL	NULL
@@ -887,12 +1039,12 @@ select length(@trace2),
 (length(@trace2) + @missing_bytes) = length(@trace),
 @query2 = @query;
 length(@trace2)	(length(@trace2) + @missing_bytes) = length(@trace)	@query2 = @query
-8631	1	1
+8872	1	1
 select length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-100) and (@@optimizer_trace_max_mem_size+100);
 length(@query2) + length(@trace2)
 between (@@optimizer_trace_max_mem_size-100) and (@@optimizer_trace_max_mem_size+100)
-0
+1
 select instr(@trace, @trace2) = 1;
 instr(@trace, @trace2) = 1
 1
@@ -902,14 +1054,14 @@ select 1;
 1
 select * from information_schema.OPTIMIZER_TRACE;
 QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
-select 1		373	0
+select 1		504	0
 set optimizer_trace_max_mem_size=0;
 select 1;
 1
 1
 select * from information_schema.OPTIMIZER_TRACE;
 QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
-		381	0
+		512	0
 set optimizer_trace_max_mem_size=1048576;
 explain SELECT c FROM t5 where c+1 in (select d+1 from t6 where d is null);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -1004,6 +1156,8 @@ explain SELECT c FROM t5 where c+1 in (s
                     "cost": 1.4233,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -1169,6 +1323,13 @@ explain SELECT c FROM t5 where c+1 in (s
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1222,8 +1383,14 @@ explain SELECT c FROM t5 where c+1 in (s
             "condition_processing": {
               "condition": "WHERE",
               "original_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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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`)))"
             } /* condition_processing */
           },
@@ -1265,129 +1432,145 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "isnull(`test`.`t6`.`d`)",
-              "after_equality_propagation": "isnull(`test`.`t6`.`d`)",
-              "after_constant_propagation": "isnull(`test`.`t6`.`d`)",
-              "after_trivial_conditions_removal": "isnull(`test`.`t6`.`d`)"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-              {
-                "condition": "t6.d= NULL",
-                "null_rejecting": false
-              }
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t6",
-                "range_analysis": {
-                  "table_scan": {
-                    "records": 2,
-                    "cost": 4.5034
-                  } /* table_scan */,
-                  "potential_range_indices": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "isnull(`test`.`t6`.`d`)",
+                    "after_equality_propagation": "isnull(`test`.`t6`.`d`)",
+                    "after_constant_propagation": "isnull(`test`.`t6`.`d`)",
+                    "after_trivial_conditions_removal": "isnull(`test`.`t6`.`d`)"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
                     {
-                      "index": "d",
-                      "usable": true,
-                      "key_parts": [
-                        "d"
-                      ] /* key_parts */
+                      "condition": "t6.d= NULL",
+                      "null_rejecting": false
                     }
-                  ] /* potential_range_indices */,
-                  "best_covering_index_scan": {
-                    "index": "d",
-                    "cost": 1.4233,
-                    "chosen": true
-                  } /* best_covering_index_scan */,
-                  "group_index_range": {
-                    "chosen": false,
-                    "cause": "not_group_by_or_distinct"
-                  } /* group_index_range */,
-                  "analyzing_range_alternatives": {
-                    "range_scan_alternatives": [
-                      {
-                        "index": "d",
-                        "ranges": [
-                          "NULL <= d <= NULL"
-                        ] /* ranges */,
-                        "index_only": true,
-                        "records": 1,
-                        "cost": 2.21,
-                        "rowid_ordered": true,
-                        "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 */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t6",
-                "best_access_path": {
-                  "considered_access_paths": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t6",
+                      "range_analysis": {
+                        "table_scan": {
+                          "records": 2,
+                          "cost": 4.5034
+                        } /* table_scan */,
+                        "potential_range_indices": [
+                          {
+                            "index": "d",
+                            "usable": true,
+                            "key_parts": [
+                              "d"
+                            ] /* key_parts */
+                          }
+                        ] /* potential_range_indices */,
+                        "best_covering_index_scan": {
+                          "index": "d",
+                          "cost": 1.4233,
+                          "chosen": true
+                        } /* best_covering_index_scan */,
+                        "setup_range_conditions": [
+                        ] /* setup_range_conditions */,
+                        "group_index_range": {
+                          "chosen": false,
+                          "cause": "not_group_by_or_distinct"
+                        } /* group_index_range */,
+                        "analyzing_range_alternatives": {
+                          "range_scan_alternatives": [
+                            {
+                              "index": "d",
+                              "ranges": [
+                                "NULL <= d <= NULL"
+                              ] /* ranges */,
+                              "index_only": true,
+                              "records": 1,
+                              "cost": 2.21,
+                              "rowid_ordered": true,
+                              "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 */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
                     {
-                      "access_type": "ref",
-                      "index": "d",
-                      "records": 1,
-                      "cost": 1,
+                      "database": "test",
+                      "table": "t6",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "ref",
+                            "index": "d",
+                            "records": 1,
+                            "cost": 1,
+                            "chosen": true
+                          },
+                          {
+                            "access_type": "scan",
+                            "cost": 2,
+                            "records": 2,
+                            "cause": "cost",
+                            "chosen": false
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 1,
+                      "records_for_plan": 1,
                       "chosen": true
-                    },
-                    {
-                      "access_type": "scan",
-                      "cost": 2,
-                      "records": 2,
-                      "cause": "cost",
-                      "chosen": false
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 1,
-                "records_for_plan": 1,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "isnull(`test`.`t6`.`d`)",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t6",
-                  "attached": "isnull(`test`.`t6`.`d`)"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "isnull(`test`.`t6`.`d`)",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t6",
+                        "attached": "isnull(`test`.`t6`.`d`)"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t6"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t6"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1438,8 +1621,14 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_condition": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<nop>((`test`.`t1`.`s1` > (/* select#2 */ select min(`test`.`t1`.`s2`) from `test`.`t1`)))"
             } /* condition_processing */
           },
@@ -1506,66 +1695,80 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": null
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1612,77 +1815,21 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "after_constant_propagation": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "after_trivial_conditions_removal": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
-              "attached_conditions": [
-                {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
-                }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
-          }
-        ] /* steps */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 2,
-        "steps": [
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_constant_propagation": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_trivial_conditions_removal": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
+            } /* condition_processing */
+          },
+          {
+            "ref-optimizer-key-uses": [
+            ] /* ref-optimizer-key-uses */
+          },
           {
             "records_estimation": [
               {
@@ -1719,12 +1866,12 @@ explain extended select * from t1 where 
           },
           {
             "attaching_conditions_to_tables": {
-              "original_condition": null,
+              "original_condition": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))",
               "attached_conditions": [
                 {
                   "database": "test",
                   "table": "t1",
-                  "attached": null
+                  "attached": "<nop>((`test`.`t1`.`s1` > <min>(/* select#2 */ select max(`test`.`t1`.`s2`) from `test`.`t1`)))"
                 }
               ] /* attached_conditions */
             } /* attaching_conditions_to_tables */
@@ -1740,6 +1887,82 @@ explain extended select * from t1 where 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1803,8 +2026,14 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_condition": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select 1 from `test`.`t1` where (<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)))"
             } /* condition_processing */
           },
@@ -1871,79 +2100,93 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "after_equality_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "after_constant_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "after_trivial_conditions_removal": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "after_equality_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "after_constant_propagation": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "after_trivial_conditions_removal": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": "(<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`)"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2006,8 +2249,14 @@ explain extended select * from t1 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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`))))"
             } /* condition_processing */
           },
@@ -2056,82 +2305,7 @@ explain extended select * from t1 where 
                 {
                   "database": "test",
                   "table": "t1",
-                  "attached": "<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`))))"
-                }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t1",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
-          }
-        ] /* steps */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 2,
-        "steps": [
-          {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "after_equality_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "after_constant_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t1",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t1",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0054,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0054,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
-              "attached_conditions": [
-                {
-                  "database": "test",
-                  "table": "t1",
-                  "attached": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
+                  "attached": "<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`))))"
                 }
               ] /* attached_conditions */
             } /* attaching_conditions_to_tables */
@@ -2147,6 +2321,95 @@ explain extended select * from t1 where 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "after_equality_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "after_constant_propagation": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "table_scan": {
+                        "records": 2,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 2,
+                            "cost": 2.0054,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0054,
+                      "records_for_plan": 2,
+                      "chosen": true
+                    }
+                  ] /* considered_execution_plans */
+                },
+                {
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t1",
+                        "attached": "((<cache>(`test`.`t1`.`s1`) = `test`.`t1`.`s2`) and (<cache>(`test`.`t1`.`s2`) = `test`.`t1`.`s1`))"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t1",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
+                }
+              ] /* steps */
+            } /* join_optimization */
+          },
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2310,12 +2573,19 @@ explain select * from t1,t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
 select @@optimizer_trace_features;
 @@optimizer_trace_features
-greedy_search=on,range_optimizer=on
+greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 set @@optimizer_trace_features="greedy_search=off";
 explain select * from t1,t2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
@@ -2395,6 +2665,13 @@ explain select * from t1,t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2492,8 +2769,14 @@ where a1 in (select b1 from t2_16 where 
             "condition_processing": {
               "condition": "WHERE",
               "original_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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "<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`))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "<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`))))"
             } /* condition_processing */
           },
@@ -2560,79 +2843,93 @@ where a1 in (select b1 from t2_16 where 
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "after_equality_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "after_constant_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "after_trivial_conditions_removal": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2_16",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2_16",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "condition_processing": {
+                    "condition": "WHERE",
+                    "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "after_equality_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "after_constant_propagation": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "after_trivial_conditions_removal": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
+                  } /* condition_processing */
+                },
+                {
+                  "ref-optimizer-key-uses": [
+                  ] /* ref-optimizer-key-uses */
+                },
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0293,
+                      "database": "test",
+                      "table": "t2_16",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t2_16",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 3,
+                            "cost": 2.0293,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0293,
+                      "records_for_plan": 3,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0293,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t2_16",
-                  "attached": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
+                  "attaching_conditions_to_tables": {
+                    "original_condition": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))",
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t2_16",
+                        "attached": "((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))"
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t2_16",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2_16",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2705,8 +3002,14 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
             "condition_processing": {
               "condition": "WHERE",
               "original_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 (`test`.`t1`.`c1` = `test`.`t2`.`c2`))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "(<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`))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "(<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`))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "(<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`))"
             } /* condition_processing */
           },
@@ -2828,79 +3131,100 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c2`))",
-              "after_equality_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
-              "after_constant_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
-              "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0051,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0051,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))",
-              "attached_conditions": [
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = `test`.`t2`.`c2`))",
+                          "after_equality_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
+                          "after_constant_propagation": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))",
+                          "after_trivial_conditions_removal": "((<cache>(`test`.`t1`.`c1`) = 1) and multiple equal(1, `test`.`t2`.`c2`))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "table_scan": {
+                              "records": 3,
+                              "cost": 2
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 3,
+                                  "cost": 2.0051,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 2.0051,
+                            "records_for_plan": 3,
+                            "chosen": true
+                          }
+                        ] /* considered_execution_plans */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))",
+                          "attached_conditions": [
+                            {
+                              "database": "test",
+                              "table": "t2",
+                              "attached": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))"
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
                 {
-                  "database": "test",
-                  "table": "t2",
-                  "attached": "((`test`.`t2`.`c2` = 1) and (<cache>(`test`.`t1`.`c1`) = 1))"
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* subselect_exec */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3004,6 +3328,13 @@ SELECT * FROM t1 WHERE c1=5 UNION SELECT
       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_optimization": {
         "select#": 2,
         "steps": [
@@ -3079,6 +3410,13 @@ SELECT * FROM t1 WHERE c1=5 UNION SELECT
       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_preparation": {
         "select#": "fake",
         "steps": [
@@ -3146,6 +3484,13 @@ SELECT * FROM t1 WHERE c1=5 UNION SELECT
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": "fake",
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3235,8 +3580,14 @@ concat(c1,'y') IN
             "condition_processing": {
               "condition": "WHERE",
               "original_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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "(<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "(<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`)))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "(<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`)))"
             } /* condition_processing */
           },
@@ -3319,128 +3670,149 @@ concat(c1,'y') IN
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 3,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 3,
+              "steps": [
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0051,
+                      "database": "test",
+                      "table": "t2",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 3,
+                            "cost": 2.0051,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0051,
+                      "records_for_plan": 3,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0051,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t2",
-                  "attached": null
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t2",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
-          }
-        ] /* steps */
-      } /* join_optimization */
-    },
-    {
-      "join_optimization": {
-        "select#": 2,
-        "steps": [
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2",
-                "table_scan": {
-                  "records": 3,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
+            "join_execution": {
+              "select#": 3,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           },
           {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2",
-                "best_access_path": {
-                  "considered_access_paths": [
+            "join_optimization": {
+              "select#": 2,
+              "steps": [
+                {
+                  "records_estimation": [
                     {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 3,
-                      "cost": 2.0051,
+                      "database": "test",
+                      "table": "t2",
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 2
+                      } /* table_scan */
+                    }
+                  ] /* records_estimation */
+                },
+                {
+                  "considered_execution_plans": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "best_access_path": {
+                        "considered_access_paths": [
+                          {
+                            "access_type": "scan",
+                            "using_join_cache": true,
+                            "records": 3,
+                            "cost": 2.0051,
+                            "chosen": true
+                          }
+                        ] /* considered_access_paths */
+                      } /* best_access_path */,
+                      "cost_for_plan": 2.0051,
+                      "records_for_plan": 3,
                       "chosen": true
                     }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0051,
-                "records_for_plan": 3,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": null,
-              "attached_conditions": [
+                  ] /* considered_execution_plans */
+                },
                 {
-                  "database": "test",
-                  "table": "t2",
-                  "attached": null
+                  "attaching_conditions_to_tables": {
+                    "original_condition": null,
+                    "attached_conditions": [
+                      {
+                        "database": "test",
+                        "table": "t2",
+                        "attached": null
+                      }
+                    ] /* attached_conditions */
+                  } /* attaching_conditions_to_tables */
+                },
+                {
+                  "refine_plan": [
+                    {
+                      "database": "test",
+                      "table": "t2",
+                      "scan_type": "table"
+                    }
+                  ] /* refine_plan */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
+              ] /* steps */
+            } /* join_optimization */
           },
           {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3502,6 +3874,13 @@ select * from t1,t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3686,6 +4065,13 @@ trace
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -3793,6 +4179,13 @@ trace
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -3929,6 +4322,13 @@ select * from t1 left join t2 on t2.a=50
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -3984,8 +4384,14 @@ select * from t1 where (t1.a,t1.b) not i
             "condition_processing": {
               "condition": "WHERE",
               "original_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))))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_equality_propagation": "(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))))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_constant_propagation": "(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))))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
               "after_trivial_conditions_removal": "(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))))))"
             } /* condition_processing */
           },
@@ -4052,87 +4458,108 @@ select * from t1 where (t1.a,t1.b) not i
       } /* join_optimization */
     },
     {
-      "join_optimization": {
-        "select#": 2,
+      "join_execution": {
+        "select#": 1,
         "steps": [
           {
-            "condition_processing": {
-              "condition": "WHERE",
-              "original_condition": "((`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))",
-              "after_equality_propagation": "((`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))",
-              "after_constant_propagation": "((`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))",
-              "after_trivial_conditions_removal": "((`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))"
-            } /* condition_processing */
-          },
-          {
-            "condition_processing": {
-              "condition": "HAVING",
-              "original_condition": "(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))",
-              "after_constant_propagation": "(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))",
-              "after_trivial_conditions_removal": "(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))"
-            } /* condition_processing */
-          },
-          {
-            "ref-optimizer-key-uses": [
-            ] /* ref-optimizer-key-uses */
-          },
-          {
-            "records_estimation": [
-              {
-                "database": "test",
-                "table": "t2",
-                "table_scan": {
-                  "records": 2,
-                  "cost": 2
-                } /* table_scan */
-              }
-            ] /* records_estimation */
-          },
-          {
-            "considered_execution_plans": [
-              {
-                "database": "test",
-                "table": "t2",
-                "best_access_path": {
-                  "considered_access_paths": [
-                    {
-                      "access_type": "scan",
-                      "using_join_cache": true,
-                      "records": 2,
-                      "cost": 2.0044,
-                      "chosen": true
-                    }
-                  ] /* considered_access_paths */
-                } /* best_access_path */,
-                "cost_for_plan": 2.0044,
-                "records_for_plan": 2,
-                "chosen": true
-              }
-            ] /* considered_execution_plans */
-          },
-          {
-            "attaching_conditions_to_tables": {
-              "original_condition": "((`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))",
-              "attached_conditions": [
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
                 {
-                  "database": "test",
-                  "table": "t2",
-                  "attached": "((`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))"
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "((`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))",
+                          "after_equality_propagation": "((`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))",
+                          "after_constant_propagation": "((`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))",
+                          "after_trivial_conditions_removal": "((`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))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "condition_processing": {
+                          "condition": "HAVING",
+                          "original_condition": "(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))",
+                          "after_constant_propagation": "(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))",
+                          "after_trivial_conditions_removal": "(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))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "table_scan": {
+                              "records": 2,
+                              "cost": 2
+                            } /* table_scan */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "best_access_path": {
+                              "considered_access_paths": [
+                                {
+                                  "access_type": "scan",
+                                  "using_join_cache": true,
+                                  "records": 2,
+                                  "cost": 2.0044,
+                                  "chosen": true
+                                }
+                              ] /* considered_access_paths */
+                            } /* best_access_path */,
+                            "cost_for_plan": 2.0044,
+                            "records_for_plan": 2,
+                            "chosen": true
+                          }
+                        ] /* considered_execution_plans */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": "((`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))",
+                          "attached_conditions": [
+                            {
+                              "database": "test",
+                              "table": "t2",
+                              "attached": "((`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))"
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "test",
+                            "table": "t2",
+                            "scan_type": "table"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
                 }
-              ] /* attached_conditions */
-            } /* attaching_conditions_to_tables */
-          },
-          {
-            "refine_plan": [
-              {
-                "database": "test",
-                "table": "t2",
-                "scan_type": "table"
-              }
-            ] /* refine_plan */
+              ] /* steps */
+            } /* subselect_exec */
           }
         ] /* steps */
-      } /* join_optimization */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4293,6 +4720,13 @@ trace
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -4339,6 +4773,13 @@ trace
           "cause": "Impossible HAVING"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -4368,6 +4809,8 @@ update t6 set d=5 where d is NULL	{
             ] /* key_parts */
           }
         ] /* potential_range_indices */,
+        "setup_range_conditions": [
+        ] /* setup_range_conditions */,
         "group_index_range": {
           "chosen": false,
           "cause": "no_join"
@@ -4433,6 +4876,8 @@ delete from t6 where d=5	{
             ] /* key_parts */
           }
         ] /* potential_range_indices */,
+        "setup_range_conditions": [
+        ] /* setup_range_conditions */,
         "group_index_range": {
           "chosen": false,
           "cause": "no_join"
@@ -4535,6 +4980,8 @@ insert into t6 select * from t6 where d>
                     "cost": 1.6465,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -4608,6 +5055,13 @@ insert into t6 select * from t6 where d>
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4669,6 +5123,8 @@ update t5, t6 set t6.d=t6.d+t5.c+4-t5.c-
                       ] /* key_parts */
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -4753,6 +5209,13 @@ update t5, t6 set t6.d=t6.d+t5.c+4-t5.c-
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4819,6 +5282,8 @@ delete t6 from t5, t6 where d>7000	{
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -4892,6 +5357,13 @@ delete t6 from t5, t6 where d>7000	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -4947,6 +5419,13 @@ select 2	{
         "steps": [
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5002,6 +5481,13 @@ select 5	{
         "steps": [
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5105,6 +5591,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5188,6 +5681,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5268,6 +5768,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5359,6 +5866,8 @@ select * from t6 where d in (select f1()
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -5625,6 +6134,13 @@ select * from t6 where d in (select f1()
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5725,6 +6241,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5825,6 +6348,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -5909,11 +6439,15 @@ select d+1 into res from t6 where d= NAM
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
+                  "setup_range_conditions": [
+                    {
+                      "impossible_condition": {
+                        "table": "t6",
+                        "field": "d",
+                        "cause": "comparison_with_null_always_false"
+                      } /* impossible_condition */
+                    }
+                  ] /* setup_range_conditions */,
                   "impossible_range": true
                 } /* range_analysis */,
                 "records": 0,
@@ -5926,6 +6460,13 @@ select d+1 into res from t6 where d= NAM
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6009,6 +6550,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6089,11 +6637,15 @@ select @trace;
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
-                  "impossible_condition": {
-                    "table": "t6",
-                    "field": "d",
-                    "cause": "comparison_with_null_always_false"
-                  } /* impossible_condition */,
+                  "setup_range_conditions": [
+                    {
+                      "impossible_condition": {
+                        "table": "t6",
+                        "field": "d",
+                        "cause": "comparison_with_null_always_false"
+                      } /* impossible_condition */
+                    }
+                  ] /* setup_range_conditions */,
                   "impossible_range": true
                 } /* range_analysis */,
                 "records": 0,
@@ -6106,6 +6658,13 @@ select @trace;
           "cause": "no matching row in const table"
         } /* empty_result */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }
@@ -6216,6 +6775,8 @@ select d into res from t6 where d in (se
                     "cost": 1.8698,
                     "chosen": true
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_single_table"
@@ -6447,6 +7008,13 @@ select d into res from t6 where d in (se
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6547,6 +7115,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6647,6 +7222,13 @@ select sum(data) into ret from t1	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6758,6 +7340,13 @@ explain select * from v1 where id="b"	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -6895,6 +7484,13 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
       "join_preparation": {
         "select#": 1,
         "steps": [
@@ -6975,6 +7571,20 @@ explain select * from v1 where id="b"	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -7072,6 +7682,13 @@ VARIABLE_NAME="optimizer_trace"	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -7108,6 +7725,13 @@ select TRACE into dumpfile 'MYSQLTEST_VA
       }
     },
     {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ]
+      }
+    },
+    {
       "join_optimization": {
         "select#": 2,
         "steps": [
@@ -7115,6 +7739,13 @@ select TRACE into dumpfile 'MYSQLTEST_VA
       }
     },
     {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+        ]
+      }
+    },
+    {
       "join_preparation": {
         "select#": "fake",
         "steps": [
@@ -7182,6 +7813,13 @@ select TRACE into dumpfile 'MYSQLTEST_VA
           }
         ]
       }
+    },
+    {
+      "join_execution": {
+        "select#": "fake",
+        "steps": [
+        ]
+      }
     }
   ]
 }set optimizer_switch='default,index_merge=on,index_merge=off,default';
@@ -7209,6 +7847,13 @@ select "abc11111111111111111111111111111
         "steps": [
         ]
       }
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ]
+      }
     }
   ]
 }	0	0

=== modified file 'mysql-test/r/optimizer_trace_range.result'
--- a/mysql-test/r/optimizer_trace_range.result	2010-11-24 18:54:26 +0000
+++ b/mysql-test/r/optimizer_trace_range.result	2010-12-13 14:03:16 +0000
@@ -84,7 +84,7 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
                     {
                       "index": "i1",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2",
@@ -96,34 +96,36 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
                     {
                       "index": "i3",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i4",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i5",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i6",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i7",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i8",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -210,6 +212,13 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -261,6 +270,8 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
                     "cost": 217.15
                   } /* table_scan */,
                   "potential_range_indices": "...",
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": "...",
                   "analyzing_range_alternatives": "...",
                   "chosen_range_access_summary": {
@@ -325,6 +336,13 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -393,34 +411,36 @@ EXPLAIN SELECT * FROM t1 WHERE key1 < 3 
                     {
                       "index": "i3",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i4",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i5",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i6",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i7",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i8",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -543,6 +563,13 @@ EXPLAIN SELECT * FROM t1 WHERE key1 < 3 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -590,12 +617,12 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
                     {
                       "index": "PRIMARY",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i1b",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2_1",
@@ -731,6 +758,13 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -777,12 +811,12 @@ EXPLAIN SELECT DISTINCT key2 FROM t2	{
                     {
                       "index": "PRIMARY",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i1b",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2_1",
@@ -918,6 +952,13 @@ EXPLAIN SELECT DISTINCT key2 FROM t2	{
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -971,12 +1012,12 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
                     {
                       "index": "PRIMARY",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i1b",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2_1",
@@ -1001,6 +1042,8 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
                     "chosen": false,
                     "cause": "cost"
                   } /* best_covering_index_scan */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "potential_group_range_indices": [
                       {
@@ -1143,6 +1186,13 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1204,12 +1254,12 @@ EXPLAIN SELECT * FROM t2 WHERE key2 = 1 
                     {
                       "index": "PRIMARY",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i1b",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2_1",
@@ -1228,6 +1278,8 @@ EXPLAIN SELECT * FROM t2 WHERE key2 = 1 
                       ] /* key_parts */
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -1336,6 +1388,13 @@ EXPLAIN SELECT * FROM t2 WHERE key2 = 1 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1389,7 +1448,7 @@ EXPLAIN SELECT * FROM t1 WHERE key2=10 O
                     {
                       "index": "i1",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2",
@@ -1415,29 +1474,33 @@ EXPLAIN SELECT * FROM t1 WHERE key2=10 O
                     {
                       "index": "i5",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i6",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i7",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i8",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     }
                   ] /* potential_range_indices */,
-                  "impossible_condition": {
-                    "table": "t1",
-                    "field": "key4",
-                    "cause": "null_field_in_non_null_column"
-                  } /* impossible_condition */,
+                  "setup_range_conditions": [
+                    {
+                      "impossible_condition": {
+                        "table": "t1",
+                        "field": "key4",
+                        "cause": "null_field_in_non_null_column"
+                      } /* impossible_condition */
+                    }
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -1588,6 +1651,13 @@ EXPLAIN SELECT * FROM t1 WHERE key2=10 O
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1641,12 +1711,12 @@ EXPLAIN SELECT * FROM t2 WHERE key2_1 < 
                     {
                       "index": "PRIMARY",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i1b",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2_1",
@@ -1665,6 +1735,8 @@ EXPLAIN SELECT * FROM t2 WHERE key2_1 < 
                       ] /* key_parts */
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "range_scan_possible": false,
                   "cause": "condition_always_true",
                   "group_index_range": {
@@ -1720,6 +1792,13 @@ EXPLAIN SELECT * FROM t2 WHERE key2_1 < 
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1793,14 +1872,16 @@ EXPLAIN SELECT * FROM t2 WHERE key1a = 5
                     {
                       "index": "i2_1",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i2_2",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -1904,6 +1985,13 @@ EXPLAIN SELECT * FROM t2 WHERE key1a = 5
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -1971,34 +2059,36 @@ EXPLAIN SELECT * FROM t1 WHERE (key1 > 1
                     {
                       "index": "i3",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i4",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i5",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i6",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i7",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     },
                     {
                       "index": "i8",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -2097,6 +2187,13 @@ EXPLAIN SELECT * FROM t1 WHERE (key1 > 1
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2180,6 +2277,8 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
                       ] /* key_parts */
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -2329,6 +2428,13 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
@@ -2393,9 +2499,11 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
                     {
                       "index": "colb",
                       "usable": false,
-                      "cause": "not_usable_by_conditions"
+                      "cause": "not_applicable"
                     }
                   ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
                   "group_index_range": {
                     "chosen": false,
                     "cause": "not_group_by_or_distinct"
@@ -2485,8 +2593,597 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
           }
         ] /* steps */
       } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+DROP TABLE t1;
+
+CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b));
+INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
+INSERT INTO t1 SELECT a + 8, 2 FROM t1;
+INSERT INTO t1 SELECT a + 16, 1 FROM t1;
+
+EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	bkey	NULL	NULL	NULL	32	Using where; Using filesort
+
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
+EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a	{
+  "steps": [
+    {
+      "expanded_query": "/* select#1 */ select `*` AS `*` from `test`.`t1` where (`b` between 1 and 2) order by `b`,`a`"
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(`test`.`t1`.`b` between 1 and 2)",
+              "after_equality_propagation": "(`test`.`t1`.`b` between 1 and 2)",
+              "after_constant_propagation": "(`test`.`t1`.`b` between 1 and 2)",
+              "after_trivial_conditions_removal": "(`test`.`t1`.`b` between 1 and 2)"
+            } /* condition_processing */
+          },
+          {
+            "ref-optimizer-key-uses": [
+            ] /* ref-optimizer-key-uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "t1",
+                "range_analysis": {
+                  "table_scan": {
+                    "records": 32,
+                    "cost": 10.57
+                  } /* table_scan */,
+                  "potential_range_indices": [
+                    {
+                      "index": "PRIMARY",
+                      "usable": false,
+                      "cause": "not_applicable"
+                    },
+                    {
+                      "index": "bkey",
+                      "usable": true,
+                      "key_parts": [
+                        "b"
+                      ] /* key_parts */
+                    }
+                  ] /* potential_range_indices */,
+                  "setup_range_conditions": [
+                  ] /* setup_range_conditions */,
+                  "group_index_range": {
+                    "chosen": false,
+                    "cause": "not_group_by_or_distinct"
+                  } /* group_index_range */,
+                  "analyzing_range_alternatives": {
+                    "range_scan_alternatives": [
+                      {
+                        "index": "bkey",
+                        "ranges": [
+                          "1 <= b <= 2"
+                        ] /* ranges */,
+                        "index_only": false,
+                        "records": 31,
+                        "cost": 38.21,
+                        "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 */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": [
+              {
+                "database": "test",
+                "table": "t1",
+                "best_access_path": {
+                  "considered_access_paths": [
+                    {
+                      "access_type": "scan",
+                      "using_join_cache": true,
+                      "records": 31,
+                      "cost": 2.2703,
+                      "chosen": true,
+                      "use_temp_table": true
+                    }
+                  ] /* considered_access_paths */
+                } /* best_access_path */,
+                "cost_for_plan": 2.2703,
+                "records_for_plan": 31,
+                "chosen": true
+              }
+            ] /* considered_execution_plans */
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": "(`test`.`t1`.`b` between 1 and 2)",
+              "attached_conditions": [
+                {
+                  "database": "test",
+                  "table": "t1",
+                  "attached": "(`test`.`t1`.`b` between 1 and 2)"
+                }
+              ] /* attached_conditions */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "t1",
+                "scan_type": "table"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
     }
   ] /* steps */
 }	0	0
 DROP TABLE t1;
-set optimizer_trace=default;
+SET optimizer_trace_features="greedy_search=off,dynamic_range=off";
+CREATE TABLE t1(c INT);
+INSERT INTO t1 VALUES (),();
+CREATE TABLE t2 (b INT, KEY(b));
+INSERT INTO t2 VALUES (),(),();
+EXPLAIN SELECT 1 FROM 
+(SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	0	const row not found
+2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2	
+2	DERIVED	t2	ALL	b	NULL	NULL	NULL	3	Range checked for each record (index map: 0x1)
+
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
+EXPLAIN SELECT 1 FROM 
+(SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2	{
+  "steps": [
+    {
+      "expanded_query": "/* select#1 */ select 1 AS `1` from (/* select#2 */ select 1 AS `1` from `test`.`t2` join `test`.`t1` where (`b` < `c`) group by 1 limit 1) `d2`"
+    },
+    {
+      "join_preparation": {
+        "select#": 2,
+        "steps": [
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 2,
+        "steps": [
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(`test`.`t2`.`b` < `test`.`t1`.`c`)",
+              "after_equality_propagation": "(`test`.`t2`.`b` < `test`.`t1`.`c`)",
+              "after_constant_propagation": "(`test`.`t2`.`b` < `test`.`t1`.`c`)",
+              "after_trivial_conditions_removal": "(`test`.`t2`.`b` < `test`.`t1`.`c`)"
+            } /* condition_processing */
+          },
+          {
+            "ref-optimizer-key-uses": [
+            ] /* ref-optimizer-key-uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "t2",
+                "table_scan": {
+                  "records": 3,
+                  "cost": 2
+                } /* table_scan */
+              },
+              {
+                "database": "test",
+                "table": "t1",
+                "table_scan": {
+                  "records": 2,
+                  "cost": 2
+                } /* table_scan */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": "..."
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": "(`test`.`t2`.`b` < `test`.`t1`.`c`)",
+              "attached_conditions": [
+                {
+                  "database": "test",
+                  "table": "t1",
+                  "attached": null
+                },
+                {
+                  "database": "test",
+                  "table": "t2",
+                  "rechecking_index_usage": {
+                    "database": "test",
+                    "table": "t2",
+                    "range_analysis": {
+                      "table_scan": {
+                        "records": 3,
+                        "cost": 5.6
+                      } /* table_scan */,
+                      "potential_range_indices": [
+                        {
+                          "index": "b",
+                          "usable": true,
+                          "key_parts": [
+                            "b"
+                          ] /* key_parts */
+                        }
+                      ] /* potential_range_indices */,
+                      "best_covering_index_scan": {
+                        "index": "b",
+                        "cost": 1.6465,
+                        "chosen": true
+                      } /* best_covering_index_scan */,
+                      "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": "b",
+                            "index_only": true,
+                            "records": 18446744073709551615,
+                            "cost": 0,
+                            "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 */
+                  } /* rechecking_index_usage */,
+                  "attached": "(`test`.`t2`.`b` < `test`.`t1`.`c`)"
+                }
+              ] /* attached_conditions */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "t1",
+                "scan_type": "table"
+              },
+              {
+                "database": "test",
+                "table": "t2",
+                "scan_type": "table"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 2,
+        "steps": [
+          {
+            "records_estimation_per_record": "..."
+          },
+          {
+            "records_estimation_per_record": "..."
+          }
+        ] /* steps */
+      } /* join_execution */
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "records_estimation": [
+              {
+                "database": "",
+                "table": "d2",
+                "records": 1,
+                "cost": 1,
+                "table_type": "system"
+              }
+            ] /* records_estimation */
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": null,
+              "attached_conditions": [
+              ] /* attached_conditions */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "refine_plan": [
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_execution": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_execution */
+          }
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+
+DROP TABLE t1,t2;
+CREATE TABLE `t1` (
+`mot` varchar(4) NOT NULL,
+`topic` int NOT NULL,
+PRIMARY KEY  (`mot`,`topic`)
+);
+INSERT INTO t1 VALUES ('joce','40143'), ('joce','43506');
+SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY topic);
+mot	topic
+
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
+SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY topic)	{
+  "steps": [
+    {
+      "expanded_query": "/* select#1 */ select `*` AS `*` from `test`.`t1` where `topic` = all (/* select#2 */ select `topic` from `test`.`t1` group by `topic`)"
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+                {
+                  "transformation": {
+                    "select#": 2,
+                    "from": "IN (SELECT)",
+                    "to": "EXISTS (CORRELATED SELECT)",
+                    "chosen": true
+                  } /* transformation */
+                }
+              ] /* steps */
+            } /* join_preparation */
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_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`)))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_equality_propagation": "<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`)))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_constant_propagation": "<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`)))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_trivial_conditions_removal": "<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`)))))"
+            } /* condition_processing */
+          },
+          {
+            "ref-optimizer-key-uses": [
+            ] /* ref-optimizer-key-uses */
+          },
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "t1",
+                "table_scan": {
+                  "records": 2,
+                  "cost": 2
+                } /* table_scan */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": "..."
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_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`)))))",
+              "attached_conditions": [
+                {
+                  "database": "test",
+                  "table": "t1",
+                  "attached": "<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`)))))"
+                }
+              ] /* attached_conditions */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "t1",
+                "scan_type": "index"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "HAVING",
+                          "original_condition": "(<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`))",
+                          "after_constant_propagation": "(<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`))",
+                          "after_trivial_conditions_removal": "(<cache>(`test`.`t1`.`topic`) <> <ref_null_helper>(`test`.`t1`.`topic`))"
+                        } /* condition_processing */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t1",
+                            "const_keys_added": {
+                              "keys": [
+                                "PRIMARY"
+                              ] /* keys */,
+                              "cause": "group_by"
+                            } /* const_keys_added */,
+                            "range_analysis": {
+                              "table_scan": {
+                                "records": 2,
+                                "cost": 4.5098
+                              } /* table_scan */,
+                              "potential_range_indices": [
+                                {
+                                  "index": "PRIMARY",
+                                  "usable": true,
+                                  "key_parts": [
+                                    "mot",
+                                    "topic"
+                                  ] /* key_parts */
+                                }
+                              ] /* potential_range_indices */,
+                              "best_covering_index_scan": {
+                                "index": "PRIMARY",
+                                "cost": 1.4303,
+                                "chosen": true
+                              } /* best_covering_index_scan */,
+                              "group_index_range": {
+                                "potential_group_range_indices": [
+                                  {
+                                    "index": "PRIMARY",
+                                    "covering": true,
+                                    "usable": false,
+                                    "cause": "group_attribute_not_prefix_in_index"
+                                  }
+                                ] /* potential_group_range_indices */
+                              } /* group_index_range */
+                            } /* range_analysis */
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "considered_execution_plans": "..."
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": null,
+                          "attached_conditions": [
+                            {
+                              "database": "test",
+                              "table": "t1",
+                              "rechecking_index_usage": {
+                                "database": "test",
+                                "table": "t1",
+                                "no_range_analysis": {
+                                  "cause": "no_indices_to_analyze"
+                                } /* no_range_analysis */
+                              } /* rechecking_index_usage */,
+                              "attached": null
+                            }
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                          {
+                            "database": "test",
+                            "table": "t1",
+                            "scan_type": "index"
+                          }
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
+          }
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+
+drop table t1;

=== added file 'mysql-test/r/optimizer_trace_subquery.result'
--- a/mysql-test/r/optimizer_trace_subquery.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/optimizer_trace_subquery.result	2010-12-13 14:03:16 +0000
@@ -0,0 +1,421 @@
+SET optimizer_trace_max_mem_size=1048576;
+SET optimizer_trace="enabled=on,end_marker=on,one_line=off";
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT, b INT);
+INSERT INTO t1 VALUES (2);
+INSERT INTO t2 VALUES (1,7),(2,7);
+# Subselect execute is traced every time it is executed
+SET @@optimizer_trace_features="greedy_search=off,repeated_subselect=on";
+SELECT (SELECT a FROM t1 WHERE t1.a=t2.a), a FROM t2;
+(SELECT a FROM t1 WHERE t1.a=t2.a)	a
+NULL	1
+2	2
+
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
+SELECT (SELECT a FROM t1 WHERE t1.a=t2.a), a FROM t2	{
+  "steps": [
+    {
+      "expanded_query": "/* select#1 */ select (/* select#2 */ select `a` from `test`.`t1` where (`t1`.`a` = `t2`.`a`)) AS `(SELECT a FROM t1 WHERE t1.a=t2.a)`,`a` AS `a` from `test`.`t2`"
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_preparation */
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "t2",
+                "table_scan": {
+                  "records": 2,
+                  "cost": 2
+                } /* table_scan */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": "..."
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": null,
+              "attached_conditions": [
+                {
+                  "database": "test",
+                  "table": "t2",
+                  "attached": null
+                }
+              ] /* attached_conditions */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "t2",
+                "scan_type": "table"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t1`.`a` = `test`.`t2`.`a`)",
+                          "after_equality_propagation": "(`test`.`t1`.`a` = `test`.`t2`.`a`)",
+                          "after_constant_propagation": "(`test`.`t1`.`a` = `test`.`t2`.`a`)",
+                          "after_trivial_conditions_removal": "(`test`.`t1`.`a` = `test`.`t2`.`a`)"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t1",
+                            "records": 1,
+                            "cost": 1,
+                            "table_type": "system"
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": "('2' = `test`.`t2`.`a`)",
+                          "attached_conditions": [
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
+          },
+          {
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
+          }
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+
+# Subselect execute is traced only the first time it is executed
+SET @@optimizer_trace_features="greedy_search=off,repeated_subselect=on";
+SELECT (SELECT a FROM t1 WHERE t1.a=t2.a), a FROM t2;
+(SELECT a FROM t1 WHERE t1.a=t2.a)	a
+NULL	1
+2	2
+
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
+SELECT (SELECT a FROM t1 WHERE t1.a=t2.a), a FROM t2	{
+  "steps": [
+    {
+      "expanded_query": "/* select#1 */ select (/* select#2 */ select `a` from `test`.`t1` where (`t1`.`a` = `t2`.`a`)) AS `(SELECT a FROM t1 WHERE t1.a=t2.a)`,`a` AS `a` from `test`.`t2`"
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_preparation */
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "records_estimation": [
+              {
+                "database": "test",
+                "table": "t2",
+                "table_scan": {
+                  "records": 2,
+                  "cost": 2
+                } /* table_scan */
+              }
+            ] /* records_estimation */
+          },
+          {
+            "considered_execution_plans": "..."
+          },
+          {
+            "attaching_conditions_to_tables": {
+              "original_condition": null,
+              "attached_conditions": [
+                {
+                  "database": "test",
+                  "table": "t2",
+                  "attached": null
+                }
+              ] /* attached_conditions */
+            } /* attaching_conditions_to_tables */
+          },
+          {
+            "refine_plan": [
+              {
+                "database": "test",
+                "table": "t2",
+                "scan_type": "table"
+              }
+            ] /* refine_plan */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+          {
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_optimization": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "condition_processing": {
+                          "condition": "WHERE",
+                          "original_condition": "(`test`.`t1`.`a` = `test`.`t2`.`a`)",
+                          "after_equality_propagation": "(`test`.`t1`.`a` = `test`.`t2`.`a`)",
+                          "after_constant_propagation": "(`test`.`t1`.`a` = `test`.`t2`.`a`)",
+                          "after_trivial_conditions_removal": "(`test`.`t1`.`a` = `test`.`t2`.`a`)"
+                        } /* condition_processing */
+                      },
+                      {
+                        "ref-optimizer-key-uses": [
+                        ] /* ref-optimizer-key-uses */
+                      },
+                      {
+                        "records_estimation": [
+                          {
+                            "database": "test",
+                            "table": "t1",
+                            "records": 1,
+                            "cost": 1,
+                            "table_type": "system"
+                          }
+                        ] /* records_estimation */
+                      },
+                      {
+                        "attaching_conditions_to_tables": {
+                          "original_condition": "('2' = `test`.`t2`.`a`)",
+                          "attached_conditions": [
+                          ] /* attached_conditions */
+                        } /* attaching_conditions_to_tables */
+                      },
+                      {
+                        "refine_plan": [
+                        ] /* refine_plan */
+                      }
+                    ] /* steps */
+                  } /* join_optimization */
+                },
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
+          },
+          {
+            "subselect_exec": {
+              "select#": 2,
+              "steps": [
+                {
+                  "join_execution": {
+                    "select#": 2,
+                    "steps": [
+                    ] /* steps */
+                  } /* join_execution */
+                }
+              ] /* steps */
+            } /* subselect_exec */
+          }
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+
+DROP TABLE t1,t2;
+SET @@optimizer_trace_features="default";
+CREATE TABLE t1 (a int, b int, c int);
+SELECT 50, 3, 3 FROM DUAL
+WHERE NOT EXISTS
+(SELECT * FROM t1 WHERE a = 50 AND b = 3);
+50	3	3
+50	3	3
+
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+QUERY	TRACE	MISSING_BYTES_BEYOND_MAX_MEM_SIZE	OS_MALLOC_ERROR
+SELECT 50, 3, 3 FROM DUAL
+WHERE NOT EXISTS
+(SELECT * FROM t1 WHERE a = 50 AND b = 3)	{
+  "steps": [
+    {
+      "expanded_query": "/* select#1 */ select 50 AS `50`,3 AS `3`,3 AS `3` from DUAL  where (not(exists(/* select#2 */ select `*` from `test`.`t1` where ((`a` = 50) and (`b` = 3)))))"
+    },
+    {
+      "join_preparation": {
+        "select#": 1,
+        "steps": [
+          {
+            "join_preparation": {
+              "select#": 2,
+              "steps": [
+              ] /* steps */
+            } /* join_preparation */
+          }
+        ] /* steps */
+      } /* join_preparation */
+    },
+    {
+      "join_optimization": {
+        "select#": 1,
+        "steps": [
+          {
+            "condition_processing": {
+              "condition": "WHERE",
+              "original_condition": "(not(exists(/* select#2 */ select 1 from `test`.`t1` where ((`test`.`t1`.`a` = 50) and (`test`.`t1`.`b` = 3)))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_equality_propagation": "(not(exists(/* select#2 */ select 1 from `test`.`t1` where ((`test`.`t1`.`a` = 50) and (`test`.`t1`.`b` = 3)))))",
+              "evaluate_subselect_cond_steps": [
+              ] /* evaluate_subselect_cond_steps */,
+              "after_constant_propagation": "(not(exists(/* select#2 */ select 1 from `test`.`t1` where ((`test`.`t1`.`a` = 50) and (`test`.`t1`.`b` = 3)))))",
+              "evaluate_subselect_cond_steps": [
+                {
+                  "subselect_exec": {
+                    "select#": 2,
+                    "steps": [
+                      {
+                        "join_optimization": {
+                          "select#": 2,
+                          "steps": [
+                            {
+                              "condition_processing": {
+                                "condition": "WHERE",
+                                "original_condition": "((`test`.`t1`.`a` = 50) and (`test`.`t1`.`b` = 3))",
+                                "after_equality_propagation": "(multiple equal(50, `test`.`t1`.`a`) and multiple equal(3, `test`.`t1`.`b`))",
+                                "after_constant_propagation": "(multiple equal(50, `test`.`t1`.`a`) and multiple equal(3, `test`.`t1`.`b`))",
+                                "after_trivial_conditions_removal": "(multiple equal(50, `test`.`t1`.`a`) and multiple equal(3, `test`.`t1`.`b`))"
+                              } /* condition_processing */
+                            },
+                            {
+                              "ref-optimizer-key-uses": [
+                              ] /* ref-optimizer-key-uses */
+                            },
+                            {
+                              "records_estimation": [
+                                {
+                                  "database": "test",
+                                  "table": "t1",
+                                  "records": 1,
+                                  "cost": 1,
+                                  "table_type": "system"
+                                }
+                              ] /* records_estimation */
+                            }
+                          ] /* steps */,
+                          "empty_result": {
+                            "cause": "no matching row in const table"
+                          } /* empty_result */
+                        } /* join_optimization */
+                      },
+                      {
+                        "join_execution": {
+                          "select#": 2,
+                          "steps": [
+                          ] /* steps */
+                        } /* join_execution */
+                      }
+                    ] /* steps */
+                  } /* subselect_exec */
+                }
+              ] /* evaluate_subselect_cond_steps */,
+              "after_trivial_conditions_removal": null
+            } /* condition_processing */
+          }
+        ] /* steps */
+      } /* join_optimization */
+    },
+    {
+      "join_execution": {
+        "select#": 1,
+        "steps": [
+        ] /* steps */
+      } /* join_execution */
+    }
+  ] /* steps */
+}	0	0
+
+DROP TABLE t1;

=== modified file 'mysql-test/suite/sys_vars/r/optimizer_trace_features_basic.result'
--- a/mysql-test/suite/sys_vars/r/optimizer_trace_features_basic.result	2010-11-23 10:21:53 +0000
+++ b/mysql-test/suite/sys_vars/r/optimizer_trace_features_basic.result	2010-12-13 14:03:16 +0000
@@ -1,45 +1,45 @@
 SET @start_global_value = @@global.optimizer_trace_features;
 SELECT @start_global_value;
 @start_global_value
-greedy_search=on,range_optimizer=on
+greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 select @@global.optimizer_trace_features;
 @@global.optimizer_trace_features
-greedy_search=on,range_optimizer=on
+greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 select @@session.optimizer_trace_features;
 @@session.optimizer_trace_features
-greedy_search=on,range_optimizer=on
+greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 show global variables like 'optimizer_trace_features';
 Variable_name	Value
-optimizer_trace_features	greedy_search=on,range_optimizer=on
+optimizer_trace_features	greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 show session variables like 'optimizer_trace_features';
 Variable_name	Value
-optimizer_trace_features	greedy_search=on,range_optimizer=on
+optimizer_trace_features	greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 select * from information_schema.global_variables where variable_name='optimizer_trace_features';
 VARIABLE_NAME	VARIABLE_VALUE
-OPTIMIZER_TRACE_FEATURES	greedy_search=on,range_optimizer=on
+OPTIMIZER_TRACE_FEATURES	greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 select * from information_schema.session_variables where variable_name='optimizer_trace_features';
 VARIABLE_NAME	VARIABLE_VALUE
-OPTIMIZER_TRACE_FEATURES	greedy_search=on,range_optimizer=on
+OPTIMIZER_TRACE_FEATURES	greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off
 set global optimizer_trace_features=2;
 select @@global.optimizer_trace_features;
 @@global.optimizer_trace_features
-greedy_search=off,range_optimizer=on
+greedy_search=off,range_optimizer=on,dynamic_range=off,repeated_subselect=off
 set session optimizer_trace_features=2;
 select @@session.optimizer_trace_features;
 @@session.optimizer_trace_features
-greedy_search=off,range_optimizer=on
+greedy_search=off,range_optimizer=on,dynamic_range=off,repeated_subselect=off
 set global optimizer_trace_features=0;
 select @@global.optimizer_trace_features;
 @@global.optimizer_trace_features
-greedy_search=off,range_optimizer=off
+greedy_search=off,range_optimizer=off,dynamic_range=off,repeated_subselect=off
 set session optimizer_trace_features=0;
 select @@session.optimizer_trace_features;
 @@session.optimizer_trace_features
-greedy_search=off,range_optimizer=off
+greedy_search=off,range_optimizer=off,dynamic_range=off,repeated_subselect=off
 set session optimizer_trace_features=default;
 select @@session.optimizer_trace_features;
 @@session.optimizer_trace_features
-greedy_search=off,range_optimizer=off
+greedy_search=off,range_optimizer=off,dynamic_range=off,repeated_subselect=off
 set global optimizer_trace_features=1.1;
 ERROR 42000: Incorrect argument type to variable 'optimizer_trace_features'
 set global optimizer_trace_features=1e1;
@@ -49,4 +49,4 @@ ERROR 42000: Variable 'optimizer_trace_f
 SET @@global.optimizer_trace_features = @start_global_value;
 SELECT @@global.optimizer_trace_features;
 @@global.optimizer_trace_features
-greedy_search=on,range_optimizer=on
+greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=off

=== modified file 'mysql-test/t/optimizer_trace_range.test'
--- a/mysql-test/t/optimizer_trace_range.test	2010-11-22 09:59:17 +0000
+++ b/mysql-test/t/optimizer_trace_range.test	2010-12-13 14:03:16 +0000
@@ -168,4 +168,46 @@ SELECT * FROM information_schema.OPTIMIZ
 
 DROP TABLE t1;
 
-set optimizer_trace=default;
+--echo
+CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b));
+INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
+INSERT INTO t1 SELECT a + 8, 2 FROM t1;
+INSERT INTO t1 SELECT a + 16, 1 FROM t1;
+
+--echo
+# Make quick select for ordering inside test_if_skip_sort_order
+EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
+--echo
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+
+DROP TABLE t1;
+
+# Test that range optimization is not shown for every outer record 
+# when there is a dynamic range.
+SET optimizer_trace_features="greedy_search=off,dynamic_range=off";
+CREATE TABLE t1(c INT);
+INSERT INTO t1 VALUES (),();
+CREATE TABLE t2 (b INT, KEY(b));
+INSERT INTO t2 VALUES (),(),();
+EXPLAIN SELECT 1 FROM 
+ (SELECT 1 FROM t2,t1 WHERE b < c GROUP BY 1 LIMIT 1) AS d2;
+--echo
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+--echo
+
+DROP TABLE t1,t2;
+
+CREATE TABLE `t1` (
+      `mot` varchar(4) NOT NULL,
+      `topic` int NOT NULL,
+       PRIMARY KEY  (`mot`,`topic`)
+    );
+INSERT INTO t1 VALUES ('joce','40143'), ('joce','43506');
+
+# rechecking_index_usage/no_indices_to_analyze
+SELECT * from t1 where topic = all (SELECT topic FROM t1 GROUP BY topic);
+--echo
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+--echo
+
+drop table t1;
\ No newline at end of file

=== added file 'mysql-test/t/optimizer_trace_subquery.test'
--- a/mysql-test/t/optimizer_trace_subquery.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/optimizer_trace_subquery.test	2010-12-13 14:03:16 +0000
@@ -0,0 +1,39 @@
+--source include/have_optimizer_trace.inc
+
+SET optimizer_trace_max_mem_size=1048576; # 1MB
+SET optimizer_trace="enabled=on,end_marker=on,one_line=off";
+
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (a INT, b INT);
+INSERT INTO t1 VALUES (2);
+INSERT INTO t2 VALUES (1,7),(2,7);
+
+--echo # Subselect execute is traced every time it is executed
+SET @@optimizer_trace_features="greedy_search=off,repeated_subselect=on";
+SELECT (SELECT a FROM t1 WHERE t1.a=t2.a), a FROM t2;
+--echo
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+--echo
+
+--echo # Subselect execute is traced only the first time it is executed
+SET @@optimizer_trace_features="greedy_search=off,repeated_subselect=on";
+SELECT (SELECT a FROM t1 WHERE t1.a=t2.a), a FROM t2;
+--echo
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+--echo
+
+DROP TABLE t1,t2;
+SET @@optimizer_trace_features="default";
+
+
+# evaluate_subquery_cond_step (subquery eval during optimize_cond)
+CREATE TABLE t1 (a int, b int, c int);
+
+SELECT 50, 3, 3 FROM DUAL
+WHERE NOT EXISTS
+  (SELECT * FROM t1 WHERE a = 50 AND b = 3);
+--echo
+SELECT * FROM information_schema.OPTIMIZER_TRACE;
+--echo
+
+DROP TABLE t1;
\ No newline at end of file

=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc	2010-09-27 09:26:39 +0000
+++ b/sql/item_subselect.cc	2010-12-13 14:03:16 +0000
@@ -46,10 +46,10 @@ inline Item * and_items(Item* cond, Item
 }
 
 Item_subselect::Item_subselect():
-  Item_result_field(), value_assigned(0), thd(0), substitution(0),
-  engine(0), old_engine(0), used_tables_cache(0), have_to_be_excluded(0),
-  const_item_cache(1), engine_changed(0), changed(0),
-  is_correlated(FALSE)
+  Item_result_field(), value_assigned(0), executed_before(false), 
+  thd(0), substitution(0), engine(0), old_engine(0), 
+  used_tables_cache(0), have_to_be_excluded(0), const_item_cache(1), 
+  engine_changed(0), changed(0), is_correlated(FALSE)
 {
   with_subselect= 1;
   reset();
@@ -309,6 +309,26 @@ bool Item_subselect::exec()
   */
   DBUG_EXECUTE_IF("subselect_exec_fail", return 1;);
 
+  /*
+    Disable tracing of subquery execution if
+    1) this is not the first time the subselect is executed, and
+    2) REPEATED_SUBSELECT is disabled
+  */
+  bool disable_trace= false;
+  bool repeated_trace_enabled= thd->opt_trace ? 
+    thd->opt_trace->feature_enabled(Opt_trace_context::REPEATED_SUBSELECT) :
+    false;
+  if (executed_before && !repeated_trace_enabled)
+    disable_trace= true;
+  Opt_trace_disable_I_S disable_trace_wrapper(thd->opt_trace, disable_trace);
+  executed_before= true;
+
+  Opt_trace_context * const trace= thd->opt_trace;
+  Opt_trace_object trace_wrapper(trace);
+  Opt_trace_object trace_exec(trace, "subselect_exec");
+  opt_trace_add_select_number(&trace_exec, get_select_lex()->select_number);
+  Opt_trace_array trace_steps(trace, "steps");
+
   res= engine->exec();
 
   if (engine_changed)

=== modified file 'sql/item_subselect.h'
--- a/sql/item_subselect.h	2010-10-19 12:56:36 +0000
+++ b/sql/item_subselect.h	2010-12-13 14:03:16 +0000
@@ -45,6 +45,7 @@ typedef Comp_creator* (*chooser_compare_
 class Item_subselect :public Item_result_field
 {
   my_bool value_assigned; /* value already assigned to subselect */
+  bool executed_before;
 public:
   /* thread handler, will be assigned in fix_fields only */
   THD *thd;

=== modified file 'sql/opt_range.cc'
--- a/sql/opt_range.cc	2010-11-24 18:54:26 +0000
+++ b/sql/opt_range.cc	2010-12-13 14:03:16 +0000
@@ -2472,7 +2472,11 @@ int SQL_SELECT::test_quick_select(THD *t
   needed_reg.clear_all();
   quick_keys.clear_all();
   if (keys_to_use.is_clear_all())
+  {
+    Opt_trace_object (thd->opt_trace, "no_range_analysis").
+      add_alnum("cause", "no_indices_to_analyze");
     DBUG_RETURN(0);
+  }
   records= head->file->stats.records;
   if (!records)
     records++;					/* purecov: inspected */
@@ -2556,7 +2560,7 @@ int SQL_SELECT::test_quick_select(THD *t
         if (!keys_to_use.is_set(idx))
         {
           trace_idx_details.add("usable", false).
-            add_alnum("cause", "not_usable_by_conditions");
+            add_alnum("cause", "not_applicable");
           continue;
         }
         if (key_info->flags & HA_FULLTEXT)
@@ -2623,7 +2627,14 @@ int SQL_SELECT::test_quick_select(THD *t
 
     if (cond)
     {
-      if ((tree= get_mm_tree(&param,cond)))
+      {
+        //Guilhem: this is needed because we might evaluate a subquery
+        //inside get_mm_tree, but if you have a better suggestion I'm
+        //all ears. I don't like this tracepoint very much.
+        Opt_trace_array trace_setup_cond(trace, "setup_range_conditions");
+        tree= get_mm_tree(&param,cond);
+      }
+      if (tree)
       {
         if (tree->type == SEL_TREE::IMPOSSIBLE)
         {
@@ -6556,6 +6567,7 @@ get_mm_leaf(RANGE_OPT_PARAM *param, Item
 end:
   if (impossible_cond_cause)
   {
+    Opt_trace_object wrapper (param->thd->opt_trace);
     Opt_trace_object (param->thd->opt_trace, "impossible_condition",
                       Opt_trace_context::RANGE_OPTIMIZER).
       add_utf8("table", *field->table_name).

=== modified file 'sql/opt_trace.cc'
--- a/sql/opt_trace.cc	2010-11-24 18:54:26 +0000
+++ b/sql/opt_trace.cc	2010-12-13 14:03:16 +0000
@@ -381,11 +381,13 @@ const char *Opt_trace_context::flag_name
 
 const char *Opt_trace_context::feature_names[]=
 {
-  "greedy_search", "range_optimizer", "default", NullS
+  "greedy_search", "range_optimizer", "dynamic_range", 
+  "repeated_subselect", "default", NullS
 };
 
 const Opt_trace_context::feature_value Opt_trace_context::FEATURES_DEFAULT=
   Opt_trace_context::feature_value(Opt_trace_context::GREEDY_SEARCH |
+                                   Opt_trace_context::DYNAMIC_RANGE |
                                    Opt_trace_context::RANGE_OPTIMIZER);
 
 Opt_trace_context::Opt_trace_context(void):

=== modified file 'sql/opt_trace.h'
--- a/sql/opt_trace.h	2010-12-03 15:26:41 +0000
+++ b/sql/opt_trace.h	2010-12-13 14:03:16 +0000
@@ -372,13 +372,18 @@ public:
      @li "greedy_search" = the greedy search for a plan
      @li "range_optimizer" = the cost analysis of accessing data through
      ranges in indices
+     @li "dynamic_range" = the range optimization performed for each record 
+                           when access method is dynamic range (off by default)
+     @li "repeated_subselect" = 
      @li "default".
   */
   static const char *feature_names[];
   /** Features' numeric values for @@@@optimizer_trace_features variable */
   enum feature_value {
     GREEDY_SEARCH= 1,
-    RANGE_OPTIMIZER= 2, ///@todo join cache, semijoin...
+    RANGE_OPTIMIZER= 2,
+    DYNAMIC_RANGE= 4,
+    REPEATED_SUBSELECT= 8, ///@todo join cache, semijoin...
     /*
       if you add here, update feature_value of empty implementation
       and FEATURES_DEFAULT!
@@ -452,6 +457,11 @@ public:
   */
   bool set_query(const char* query, size_t length, CHARSET_INFO *charset);
 
+  bool feature_enabled(feature_value arg)
+  {
+    return features & arg;
+  }
+
 private:
 
   /**
@@ -1360,6 +1370,8 @@ public:
   enum feature_value {
     GREEDY_SEARCH= 1,
     RANGE_OPTIMIZER= 2,
+    DYNAMIC_RANGE= 4,
+    REPEATED_SUBSELECT= 8,
     MISC= 128
   };
 };

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-12-09 07:34:09 +0000
+++ b/sql/sql_select.cc	2010-12-13 14:03:16 +0000
@@ -2663,9 +2663,6 @@ JOIN::optimize()
 setup_subq_exit:
 
   DBUG_ASSERT(zero_result_cause != NULL);
-  trace_steps.end();   // because all steps are done
-  Opt_trace_object trace_empty_result(trace, "empty_result");
-  trace_empty_result.add_alnum("cause", zero_result_cause);
   /*
     Even with zero matching rows, subqueries in the HAVING clause may
     need to be evaluated if there are aggregate functions in the
@@ -2674,6 +2671,11 @@ setup_subq_exit:
   */
   if (setup_subquery_materialization())
     DBUG_RETURN(1);
+
+  trace_steps.end();   // because all steps are done
+  Opt_trace_object trace_empty_result(trace, "empty_result");
+  trace_empty_result.add_alnum("cause", zero_result_cause);
+
   error= 0;
   DBUG_RETURN(0);
 }
@@ -2792,6 +2794,12 @@ JOIN::save_join_tab()
 void
 JOIN::exec()
 {
+  Opt_trace_context * const trace= thd->opt_trace;
+  Opt_trace_object trace_wrapper(trace);
+  Opt_trace_object trace_exec(trace, "join_execution");
+  opt_trace_add_select_number(&trace_exec, select_lex->select_number);
+  Opt_trace_array trace_steps(trace, "steps");
+
   List<Item> *columns_list= &fields_list;
   int      tmp_error;
   DBUG_ENTER("JOIN::exec");
@@ -4737,7 +4745,6 @@ make_join_statistics(JOIN *join, TABLE_L
   join->const_table_map= 0;
 
   {
-    Opt_trace_object trace_wrapper(trace);
     for (POSITION *p_pos= join->positions, *p_end= p_pos + const_count;
          p_pos < p_end ;
          p_pos++)
@@ -4921,6 +4928,7 @@ make_join_statistics(JOIN *join, TABLE_L
       }
     }
 
+    Opt_trace_object trace_wrapper(trace);
     {
       /* Calc how many (possible) matched records in each table */
       Opt_trace_array trace_records(trace, "records_estimation");
@@ -7611,17 +7619,22 @@ choose_plan(JOIN *join, table_map join_t
             jtab_sort_func, (void*)join->emb_sjm_nest);
   join->cur_sj_inner_tables= 0;
 
-  if (straight_join)
   {
-    optimize_straight_join(join, join_tables);
-  }
-  else
-  {
-    if (search_depth == 0)
-      /* Automatically determine a reasonable value for 'search_depth' */
-      search_depth= determine_search_depth(join);
-    if (greedy_search(join, join_tables, search_depth, prune_level))
-      DBUG_RETURN(TRUE);
+    Opt_trace_object wrapper(join->thd->opt_trace);
+    Opt_trace_array trace_plan(join->thd->opt_trace, "considered_execution_plans",
+                               Opt_trace_context::GREEDY_SEARCH);
+    if (straight_join)
+    {
+      optimize_straight_join(join, join_tables);
+    }
+    else
+    {
+      if (search_depth == 0)
+        /* Automatically determine a reasonable value for 'search_depth' */
+        search_depth= determine_search_depth(join);
+      if (greedy_search(join, join_tables, search_depth, prune_level))
+        DBUG_RETURN(TRUE);
+    }
   }
 
   /* 
@@ -7823,6 +7836,9 @@ optimize_straight_join(JOIN *join, table
  
   for (JOIN_TAB **pos= join->best_ref + idx ; (s= *pos) ; pos++)
   {
+    Opt_trace_object trace_table(join->thd->opt_trace);
+    trace_table.add_utf8_table(s->table);
+
     /* Find the best access method from 's' to the current partial plan */
     best_access_path(join, s, join_tables, idx, FALSE, record_count,
                      join->positions + idx, &loose_scan_pos);
@@ -7833,6 +7849,8 @@ optimize_straight_join(JOIN *join, table
     advance_sj_state(join, join_tables, s, idx, &record_count, &read_time,
                      &loose_scan_pos);
 
+    trace_table.add("cost_for_plan", read_time).
+      add("records_for_plan", record_count);
     join_tables&= ~(s->table->map);
     ++idx;
   }
@@ -8014,7 +8032,6 @@ greedy_search(JOIN      *join,
   POSITION  best_pos;
   JOIN_TAB  *best_table; // the next plan node to be added to the curr QEP
   uint      n_tables; // ==join->tables or # tables in the sj-mat nest we're optimizing
-  Opt_trace_context * const opt_trace= join->thd->opt_trace;
   DBUG_ENTER("greedy_search");
 
   /* number of tables that remain to be optimized */
@@ -8023,10 +8040,6 @@ greedy_search(JOIN      *join,
                                          join->emb_sjm_nest->sj_inner_tables :
                                          ~(table_map)0));
 
-  Opt_trace_object trace_wrapper(opt_trace);
-  Opt_trace_array trace_plans(opt_trace, "considered_execution_plans",
-                              Opt_trace_context::GREEDY_SEARCH);
-
   do {
     /* Find the extension of the current QEP with the lowest cost */
     join->best_read= DBL_MAX;
@@ -9839,6 +9852,10 @@ static bool make_join_select(JOIN *join,
 	       join->best_positions[i].records_read &&
 	       !(join->select_options & OPTION_FOUND_ROWS)))
 	  {
+            Opt_trace_object trace_table(join->thd->opt_trace, 
+                                         "rechecking_index_usage");
+            trace_table.add_utf8_table(tab->table);
+
 	    /* Join with outer join condition */
 	    Item *orig_cond=sel->cond;
 	    sel->cond= and_conds(sel->cond, *tab->on_expr_ref);
@@ -14565,19 +14582,38 @@ optimize_cond(JOIN *join, Item *conds, L
     trace_cond.add("original_condition", conds);
     if (build_equalities)
     {
-      conds= build_equal_items(join->thd, conds, NULL, join_list,
-                               &join->cond_equal);
+      {
+        //Guilhem: Let me know if you have a suggestion for how to
+        //move these three "evaluate_subselect_cond_steps" tracepoints
+        //to one location
+        Opt_trace_disable_I_S disable_trace_wrapper(trace, 
+                                                    !conds->with_subselect);
+        Opt_trace_array trace_subselect(trace, "evaluate_subselect_cond_steps");
+        conds= build_equal_items(join->thd, conds, NULL, join_list,
+                                 &join->cond_equal);
+      }
       trace_cond.add("after_equality_propagation", conds);
     }
-    /* change field = field to field = const for each found field = const */
-    propagate_cond_constants(thd, (I_List<COND_CMP> *) 0, conds, conds);
+
+    {
+      Opt_trace_disable_I_S disable_trace_wrapper(trace, 
+                                                  !conds->with_subselect);
+      Opt_trace_array trace_subselect(trace, "evaluate_subselect_cond_steps");
+      /* change field = field to field = const for each found field = const */
+      propagate_cond_constants(thd, (I_List<COND_CMP> *) 0, conds, conds);
+    }
     /*
       Remove all instances of item == item
       Remove all and-levels where CONST item != CONST item
     */
     trace_cond.add("after_constant_propagation", conds);
     DBUG_EXECUTE("where",print_where(conds,"after const change", QT_ORDINARY););
-    conds= remove_eq_conds(thd, conds, cond_value) ;
+    {
+      Opt_trace_disable_I_S disable_trace_wrapper(trace, 
+                                                  !conds->with_subselect);
+      Opt_trace_array trace_subselect(trace, "evaluate_subselect_cond_steps");
+      conds= remove_eq_conds(thd, conds, cond_value) ;
+    }
     trace_cond.add("after_trivial_conditions_removal", conds);
   }
   DBUG_RETURN(conds);
@@ -18372,6 +18408,21 @@ join_read_prev_same(READ_RECORD *info)
 static int
 join_init_quick_read_record(JOIN_TAB *tab)
 {
+  /* This is for QS_DYNAMIC_RANGE, i.e., "Range checked for each
+     record". The trace for the range analysis below this point will
+     be printed with different ranges for every record to the left of
+     this table in the join.
+   */
+  // Guilhem: should we do like for REPEATED_SUBQUERY feature here,
+  // i.e., show the first optimization but not 2nd...Nth? That will
+  // require a new variable similar to executed_before (see
+  // changes in item_subselect.cc
+  Opt_trace_object wrapper(tab->join->thd->opt_trace);
+  Opt_trace_object trace_table(tab->join->thd->opt_trace,
+                               "records_estimation_per_record", 
+                               Opt_trace_context::DYNAMIC_RANGE);
+  trace_table.add_utf8_table(tab->table);
+
   if (test_if_quick_select(tab) == -1)
     return -1;					/* No possible records */
   return join_init_read_record(tab);
@@ -20013,6 +20064,12 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
           key_map new_ref_key_map;  // Force the creation of quick select
           new_ref_key_map.set_bit(new_ref_key); // only for new_ref_key.
 
+          Opt_trace_context * const trace= tab->join->thd->opt_trace;
+          Opt_trace_object trace_wrapper(trace);
+          Opt_trace_object trace_recest(trace, 
+                                    "records_estimation_for_index_ordering");
+          trace_recest.add_utf8_table(tab->table).
+          add_utf8("index", table->key_info[new_ref_key].name);
           if (select->test_quick_select(tab->join->thd, new_ref_key_map, 0,
                                         (tab->join->select_options &
                                          OPTION_FOUND_ROWS) ?
@@ -20062,6 +20119,13 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
       bool quick_created= FALSE;
       if (table->quick_keys.is_set(best_key) && best_key != ref_key)
       {
+        Opt_trace_context * const trace= join->thd->opt_trace;
+        Opt_trace_object trace_wrapper(trace);
+        Opt_trace_object trace_recest(trace, 
+                                     "records_estimation_for_index_ordering");
+        trace_recest.add_utf8_table(tab->table).
+          add_utf8("index", table->key_info[best_key].name);
+
         key_map map;           // Force the creation of quick select
         map.set_bit(best_key); // only best_key.
         quick_created=         

Attachment: [text/bzr-bundle] bzr/jorgen.loland@oracle.com-20101213140316-v20mgajcaruau5p3.bundle
Thread
bzr commit into mysql-next-mr-bugfixing branch (jorgen.loland:3242) WL#4800Jorgen Loland13 Dec