List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:November 8 2011 9:04am
Subject:bzr push into mysql-trunk branch (jorgen.loland:3475 to 3476) WL#5585
View as plain text  
 3476 Jorgen Loland	2011-11-08 [merge]
      Merge WL#5585 to opt-backporting

    modified:
      mysql-test/suite/opt_trace/r/charset.result
      mysql-test/suite/opt_trace/r/general2_no_prot.result
      mysql-test/suite/opt_trace/r/general2_ps_prot.result
      mysql-test/suite/opt_trace/r/general_no_prot_all.result
      mysql-test/suite/opt_trace/r/general_no_prot_none.result
      mysql-test/suite/opt_trace/r/general_ps_prot_all.result
      mysql-test/suite/opt_trace/r/general_ps_prot_none.result
      mysql-test/suite/opt_trace/r/range_no_prot.result
      mysql-test/suite/opt_trace/r/range_ps_prot.result
      sql/mysqld.cc
      sql/mysqld.h
      sql/opt_explain.cc
      sql/sql_lex.h
      sql/sql_select.cc
      sql/sql_select.h
      sql/sql_union.cc
 3475 Roy Lyseng	2011-11-07
      Bug#13340270: assertion table->sort.record_pointers == __null
      
      bug#12694872 fixed a memory leak in Unique::get(), but did not expect
      Unique::get() to be called twice before the end of the query, where
      buffers are freed.
      
      The solution to this problem is to free the filesort buffers if the
      Unique object is reused.
      
      mysql-test/include/subquery_sj.inc
        Added test case for bug#13340270
      
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
        Added test case results for bug#13340270
      
      sql/opt_range.cc
        In QUICK_INDEX_MERGE_SELECT::read_keys_and_merge(), delete existing
        filesort buffers when reusing a Unique buffer.

    modified:
      mysql-test/include/subquery_sj.inc
      mysql-test/r/subquery_sj_all.result
      mysql-test/r/subquery_sj_all_bka.result
      mysql-test/r/subquery_sj_all_bka_nixbnl.result
      mysql-test/r/subquery_sj_all_bkaunique.result
      mysql-test/r/subquery_sj_dupsweed.result
      mysql-test/r/subquery_sj_dupsweed_bka.result
      mysql-test/r/subquery_sj_dupsweed_bka_nixbnl.result
      mysql-test/r/subquery_sj_dupsweed_bkaunique.result
      mysql-test/r/subquery_sj_firstmatch.result
      mysql-test/r/subquery_sj_firstmatch_bka.result
      mysql-test/r/subquery_sj_firstmatch_bka_nixbnl.result
      mysql-test/r/subquery_sj_firstmatch_bkaunique.result
      mysql-test/r/subquery_sj_loosescan.result
      mysql-test/r/subquery_sj_loosescan_bka.result
      mysql-test/r/subquery_sj_loosescan_bka_nixbnl.result
      mysql-test/r/subquery_sj_loosescan_bkaunique.result
      mysql-test/r/subquery_sj_mat.result
      mysql-test/r/subquery_sj_mat_bka.result
      mysql-test/r/subquery_sj_mat_bka_nixbnl.result
      mysql-test/r/subquery_sj_mat_bkaunique.result
      mysql-test/r/subquery_sj_mat_nosj.result
      mysql-test/r/subquery_sj_none.result
      mysql-test/r/subquery_sj_none_bka.result
      mysql-test/r/subquery_sj_none_bka_nixbnl.result
      mysql-test/r/subquery_sj_none_bkaunique.result
      sql/opt_range.cc
=== modified file 'mysql-test/suite/opt_trace/r/charset.result'
--- a/mysql-test/suite/opt_trace/r/charset.result	2011-09-22 12:51:05 +0000
+++ b/mysql-test/suite/opt_trace/r/charset.result	2011-10-10 09:08:15 +0000
@@ -68,11 +68,11 @@ explain extended select '���, _latin1
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }
@@ -135,11 +135,11 @@ explain extended select 'ÁÂÃÄÅ', _l
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }

=== modified file 'mysql-test/suite/opt_trace/r/general2_no_prot.result'
--- a/mysql-test/suite/opt_trace/r/general2_no_prot.result	2011-10-13 13:22:45 +0000
+++ b/mysql-test/suite/opt_trace/r/general2_no_prot.result	2011-11-08 09:02:58 +0000
@@ -2714,7 +2714,7 @@ from t0 where a in
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -3230,14 +3230,14 @@ from t0 where a in
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/general2_ps_prot.result'
--- a/mysql-test/suite/opt_trace/r/general2_ps_prot.result	2011-10-13 13:22:45 +0000
+++ b/mysql-test/suite/opt_trace/r/general2_ps_prot.result	2011-11-08 09:02:58 +0000
@@ -2767,7 +2767,7 @@ from t0 where a in
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -3283,14 +3283,14 @@ from t0 where a in
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/general_no_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/general_no_prot_all.result	2011-11-03 14:17:25 +0000
+++ b/mysql-test/suite/opt_trace/r/general_no_prot_all.result	2011-11-08 09:02:58 +0000
@@ -281,7 +281,7 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -376,14 +376,14 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1655,11 +1655,11 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1790,7 +1790,7 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1949,14 +1949,14 @@ explain SELECT c FROM t5 where c+1 in (s
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2108,7 +2108,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2187,14 +2187,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2342,7 +2342,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2421,14 +2421,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2594,7 +2594,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2697,14 +2697,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2870,7 +2870,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2973,14 +2973,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3166,11 +3166,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3280,11 +3280,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3484,7 +3484,7 @@ where a1 in (select b1 from t2_16 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -3587,14 +3587,14 @@ where a1 in (select b1 from t2_16 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4529,7 +4529,7 @@ concat(c1,'y') IN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -4608,11 +4608,11 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 3,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           },
           {
             "join_optimization": {
@@ -4690,14 +4690,14 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10552,11 +10552,11 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10850,18 +10850,18 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/general_no_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/general_no_prot_none.result	2011-10-13 13:22:45 +0000
+++ b/mysql-test/suite/opt_trace/r/general_no_prot_none.result	2011-11-08 09:02:58 +0000
@@ -280,7 +280,7 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -375,14 +375,14 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1475,7 +1475,7 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1634,14 +1634,14 @@ explain SELECT c FROM t5 where c+1 in (s
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1764,7 +1764,7 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1923,14 +1923,14 @@ explain SELECT c FROM t5 where c+1 in (s
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2082,7 +2082,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2161,14 +2161,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2316,7 +2316,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2395,14 +2395,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2568,7 +2568,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2671,14 +2671,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2844,7 +2844,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2947,14 +2947,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3140,11 +3140,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3254,11 +3254,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3457,7 +3457,7 @@ where a1 in (select b1 from t2_16 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -3560,14 +3560,14 @@ where a1 in (select b1 from t2_16 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4505,7 +4505,7 @@ concat(c1,'y') IN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -4608,11 +4608,11 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 3,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           },
           {
             "join_optimization": {
@@ -4714,14 +4714,14 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10027,11 +10027,11 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10325,18 +10325,18 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/general_ps_prot_all.result'
--- a/mysql-test/suite/opt_trace/r/general_ps_prot_all.result	2011-11-03 14:17:25 +0000
+++ b/mysql-test/suite/opt_trace/r/general_ps_prot_all.result	2011-11-08 09:02:58 +0000
@@ -281,7 +281,7 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -376,14 +376,14 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1635,11 +1635,11 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1770,7 +1770,7 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1929,14 +1929,14 @@ explain SELECT c FROM t5 where c+1 in (s
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2088,7 +2088,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2167,14 +2167,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2322,7 +2322,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2401,14 +2401,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2574,7 +2574,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2677,14 +2677,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2850,7 +2850,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2953,14 +2953,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3146,11 +3146,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3260,11 +3260,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3464,7 +3464,7 @@ where a1 in (select b1 from t2_16 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -3567,14 +3567,14 @@ where a1 in (select b1 from t2_16 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4509,7 +4509,7 @@ concat(c1,'y') IN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -4588,11 +4588,11 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 3,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           },
           {
             "join_optimization": {
@@ -4670,14 +4670,14 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10528,11 +10528,11 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10808,18 +10808,18 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/general_ps_prot_none.result'
--- a/mysql-test/suite/opt_trace/r/general_ps_prot_none.result	2011-10-13 13:22:45 +0000
+++ b/mysql-test/suite/opt_trace/r/general_ps_prot_none.result	2011-11-08 09:02:58 +0000
@@ -280,7 +280,7 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -375,14 +375,14 @@ EXPLAIN SELECT (SELECT 1 FROM t6 WHERE d
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1455,7 +1455,7 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1614,14 +1614,14 @@ explain SELECT c FROM t5 where c+1 in (s
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1744,7 +1744,7 @@ explain SELECT c FROM t5 where c+1 in (s
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1903,14 +1903,14 @@ explain SELECT c FROM t5 where c+1 in (s
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2062,7 +2062,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2141,14 +2141,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2296,7 +2296,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2375,14 +2375,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2548,7 +2548,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2651,14 +2651,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2824,7 +2824,7 @@ explain extended select * from t1 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -2927,14 +2927,14 @@ explain extended select * from t1 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3120,11 +3120,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3234,11 +3234,11 @@ explain select * from t1,t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3437,7 +3437,7 @@ where a1 in (select b1 from t2_16 where 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -3540,14 +3540,14 @@ where a1 in (select b1 from t2_16 where 
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4475,7 +4475,7 @@ concat(c1,'y') IN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -4578,11 +4578,11 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 3,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           },
           {
             "join_optimization": {
@@ -4684,14 +4684,14 @@ concat(c1,'y') IN
             } /* join_optimization */
           },
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -9961,11 +9961,11 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -10241,18 +10241,18 @@ explain select * from v1 where id="b"	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/range_no_prot.result'
--- a/mysql-test/suite/opt_trace/r/range_no_prot.result	2011-10-31 08:27:57 +0000
+++ b/mysql-test/suite/opt_trace/r/range_no_prot.result	2011-11-08 09:02:58 +0000
@@ -241,11 +241,11 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -392,11 +392,11 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -644,11 +644,11 @@ EXPLAIN SELECT * FROM t1 WHERE key1 < 3 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -872,7 +872,7 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -880,7 +880,7 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1101,11 +1101,11 @@ EXPLAIN SELECT DISTINCT key2 FROM t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1407,7 +1407,7 @@ GROUP BY key2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1415,7 +1415,7 @@ GROUP BY key2	{
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1644,11 +1644,11 @@ EXPLAIN SELECT * FROM t2 WHERE key2 = 1 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1930,11 +1930,11 @@ EXPLAIN SELECT * FROM t1 WHERE key2=10 O
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2095,11 +2095,11 @@ EXPLAIN SELECT * FROM t2 WHERE key2_1 < 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2318,11 +2318,11 @@ EXPLAIN SELECT * FROM t2 WHERE key1a = 5
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2533,11 +2533,11 @@ EXPLAIN SELECT * FROM t2 WHERE (key1a = 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2746,11 +2746,11 @@ EXPLAIN SELECT * FROM t2 WHERE (key1b < 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2972,11 +2972,11 @@ EXPLAIN SELECT * FROM t1 WHERE (key1 > 1
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3257,11 +3257,11 @@ WHERE t1.key1=t2.key1a AND t1.key2 > 102
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3529,11 +3529,11 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3724,11 +3724,11 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4059,18 +4059,18 @@ EXPLAIN SELECT 1 FROM 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4363,18 +4363,18 @@ EXPLAIN SELECT 1 FROM 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4597,7 +4597,7 @@ EXPLAIN SELECT * FROM t1 WHERE i1 > '2' 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -4678,7 +4678,7 @@ EXPLAIN SELECT * FROM t1 WHERE i1 > '2' 
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5015,7 +5015,7 @@ EXPLAIN SELECT DISTINCT i1 FROM t1 WHERE
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -5031,7 +5031,7 @@ EXPLAIN SELECT DISTINCT i1 FROM t1 WHERE
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5338,11 +5338,11 @@ EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5638,11 +5638,11 @@ EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5922,11 +5922,11 @@ EXPLAIN SELECT MAX(b), a FROM t1 WHERE b
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -6380,7 +6380,7 @@ GROUP BY field1	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -6388,7 +6388,7 @@ GROUP BY field1	{
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'mysql-test/suite/opt_trace/r/range_ps_prot.result'
--- a/mysql-test/suite/opt_trace/r/range_ps_prot.result	2011-10-31 08:27:57 +0000
+++ b/mysql-test/suite/opt_trace/r/range_ps_prot.result	2011-11-08 09:02:58 +0000
@@ -241,11 +241,11 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -392,11 +392,11 @@ EXPLAIN SELECT * FROM t1 WHERE key2 < 5 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -644,11 +644,11 @@ EXPLAIN SELECT * FROM t1 WHERE key1 < 3 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -872,7 +872,7 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -880,7 +880,7 @@ EXPLAIN SELECT key2, MIN(key2_1) FROM t2
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1101,11 +1101,11 @@ EXPLAIN SELECT DISTINCT key2 FROM t2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1407,7 +1407,7 @@ GROUP BY key2	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -1415,7 +1415,7 @@ GROUP BY key2	{
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1644,11 +1644,11 @@ EXPLAIN SELECT * FROM t2 WHERE key2 = 1 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -1930,11 +1930,11 @@ EXPLAIN SELECT * FROM t1 WHERE key2=10 O
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2095,11 +2095,11 @@ EXPLAIN SELECT * FROM t2 WHERE key2_1 < 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2318,11 +2318,11 @@ EXPLAIN SELECT * FROM t2 WHERE key1a = 5
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2533,11 +2533,11 @@ EXPLAIN SELECT * FROM t2 WHERE (key1a = 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2746,11 +2746,11 @@ EXPLAIN SELECT * FROM t2 WHERE (key1b < 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -2972,11 +2972,11 @@ EXPLAIN SELECT * FROM t1 WHERE (key1 > 1
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3257,11 +3257,11 @@ WHERE t1.key1=t2.key1a AND t1.key2 > 102
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3529,11 +3529,11 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -3724,11 +3724,11 @@ EXPLAIN SELECT * FROM t1 WHERE cola = 'f
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4059,18 +4059,18 @@ EXPLAIN SELECT 1 FROM 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4363,18 +4363,18 @@ EXPLAIN SELECT 1 FROM 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
-            "join_execution": {
+            "join_explain": {
               "select#": 2,
               "steps": [
               ] /* steps */
-            } /* join_execution */
+            } /* join_explain */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -4597,7 +4597,7 @@ EXPLAIN SELECT * FROM t1 WHERE i1 > '2' 
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -4678,7 +4678,7 @@ EXPLAIN SELECT * FROM t1 WHERE i1 > '2' 
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5015,7 +5015,7 @@ EXPLAIN SELECT DISTINCT i1 FROM t1 WHERE
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -5031,7 +5031,7 @@ EXPLAIN SELECT DISTINCT i1 FROM t1 WHERE
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5338,11 +5338,11 @@ EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5638,11 +5638,11 @@ EXPLAIN SELECT v FROM t1 WHERE i1 = 1 AN
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -5922,11 +5922,11 @@ EXPLAIN SELECT MAX(b), a FROM t1 WHERE b
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0
@@ -6380,7 +6380,7 @@ GROUP BY field1	{
       } /* join_optimization */
     },
     {
-      "join_execution": {
+      "join_explain": {
         "select#": 1,
         "steps": [
           {
@@ -6388,7 +6388,7 @@ GROUP BY field1	{
             } /* reconsidering_access_paths_for_index_ordering */
           }
         ] /* steps */
-      } /* join_execution */
+      } /* join_explain */
     }
   ] /* steps */
 }	0	0

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-10-13 12:33:08 +0000
+++ b/sql/mysqld.cc	2011-11-08 09:02:58 +0000
@@ -8557,6 +8557,7 @@ PSI_stage_info stage_discard_or_import_t
 PSI_stage_info stage_end= { 0, "end", 0};
 PSI_stage_info stage_executing= { 0, "executing", 0};
 PSI_stage_info stage_execution_of_init_command= { 0, "Execution of init_command", 0};
+PSI_stage_info stage_explaining= { 0, "explaining", 0};
 PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog= { 0, "Finished reading one binlog; switching to next binlog", 0};
 PSI_stage_info stage_flushing_relay_log_and_master_info_repository= { 0, "Flushing relay log and master info repository.", 0};
 PSI_stage_info stage_flushing_relay_log_info_file= { 0, "Flushing relay-log info file.", 0};
@@ -8660,6 +8661,7 @@ PSI_stage_info *all_server_stages[]=
   & stage_end,
   & stage_executing,
   & stage_execution_of_init_command,
+  & stage_explaining,
   & stage_finished_reading_one_binlog_switching_to_next_binlog,
   & stage_flushing_relay_log_and_master_info_repository,
   & stage_flushing_relay_log_info_file,

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2011-08-20 00:25:14 +0000
+++ b/sql/mysqld.h	2011-10-10 09:08:15 +0000
@@ -345,6 +345,7 @@ extern PSI_stage_info stage_discard_or_i
 extern PSI_stage_info stage_end;
 extern PSI_stage_info stage_executing;
 extern PSI_stage_info stage_execution_of_init_command;
+extern PSI_stage_info stage_explaining;
 extern PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog;
 extern PSI_stage_info stage_flushing_relay_log_and_master_info_repository;
 extern PSI_stage_info stage_flushing_relay_log_info_file;

=== modified file 'sql/opt_explain.cc'
--- a/sql/opt_explain.cc	2011-10-05 13:16:38 +0000
+++ b/sql/opt_explain.cc	2011-11-08 09:02:58 +0000
@@ -19,8 +19,8 @@
 #include "sql_select.h"
 #include "sql_partition.h" // for make_used_partitions_str()
 
-static bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
-                                select_result *result);
+static bool mysql_explain_unit(THD *thd, SELECT_LEX_UNIT *unit,
+                               select_result *result);
 
 /**
   A base for all Explain_* classes
@@ -433,7 +433,7 @@ bool Explain::send()
   for (SELECT_LEX_UNIT *unit= select_lex()->first_inner_unit();
        unit && !ret;
        unit= unit->next_unit())
-    ret= mysql_explain_union(thd, unit, result);
+    ret= mysql_explain_unit(thd, unit, result);
 
   if (external_result == NULL)
   {
@@ -1445,7 +1445,7 @@ bool explain_query_expression(THD *thd, 
 {
   DBUG_ENTER("explain_query_expression");
   const bool res= thd->send_explain_fields(result) ||
-                  mysql_explain_union(thd, &thd->lex->unit, result) ||
+                  mysql_explain_unit(thd, &thd->lex->unit, result) ||
                   thd->is_error();
   /*
     The code which prints the extended description is not robust
@@ -1483,9 +1483,9 @@ bool explain_query_expression(THD *thd, 
 
   @return false if success, true if error
 */
-bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
+bool mysql_explain_unit(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
 {
-  DBUG_ENTER("mysql_explain_union");
+  DBUG_ENTER("mysql_explain_unit");
   bool res= 0;
   SELECT_LEX *first= unit->first_select();
 
@@ -1513,12 +1513,13 @@ bool mysql_explain_union(THD *thd, SELEC
   }
   if (unit->is_union())
   {
-    unit->fake_select_lex->select_number= UINT_MAX; // jost for initialization
+    unit->fake_select_lex->select_number= UINT_MAX; // just for initialization
     unit->fake_select_lex->type= "UNION RESULT";
     unit->fake_select_lex->options|= SELECT_DESCRIBE;
     res= unit->prepare(thd, result, SELECT_NO_UNLOCK | SELECT_DESCRIBE) ||
-         unit->optimize() ||
-         unit->exec();
+         unit->optimize();
+    if (!res)
+      unit->explain();
   }
   else
   {

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2011-10-13 12:33:08 +0000
+++ b/sql/sql_lex.h	2011-11-08 09:02:58 +0000
@@ -591,6 +591,7 @@ public:
   bool prepare(THD *thd, select_result *result, ulong additional_options);
   bool optimize();
   bool exec();
+  void explain();
   bool cleanup();
   inline void unclean() { cleaned= 0; }
   void reinit_exec_mechanism();
@@ -598,7 +599,7 @@ public:
   void print(String *str, enum_query_type query_type);
 
   bool add_fake_select_lex(THD *thd);
-  void init_prepare_fake_select_lex(THD *thd);
+  bool init_prepare_fake_select_lex(THD *thd, bool no_const_tables);
   inline bool is_prepared() { return prepared; }
   bool change_result(select_result_interceptor *result,
                      select_result_interceptor *old_result);

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2011-11-02 12:47:31 +0000
+++ b/sql/sql_select.cc	2011-11-08 09:02:58 +0000
@@ -3050,6 +3050,118 @@ disable_sorted_access(JOIN_TAB* join_tab
 
 
 /**
+  Prepare join result.
+
+  @details Prepare join result prior to join execution or describing.
+  Instantiate derived tables and get schema tables result if necessary.
+
+  @return
+    TRUE  An error during derived or schema tables instantiation.
+    FALSE Ok
+*/
+
+bool JOIN::prepare_result()
+{
+  DBUG_ENTER("JOIN::prepare_result");
+
+  error= 0;
+  /* Create result tables for materialized views. */
+  if (select_lex->handle_derived(thd->lex, &mysql_derived_create))
+    goto err;
+
+  (void) result->prepare2(); // Currently, this cannot fail.
+
+  if ((select_lex->options & OPTION_SCHEMA_TABLE) &&
+      get_schema_tables_result(this, PROCESSED_BY_JOIN_EXEC))
+    goto err;
+
+  DBUG_RETURN(FALSE);
+
+err:
+  error= 1;
+  DBUG_RETURN(TRUE);
+}
+
+
+/**
+  Explain join.
+*/
+
+void
+JOIN::explain()
+{
+  Opt_trace_context * const trace= &thd->opt_trace;
+  Opt_trace_object trace_wrapper(trace);
+  Opt_trace_object trace_exec(trace, "join_explain");
+  trace_exec.add_select_number(select_lex->select_number);
+  Opt_trace_array trace_steps(trace, "steps");
+
+  DBUG_ENTER("JOIN::explain");
+
+  THD_STAGE_INFO(thd, stage_explaining);
+
+  if (prepare_result())
+    DBUG_VOID_RETURN;
+
+  if (!tables_list && (tables || !select_lex->with_sum_func))
+  {                                           // Only test of functions
+    explain_no_table(thd, this, zero_result_cause ? zero_result_cause 
+                                                  : "No tables used");
+    /* Single select (without union) always returns 0 or 1 row */
+    thd->limit_found_rows= send_records;
+    thd->set_examined_row_count(0);
+    DBUG_VOID_RETURN;
+  }
+  /*
+    Don't reset the found rows count if there're no tables as
+    FOUND_ROWS() may be called. Never reset the examined row count here.
+    It must be accumulated from all join iterations of all join parts.
+  */
+  if (tables)
+    thd->limit_found_rows= 0;
+
+  if (zero_result_cause)
+  {
+    explain_no_table(thd, this, zero_result_cause);
+    DBUG_VOID_RETURN;
+  }
+
+  /*
+    Check if we managed to optimize ORDER BY away and don't use temporary
+    table to resolve ORDER BY: in that case, we only may need to do
+    filesort for GROUP BY.
+  */
+  if (!order && !no_order && (!skip_sort_order || !need_tmp))
+  {
+    /*
+      Reset 'order' to 'group_list' and reinit variables describing
+      'order'
+    */
+    order= group_list;
+    simple_order= simple_group;
+    skip_sort_order= 0;
+  }
+  if (order && 
+      (order != group_list || !(select_options & SELECT_BIG_RESULT)) &&
+      (const_tables == tables ||
+       ((simple_order || skip_sort_order) &&
+        test_if_skip_sort_order(&join_tab[const_tables], order,
+                                m_select_limit, 0, 
+                                &join_tab[const_tables].table->
+                                keys_in_use_for_query))))
+    order=0;
+  having= tmp_having;
+  if (tables)
+    explain_query_specification(thd, this, need_tmp,
+                                order != 0 && !skip_sort_order,
+                                select_distinct);
+  else
+    explain_no_table(thd, this, "No tables used");
+
+  DBUG_VOID_RETURN;
+}
+
+/**
   Exec select.
 
   @todo
@@ -3068,18 +3180,19 @@ JOIN::exec()
   Opt_trace_object trace_exec(trace, "join_execution");
   trace_exec.add_select_number(select_lex->select_number);
   Opt_trace_array trace_steps(trace, "steps");
-
   List<Item> *columns_list= &fields_list;
   int      tmp_error;
   DBUG_ENTER("JOIN::exec");
 
-  const bool has_group_by= this->group;
+  DBUG_ASSERT(!(select_options & SELECT_DESCRIBE));
 
   THD_STAGE_INFO(thd, stage_executing);
-  error= 0;
-  /* Create result tables for materialized views. */
-  if (select_lex->handle_derived(thd->lex, &mysql_derived_create))
+
+  const bool has_group_by= this->group;
+
+  if (prepare_result())
     DBUG_VOID_RETURN;
+
   if (procedure)
   {
     procedure_fields_list= fields_list;
@@ -3092,51 +3205,45 @@ JOIN::exec()
     }
     columns_list= &procedure_fields_list;
   }
-  (void) result->prepare2(); // Currently, this cannot fail.
 
   if (!tables_list && (tables || !select_lex->with_sum_func))
   {                                           // Only test of functions
-    if (select_options & SELECT_DESCRIBE)
-      explain_no_table(thd, this, zero_result_cause ? zero_result_cause 
-                                                    : "No tables used");
-    else
+    if (result->send_result_set_metadata(*columns_list,
+                                         Protocol::SEND_NUM_ROWS |
+                                         Protocol::SEND_EOF))
     {
-      if (result->send_result_set_metadata(*columns_list,
-                                           Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
-      {
-        DBUG_VOID_RETURN;
-      }
-      /*
-        We have to test for 'conds' here as the WHERE may not be constant
-        even if we don't have any tables for prepared statements or if
-        conds uses something like 'rand()'.
-        If the HAVING clause is either impossible or always true, then
-        JOIN::having is set to NULL by optimize_cond.
-        In this case JOIN::exec must check for JOIN::having_value, in the
-        same way it checks for JOIN::cond_value.
-      */
-      if (select_lex->cond_value != Item::COND_FALSE &&
-          select_lex->having_value != Item::COND_FALSE &&
-          (!conds || conds->val_int()) &&
-          (!having || having->val_int()))
-      {
-	if (do_send_rows &&
-            (procedure ? (procedure->send_row(procedure_fields_list) ||
-             procedure->end_of_records()) : result->send_data(fields_list)))
-	  error= 1;
-	else
-	{
-	  error= (int) result->send_eof();
-	  send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 :
-                         thd->get_sent_row_count());
-	}
-      }
+      DBUG_VOID_RETURN;
+    }
+    /*
+      We have to test for 'conds' here as the WHERE may not be constant
+      even if we don't have any tables for prepared statements or if
+      conds uses something like 'rand()'.
+      If the HAVING clause is either impossible or always true, then
+      JOIN::having is set to NULL by optimize_cond.
+      In this case JOIN::exec must check for JOIN::having_value, in the
+      same way it checks for JOIN::cond_value.
+    */
+    if (select_lex->cond_value != Item::COND_FALSE &&
+        select_lex->having_value != Item::COND_FALSE &&
+        (!conds || conds->val_int()) &&
+        (!having || having->val_int()))
+    {
+      if (do_send_rows &&
+          (procedure ? (procedure->send_row(procedure_fields_list) ||
+           procedure->end_of_records()) : result->send_data(fields_list)))
+        error= 1;
       else
       {
-	error=(int) result->send_eof();
-        send_records= 0;
+        error= (int) result->send_eof();
+        send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 :
+                       thd->get_sent_row_count());
       }
     }
+    else
+    {
+      error=(int) result->send_eof();
+      send_records= 0;
+    }
     /* Single select (without union) always returns 0 or 1 row */
     thd->limit_found_rows= send_records;
     thd->set_examined_row_count(0);
@@ -3161,46 +3268,6 @@ JOIN::exec()
     DBUG_VOID_RETURN;
   }
 
-  if ((this->select_lex->options & OPTION_SCHEMA_TABLE) &&
-      get_schema_tables_result(this, PROCESSED_BY_JOIN_EXEC))
-    DBUG_VOID_RETURN;
-
-  if (select_options & SELECT_DESCRIBE)
-  {
-    /*
-      Check if we managed to optimize ORDER BY away and don't use temporary
-      table to resolve ORDER BY: in that case, we only may need to do
-      filesort for GROUP BY.
-    */
-    if (!order && !no_order && (!skip_sort_order || !need_tmp))
-    {
-      /*
-	Reset 'order' to 'group_list' and reinit variables describing
-	'order'
-      */
-      order= group_list;
-      simple_order= simple_group;
-      skip_sort_order= 0;
-    }
-    if (order && 
-        (order != group_list || !(select_options & SELECT_BIG_RESULT)) &&
-	(const_tables == tables ||
- 	 ((simple_order || skip_sort_order) &&
-	  test_if_skip_sort_order(&join_tab[const_tables], order,
-				  m_select_limit, 0, 
-                                  &join_tab[const_tables].table->
-                                    keys_in_use_for_query))))
-      order=0;
-    having= tmp_having;
-    if (tables)
-      explain_query_specification(thd, this, need_tmp,
-                                  order != 0 && !skip_sort_order,
-                                  select_distinct);
-    else
-      explain_no_table(thd, this, "No tables used");
-    DBUG_VOID_RETURN;
-  }
-
   JOIN *curr_join= this;
   List<Item> *curr_all_fields= &all_fields;
   List<Item> *curr_fields_list= &fields_list;
@@ -3707,27 +3774,6 @@ JOIN::exec()
   DBUG_PRINT("counts", ("thd->examined_row_count: %lu",
                         (ulong) thd->get_examined_row_count()));
 
-  /* 
-    With EXPLAIN EXTENDED we have to restore original ref_array
-    for a derived table which is always materialized.
-    We also need to do this when we have temp table(s).
-    Otherwise we would not be able to print the query correctly.
-    Same applies to the optimizer trace; note that changing the ref_array like
-    this affects the Item-s, so we don't do it unless the expanded query
-    is needed (@see opt_trace_print_expanded_query()).
-  */
-  if (!items0.is_null() && ((thd->lex->describe & DESCRIBE_EXTENDED)
-#ifdef OPTIMIZER_TRACE
-                            || trace->support_I_S()
-#endif
-                            ) &&
-      (select_lex->linkage == DERIVED_TABLE_TYPE ||
-       exec_tmp_table1 || exec_tmp_table2))
-  {
-    DBUG_PRINT("info", ("restoring ref array for EXPLAIN / opt trace"));
-    set_items_ref_array(items0);
-  }
-
   DBUG_VOID_RETURN;
 }
 
@@ -3917,24 +3963,16 @@ mysql_select(THD *thd, 
     goto err;					// 1
   }
 
-  if (thd->lex->describe & DESCRIBE_EXTENDED)
-  {
-    join->conds_history= join->conds;
-    join->having_history= (join->having?join->having:join->tmp_having);
-  }
-
   if (thd->is_error())
     goto err;
 
-  join->exec();
-
-  if (thd->lex->describe & DESCRIBE_EXTENDED)
-  {
-    select_lex->where= join->conds_history;
-    select_lex->having= join->having_history;
-  }
   if (select_options & SELECT_DESCRIBE)
+  {
+    join->explain();
     free_join= 0;
+  }
+  else
+    join->exec();
 
 err:
   if (free_join)
@@ -13400,12 +13438,6 @@ return_zero_rows(JOIN *join, select_resu
 {
   DBUG_ENTER("return_zero_rows");
 
-  if (select_options & SELECT_DESCRIBE)
-  {
-    explain_no_table(join->thd, join, info);
-    DBUG_RETURN(0);
-  }
-
   join->join_free();
 
   if (send_row)

=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h	2011-10-26 13:23:01 +0000
+++ b/sql/sql_select.h	2011-11-08 09:02:58 +0000
@@ -1935,8 +1935,6 @@ public:
   */
   Item       *conds;                      ///< The where clause item tree
   Item       *having;                     ///< The having clause item tree
-  Item       *conds_history;              ///< store WHERE for explain
-  Item       *having_history;             ///< Store having for explain
   Item       *tmp_having; ///< To store having when processed temporary table
   TABLE_LIST *tables_list;           ///<hold 'tables' parameter of mysql_select
   List<TABLE_LIST> *join_list;       ///< list of joined tables in reverse order
@@ -2022,7 +2020,7 @@ public:
     thd= thd_arg;
     sum_funcs= sum_funcs2= 0;
     procedure= 0;
-    having= tmp_having= having_history= 0;
+    having= tmp_having= 0;
     select_options= select_options_arg;
     result= result_arg;
     lock= thd_arg->lock;
@@ -2068,6 +2066,8 @@ public:
   int optimize();
   void reset();
   void exec();
+  bool prepare_result();
+  void explain();
   bool destroy();
   void restore_tmp();
   bool alloc_func_list();

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2011-09-21 11:01:41 +0000
+++ b/sql/sql_union.cc	2011-10-10 09:08:15 +0000
@@ -156,20 +156,22 @@ void select_union::cleanup()
 }
 
 
-/*
-  initialization procedures before fake_select_lex preparation()
+/**
+  Initialization procedures before fake_select_lex preparation()
 
-  SYNOPSIS
-    st_select_lex_unit::init_prepare_fake_select_lex()
-    thd		- thread handler
+  @param thd		 Thread handler
+  @param no_const_tables Skip reading const tables. TRUE for EXPLAIN.
 
-  RETURN
-    options of SELECT
+  @returns
+    TRUE  OOM
+    FALSE Ok
 */
 
-void
-st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg) 
+bool
+st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg,
+                                                 bool no_const_tables)
 {
+  DBUG_ENTER("st_select_lex_unit::init_prepare_fake_select_lex");
   thd_arg->lex->current_select= fake_select_lex;
   fake_select_lex->table_list.link_in_list(&result_table_list,
                                            &result_table_list.next_local);
@@ -190,6 +192,42 @@ st_select_lex_unit::init_prepare_fake_se
     (*order->item)->walk(&Item::change_context_processor, 0,
                          (uchar*) &fake_select_lex->context);
   }
+  if (!fake_select_lex->join)
+  {
+    /*
+      allocate JOIN for fake select only once (prevent
+      mysql_select automatic allocation)
+      TODO: The above is nonsense. mysql_select() will not allocate the
+      join if one already exists. There must be some other reason why we
+      don't let it allocate the join. Perhaps this is because we need
+      some special parameter values passed to join constructor?
+    */
+    if (!(fake_select_lex->join=
+        new JOIN(thd, item_list, fake_select_lex->options, result)))
+    {
+      fake_select_lex->table_list.empty();
+      DBUG_RETURN(true);
+    }
+    fake_select_lex->join->init(thd, item_list, fake_select_lex->options,
+                                result);
+    fake_select_lex->join->no_const_tables= no_const_tables;
+
+    /*
+      Fake st_select_lex should have item list for correct ref_array
+      allocation.
+    */
+    fake_select_lex->item_list= item_list;
+
+    /*
+      We need to add up n_sum_items in order to make the correct
+      allocation in setup_ref_array().
+      Don't add more sum_items if we have already done JOIN::prepare
+      for this (with a different join object)
+    */
+    if (fake_select_lex->ref_pointer_array.is_null())
+      fake_select_lex->n_child_sum_items+= global_parameters->n_sum_items;
+  }
+  DBUG_RETURN(false);
 }
 
 
@@ -228,6 +266,8 @@ bool st_select_lex_unit::prepare(THD *th
         sl->join->select_options|= SELECT_DESCRIBE;
         sl->join->reset();
       }
+      if (fake_select_lex->join)
+        fake_select_lex->join->result= result;
     }
     DBUG_RETURN(FALSE);
   }
@@ -417,30 +457,7 @@ bool st_select_lex_unit::prepare(THD *th
       if (thd->stmt_arena->is_stmt_prepare())
       {
         /* Validate the global parameters of this union */
-
-	init_prepare_fake_select_lex(thd);
-        /* Should be done only once (the only item_list per statement) */
-        DBUG_ASSERT(fake_select_lex->join == 0);
-	if (!(fake_select_lex->join=
-              new JOIN(thd, item_list, thd->variables.option_bits, result)))
-	{
-	  fake_select_lex->table_list.empty();
-	  DBUG_RETURN(TRUE);
-	}
-
-        /*
-          Fake st_select_lex should have item list for correct ref_array
-          allocation.
-        */
-        fake_select_lex->item_list= item_list;
-
-        thd_arg->lex->current_select= fake_select_lex;
-
-        /*
-          We need to add up n_sum_items in order to make the correct
-          allocation in setup_ref_array().
-        */
-        fake_select_lex->n_child_sum_items+= global_parameters->n_sum_items;
+        init_prepare_fake_select_lex(thd, false);
 
 	saved_error= fake_select_lex->join->
 	  prepare(fake_select_lex->table_list.first, // tables_init
@@ -539,6 +556,61 @@ bool st_select_lex_unit::optimize()
 }
 
 
+/**
+  Explain UNION.
+*/
+
+void st_select_lex_unit::explain()
+{
+  SELECT_LEX *lex_select_save= thd->lex->current_select;
+  DBUG_ENTER("st_select_lex_unit::explain");
+  JOIN *join;
+
+  DBUG_ASSERT((is_union() || fake_select_lex) && describe && optimized);
+  executed= true;
+
+  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
+  {
+    DBUG_ASSERT(sl->join);
+    sl->join->explain();
+  }
+
+  if (init_prepare_fake_select_lex(thd, true))
+    DBUG_VOID_RETURN;
+
+  if (thd->is_fatal_error)
+    DBUG_VOID_RETURN;
+  join= fake_select_lex->join;
+  /*
+    In EXPLAIN command, constant subqueries that do not use any
+    tables are executed two times:
+     - 1st time is a real evaluation to get the subquery value
+     - 2nd time is to produce EXPLAIN output rows.
+    1st execution sets certain members (e.g. select_result) to perform
+    subquery execution rather than EXPLAIN line production. In order 
+    to reset them back, we re-do all of the actions (yes it is ugly).
+  */
+  if (!join->optimized || !join->tables)
+  {
+    saved_error= mysql_select(thd,
+                          &result_table_list,
+                          0, item_list, NULL,
+                          global_parameters->order_list.elements,
+                          global_parameters->order_list.first,
+                          NULL, NULL, NULL,
+                          fake_select_lex->options | SELECT_NO_UNLOCK,
+                          result, this, fake_select_lex);
+  }
+  else
+    join->explain();
+  thd->lex->current_select= lex_select_save;
+  DBUG_VOID_RETURN;
+}
+
+
+/**
+  Execute UNION.
+*/
 
 bool st_select_lex_unit::exec()
 {
@@ -546,12 +618,13 @@ bool st_select_lex_unit::exec()
   ulonglong add_rows=0;
   ha_rows examined_rows= 0;
   DBUG_ENTER("st_select_lex_unit::exec");
+  DBUG_ASSERT((is_union() || fake_select_lex) && !describe && optimized);
 
-  if (executed && !uncacheable && !describe)
+  if (executed && !uncacheable)
     DBUG_RETURN(false);
   executed= true;
   
-  if (uncacheable || !item || !item->assigned() || describe)
+  if (uncacheable || !item || !item->assigned())
   {
     if (item)
       item->reset_value_registration();
@@ -636,111 +709,51 @@ bool st_select_lex_unit::exec()
       }
     }
   }
-  DBUG_ASSERT(optimized);
 
-  /* Send result to 'result' */
-  saved_error= true;
+  if (!saved_error && !thd->is_fatal_error)
   {
+    /* Send result to 'result' */
+    saved_error= true;
     List<Item_func_match> empty_list;
     empty_list.empty();
 
-    if (!thd->is_fatal_error)				// Check if EOM
+    set_limit(global_parameters);
+    if (init_prepare_fake_select_lex(thd, true))
+      DBUG_RETURN(true);
+    JOIN *join= fake_select_lex->join;
+    if (!join->optimized)
+    {
+      saved_error=
+        mysql_select(thd,
+                     &result_table_list,      // tables
+                     0,                       // wild_num
+                     item_list,               // fields
+                     NULL,                    // conds
+                     global_parameters->order_list.elements, // og_num
+                     global_parameters->order_list.first,    // order
+                     NULL,                    // group
+                     NULL,                    // having
+                     NULL,                    // proc_param
+                     fake_select_lex->options | SELECT_NO_UNLOCK,
+                     result,                  // result
+                     this,                    // unit
+                     fake_select_lex);        // select_lex
+    }
+    else
     {
-      set_limit(global_parameters);
-      init_prepare_fake_select_lex(thd);
-      JOIN *join= fake_select_lex->join;
-      if (!join)
-      {
-        /*
-          allocate JOIN for fake select only once (prevent
-          mysql_select automatic allocation)
-          TODO: The above is nonsense. mysql_select() will not allocate the
-          join if one already exists. There must be some other reason why we
-          don't let it allocate the join. Perhaps this is because we need
-          some special parameter values passed to join constructor?
-	*/
-        if (!(fake_select_lex->join=
-            new JOIN(thd, item_list, fake_select_lex->options, result)))
-	{
-          fake_select_lex->table_list.empty();
-          DBUG_RETURN(true);
-	}
-        fake_select_lex->join->no_const_tables= true;
-
-        /*
-          Fake st_select_lex should have item list for correct ref_array
-          allocation.
-        */
-        fake_select_lex->item_list= item_list;
-
-        /*
-          We need to add up n_sum_items in order to make the correct
-          allocation in setup_ref_array().
-          Don't add more sum_items if we have already done JOIN::prepare
-          for this (with a different join object)
-        */
-        if (fake_select_lex->ref_pointer_array.is_null())
-          fake_select_lex->n_child_sum_items+= global_parameters->n_sum_items;
+      join->examined_rows= 0;
+      saved_error= false;
+      join->reset();
+      join->exec();
+    }
 
-        saved_error=
-          mysql_select(thd,
-                       &result_table_list,      // tables
-                       0,                       // wild_num
-                       item_list,               // fields
-                       NULL,                    // conds
-                       global_parameters->order_list.elements, // og_num
-                       global_parameters->order_list.first,    // order
-                       NULL,                    // group
-                       NULL,                    // having
-                       NULL,                    // proc_param
-                       fake_select_lex->options | SELECT_NO_UNLOCK,
-                       result,                  // result
-                       this,                    // unit
-                       fake_select_lex);        // select_lex
-      }
-      else
-      {
-        if (describe)
-        {
-          /*
-            In EXPLAIN command, constant subqueries that do not use any
-            tables are executed two times:
-             - 1st time is a real evaluation to get the subquery value
-             - 2nd time is to produce EXPLAIN output rows.
-            1st execution sets certain members (e.g. select_result) to perform
-            subquery execution rather than EXPLAIN line production. In order 
-            to reset them back, we re-do all of the actions (yes it is ugly):
-          */
-          join->init(thd, item_list, fake_select_lex->options, result);
-          saved_error= mysql_select(thd,
-                                &result_table_list,
-                                0, item_list, NULL,
-                                global_parameters->order_list.elements,
-                                global_parameters->order_list.first,
-                                NULL, NULL, NULL,
-                                fake_select_lex->options | SELECT_NO_UNLOCK,
-                                result, this, fake_select_lex);
-        }
-        else
-        {
-          join->examined_rows= 0;
-          saved_error= false;
-          join->reset();
-          join->exec();
-        }
-      }
+    fake_select_lex->table_list.empty();
+  }
+  if (!saved_error && !thd->is_fatal_error)
+  {
 
-      fake_select_lex->table_list.empty();
-      if (!saved_error)
-      {
-	thd->limit_found_rows = (ulonglong)table->file->stats.records + add_rows;
-        thd->inc_examined_row_count(examined_rows);
-      }
-      /*
-        Mark for slow query log if any of the union parts didn't use
-        indexes efficiently
-      */
-    }
+    thd->limit_found_rows = (ulonglong)table->file->stats.records + add_rows;
+    thd->inc_examined_row_count(examined_rows);
   }
   thd->lex->current_select= lex_select_save;
   DBUG_RETURN(saved_error);

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (jorgen.loland:3475 to 3476) WL#5585Jorgen Loland11 Nov