List:Commits« Previous MessageNext Message »
From:Gleb Shchepa Date:July 2 2011 10:06pm
Subject:bzr push into mysql-trunk branch (gleb.shchepa:3397 to 3398) WL#4897
View as plain text  
 3398 Gleb Shchepa	2011-07-03
      WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
      
      WL#4897 implements EXPLAIN command for INSERT, REPLACE and
      single- and multi-table UPDATE and DELETE queries.
     @ client/mysqltest.cc
        + Guilhem's patch for MTR --explain-protocol has been added.
        * Minor help message update and commentary cleanup.
     @ mysql-test/include/explain_non_select.inc
        New coverage and regression tests and sanity checks for WL#4897 have been added.
     @ mysql-test/include/explain_utils.inc
        New utility file for WL#4897 tests has been added.
     @ mysql-test/r/explain.result
        + Regression test for WL#4897 has been added.
        * Minor changes ("explain" column message reordering) after WL#4897.
     @ mysql-test/r/grant_explain_non_select.result
        + Privilege-specific test file for WL#4897 has been added.
        + Permission tests for underlying queries of EXPLAIN commands have been added.
     @ mysql-test/r/innodb_explain_non_select_all.result
        New test file for WL#4897 has been added (default engine is InnoDB, all
        @optimizer_switches features are enabled)
     @ mysql-test/r/innodb_explain_non_select_none.result
        New test file for WL#4897 has been added (default engine is InnoDB, all
        @optimizer_switches features are disabled)
     @ mysql-test/r/join_outer.result
        Minor changes ("extra" column message reordering) after WL#4897.
     @ mysql-test/r/join_outer_jcl6.result
        Minor changes ("extra" column message reordering) after WL#4897.
     @ mysql-test/r/myisam_explain_non_select_all.result
        New test file for WL#4897 has been added (default engine is MyISAM, all
        @optimizer_switches features are enabled)
     @ mysql-test/r/myisam_explain_non_select_none.result
        New test file for WL#4897 has been added (default engine is MyISAM, all
        @optimizer_switches features are disabled)
     @ mysql-test/r/partition_pruning.result
        Coverage tests for WL#4897 have been added.
     @ mysql-test/t/explain.test
        Regression test for WL#4897 has been added.
     @ mysql-test/t/grant_explain_non_select.test
        + Permission tests for regular tables have been added.
        + Permission tests for underlying queries of EXPLAIN commands have been added.
     @ mysql-test/t/innodb_explain_non_select_all.test
        New test file for WL#4897 has been added (default engine is InnoDB, all
        @optimizer_switches features are enabled)
     @ mysql-test/t/innodb_explain_non_select_none.test
        New test file for WL#4897 has been added (default engine is InnoDB, all
        @optimizer_switches features are disabled)
     @ mysql-test/t/myisam_explain_non_select_all.test
        New test file for WL#4897 has been added (default engine is MyISAM, all
        @optimizer_switches features are enabled)
     @ mysql-test/t/myisam_explain_non_select_none.test
        New test file for WL#4897 has been added (default engine is MyISAM, all
        @optimizer_switches features are disabled)
     @ mysql-test/t/partition_pruning.test
        Coverage tests for WL#4897 have been added.
     @ sql/CMakeLists.txt
        New opt_explain.cc source file has been added.
     @ sql/opt_explain.cc
        The select_describe() functions has been refactored into
        explain_no_table(), explain_single_table_modification(),
        explain_query_specification(), and explain_query_expression()
        global functions and a few local auxiliary classes: Explain, 
        Explain_no_table, Explain_table_base, Explain_table, 
        Explain_join and Explain_union,
        
        Also the functionality of select_describe() has been
        improved to serve top-JOIN-less EXPLAIN queries (EXPLAIN
        single-table UPDATE and DELETE) with the help of the new
        global explain_single_table_modification() function and 
        auxiliary Explain_table class.
        
        explain_send class and explain_multi_table_modification() 
        function have been added to adapt select_insert, multi_update 
        and multi_delete classes to work in EXPLAIN context (to
        implement EXPLAIN INSERT...SELECT and EXPLAIN multi-table
        UPDATE and DELETE commands).
        
        The explain_query_expression() function has been added to
        reuse part of the execute_sqlcom_select function.
        
        The mysql_explain_union function has been made static and
        moved there from the sql_parse.cc file.
     @ sql/opt_explain.h
        New functions have been added:
          explain_no_table(),
          explain_single_table_modification(),
          explain_query_specification(),
          explain_multi_table_modification(),
          explain_query_expression().
     @ sql/opt_range.h
        Minor change: unnecessary friending of the select_describe()
        function has been removed.
     @ sql/sql_class.h
        + The select_result::reset_offset_limit_cnt() function has been added
          to reset protected offset_limit_cnt field.
        + The CF_CAN_BE_EXPLAINED flag has been introduced to mark
          all SQL commands that can be explained by EXPLAIN.
     @ sql/sql_delete.cc
        The mysql_delete() function has been improved to work in the
        EXPLAIN multi-table DELETE context to produce EXPLAIN instead
        table data modification.
     @ sql/sql_insert.cc
        The mysql_insert() function has been improved to work in the
        EXPLAIN INSERT...SELECT context to produce EXPLAIN instead
        table data modification.
        
        The upgrade_lock_type function has been modified to replace
        TL_WRITE_DELAYED lock with TL_WRITE since there is no need to
        delay the EXPLAIN command.
     @ sql/sql_parse.cc
        INSERT...SELECT, REPLACE...SELECT and multi-table UPDATE/DELETE
        handlers have been improved to work with EXPLAIN of these
        queries.
        
        Part of the execute_sqlcom_select function has been replaced
        with the call to the new explain_query_specification function.
     @ sql/sql_parse.h
        The is_explainable_query function has been added.
     @ sql/sql_select.cc
        * select_describe() function has been moved to opt_explain.{h,cc}
          files and refactored.
        * mysql_explain_union() has been moved to opt_explain.cc.
     @ sql/sql_select.h
        mysql_explain_union() has been moved to opt_explain.cc
     @ sql/sql_show.cc
        Minor cleanup.
     @ sql/sql_string.h
        The StringBuffer template helper has been introduced.
     @ sql/sql_update.cc
        The mysql_delete() function has been improved to work in the
        EXPLAIN multi-table UPDATE context to produce EXPLAIN instead
        table data modification.
     @ sql/sql_view.cc
        mysql_make_view(): the check for SELECT or SHOW VIEW
        permission has been extended to all explainable SQL
        commands (including INSERT, REPLACE, UPDATE and DELETE
        commands in addition to SELECT).
     @ sql/sql_yacc.yy
        New EXPLAIN INSERT/REPLACE/UPDATE/DELETE syntax has been added.

    added:
      mysql-test/include/explain_non_select.inc
      mysql-test/include/explain_utils.inc
      mysql-test/r/grant_explain_non_select.result
      mysql-test/r/innodb_explain_non_select_all.result
      mysql-test/r/innodb_explain_non_select_none.result
      mysql-test/r/myisam_explain_non_select_all.result
      mysql-test/r/myisam_explain_non_select_none.result
      mysql-test/t/grant_explain_non_select.test
      mysql-test/t/innodb_explain_non_select_all.test
      mysql-test/t/innodb_explain_non_select_none.test
      mysql-test/t/myisam_explain_non_select_all.test
      mysql-test/t/myisam_explain_non_select_none.test
      sql/opt_explain.cc
      sql/opt_explain.h
    modified:
      client/mysqltest.cc
      mysql-test/r/explain.result
      mysql-test/r/join_outer.result
      mysql-test/r/join_outer_jcl6.result
      mysql-test/r/partition_pruning.result
      mysql-test/t/explain.test
      mysql-test/t/partition_pruning.test
      sql/CMakeLists.txt
      sql/opt_range.h
      sql/sql_class.h
      sql/sql_delete.cc
      sql/sql_insert.cc
      sql/sql_parse.cc
      sql/sql_parse.h
      sql/sql_select.cc
      sql/sql_select.h
      sql/sql_show.cc
      sql/sql_string.h
      sql/sql_update.cc
      sql/sql_view.cc
      sql/sql_yacc.yy
 3397 Guilhem Bichot	2011-06-29
      Backport of fix for
      "BUG#12430646 - SEL_ARG::LEFT AND RIGHT POINTERS INCORRECTLY USED. CRASHES OPTIMIZER TRACING"
      from opt-backporting-wl4800 tree. Original revid
      jorgen.loland@stripped

    modified:
      sql/opt_range.cc
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2011-06-06 10:29:45 +0000
+++ b/client/mysqltest.cc	2011-07-02 21:01:41 +0000
@@ -201,6 +201,7 @@ static char *opt_plugin_dir= 0;
 static my_regex_t ps_re;     /* the query can be run using PS protocol */
 static my_regex_t sp_re;     /* the query can be run as a SP */
 static my_regex_t view_re;   /* the query can be run as a view*/
+static my_regex_t explain_re;/* the query can be converted to EXPLAIN */
 
 static void init_re(void);
 static int match_re(my_regex_t *, char *);
@@ -6391,7 +6392,8 @@ static struct my_option my_long_options[
   {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select.",
    &view_protocol, &view_protocol, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"explain-protocol", OPT_EXPLAIN_PROTOCOL, "Explains all select.",
+  {"explain-protocol", OPT_EXPLAIN_PROTOCOL,
+   "Explain all SELECT/INSERT/REPLACE/UPDATE/DELETE statements",
    &explain_protocol, &explain_protocol, 0,
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"connect_timeout", OPT_CONNECT_TIMEOUT,
@@ -7882,7 +7884,7 @@ void run_explain(struct st_connection *c
 {
   if (explain_protocol_enabled &&
       !command->expected_errors.count &&
-      match_re(&view_re, command->query))
+      match_re(&explain_re, command->query))
   {
     st_command save_command= *command;
     DYNAMIC_STRING query_str;
@@ -7892,6 +7894,7 @@ void run_explain(struct st_connection *c
     init_dynamic_string(&query_str, "EXPLAIN EXTENDED ", 256, 256);
     dynstr_append_mem(&query_str, command->query,
                       command->end - command->query);
+    
     command->query= query_str.str;
     command->query_len= query_str.length;
     command->end= strend(command->query);
@@ -7965,9 +7968,16 @@ void init_re(void)
     "^("
     "[[:space:]]*SELECT[[:space:]])";
 
+
+  /* Filter for queries that can be converted to EXPLAIN */
+  const char *explain_re_str =
+    "^("
+    "[[:space:]]*(SELECT|DELETE|UPDATE|INSERT|REPLACE)[[:space:]])";
+
   init_re_comp(&ps_re, ps_re_str);
   init_re_comp(&sp_re, sp_re_str);
   init_re_comp(&view_re, view_re_str);
+  init_re_comp(&explain_re, explain_re_str);
 }
 
 
@@ -8631,8 +8641,14 @@ int main(int argc, char **argv)
 	  strmake(command->require_file, save_file, sizeof(save_file) - 1);
 	  save_file[0]= 0;
 	}
-	run_query(cur_con, command, flags);
+        /*
+          We run EXPLAIN _before_ the query. If query is UPDATE/DELETE is
+          matters: a DELETE may delete rows, and then EXPLAIN DELETE will
+          usually terminate quickly with "no matching rows". To make it more
+          interesting, EXPLAIN is now first.
+        */
 	run_explain(cur_con, command, flags);
+	run_query(cur_con, command, flags);
 	command_executed++;
         command->last_argument= command->end;
 

=== added file 'mysql-test/include/explain_non_select.inc'
--- a/mysql-test/include/explain_non_select.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/explain_non_select.inc	2011-07-02 21:01:41 +0000
@@ -0,0 +1,752 @@
+# This file is a collection of regression and coverage tests
+# for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE.
+
+--echo #1
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  UPDATE t1 SET a = 10 WHERE a < 10
+--let $select = SELECT * FROM t1     WHERE a < 10
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #2
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  DELETE   FROM t1 WHERE a < 10
+--let $select = SELECT * FROM t1 WHERE a < 10
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #3
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  DELETE   FROM t1 USING t1 WHERE a = 1
+--let $select = SELECT * FROM t1          WHERE a = 1
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #4
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1
+--let $select = SELECT * FROM t1, t2               WHERE t1.a = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #5
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1
+--let $select = SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #6
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+--let $select = SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+--let $select = SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+--let $select = SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #8
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10
+--let $select = SELECT * FROM t1 t11, (SELECT * FROM t2) t12
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #9
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10
+--let $select = SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #10
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1
+--let $select = SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #11
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  DELETE   FROM t1 WHERE a > 1 LIMIT 1
+--let $select = SELECT * FROM t1 WHERE a > 1 LIMIT 1
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #12
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  DELETE   FROM t1 WHERE 0
+--let $select = SELECT * FROM t1 WHERE 0
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #13
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  DELETE   FROM t1 USING t1 WHERE 0
+--let $select = SELECT * FROM t1          WHERE 0
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #14
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+--let $query =  DELETE   FROM t1 WHERE a = 3
+--let $select = SELECT * FROM t1 WHERE a = 3
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #15
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+--let $query =  DELETE   FROM t1 WHERE a < 3
+--let $select = SELECT * FROM t1 WHERE a < 3
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #16
+CREATE TABLE t1 ( a int PRIMARY KEY );
+--let $query =  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+--let $select = SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+--source include/explain_utils.inc
+INSERT INTO t1 VALUES (1), (2), (3);
+--let $query =  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+--let $select = SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #17
+CREATE TABLE t1(a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (4),(3),(1),(2);
+--let $query =  DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+--let $select = SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #18
+CREATE TABLE t1 (a DATE, b TIME, c INT, KEY c(c), KEY b(b), KEY a(a));
+INSERT INTO t1 VALUES (), (), (), (), (), (), (), (), (), ();
+UPDATE t1 SET a = c, b = c;
+--let $query =  DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+--let $select = SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #19
+CREATE TABLE t1 (a1 INT NOT NULL, b1 INT NOT NULL);
+CREATE TABLE t2 (a2 INT NOT NULL, b2 INT NOT NULL, PRIMARY KEY (a2,b2));
+CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3));
+INSERT INTO t1 VALUES (1,1), (2,1), (1,3);
+INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
+INSERT INTO t3 VALUES (1,1), (2,1), (1,3);
+--let $query =  DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+--let $select = SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+--source include/explain_utils.inc
+DROP TABLE t1, t2, t3;
+
+--echo #20
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2)
+--let $select = SELECT * FROM t1     WHERE a IN (SELECT a FROM t2)
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #21
+CREATE TABLE t1 (a1 INT);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (a2 VARCHAR(10));
+INSERT INTO t2 VALUES (1), (2), (3), (4), (5);
+SET @save_optimizer_switch= @@optimizer_switch;
+SET @@optimizer_switch= 'semijoin=off';
+--let $query =  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+--let $select = SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+--source include/explain_utils.inc
+SET @@optimizer_switch= @save_optimizer_switch;
+TRUNCATE t1;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+--let $query =  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+--let $select = SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #22
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+--let $query =  UPDATE t1 SET i = 10
+--let $select = SELECT * FROM t1
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #23
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+--let $query =  DELETE FROM t1
+--let $select = SELECT * FROM t1
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #24
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+--let $query =  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $no_rows = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #25
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+--let $query =  INSERT INTO t2 SELECT * FROM t1
+--let $select =                SELECT * FROM t1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #26
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+--let $query =  REPLACE INTO t2 SELECT * FROM t1
+--let $select =                 SELECT * FROM t1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #27
+CREATE TABLE t1 (i INT);
+--let $query = INSERT INTO t1 SET i = 10
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #28
+CREATE TABLE t1 (i INT);
+--let $query = REPLACE INTO t1 SET i = 10
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #29
+CREATE TABLE t1 (a INT, i INT PRIMARY KEY);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+--let $query =  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--let $select = SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #30
+CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+--let $query =  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--let $select = SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #31
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+--let $query =  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #32
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+--let $query =  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $no_rows = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #33
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+--let $query =  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #34
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+  ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+--let $query =  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #35
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+--let $query =  DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+--let $select = SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #36
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+--let $query =  DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+--let $select = SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #37
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                          (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                          (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+--let $query =  DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5
+--let $select = SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #38
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+--let $query =  DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+--let $select = SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+--let $no_rows = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #39
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+--let $query =  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--let $select = SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--let $no_rows = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #40
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t2 (i) SELECT i FROM t1;
+--let $query =  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--let $select = SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #41
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+--let $query =  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #42
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+--let $query =  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $no_rows = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #43
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+--let $query =  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #44
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+  ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+--let $query =  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+--let $select = SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #45
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+--let $query =  UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+--let $select = SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #46
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+--let $query =  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+--let $select = SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #47
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+--let $query =  UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5
+--let $select = SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #48
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+                      (20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+                      (30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+--let $query =  UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5
+--let $select = SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5
+--let $no_rows = 1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #49
+CREATE TABLE t1 (
+  pk INT NOT NULL AUTO_INCREMENT,
+  c1_idx CHAR(1) DEFAULT 'y',
+  c2 INT,
+  PRIMARY KEY (pk),
+  INDEX c1_idx (c1_idx)
+);
+INSERT INTO t1 VALUES (1,'y',1), (2,'n',2), (3,'y',3), (4,'n',4);
+--let $query =  UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+--let $select = SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+--source include/explain_utils.inc
+--let $query =  DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+--let $select = SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #50
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
+INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(); 
+--let $query =  UPDATE t1 SET a=a+10 WHERE a > 34
+--let $select = SELECT * FROM t1     WHERE a > 34
+--source include/explain_utils.inc
+DROP TABLE t1;
+
+--echo #51
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT);
+CREATE TABLE t2 (c1 INT, c2 INT);
+INSERT INTO t1 VALUES (1, 1, 10), (2, 2, 20);
+--let $query =  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10
+--let $select = SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+--source include/explain_utils.inc
+--let $query =  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10
+--let $select = SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #52
+CREATE TABLE t1(f1 INT, f2 INT);
+CREATE TABLE t2(f3 INT, f4 INT);
+CREATE INDEX IDX ON t2(f3);
+INSERT INTO t1 VALUES(1,0),(2,0);
+INSERT INTO t2 VALUES(1,1),(2,2);
+--let $query =  UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)
+--let $select = SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+
+--echo #55
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1);
+SET @a = NULL;
+EXPLAIN DELETE FROM t1 WHERE (@a:= a);
+if (`SELECT @a IS NOT NULL`) {
+  die Unexpectedly modified user variable;
+}
+DROP TABLE t1;
+
+--echo #56
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+--error ER_BAD_FIELD_ERROR
+                 DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+--error ER_BAD_FIELD_ERROR
+EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+DROP TABLE t1;
+
+--echo #57
+CREATE TABLE t1(f1 INT);
+--error ER_BAD_FIELD_ERROR
+EXPLAIN EXTENDED UPDATE t1 SET f2=1 ORDER BY f2;
+--error ER_BAD_FIELD_ERROR
+UPDATE t1 SET f2=1 ORDER BY f2;
+DROP TABLE t1;
+
+--echo #59
+CREATE TABLE t1 ( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+SET SESSION sql_safe_updates = 1;
+--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
+EXPLAIN EXTENDED UPDATE IGNORE v1 SET a = 1;
+--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
+UPDATE IGNORE v1 SET a = 1;
+SET SESSION sql_safe_updates = DEFAULT;
+DROP TABLE t1;
+DROP VIEW v1;
+
+--echo #62
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+--let $query =  UPDATE        v1 SET a = 1 WHERE a > 0
+--let $select = SELECT * FROM v1           WHERE a > 0
+--source include/explain_utils.inc
+--let $query =  UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a
+--let $select = SELECT * FROM t1, v1              WHERE t1.a = v1.a
+--source include/explain_utils.inc
+DROP TABLE t1;
+DROP VIEW v1;
+
+--echo #63
+CREATE TABLE t1 (a INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE VIEW v1 (a) AS SELECT a FROM t1;
+--let $query =  DELETE   FROM v1 WHERE a < 4
+--let $select = SELECT * FROM v1 WHERE a < 4
+--source include/explain_utils.inc
+DROP TABLE t1;
+DROP VIEW v1;
+
+--echo #64
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+--let $query =  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+--let $select = SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+--source include/explain_utils.inc
+DROP TABLE t1,t2;
+DROP VIEW v1;
+
+--echo #65
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+--let $query =  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+--let $select = SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+--source include/explain_utils.inc
+DROP TABLE t1,t2;
+DROP VIEW v1;
+
+--echo #66
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 (x) AS SELECT a FROM t1;
+--let $query =  INSERT INTO v1 VALUES (10)
+--let $select = SELECT NULL
+--source include/explain_utils.inc
+DROP TABLE t1;
+DROP VIEW v1;
+
+--echo #67
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+CREATE VIEW v1 (x) AS SELECT b FROM t2;
+--let $query =  INSERT INTO v1 SELECT * FROM t1
+--let $select =                SELECT * FROM t1
+--source include/explain_utils.inc
+DROP TABLE t1, t2;
+DROP VIEW v1;
+
+--echo #68
+CREATE TABLE t1 (i INT);
+EXPLAIN INSERT DELAYED INTO t1 VALUES (1);
+DROP TABLE t1;
+
+--echo #69
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+--let $query =  UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+--let $select = SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+--source include/explain_utils.inc
+--let $query =  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+--let $select = SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+--source include/explain_utils.inc
+--let $query =  UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+--let $select = SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+--source include/explain_utils.inc
+DROP TABLE t1,t2;
+
+--echo #70
+CREATE TABLE t1 (c1 INT KEY);
+CREATE TABLE t2 (c2 INT);
+CREATE TABLE t3 (c3 INT);
+EXPLAIN EXTENDED UPDATE t3 SET c3 = (
+  SELECT COUNT(d1.c1)
+    FROM (
+      SELECT a11.c1 FROM t1 AS a11 
+        STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1
+        JOIN t1 AS a12 ON a12.c1 = a11.c1
+    ) d1
+); 
+
+DROP TABLE t1, t2, t3;
+
+--echo #71
+#
+# Bug: after EXPLAIN bulk INSERT...SELECT and bulk INSERT...SELECT
+# to a # MyISAM table the SELECT query may fail with the
+# "1030: Got error 124 from storage engine" error message.
+#
+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, INDEX i1(c1));
+INSERT INTO t1 VALUES (1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0);
+--disable_query_log
+let $1=7;
+SET @d=8;
+while ($1) {
+  eval INSERT INTO t1 SELECT c1 + @d, c2 + @d FROM t1;
+  eval SET @d = @d*2;
+  dec $1;
+}
+--enable_query_log
+CREATE TABLE t2 LIKE t1;
+
+# replace "rows" column for InnoDB
+--replace_column 9 X
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+INSERT INTO t2 SELECT * FROM t1;
+--disable_result_log
+SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+--enable_result_log
+
+DROP TABLE t1, t2;
+
+--echo #73
+
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 (id INT);
+INSERT INTO t1 VALUES (1), (2);
+
+EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USING(id) GROUP BY t1.id;
+
+DROP TABLE t1,t2;
+

=== added file 'mysql-test/include/explain_utils.inc'
--- a/mysql-test/include/explain_utils.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/explain_utils.inc	2011-07-02 21:01:41 +0000
@@ -0,0 +1,126 @@
+# This file is a collection of utility tests
+# for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE.
+#
+# Since MTR doesn't have functions, we use this file instead
+# including it many times.
+#
+# Parameters:
+#
+#  $query:   INSERT/REPLACE/UPDATE/DELETE query to explain
+#            NOTE: this file resets this variable
+#
+#  $select:  may be empty; the SELECT query similar to $query
+#            We use it to compare:
+#              1) table data before and after EXPLAIN $query evaluation;
+#              2) EXPLAIN $query and EXPLAIN $select output and
+#                 handler/filesort statistics
+#            NOTE: this file resets this variable
+#  $innodb:  take $no_rows parameter into account if not 0;
+#  $no_rows: filter out "rows" and "filtered" columns of EXPLAIN if not 0;
+#            it may be necessary for InnoDB tables since InnoDB's table row
+#            counter can't return precise and repeatable values;
+#	     NOTE: ANALYZE TABLE doesn't help
+#            NOTE: this file resets this variable
+
+--echo #
+--echo # query:  $query
+--echo # select: $select
+--echo #
+
+if ($select) {
+--disable_query_log
+--eval $select INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/before_explain.txt'
+--enable_query_log
+}
+
+if ($innodb) {
+  if ($no_rows) {
+--replace_column 9 X
+  }
+}
+--eval EXPLAIN $query
+if (`SELECT ROW_COUNT() > 0`) {
+--echo # Erroneous query: EXPLAIN $query
+--die Unexpected ROW_COUNT() <> 0
+}
+
+FLUSH STATUS;
+FLUSH TABLES;
+if ($innodb) {
+  if ($no_rows) {
+--replace_column 9 X 10 X
+  }
+}
+--eval EXPLAIN EXTENDED $query
+if (`SELECT ROW_COUNT() > 0`) {
+--echo # Erroneous query: EXPLAIN EXTENDED $query
+--die Unexpected ROW_COUNT() <> 0
+}
+--echo # Status of EXPLAIN EXTENDED query
+--disable_query_log
+SHOW STATUS WHERE (Variable_name LIKE 'Sort%' OR
+                   Variable_name LIKE 'Handler_read_%' OR
+                   Variable_name = 'Handler_write' OR
+                   Variable_name = 'Handler_update' OR
+                   Variable_name = 'Handler_delete') AND Value <> 0;
+--enable_query_log
+
+if ($select) {
+FLUSH STATUS;
+FLUSH TABLES;
+if ($innodb) {
+  if ($no_rows) {
+--replace_column 9 X 10 X
+  }
+}
+--eval EXPLAIN EXTENDED $select
+--echo # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+--disable_query_log
+SHOW STATUS WHERE (Variable_name LIKE 'Sort%' OR
+                   Variable_name LIKE 'Handler_read_%' OR
+                   Variable_name = 'Handler_write' OR
+                   Variable_name = 'Handler_update' OR
+                   Variable_name = 'Handler_delete') AND Value <> 0;
+--enable_query_log
+}
+
+--disable_query_log
+
+if ($select) {
+--eval $select INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/after_explain.txt'
+--diff_files '$MYSQLTEST_VARDIR/tmp/before_explain.txt' '$MYSQLTEST_VARDIR/tmp/after_explain.txt'
+--remove_file '$MYSQLTEST_VARDIR/tmp/before_explain.txt'
+--remove_file '$MYSQLTEST_VARDIR/tmp/after_explain.txt'
+}
+
+FLUSH STATUS;
+FLUSH TABLES;
+if ($select) {
+--disable_result_log
+--eval $select
+--enable_result_log
+--echo # Status of "equivalent" SELECT query execution:
+SHOW STATUS WHERE (Variable_name LIKE 'Sort%' OR
+                   Variable_name LIKE 'Handler_read_%' OR
+                   Variable_name = 'Handler_write' OR
+                   Variable_name = 'Handler_update' OR
+                   Variable_name = 'Handler_delete') AND Value <> 0;
+}
+
+FLUSH STATUS;
+FLUSH TABLES;
+--eval $query
+--echo # Status of testing query execution:
+SHOW STATUS WHERE (Variable_name LIKE 'Sort%' OR
+                   Variable_name LIKE 'Handler_read_%' OR
+                   Variable_name = 'Handler_write' OR
+                   Variable_name = 'Handler_update' OR
+                   Variable_name = 'Handler_delete') AND Value <> 0;
+
+--let $query=
+--let $select=
+--let $no_rows=
+
+--enable_query_log
+
+--echo

=== modified file 'mysql-test/r/explain.result'
--- a/mysql-test/r/explain.result	2011-05-10 13:37:37 +0000
+++ b/mysql-test/r/explain.result	2011-07-02 21:01:41 +0000
@@ -456,4 +456,21 @@ EXECUTE s;
 ERROR 21000: Subquery returns more than 1 row
 DEALLOCATE PREPARE s;
 DROP TABLE t1;
+#
+# WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
+# 
+# Coverage tests after code refactoring
+#
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (3),(4),(5);
+# EXPLAIN must return 3 rows:
+EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2,2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	
+2	UNION	t2	ALL	NULL	NULL	NULL	NULL	3	
+NULL	UNION RESULT	<union1,2>	ALL	NULL	NULL	NULL	NULL	NULL	
+DROP TABLE t1, t2;
+# End WL#4897
 End of 6.0 tests.

=== added file 'mysql-test/r/grant_explain_non_select.result'
--- a/mysql-test/r/grant_explain_non_select.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/grant_explain_non_select.result	2011-07-02 21:01:41 +0000
@@ -0,0 +1,178 @@
+CREATE DATABASE privtest_db;
+CREATE TABLE privtest_db.t1 (a INT);
+CREATE TABLE privtest_db.t2 (a INT);
+INSERT INTO privtest_db.t2 VALUES (1), (2), (3);
+GRANT USAGE ON *.* TO 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost';
+USE privtest_db;
+EXPLAIN INSERT INTO t1 VALUES (10);
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+INSERT INTO t1 VALUES (10);
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN INSERT INTO t1 SELECT * FROM t2;
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+INSERT INTO t1 SELECT * FROM t2;
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN INSERT INTO t1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+INSERT INTO t1 VALUES (10);
+EXPLAIN INSERT INTO t1 SELECT * FROM t2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	
+INSERT INTO t1 SELECT * FROM t2;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+EXPLAIN REPLACE INTO t1 VALUES (10);
+ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1'
+REPLACE INTO t1 VALUES (10);
+ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1'
+REPLACE INTO t1 SELECT * FROM t2;
+ERROR 42000: INSERT, DELETE command denied to user 'privtest'@'localhost' for table 't1'
+GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN REPLACE INTO t1 VALUES (10);
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+REPLACE INTO t1 VALUES (10);
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+REPLACE INTO t1 SELECT * FROM t2;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+REVOKE INSERT ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN REPLACE INTO t1 VALUES (10);
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+REPLACE INTO t1 VALUES (10);
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+REPLACE INTO t1 SELECT * FROM t2;
+ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1'
+GRANT INSERT, DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN REPLACE INTO t1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+REPLACE INTO t1 VALUES (10);
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	
+REPLACE INTO t1 SELECT * FROM t2;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+EXPLAIN UPDATE t1 SET a = a + 1;
+ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1'
+UPDATE t1 SET a = a + 1;
+ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1'
+UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1'
+GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN UPDATE t1 SET a = a + 1;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1'
+UPDATE t1 SET a = a + 1;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1'
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1'
+UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1'
+REVOKE UPDATE ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN UPDATE t1 SET a = a + 1;
+ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1'
+UPDATE t1 SET a = a + 1;
+ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1'
+UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1'
+GRANT UPDATE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN UPDATE t1 SET a = a + 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	8	
+UPDATE t1 SET a = a + 1;
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using join buffer (BNL, incremental buffers)
+UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+DELETE FROM t1 WHERE a = 10;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1'
+DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1'
+GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1'
+DELETE FROM t1 WHERE a = 10;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1'
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1'
+DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1'
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+DELETE FROM t1 WHERE a = 10;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1'
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT DELETE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	8	Using where
+DELETE FROM t1 WHERE a = 10;
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using join buffer (BNL, incremental buffers)
+DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+CREATE VIEW privtest_db.v1 (a) AS SELECT a FROM privtest_db.t1;
+GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.v1 TO 'privtest'@'localhost';
+EXPLAIN SELECT * FROM v1;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+SELECT * FROM v1;
+a
+11
+4
+4
+11
+4
+4
+EXPLAIN INSERT INTO v1 VALUES (10);
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+INSERT INTO v1 VALUES (10);
+EXPLAIN INSERT INTO v1 SELECT * FROM t2;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+INSERT INTO v1 SELECT * FROM t2;
+EXPLAIN REPLACE  INTO v1 VALUES (10);
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+REPLACE  INTO v1 VALUES (10);
+EXPLAIN REPLACE INTO v1 SELECT * FROM t2;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+REPLACE INTO v1 SELECT * FROM t2;
+EXPLAIN UPDATE v1 SET a = a + 1;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+UPDATE v1 SET a = a + 1;
+EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
+EXPLAIN DELETE FROM v1 WHERE a = 10;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+DELETE FROM v1 WHERE a = 10;
+EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
+ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
+DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
+DROP USER 'privtest'@localhost;
+USE test;
+DROP DATABASE privtest_db;

=== added file 'mysql-test/r/innodb_explain_non_select_all.result'
--- a/mysql-test/r/innodb_explain_non_select_all.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_explain_non_select_all.result	2011-07-02 21:01:41 +0000
@@ -0,0 +1,3091 @@
+set optimizer_switch='semijoin=on,materialization=on,firstmatch=on,loosescan=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=off';
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = InnoDB;
+#1
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a < 10
+# select: SELECT * FROM t1     WHERE a < 10
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_update	3
+
+DROP TABLE t1;
+#2
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a < 10
+# select: SELECT * FROM t1 WHERE a < 10
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#3
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE a = 1
+# select: SELECT * FROM t1          WHERE a = 1
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#4
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1
+# select: SELECT * FROM t1, t2               WHERE t1.a = 1
+#
+EXPLAIN UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2               WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+Handler_update	1
+
+DROP TABLE t1, t2;
+#5
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_update	1
+Handler_write	3
+
+DROP TABLE t1, t2;
+#6
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t2`.`b` < 3)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	7
+Handler_update	3
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+# select: SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` < 3))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	11
+Handler_update	2
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where; FirstMatch(t2); Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t2); Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t2); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` < 3))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	6
+Handler_read_rnd_next	12
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	9
+Handler_read_key	18
+Handler_read_rnd_next	31
+Handler_update	2
+
+DROP TABLE t1, t2;
+#8
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	8
+Handler_read_rnd	3
+Handler_read_rnd_next	25
+Handler_update	3
+Handler_write	12
+
+DROP TABLE t1, t2;
+#9
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,'1' AS `1` from `test`.`t1` `t11`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	2
+Handler_read_rnd_next	5
+Handler_write	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	6
+Handler_read_rnd	3
+Handler_read_rnd_next	9
+Handler_update	3
+Handler_write	4
+
+DROP TABLE t1, t2;
+#10
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` > 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	16
+Handler_update	2
+Handler_write	3
+
+DROP TABLE t1, t2;
+#11
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a > 1 LIMIT 1
+# select: SELECT * FROM t1 WHERE a > 1 LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 1) limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	2
+
+DROP TABLE t1;
+#12
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE 0
+# select: SELECT * FROM t1 WHERE 0
+#
+EXPLAIN DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#13
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE 0
+# select: SELECT * FROM t1          WHERE 0
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#14
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a = 3
+# select: SELECT * FROM t1 WHERE a = 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	const	a	a	5	const	1	100.00	
+Warnings:
+Note	1003	select '3' AS `a`,'3' AS `b` from `test`.`t1` where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	4
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_key	4
+
+DROP TABLE t1;
+#15
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a < 3
+# select: SELECT * FROM t1 WHERE a < 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	1	100.00	Using index condition; Using MRR
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` < 3)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	9
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	5
+
+DROP TABLE t1;
+#16
+CREATE TABLE t1 ( a int PRIMARY KEY );
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	4
+
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_key	4
+Handler_read_next	3
+
+DROP TABLE t1;
+#17
+CREATE TABLE t1(a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (4),(3),(1),(2);
+#
+# query:  DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+# select: SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	1	400.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (@a:=`test`.`t1`.`a`) order by `test`.`t1`.`a` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	3
+
+DROP TABLE t1;
+#18
+CREATE TABLE t1 (a DATE, b TIME, c INT, KEY c(c), KEY b(b), KEY a(a));
+INSERT INTO t1 VALUES (), (), (), (), (), (), (), (), (), ();
+UPDATE t1 SET a = c, b = c;
+#
+# query:  DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+# select: SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	6
+Handler_read_rnd_next	11
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_rnd	1
+Handler_read_rnd_next	11
+Sort_rows	10
+Sort_scan	1
+
+DROP TABLE t1;
+#19
+CREATE TABLE t1 (a1 INT NOT NULL, b1 INT NOT NULL);
+CREATE TABLE t2 (a2 INT NOT NULL, b2 INT NOT NULL, PRIMARY KEY (a2,b2));
+CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3));
+INSERT INTO t1 VALUES (1,1), (2,1), (1,3);
+INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
+INSERT INTO t3 VALUES (1,1), (2,1), (1,3);
+#
+# query:  DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+# select: SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+#
+EXPLAIN DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	Using index
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`b3` AS `b3` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`b3` = `test`.`t1`.`b1`) and (`test`.`t3`.`a3` = `test`.`t2`.`b2`) and (`test`.`t2`.`a2` = `test`.`t1`.`a1`))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	2
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	12
+Handler_read_next	3
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	8
+Handler_read_first	1
+Handler_read_key	19
+Handler_read_next	3
+Handler_read_rnd	5
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2, t3;
+#20
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2)
+# select: SELECT * FROM t1     WHERE a IN (SELECT a FROM t2)
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t2`.`a` = `test`.`t1`.`a`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	10
+Handler_update	3
+
+DROP TABLE t1, t2;
+#21
+CREATE TABLE t1 (a1 INT);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (a2 VARCHAR(10));
+INSERT INTO t2 VALUES (1), (2), (3), (4), (5);
+SET @save_optimizer_switch= @@optimizer_switch;
+SET @@optimizer_switch= 'semijoin=off';
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+
+SET @@optimizer_switch= @save_optimizer_switch;
+TRUNCATE t1;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`a2` > 2) and (`test`.`t1`.`a1` = `test`.`t2`.`a2`))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+
+DROP TABLE t1, t2;
+#22
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  UPDATE t1 SET i = 10
+# select: SELECT * FROM t1
+#
+EXPLAIN UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+Handler_update	5
+
+DROP TABLE t1;
+#23
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  DELETE FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	Deleting all rows
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	NULL	Deleting all rows
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+
+DROP TABLE t1;
+#24
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	X	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#25
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  INSERT INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#26
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  REPLACE INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#27
+CREATE TABLE t1 (i INT);
+#
+# query:  INSERT INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#28
+CREATE TABLE t1 (i INT);
+#
+# query:  REPLACE INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#29
+CREATE TABLE t1 (a INT, i INT PRIMARY KEY);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	4
+Handler_read_next	4
+
+DROP TABLE t1;
+#30
+CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	8
+Sort_scan	1
+
+DROP TABLE t1;
+#31
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#32
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	X	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#33
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#34
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#35
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	4
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	4
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_rnd_next	27
+Sort_rows	4
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_first	1
+Handler_read_key	11
+Handler_read_rnd	4
+Handler_read_rnd_next	27
+Sort_rows	4
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#36
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	4
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#37
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	26
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#38
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	X	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	X	X	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	3
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	3
+Handler_read_last	1
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#39
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	X	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	X	X	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	X	X	Using index condition
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	10
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#40
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	5
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#41
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Handler_update	1
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#42
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	X	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#43
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#44
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#45
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	4
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	4
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_rnd_next	27
+Sort_rows	4
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	11
+Handler_read_rnd	4
+Handler_read_rnd_next	27
+Handler_update	4
+Sort_rows	4
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#46
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	10
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#47
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	4
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#48
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	X	Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	X	X	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	3
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	9
+Handler_read_last	1
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#49
+CREATE TABLE t1 (
+pk INT NOT NULL AUTO_INCREMENT,
+c1_idx CHAR(1) DEFAULT 'y',
+c2 INT,
+PRIMARY KEY (pk),
+INDEX c1_idx (c1_idx)
+);
+INSERT INTO t1 VALUES (1,'y',1), (2,'n',2), (3,'y',3), (4,'n',4);
+#
+# query:  UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using index condition; Using where
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	8
+Handler_read_prev	1
+Handler_read_rnd	2
+Handler_update	2
+
+#
+# query:  DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using index condition; Using where
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	2
+Handler_read_key	5
+Handler_read_prev	1
+
+DROP TABLE t1;
+#50
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
+INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
+#
+# query:  UPDATE t1 SET a=a+10 WHERE a > 34
+# select: SELECT * FROM t1     WHERE a > 34
+#
+EXPLAIN UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 34)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	2
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+Handler_read_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	7
+Handler_read_next	2
+Handler_read_rnd	2
+Handler_update	2
+
+DROP TABLE t1;
+#51
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT);
+CREATE TABLE t2 (c1 INT, c2 INT);
+INSERT INTO t1 VALUES (1, 1, 10), (2, 2, 20);
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,`test`.`t2`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`c1` = `test`.`t2`.`c1`)) where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	6
+Handler_read_rnd_next	5
+
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,`test`.`t2`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`c1` = `test`.`t1`.`c1`)) where (`test`.`t1`.`c3` = 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2;
+#52
+CREATE TABLE t1(f1 INT, f2 INT);
+CREATE TABLE t2(f3 INT, f4 INT);
+CREATE INDEX IDX ON t2(f3);
+INSERT INTO t1 VALUES(1,0),(2,0);
+INSERT INTO t2 VALUES(1,1),(2,2);
+#
+# query:  UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)
+# select: SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1
+#
+EXPLAIN UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	1	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	1	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note	1003	select (select max(`test`.`t2`.`f4`) from `test`.`t2` where (`test`.`t2`.`f3` = `test`.`t1`.`f1`)) AS `(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_next	2
+Handler_read_rnd_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_next	2
+Handler_read_rnd_next	3
+Handler_update	2
+
+DROP TABLE t1, t2;
+#55
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1);
+SET @a = NULL;
+EXPLAIN DELETE FROM t1 WHERE (@a:= a);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using where
+DROP TABLE t1;
+#56
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+DROP TABLE t1;
+#57
+CREATE TABLE t1(f1 INT);
+EXPLAIN EXTENDED UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+DROP TABLE t1;
+#59
+CREATE TABLE t1 ( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+SET SESSION sql_safe_updates = 1;
+EXPLAIN EXTENDED UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+SET SESSION sql_safe_updates = DEFAULT;
+DROP TABLE t1;
+DROP VIEW v1;
+#62
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+#
+# query:  UPDATE        v1 SET a = 1 WHERE a > 0
+# select: SELECT * FROM v1           WHERE a > 0
+#
+EXPLAIN UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1           WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` > 0)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	6
+Handler_read_rnd	1
+Handler_read_rnd_next	9
+Handler_write	2
+
+#
+# query:  UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a
+# select: SELECT * FROM t1, v1              WHERE t1.a = v1.a
+#
+EXPLAIN UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, v1              WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` = `test`.`t1`.`a`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	6
+Handler_read_rnd_next	9
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	5
+Handler_read_key	13
+Handler_read_rnd	2
+Handler_read_rnd_next	19
+Handler_update	1
+Handler_write	4
+
+DROP TABLE t1;
+DROP VIEW v1;
+#63
+CREATE TABLE t1 (a INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE VIEW v1 (a) AS SELECT a FROM t1;
+#
+# query:  DELETE   FROM v1 WHERE a < 4
+# select: SELECT * FROM v1 WHERE a < 4
+#
+EXPLAIN DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 4)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	2
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_next	3
+
+DROP TABLE t1;
+DROP VIEW v1;
+#64
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	
+1	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	5	80.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	11
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_first	1
+Handler_read_key	13
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#65
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	
+1	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	5	80.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	11
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_first	1
+Handler_read_key	13
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#66
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 (x) AS SELECT a FROM t1;
+#
+# query:  INSERT INTO v1 VALUES (10)
+# select: SELECT NULL
+#
+EXPLAIN INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select NULL AS `NULL`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+DROP VIEW v1;
+#67
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+CREATE VIEW v1 (x) AS SELECT b FROM t2;
+#
+# query:  INSERT INTO v1 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	1
+
+DROP TABLE t1, t2;
+DROP VIEW v1;
+#68
+CREATE TABLE t1 (i INT);
+EXPLAIN INSERT DELAYED INTO t1 VALUES (1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+DROP TABLE t1;
+#69
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	3
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	100.00	Materialize; Scan
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) where (`test`.`t1`.`a` = `x`.`b`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_rnd_next	4
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	12
+Handler_write	2
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_update	1
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	End temporary; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_rnd_next	4
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` where (`test`.`t1`.`a` = `x`.`b`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_rnd_next	4
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	10
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	10
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	1	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	End temporary; Using join buffer (BNL, incremental buffers)
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	8
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`y`.`b` AS `b` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` where (`test`.`t1`.`a` = `x`.`b`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	8
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	7
+Handler_read_rnd_next	14
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	7
+Handler_read_rnd_next	14
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+
+DROP TABLE t1,t2;
+#70
+CREATE TABLE t1 (c1 INT KEY);
+CREATE TABLE t2 (c2 INT);
+CREATE TABLE t3 (c3 INT);
+EXPLAIN EXTENDED UPDATE t3 SET c3 = (
+SELECT COUNT(d1.c1)
+FROM (
+SELECT a11.c1 FROM t1 AS a11 
+STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1
+JOIN t1 AS a12 ON a12.c1 = a11.c1
+) d1
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	1	100.00	
+2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+3	DERIVED	a11	index	PRIMARY	PRIMARY	4	NULL	1	100.00	Using index
+3	DERIVED	a21	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+3	DERIVED	a12	eq_ref	PRIMARY	PRIMARY	4	test.a11.c1	1	100.00	Using index
+DROP TABLE t1, t2, t3;
+#71
+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, INDEX i1(c1));
+INSERT INTO t1 VALUES (1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0);
+CREATE TABLE t2 LIKE t1;
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	X	
+INSERT INTO t2 SELECT * FROM t1;
+SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+DROP TABLE t1, t2;
+#73
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 (id INT);
+INSERT INTO t1 VALUES (1), (2);
+EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USING(id) GROUP BY t1.id;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (BNL, incremental buffers)
+DROP TABLE t1,t2;
+set default_storage_engine= @save_storage_engine;
+set optimizer_switch=default;

=== added file 'mysql-test/r/innodb_explain_non_select_none.result'
--- a/mysql-test/r/innodb_explain_non_select_none.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_explain_non_select_none.result	2011-07-02 21:01:41 +0000
@@ -0,0 +1,3093 @@
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = InnoDB;
+#1
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a < 10
+# select: SELECT * FROM t1     WHERE a < 10
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_update	3
+
+DROP TABLE t1;
+#2
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a < 10
+# select: SELECT * FROM t1 WHERE a < 10
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#3
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE a = 1
+# select: SELECT * FROM t1          WHERE a = 1
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#4
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1
+# select: SELECT * FROM t1, t2               WHERE t1.a = 1
+#
+EXPLAIN UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2               WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	8
+Handler_update	1
+
+DROP TABLE t1, t2;
+#5
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_update	1
+Handler_write	3
+
+DROP TABLE t1, t2;
+#6
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t2` where (`test`.`t2`.`b` < 3)))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	7
+Handler_update	3
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+# select: SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from `test`.`t2` where ((`test`.`t1`.`a` < 3) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	11
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	11
+Handler_update	2
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`b` < 3) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	5
+Handler_read_key	10
+Handler_read_rnd_next	15
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	19
+Handler_update	2
+
+DROP TABLE t1, t2;
+#8
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	8
+Handler_read_rnd	3
+Handler_read_rnd_next	25
+Handler_update	3
+Handler_write	12
+
+DROP TABLE t1, t2;
+#9
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,'1' AS `1` from `test`.`t1` `t11`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	2
+Handler_read_rnd_next	5
+Handler_write	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	6
+Handler_read_rnd	3
+Handler_read_rnd_next	9
+Handler_update	3
+Handler_write	4
+
+DROP TABLE t1, t2;
+#10
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` > 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	16
+Handler_update	2
+Handler_write	3
+
+DROP TABLE t1, t2;
+#11
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a > 1 LIMIT 1
+# select: SELECT * FROM t1 WHERE a > 1 LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 1) limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	2
+
+DROP TABLE t1;
+#12
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE 0
+# select: SELECT * FROM t1 WHERE 0
+#
+EXPLAIN DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#13
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE 0
+# select: SELECT * FROM t1          WHERE 0
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#14
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a = 3
+# select: SELECT * FROM t1 WHERE a = 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	const	a	a	5	const	1	100.00	
+Warnings:
+Note	1003	select '3' AS `a`,'3' AS `b` from `test`.`t1` where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	4
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_key	4
+
+DROP TABLE t1;
+#15
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a < 3
+# select: SELECT * FROM t1 WHERE a < 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	1	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` < 3)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	5
+
+DROP TABLE t1;
+#16
+CREATE TABLE t1 ( a int PRIMARY KEY );
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	4
+
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_key	4
+Handler_read_next	3
+
+DROP TABLE t1;
+#17
+CREATE TABLE t1(a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (4),(3),(1),(2);
+#
+# query:  DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+# select: SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	1	400.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (@a:=`test`.`t1`.`a`) order by `test`.`t1`.`a` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	3
+
+DROP TABLE t1;
+#18
+CREATE TABLE t1 (a DATE, b TIME, c INT, KEY c(c), KEY b(b), KEY a(a));
+INSERT INTO t1 VALUES (), (), (), (), (), (), (), (), (), ();
+UPDATE t1 SET a = c, b = c;
+#
+# query:  DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+# select: SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	6
+Handler_read_rnd_next	11
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_rnd	1
+Handler_read_rnd_next	11
+Sort_rows	10
+Sort_scan	1
+
+DROP TABLE t1;
+#19
+CREATE TABLE t1 (a1 INT NOT NULL, b1 INT NOT NULL);
+CREATE TABLE t2 (a2 INT NOT NULL, b2 INT NOT NULL, PRIMARY KEY (a2,b2));
+CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3));
+INSERT INTO t1 VALUES (1,1), (2,1), (1,3);
+INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
+INSERT INTO t3 VALUES (1,1), (2,1), (1,3);
+#
+# query:  DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+# select: SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+#
+EXPLAIN DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	Using index
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`b3` AS `b3` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`b3` = `test`.`t1`.`b1`) and (`test`.`t3`.`a3` = `test`.`t2`.`b2`) and (`test`.`t2`.`a2` = `test`.`t1`.`a1`))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	2
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	12
+Handler_read_next	3
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	8
+Handler_read_first	1
+Handler_read_key	19
+Handler_read_next	3
+Handler_read_rnd	5
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2, t3;
+#20
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2)
+# select: SELECT * FROM t1     WHERE a IN (SELECT a FROM t2)
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from `test`.`t2` where (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`)))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	10
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	8
+Handler_read_rnd_next	10
+Handler_update	3
+
+DROP TABLE t1, t2;
+#21
+CREATE TABLE t1 (a1 INT);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (a2 VARCHAR(10));
+INSERT INTO t2 VALUES (1), (2), (3), (4), (5);
+SET @save_optimizer_switch= @@optimizer_switch;
+SET @@optimizer_switch= 'semijoin=off';
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+
+SET @@optimizer_switch= @save_optimizer_switch;
+TRUNCATE t1;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	6
+Handler_read_key	12
+Handler_read_rnd_next	30
+
+DROP TABLE t1, t2;
+#22
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  UPDATE t1 SET i = 10
+# select: SELECT * FROM t1
+#
+EXPLAIN UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+Handler_update	5
+
+DROP TABLE t1;
+#23
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  DELETE FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	Deleting all rows
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	NULL	Deleting all rows
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	6
+
+DROP TABLE t1;
+#24
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	X	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#25
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  INSERT INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#26
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  REPLACE INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#27
+CREATE TABLE t1 (i INT);
+#
+# query:  INSERT INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#28
+CREATE TABLE t1 (i INT);
+#
+# query:  REPLACE INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#29
+CREATE TABLE t1 (a INT, i INT PRIMARY KEY);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	4
+Handler_read_next	4
+
+DROP TABLE t1;
+#30
+CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	8
+Sort_scan	1
+
+DROP TABLE t1;
+#31
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#32
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	X	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#33
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#34
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#35
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	4
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	4
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_rnd_next	27
+Sort_rows	4
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_first	1
+Handler_read_key	11
+Handler_read_rnd	4
+Handler_read_rnd_next	27
+Sort_rows	4
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#36
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	4
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#37
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	26
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#38
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	X	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	X	X	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	3
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	3
+Handler_read_last	1
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#39
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	X	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	X	X	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	10
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#40
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	5
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#41
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Handler_update	1
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#42
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	X	X	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	X	X	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	3
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#43
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	5
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#44
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#45
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	4
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	key1,key2	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	4
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_rnd_next	27
+Sort_rows	4
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	11
+Handler_read_rnd	4
+Handler_read_rnd_next	27
+Handler_update	4
+Sort_rows	4
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#46
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	10
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#47
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	9
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	4
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#48
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	X	X	Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	X	X	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	3
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	9
+Handler_read_last	1
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#49
+CREATE TABLE t1 (
+pk INT NOT NULL AUTO_INCREMENT,
+c1_idx CHAR(1) DEFAULT 'y',
+c2 INT,
+PRIMARY KEY (pk),
+INDEX c1_idx (c1_idx)
+);
+INSERT INTO t1 VALUES (1,'y',1), (2,'n',2), (3,'y',3), (4,'n',4);
+#
+# query:  UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	8
+Handler_read_prev	1
+Handler_read_rnd	2
+Handler_update	2
+
+#
+# query:  DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	5
+Handler_read_prev	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	2
+Handler_read_key	5
+Handler_read_prev	1
+
+DROP TABLE t1;
+#50
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
+INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
+#
+# query:  UPDATE t1 SET a=a+10 WHERE a > 34
+# select: SELECT * FROM t1     WHERE a > 34
+#
+EXPLAIN UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 34)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	2
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+Handler_read_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	7
+Handler_read_next	2
+Handler_read_rnd	2
+Handler_update	2
+
+DROP TABLE t1;
+#51
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT);
+CREATE TABLE t2 (c1 INT, c2 INT);
+INSERT INTO t1 VALUES (1, 1, 10), (2, 2, 20);
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,`test`.`t2`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` left join `test`.`t2` on((`test`.`t1`.`c1` = `test`.`t2`.`c1`)) where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	6
+Handler_read_rnd_next	5
+
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,`test`.`t2`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`c1` = `test`.`t1`.`c1`)) where (`test`.`t1`.`c3` = 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2;
+#52
+CREATE TABLE t1(f1 INT, f2 INT);
+CREATE TABLE t2(f3 INT, f4 INT);
+CREATE INDEX IDX ON t2(f3);
+INSERT INTO t1 VALUES(1,0),(2,0);
+INSERT INTO t2 VALUES(1,1),(2,2);
+#
+# query:  UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)
+# select: SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1
+#
+EXPLAIN UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	1	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	1	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note	1003	select (select max(`test`.`t2`.`f4`) from `test`.`t2` where (`test`.`t2`.`f3` = `test`.`t1`.`f1`)) AS `(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_next	2
+Handler_read_rnd_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	7
+Handler_read_next	2
+Handler_read_rnd_next	3
+Handler_update	2
+
+DROP TABLE t1, t2;
+#55
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1);
+SET @a = NULL;
+EXPLAIN DELETE FROM t1 WHERE (@a:= a);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using where
+DROP TABLE t1;
+#56
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+DROP TABLE t1;
+#57
+CREATE TABLE t1(f1 INT);
+EXPLAIN EXTENDED UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+DROP TABLE t1;
+#59
+CREATE TABLE t1 ( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+SET SESSION sql_safe_updates = 1;
+EXPLAIN EXTENDED UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+SET SESSION sql_safe_updates = DEFAULT;
+DROP TABLE t1;
+DROP VIEW v1;
+#62
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+#
+# query:  UPDATE        v1 SET a = 1 WHERE a > 0
+# select: SELECT * FROM v1           WHERE a > 0
+#
+EXPLAIN UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1           WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` > 0)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	4
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	6
+Handler_read_rnd	1
+Handler_read_rnd_next	9
+Handler_write	2
+
+#
+# query:  UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a
+# select: SELECT * FROM t1, v1              WHERE t1.a = v1.a
+#
+EXPLAIN UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, v1              WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` = `test`.`t1`.`a`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	6
+Handler_read_rnd_next	9
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	5
+Handler_read_key	13
+Handler_read_rnd	2
+Handler_read_rnd_next	19
+Handler_update	1
+Handler_write	4
+
+DROP TABLE t1;
+DROP VIEW v1;
+#63
+CREATE TABLE t1 (a INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE VIEW v1 (a) AS SELECT a FROM t1;
+#
+# query:  DELETE   FROM v1 WHERE a < 4
+# select: SELECT * FROM v1 WHERE a < 4
+#
+EXPLAIN DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	2
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 4)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	2
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	1
+Handler_read_key	4
+Handler_read_next	3
+
+DROP TABLE t1;
+DROP VIEW v1;
+#64
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	
+1	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	5	80.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	11
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_first	1
+Handler_read_key	13
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#65
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_key	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	
+1	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	5	80.00	Using where; Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	5
+Handler_read_rnd_next	11
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_first	1
+Handler_read_key	13
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#66
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 (x) AS SELECT a FROM t1;
+#
+# query:  INSERT INTO v1 VALUES (10)
+# select: SELECT NULL
+#
+EXPLAIN INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select NULL AS `NULL`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+DROP VIEW v1;
+#67
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+CREATE VIEW v1 (x) AS SELECT b FROM t2;
+#
+# query:  INSERT INTO v1 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_key	2
+Handler_read_rnd_next	1
+
+DROP TABLE t1, t2;
+DROP VIEW v1;
+#68
+CREATE TABLE t1 (i INT);
+EXPLAIN INSERT DELAYED INTO t1 VALUES (1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+DROP TABLE t1;
+#69
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	3
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from dual where (<cache>(`test`.`t1`.`a`) = '3')))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	3
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_update	1
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	3
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from dual where (<cache>(`test`.`t1`.`a`) = '3')))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	2
+Handler_read_key	3
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+3	DEPENDENT SUBQUERY	<derived4>	system	NULL	NULL	NULL	NULL	1	
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+3	DEPENDENT SUBQUERY	<derived4>	system	NULL	NULL	NULL	NULL	1	100.00	
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+3	DEPENDENT SUBQUERY	<derived4>	system	NULL	NULL	NULL	NULL	1	100.00	
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`y`.`b` AS `b` from `test`.`t1` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from dual where (<cache>(`test`.`t1`.`a`) = '3')))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	3
+Handler_read_key	5
+Handler_read_rnd_next	9
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	7
+Handler_read_rnd_next	13
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	4
+Handler_read_key	7
+Handler_read_rnd_next	13
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+
+DROP TABLE t1,t2;
+#70
+CREATE TABLE t1 (c1 INT KEY);
+CREATE TABLE t2 (c2 INT);
+CREATE TABLE t3 (c3 INT);
+EXPLAIN EXTENDED UPDATE t3 SET c3 = (
+SELECT COUNT(d1.c1)
+FROM (
+SELECT a11.c1 FROM t1 AS a11 
+STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1
+JOIN t1 AS a12 ON a12.c1 = a11.c1
+) d1
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	1	100.00	
+2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+3	DERIVED	a11	index	PRIMARY	PRIMARY	4	NULL	1	100.00	Using index
+3	DERIVED	a21	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where; Using join buffer (BNL, incremental buffers)
+3	DERIVED	a12	eq_ref	PRIMARY	PRIMARY	4	test.a11.c1	1	100.00	Using index
+DROP TABLE t1, t2, t3;
+#71
+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, INDEX i1(c1));
+INSERT INTO t1 VALUES (1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0);
+CREATE TABLE t2 LIKE t1;
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	X	
+INSERT INTO t2 SELECT * FROM t1;
+SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+DROP TABLE t1, t2;
+#73
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 (id INT);
+INSERT INTO t1 VALUES (1), (2);
+EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USING(id) GROUP BY t1.id;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (BNL, incremental buffers)
+DROP TABLE t1,t2;
+set default_storage_engine= @save_storage_engine;
+set optimizer_switch=default;

=== modified file 'mysql-test/r/join_outer.result'
--- a/mysql-test/r/join_outer.result	2011-06-11 13:38:32 +0000
+++ b/mysql-test/r/join_outer.result	2011-07-02 21:01:41 +0000
@@ -610,7 +610,7 @@ INSERT INTO t2 VALUES (1,1);
 explain SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
-1	SIMPLE	t2	ref	id	id	4	test.t1.id	1	Using where; Using index; Not exists
+1	SIMPLE	t2	ref	id	id	4	test.t1.id	1	Using where; Not exists; Using index
 SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL;
 id	name	id	idx
 2	no	NULL	NULL
@@ -1251,7 +1251,7 @@ INSERT INTO t2 VALUES (1), (2), (3);
 EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d IS NULL;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
-1	SIMPLE	t2	index	NULL	PRIMARY	4	NULL	3	Using where; Using index; Not exists
+1	SIMPLE	t2	index	NULL	PRIMARY	4	NULL	3	Using where; Not exists; Using index
 SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d IS NULL;
 c	e	d
 1	0	NULL

=== modified file 'mysql-test/r/join_outer_jcl6.result'
--- a/mysql-test/r/join_outer_jcl6.result	2011-06-11 13:38:32 +0000
+++ b/mysql-test/r/join_outer_jcl6.result	2011-07-02 21:01:41 +0000
@@ -615,7 +615,7 @@ INSERT INTO t2 VALUES (1,1);
 explain SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
-1	SIMPLE	t2	ref	id	id	4	test.t1.id	1	Using where; Using index; Not exists
+1	SIMPLE	t2	ref	id	id	4	test.t1.id	1	Using where; Not exists; Using index
 SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL;
 id	name	id	idx
 2	no	NULL	NULL
@@ -1256,7 +1256,7 @@ INSERT INTO t2 VALUES (1), (2), (3);
 EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d IS NULL;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
-1	SIMPLE	t2	index	NULL	PRIMARY	4	NULL	3	Using where; Using index; Not exists
+1	SIMPLE	t2	index	NULL	PRIMARY	4	NULL	3	Using where; Not exists; Using index
 SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d IS NULL;
 c	e	d
 1	0	NULL

=== added file 'mysql-test/r/myisam_explain_non_select_all.result'
--- a/mysql-test/r/myisam_explain_non_select_all.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/myisam_explain_non_select_all.result	2011-07-02 21:01:41 +0000
@@ -0,0 +1,2864 @@
+set optimizer_switch='semijoin=on,materialization=on,firstmatch=on,loosescan=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=off';
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = MyISAM;
+#1
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a < 10
+# select: SELECT * FROM t1     WHERE a < 10
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_update	3
+
+DROP TABLE t1;
+#2
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a < 10
+# select: SELECT * FROM t1 WHERE a < 10
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#3
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE a = 1
+# select: SELECT * FROM t1          WHERE a = 1
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#4
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1
+# select: SELECT * FROM t1, t2               WHERE t1.a = 1
+#
+EXPLAIN UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2               WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+Handler_update	1
+
+DROP TABLE t1, t2;
+#5
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_update	1
+Handler_write	3
+
+DROP TABLE t1, t2;
+#6
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t2`.`b` < 3)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	7
+Handler_update	3
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+# select: SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` < 3))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	11
+Handler_update	2
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where; FirstMatch(t2); Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t2); Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t2); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` < 3))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	31
+Handler_update	2
+
+DROP TABLE t1, t2;
+#8
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	3
+Handler_read_rnd_next	25
+Handler_update	3
+Handler_write	12
+
+DROP TABLE t1, t2;
+#9
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,'1' AS `1` from `test`.`t1` `t11`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd	3
+Handler_read_rnd_next	9
+Handler_update	3
+Handler_write	4
+
+DROP TABLE t1, t2;
+#10
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` > 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	16
+Handler_update	2
+Handler_write	3
+
+DROP TABLE t1, t2;
+#11
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a > 1 LIMIT 1
+# select: SELECT * FROM t1 WHERE a > 1 LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 1) limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd_next	2
+
+DROP TABLE t1;
+#12
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE 0
+# select: SELECT * FROM t1 WHERE 0
+#
+EXPLAIN DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#13
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE 0
+# select: SELECT * FROM t1          WHERE 0
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#14
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a = 3
+# select: SELECT * FROM t1 WHERE a = 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	const	a	a	5	const	1	100.00	
+Warnings:
+Note	1003	select '3' AS `a`,'3' AS `b` from `test`.`t1` where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_key	1
+
+DROP TABLE t1;
+#15
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a < 3
+# select: SELECT * FROM t1 WHERE a < 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	1	100.00	Using index condition; Using MRR
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` < 3)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+
+DROP TABLE t1;
+#16
+CREATE TABLE t1 ( a int PRIMARY KEY );
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
+Warnings:
+Note	1003	select NULL AS `a` from `test`.`t1` where 0 order by NULL
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_key	1
+Handler_read_next	3
+
+DROP TABLE t1;
+#17
+CREATE TABLE t1(a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (4),(3),(1),(2);
+#
+# query:  DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+# select: SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	1	400.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (@a:=`test`.`t1`.`a`) order by `test`.`t1`.`a` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+
+DROP TABLE t1;
+#18
+CREATE TABLE t1 (a DATE, b TIME, c INT, KEY c(c), KEY b(b), KEY a(a));
+INSERT INTO t1 VALUES (), (), (), (), (), (), (), (), (), ();
+UPDATE t1 SET a = c, b = c;
+#
+# query:  DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+# select: SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	11
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	11
+Sort_rows	10
+Sort_scan	1
+
+DROP TABLE t1;
+#19
+CREATE TABLE t1 (a1 INT NOT NULL, b1 INT NOT NULL);
+CREATE TABLE t2 (a2 INT NOT NULL, b2 INT NOT NULL, PRIMARY KEY (a2,b2));
+CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3));
+INSERT INTO t1 VALUES (1,1), (2,1), (1,3);
+INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
+INSERT INTO t3 VALUES (1,1), (2,1), (1,3);
+#
+# query:  DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+# select: SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+#
+EXPLAIN DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	Using index
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`b3` AS `b3` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`b3` = `test`.`t1`.`b1`) and (`test`.`t3`.`a3` = `test`.`t2`.`b2`) and (`test`.`t2`.`a2` = `test`.`t1`.`a1`))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	6
+Handler_read_next	3
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	8
+Handler_read_key	6
+Handler_read_next	3
+Handler_read_rnd	5
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2, t3;
+#20
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2)
+# select: SELECT * FROM t1     WHERE a IN (SELECT a FROM t2)
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t2`.`a` = `test`.`t1`.`a`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	10
+Handler_update	3
+
+DROP TABLE t1, t2;
+#21
+CREATE TABLE t1 (a1 INT);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (a2 VARCHAR(10));
+INSERT INTO t2 VALUES (1), (2), (3), (4), (5);
+SET @save_optimizer_switch= @@optimizer_switch;
+SET @@optimizer_switch= 'semijoin=off';
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	30
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_rnd_next	30
+
+SET @@optimizer_switch= @save_optimizer_switch;
+TRUNCATE t1;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where; FirstMatch(t1); Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`a2` > 2) and (`test`.`t1`.`a1` = `test`.`t2`.`a2`))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_rnd_next	30
+
+DROP TABLE t1, t2;
+#22
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  UPDATE t1 SET i = 10
+# select: SELECT * FROM t1
+#
+EXPLAIN UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+Handler_update	5
+
+DROP TABLE t1;
+#23
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  DELETE FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	Deleting all rows
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	NULL	Deleting all rows
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#24
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	5	352040.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#25
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  INSERT INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#26
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  REPLACE INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#27
+CREATE TABLE t1 (i INT);
+#
+# query:  INSERT INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#28
+CREATE TABLE t1 (i INT);
+#
+# query:  REPLACE INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#29
+CREATE TABLE t1 (a INT, i INT PRIMARY KEY);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	1
+Handler_read_next	4
+
+DROP TABLE t1;
+#30
+CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	8
+Sort_scan	1
+
+DROP TABLE t1;
+#31
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#32
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	5	352040.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#33
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#34
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#35
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	Using sort_union(key1,key2); Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	4
+Sort_range	1
+Sort_rows	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	8
+Sort_range	1
+Sort_rows	4
+
+DROP TABLE t1, t2;
+#36
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	1
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#37
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	26
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#38
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	5	352040.00	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_last	1
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#39
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#40
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	5
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#41
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Handler_update	1
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#42
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	5	352040.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#43
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#44
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#45
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	Using sort_union(key1,key2); Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	4
+Sort_range	1
+Sort_rows	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	8
+Handler_update	4
+Sort_range	1
+Sort_rows	4
+
+DROP TABLE t1, t2;
+#46
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using index condition
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#47
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	4
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#48
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	100.00	Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	5	352040.00	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_last	1
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#49
+CREATE TABLE t1 (
+pk INT NOT NULL AUTO_INCREMENT,
+c1_idx CHAR(1) DEFAULT 'y',
+c2 INT,
+PRIMARY KEY (pk),
+INDEX c1_idx (c1_idx)
+);
+INSERT INTO t1 VALUES (1,'y',1), (2,'n',2), (3,'y',3), (4,'n',4);
+#
+# query:  UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using index condition; Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Sort_range	1
+Sort_rows	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Handler_update	2
+Sort_range	1
+Sort_rows	2
+
+#
+# query:  DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using index condition; Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Sort_range	1
+Sort_rows	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	2
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Sort_range	1
+Sort_rows	2
+
+DROP TABLE t1;
+#50
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
+INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
+#
+# query:  UPDATE t1 SET a=a+10 WHERE a > 34
+# select: SELECT * FROM t1     WHERE a > 34
+#
+EXPLAIN UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 34)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Handler_update	2
+
+DROP TABLE t1;
+#51
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT);
+CREATE TABLE t2 (c1 INT, c2 INT);
+INSERT INTO t1 VALUES (1, 1, 10), (2, 2, 20);
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,NULL AS `c1`,NULL AS `c2` from `test`.`t1` where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,NULL AS `c1`,NULL AS `c2` from `test`.`t1` where (`test`.`t1`.`c3` = 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2;
+#52
+CREATE TABLE t1(f1 INT, f2 INT);
+CREATE TABLE t2(f3 INT, f4 INT);
+CREATE INDEX IDX ON t2(f3);
+INSERT INTO t1 VALUES(1,0),(2,0);
+INSERT INTO t2 VALUES(1,1),(2,2);
+#
+# query:  UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)
+# select: SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1
+#
+EXPLAIN UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	2	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	2	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	2	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note	1003	select (select max(`test`.`t2`.`f4`) from `test`.`t2` where (`test`.`t2`.`f3` = `test`.`t1`.`f1`)) AS `(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	2
+Handler_read_rnd_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	2
+Handler_read_rnd_next	3
+Handler_update	2
+
+DROP TABLE t1, t2;
+#55
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1);
+SET @a = NULL;
+EXPLAIN DELETE FROM t1 WHERE (@a:= a);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using where
+DROP TABLE t1;
+#56
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+DROP TABLE t1;
+#57
+CREATE TABLE t1(f1 INT);
+EXPLAIN EXTENDED UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+DROP TABLE t1;
+#59
+CREATE TABLE t1 ( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+SET SESSION sql_safe_updates = 1;
+EXPLAIN EXTENDED UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+SET SESSION sql_safe_updates = DEFAULT;
+DROP TABLE t1;
+DROP VIEW v1;
+#62
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+#
+# query:  UPDATE        v1 SET a = 1 WHERE a > 0
+# select: SELECT * FROM v1           WHERE a > 0
+#
+EXPLAIN UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1           WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` > 0)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	9
+Handler_write	2
+
+#
+# query:  UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a
+# select: SELECT * FROM t1, v1              WHERE t1.a = v1.a
+#
+EXPLAIN UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, v1              WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` = `test`.`t1`.`a`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	9
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	2
+Handler_read_rnd_next	19
+Handler_update	1
+Handler_write	4
+
+DROP TABLE t1;
+DROP VIEW v1;
+#63
+CREATE TABLE t1 (a INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE VIEW v1 (a) AS SELECT a FROM t1;
+#
+# query:  DELETE   FROM v1 WHERE a < 4
+# select: SELECT * FROM v1 WHERE a < 4
+#
+EXPLAIN DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 4)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	1
+Handler_read_next	3
+
+DROP TABLE t1;
+DROP VIEW v1;
+#64
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+Handler_read_rnd_next	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_key	4
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#65
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+Handler_read_rnd_next	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_key	4
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#66
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 (x) AS SELECT a FROM t1;
+#
+# query:  INSERT INTO v1 VALUES (10)
+# select: SELECT NULL
+#
+EXPLAIN INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select NULL AS `NULL`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+DROP VIEW v1;
+#67
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+CREATE VIEW v1 (x) AS SELECT b FROM t2;
+#
+# query:  INSERT INTO v1 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	const row not found
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+Warnings:
+Note	1003	select NULL AS `a` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+
+DROP TABLE t1, t2;
+DROP VIEW v1;
+#68
+CREATE TABLE t1 (i INT);
+EXPLAIN INSERT DELAYED INTO t1 VALUES (1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+DROP TABLE t1;
+#69
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	100.00	Materialize; Scan
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) where (`test`.`t1`.`a` = `x`.`b`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	2
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_update	1
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	End temporary; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived3>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` where (`test`.`t1`.`a` = `x`.`b`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	10
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	10
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	1	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	End temporary; Using join buffer (BNL, incremental buffers)
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	8
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived4>	ALL	NULL	NULL	NULL	NULL	1	100.00	Start temporary
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	End temporary; Using join buffer (BNL, incremental buffers)
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`y`.`b` AS `b` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` where (`test`.`t1`.`a` = `x`.`b`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	8
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	14
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	14
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+
+DROP TABLE t1,t2;
+#70
+CREATE TABLE t1 (c1 INT KEY);
+CREATE TABLE t2 (c2 INT);
+CREATE TABLE t3 (c3 INT);
+EXPLAIN EXTENDED UPDATE t3 SET c3 = (
+SELECT COUNT(d1.c1)
+FROM (
+SELECT a11.c1 FROM t1 AS a11 
+STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1
+JOIN t1 AS a12 ON a12.c1 = a11.c1
+) d1
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	0	100.00	
+2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+3	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
+DROP TABLE t1, t2, t3;
+#71
+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, INDEX i1(c1));
+INSERT INTO t1 VALUES (1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0);
+CREATE TABLE t2 LIKE t1;
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	X	
+INSERT INTO t2 SELECT * FROM t1;
+SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+DROP TABLE t1, t2;
+#73
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 (id INT);
+INSERT INTO t1 VALUES (1), (2);
+EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USING(id) GROUP BY t1.id;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort
+DROP TABLE t1,t2;
+set default_storage_engine= @save_storage_engine;
+set optimizer_switch=default;

=== added file 'mysql-test/r/myisam_explain_non_select_none.result'
--- a/mysql-test/r/myisam_explain_non_select_none.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/myisam_explain_non_select_none.result	2011-07-02 21:01:41 +0000
@@ -0,0 +1,2872 @@
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = MyISAM;
+#1
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a < 10
+# select: SELECT * FROM t1     WHERE a < 10
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_update	3
+
+DROP TABLE t1;
+#2
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a < 10
+# select: SELECT * FROM t1 WHERE a < 10
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#3
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE a = 1
+# select: SELECT * FROM t1          WHERE a = 1
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd_next	4
+
+DROP TABLE t1;
+#4
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1
+# select: SELECT * FROM t1, t2               WHERE t1.a = 1
+#
+EXPLAIN UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET t1.a = 10 WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2               WHERE t1.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	8
+Handler_update	1
+
+DROP TABLE t1, t2;
+#5
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a = 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` = 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_update	1
+Handler_write	3
+
+DROP TABLE t1, t2;
+#6
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(1,<exists>(select 1 from `test`.`t2` where (`test`.`t2`.`b` < 3)))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	7
+Handler_update	3
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+# select: SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from `test`.`t2` where ((`test`.`t1`.`a` < 3) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	11
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	11
+Handler_update	2
+
+DROP TABLE t1, t2;
+#7
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`b` < 3) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	15
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	19
+Handler_update	2
+
+DROP TABLE t1, t2;
+#8
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	3
+Handler_read_rnd_next	25
+Handler_update	3
+Handler_write	12
+
+DROP TABLE t1, t2;
+#9
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10
+# select: SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12
+#
+EXPLAIN UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	
+2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,'1' AS `1` from `test`.`t1` `t11`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+Handler_write	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd	3
+Handler_read_rnd_next	9
+Handler_update	3
+Handler_write	4
+
+DROP TABLE t1, t2;
+#10
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1
+# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1
+#
+EXPLAIN UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12                WHERE t11.a > 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t11	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`t12`.`b` AS `b` from `test`.`t1` `t11` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `t12` where (`test`.`t11`.`a` > 1)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	12
+Handler_write	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	16
+Handler_update	2
+Handler_write	3
+
+DROP TABLE t1, t2;
+#11
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE a > 1 LIMIT 1
+# select: SELECT * FROM t1 WHERE a > 1 LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > 1 LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 1) limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd_next	2
+
+DROP TABLE t1;
+#12
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE 0
+# select: SELECT * FROM t1 WHERE 0
+#
+EXPLAIN DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#13
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 USING t1 WHERE 0
+# select: SELECT * FROM t1          WHERE 0
+#
+EXPLAIN DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 USING t1 WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1          WHERE 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#14
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a = 3
+# select: SELECT * FROM t1 WHERE a = 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	const	a	a	5	const	1	100.00	
+Warnings:
+Note	1003	select '3' AS `a`,'3' AS `b` from `test`.`t1` where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_key	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_key	1
+
+DROP TABLE t1;
+#15
+CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b));
+INSERT INTO t1 VALUES (3, 3), (7, 7);
+#
+# query:  DELETE   FROM t1 WHERE a < 3
+# select: SELECT * FROM t1 WHERE a < 3
+#
+EXPLAIN DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a,b	a	5	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	1	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` < 3)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+
+DROP TABLE t1;
+#16
+CREATE TABLE t1 ( a int PRIMARY KEY );
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	1	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
+Warnings:
+Note	1003	select NULL AS `a` from `test`.`t1` where 0 order by NULL
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+
+INSERT INTO t1 VALUES (1), (2), (3);
+#
+# query:  DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a
+#
+EXPLAIN DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_key	1
+Handler_read_next	3
+
+DROP TABLE t1;
+#17
+CREATE TABLE t1(a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (4),(3),(1),(2);
+#
+# query:  DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+# select: SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	PRIMARY	PRIMARY	4	NULL	4	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	1	400.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (@a:=`test`.`t1`.`a`) order by `test`.`t1`.`a` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_first	1
+
+DROP TABLE t1;
+#18
+CREATE TABLE t1 (a DATE, b TIME, c INT, KEY c(c), KEY b(b), KEY a(a));
+INSERT INTO t1 VALUES (), (), (), (), (), (), (), (), (), ();
+UPDATE t1 SET a = c, b = c;
+#
+# query:  DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+# select: SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1
+#
+EXPLAIN DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	c,b,a	NULL	NULL	NULL	10	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	11
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	11
+Sort_rows	10
+Sort_scan	1
+
+DROP TABLE t1;
+#19
+CREATE TABLE t1 (a1 INT NOT NULL, b1 INT NOT NULL);
+CREATE TABLE t2 (a2 INT NOT NULL, b2 INT NOT NULL, PRIMARY KEY (a2,b2));
+CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3));
+INSERT INTO t1 VALUES (1,1), (2,1), (1,3);
+INSERT INTO t2 VALUES (1,1), (2,2), (3,3);
+INSERT INTO t3 VALUES (1,1), (2,1), (1,3);
+#
+# query:  DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+# select: SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3
+#
+EXPLAIN DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *        FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	100.00	Using index
+1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b2,test.t1.b1	1	100.00	Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`b3` AS `b3` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`b3` = `test`.`t1`.`b1`) and (`test`.`t3`.`a3` = `test`.`t2`.`b2`) and (`test`.`t2`.`a2` = `test`.`t1`.`a1`))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	6
+Handler_read_next	3
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	8
+Handler_read_key	6
+Handler_read_next	3
+Handler_read_rnd	5
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2, t3;
+#20
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2)
+# select: SELECT * FROM t1     WHERE a IN (SELECT a FROM t2)
+#
+EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a IN (SELECT a FROM t2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from `test`.`t2` where (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`)))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	10
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	10
+Handler_update	3
+
+DROP TABLE t1, t2;
+#21
+CREATE TABLE t1 (a1 INT);
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE TABLE t2 (a2 VARCHAR(10));
+INSERT INTO t2 VALUES (1), (2), (3), (4), (5);
+SET @save_optimizer_switch= @@optimizer_switch;
+SET @@optimizer_switch= 'semijoin=off';
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	30
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_rnd_next	30
+
+SET @@optimizer_switch= @save_optimizer_switch;
+TRUNCATE t1;
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+#
+# query:  DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2)
+#
+EXPLAIN DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	5	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,<exists>(select 1 from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	30
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_rnd_next	30
+
+DROP TABLE t1, t2;
+#22
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  UPDATE t1 SET i = 10
+# select: SELECT * FROM t1
+#
+EXPLAIN UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+Handler_update	5
+
+DROP TABLE t1;
+#23
+CREATE TABLE t1 (i INT, j INT);
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+#
+# query:  DELETE FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	Deleting all rows
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	5	NULL	Deleting all rows
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+
+DROP TABLE t1;
+#24
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	5	352040.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#25
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  INSERT INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#26
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (i INT);
+#
+# query:  REPLACE INTO t2 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`i` AS `i` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd_next	4
+Handler_write	3
+
+DROP TABLE t1, t2;
+#27
+CREATE TABLE t1 (i INT);
+#
+# query:  INSERT INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#28
+CREATE TABLE t1 (i INT);
+#
+# query:  REPLACE INTO t1 SET i = 10
+# select: 
+#
+EXPLAIN REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+#29
+CREATE TABLE t1 (a INT, i INT PRIMARY KEY);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	1
+Handler_read_next	4
+
+DROP TABLE t1;
+#30
+CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+#
+# query:  DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	8
+Sort_scan	1
+
+DROP TABLE t1;
+#31
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#32
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	5	352040.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_first	1
+Handler_read_next	4
+
+DROP TABLE t1, t2;
+#33
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#34
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	1
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#35
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	Using sort_union(key1,key2); Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	4
+Sort_range	1
+Sort_rows	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	8
+Sort_range	1
+Sort_rows	4
+
+DROP TABLE t1, t2;
+#36
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_key	1
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#37
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Sort_rows	26
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#38
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	5	352040.00	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	5
+Handler_read_last	1
+Handler_read_prev	4
+
+DROP TABLE t1, t2;
+#39
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM  t2    WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#40
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i CHAR(2), INDEX(i(1)));
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	i	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Warning	1713	Cannot use range access on index 'i' due to type or collation conversion on field 'i'
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	5
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#41
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Handler_update	1
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#42
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c));
+INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1;
+INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	15	NULL	17602	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	15	NULL	5	352040.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#43
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c));
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#44
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c))
+ENGINE=HEAP;
+INSERT INTO t2 SELECT i, i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5
+# select: SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5
+#
+EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Warning	1713	Cannot use range access on index 'a' due to type or collation conversion on field 'b'
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE b = 10 ORDER BY a, c LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	27
+Sort_rows	1
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#45
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2));
+INSERT INTO t2 (key1, key2) SELECT i, i FROM t1;
+#
+# query:  UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1
+# select: SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1
+#
+EXPLAIN UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	Using sort_union(key1,key2); Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2      WHERE key1 < 13 or key2 < 14 ORDER BY key1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index_merge	key1,key2	key1,key2	5,5	NULL	7	100.00	Using sort_union(key1,key2); Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	4
+Sort_range	1
+Sort_rows	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	7
+Handler_read_rnd	8
+Handler_update	4
+Sort_range	1
+Sort_rows	4
+
+DROP TABLE t1, t2;
+#46
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2(a INT, i INT PRIMARY KEY);
+INSERT INTO t2 (i) SELECT i FROM t1;
+#
+# query:  UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+# select: SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	8	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#47
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b));
+INSERT INTO t2 SELECT i, i, i FROM t1;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	NULL	NULL	NULL	26	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	26	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	27
+Sort_rows	5
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	5
+Handler_read_rnd_next	27
+Handler_update	4
+Sort_rows	5
+Sort_scan	1
+
+DROP TABLE t1, t2;
+#48
+CREATE TABLE t1 (i INT);
+INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19),
+(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),
+(30),(31),(32),(33),(34),(35);
+CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b));
+INSERT INTO t2 (a, b) SELECT i, i FROM t1;
+INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2;
+#
+# query:  UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5
+# select: SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5
+#
+EXPLAIN UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	a	a	6	NULL	5	100.00	Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t2     ORDER BY a DESC, b DESC LIMIT 5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	index	NULL	a	6	NULL	5	352040.00	
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_last	1
+Handler_read_prev	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_last	1
+Handler_read_prev	4
+Handler_read_rnd	5
+Handler_update	5
+
+DROP TABLE t1, t2;
+#49
+CREATE TABLE t1 (
+pk INT NOT NULL AUTO_INCREMENT,
+c1_idx CHAR(1) DEFAULT 'y',
+c2 INT,
+PRIMARY KEY (pk),
+INDEX c1_idx (c1_idx)
+);
+INSERT INTO t1 VALUES (1,'y',1), (2,'n',2), (3,'y',3), (4,'n',4);
+#
+# query:  UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Sort_range	1
+Sort_rows	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Handler_update	2
+Sort_range	1
+Sort_rows	2
+
+#
+# query:  DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+# select: SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2
+#
+EXPLAIN DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	Using where; Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY,c1_idx	c1_idx	2	NULL	2	100.00	Using where; Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ref	c1_idx	c1_idx	2	const	2	100.00	Using where; Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Sort_range	1
+Sort_rows	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	2
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Sort_range	1
+Sort_rows	2
+
+DROP TABLE t1;
+#50
+CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY);
+INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),();
+#
+# query:  UPDATE t1 SET a=a+10 WHERE a > 34
+# select: SELECT * FROM t1     WHERE a > 34
+#
+EXPLAIN UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where; Using temporary
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using temporary
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1     WHERE a > 34;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 34)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	1
+Handler_read_next	2
+Handler_read_rnd	2
+Handler_update	2
+
+DROP TABLE t1;
+#51
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT);
+CREATE TABLE t2 (c1 INT, c2 INT);
+INSERT INTO t1 VALUES (1, 1, 10), (2, 2, 20);
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,NULL AS `c1`,NULL AS `c2` from `test`.`t1` where 1
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+
+#
+# query:  UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10
+# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10
+#
+EXPLAIN UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1                WHERE t1.c3 = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+Warnings:
+Note	1003	select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,NULL AS `c1`,NULL AS `c2` from `test`.`t1` where (`test`.`t1`.`c3` = 10)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	4
+
+DROP TABLE t1, t2;
+#52
+CREATE TABLE t1(f1 INT, f2 INT);
+CREATE TABLE t2(f3 INT, f4 INT);
+CREATE INDEX IDX ON t2(f3);
+INSERT INTO t1 VALUES(1,0),(2,0);
+INSERT INTO t2 VALUES(1,1),(2,2);
+#
+# query:  UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)
+# select: SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1
+#
+EXPLAIN UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	2	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	2	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT              (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+2	DEPENDENT SUBQUERY	t2	ref	IDX	IDX	5	test.t1.f1	2	100.00	
+Warnings:
+Note	1276	Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
+Note	1003	select (select max(`test`.`t2`.`f4`) from `test`.`t2` where (`test`.`t2`.`f3` = `test`.`t1`.`f1`)) AS `(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	2
+Handler_read_rnd_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_key	2
+Handler_read_next	2
+Handler_read_rnd_next	3
+Handler_update	2
+
+DROP TABLE t1, t2;
+#55
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES (1);
+SET @a = NULL;
+EXPLAIN DELETE FROM t1 WHERE (@a:= a);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using where
+DROP TABLE t1;
+#56
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE uknown_column = 12345;
+ERROR 42S22: Unknown column 'uknown_column' in 'where clause'
+DROP TABLE t1;
+#57
+CREATE TABLE t1(f1 INT);
+EXPLAIN EXTENDED UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+UPDATE t1 SET f2=1 ORDER BY f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+DROP TABLE t1;
+#59
+CREATE TABLE t1 ( a INT, KEY( a ) );
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+SET SESSION sql_safe_updates = 1;
+EXPLAIN EXTENDED UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+UPDATE IGNORE v1 SET a = 1;
+ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
+SET SESSION sql_safe_updates = DEFAULT;
+DROP TABLE t1;
+DROP VIEW v1;
+#62
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0), (1);
+CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12;
+#
+# query:  UPDATE        v1 SET a = 1 WHERE a > 0
+# select: SELECT * FROM v1           WHERE a > 0
+#
+EXPLAIN UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        v1 SET a = 1 WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1           WHERE a > 0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` > 0)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	6
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	1
+Handler_read_rnd_next	9
+Handler_write	2
+
+#
+# query:  UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a
+# select: SELECT * FROM t1, v1              WHERE t1.a = v1.a
+#
+EXPLAIN UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (BNL, incremental buffers)
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, v1 SET v1.a = 1 WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, v1              WHERE t1.a = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t11	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (BNL, incremental buffers)
+1	SIMPLE	t12	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer (BNL, incremental buffers)
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` = `test`.`t1`.`a`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_rnd_next	9
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_rnd	2
+Handler_read_rnd_next	19
+Handler_update	1
+Handler_write	4
+
+DROP TABLE t1;
+DROP VIEW v1;
+#63
+CREATE TABLE t1 (a INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
+CREATE VIEW v1 (a) AS SELECT a FROM t1;
+#
+# query:  DELETE   FROM v1 WHERE a < 4
+# select: SELECT * FROM v1 WHERE a < 4
+#
+EXPLAIN DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	Using where
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE   FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM v1 WHERE a < 4;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	3	100.00	Using where; Using index
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 4)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_next	3
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	3
+Handler_read_first	1
+Handler_read_next	3
+
+DROP TABLE t1;
+DROP VIEW v1;
+#64
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+Handler_read_rnd_next	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_key	4
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#65
+CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a));
+INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10);
+CREATE TABLE t2 (x INT);
+INSERT INTO t2 VALUES (1), (2), (3), (4);
+CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1;
+#
+# query:  DELETE v1 FROM t2, v1 WHERE t2.x = v1.a
+# select: SELECT *  FROM t2, v1 WHERE t2.x = v1.a
+#
+EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT *  FROM t2, v1 WHERE t2.x = v1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.x	1	100.00	
+Warnings:
+Note	1003	select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`)
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_key	4
+Handler_read_rnd_next	5
+# Status of testing query execution:
+Variable_name	Value
+Handler_delete	4
+Handler_read_key	4
+Handler_read_rnd	4
+Handler_read_rnd_next	5
+
+DROP TABLE t1,t2;
+DROP VIEW v1;
+#66
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 (x) AS SELECT a FROM t1;
+#
+# query:  INSERT INTO v1 VALUES (10)
+# select: SELECT NULL
+#
+EXPLAIN INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 VALUES (10);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+Warnings:
+Note	1003	select NULL AS `NULL`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+# Status of testing query execution:
+Variable_name	Value
+Handler_write	1
+
+DROP TABLE t1;
+DROP VIEW v1;
+#67
+CREATE TABLE t1 (a INT);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+CREATE VIEW v1 (x) AS SELECT b FROM t2;
+#
+# query:  INSERT INTO v1 SELECT * FROM t1
+# select: SELECT * FROM t1
+#
+EXPLAIN INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	const row not found
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
+Warnings:
+Note	1003	select NULL AS `a` from `test`.`t1`
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	1
+
+DROP TABLE t1, t2;
+DROP VIEW v1;
+#68
+CREATE TABLE t1 (i INT);
+EXPLAIN INSERT DELAYED INTO t1 VALUES (1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
+DROP TABLE t1;
+#69
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1), (2), (3);
+CREATE TABLE t2 (b INT);
+INSERT INTO t2 VALUES (1), (2), (3);
+#
+# query:  UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from dual where (<cache>(`test`.`t1`.`a`) = '3')))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_update	1
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, t2            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+2	DEPENDENT SUBQUERY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
+3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from dual where (<cache>(`test`.`t1`.`a`) = '3')))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	5
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_write	1
+Sort_rows	3
+Sort_scan	1
+
+#
+# query:  UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+# select: SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x)
+#
+EXPLAIN UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (BNL, incremental buffers)
+3	DEPENDENT SUBQUERY	<derived4>	system	NULL	NULL	NULL	NULL	1	
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED UPDATE        t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+3	DEPENDENT SUBQUERY	<derived4>	system	NULL	NULL	NULL	NULL	1	100.00	
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+# Status of EXPLAIN EXTENDED query
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+FLUSH STATUS;
+FLUSH TABLES;
+EXPLAIN EXTENDED SELECT * FROM t1, (SELECT * FROM t2) y            WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer (BNL, incremental buffers)
+3	DEPENDENT SUBQUERY	<derived4>	system	NULL	NULL	NULL	NULL	1	100.00	
+4	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
+2	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`y`.`b` AS `b` from `test`.`t1` join (select `test`.`t2`.`b` AS `b` from `test`.`t2`) `y` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 from dual where (<cache>(`test`.`t1`.`a`) = '3')))
+# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	9
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of "equivalent" SELECT query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	13
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+# Status of testing query execution:
+Variable_name	Value
+Handler_read_first	1
+Handler_read_rnd_next	13
+Handler_write	4
+Sort_rows	3
+Sort_scan	1
+
+DROP TABLE t1,t2;
+#70
+CREATE TABLE t1 (c1 INT KEY);
+CREATE TABLE t2 (c2 INT);
+CREATE TABLE t3 (c3 INT);
+EXPLAIN EXTENDED UPDATE t3 SET c3 = (
+SELECT COUNT(d1.c1)
+FROM (
+SELECT a11.c1 FROM t1 AS a11 
+STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1
+JOIN t1 AS a12 ON a12.c1 = a11.c1
+) d1
+);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	0	100.00	
+2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
+3	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
+DROP TABLE t1, t2, t3;
+#71
+CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, INDEX i1(c1));
+INSERT INTO t1 VALUES (1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0);
+CREATE TABLE t2 LIKE t1;
+EXPLAIN INSERT INTO t2 SELECT * FROM t1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	X	
+INSERT INTO t2 SELECT * FROM t1;
+SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1;
+DROP TABLE t1, t2;
+#73
+CREATE TABLE t1 (id INT);
+CREATE TABLE t2 (id INT);
+INSERT INTO t1 VALUES (1), (2);
+EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USING(id) GROUP BY t1.id;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort
+DROP TABLE t1,t2;
+set default_storage_engine= @save_storage_engine;
+set optimizer_switch=default;

=== modified file 'mysql-test/r/partition_pruning.result'
--- a/mysql-test/r/partition_pruning.result	2010-09-27 13:20:24 +0000
+++ b/mysql-test/r/partition_pruning.result	2011-07-02 21:01:41 +0000
@@ -2717,33 +2717,61 @@ partition p0 values in (1,2),
 partition p1 values in (3,4)
 );
 insert into t1 values (1),(1),(2),(2),(3),(4),(3),(4);
+# This won't do any table access
+explain extended update t1 set a=100 where a=5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No matching rows after partition pruning
+explain partitions update t1 set a=100 where a=5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No matching rows after partition pruning
 flush status;
 update t1 set a=100 where a=5;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	0
+# ... as compared to this, which will scan both partitions
+explain partitions update t1 set a=100 where a+1=5+1;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	8	Using where; Using temporary
 flush status;
 update t1 set a=100 where a+1=5+1;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	10
+# Same as above for DELETE:
+explain extended delete from t1 where a=5;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No matching rows after partition pruning
+explain partitions delete from t1 where a=5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No matching rows after partition pruning
 flush status;
 delete from t1 where a=5;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	0
+explain partitions delete from t1 where a+1=5+1;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	p0,p1	ALL	NULL	NULL	NULL	NULL	8	Using where
 flush status;
 delete from t1 where a+1=5+1;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	10
+# Same as above multi-table UPDATE/DELETE
 create table t2 like t1;
 insert into t2 select * from t2;
+explain partitions update t1,t2 set t1.a=1000, t2.a=1000 where t1.a=5 and t2.a=5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
 flush status;
 update t1,t2 set t1.a=1000, t2.a=1000 where t1.a=5 and t2.a=5;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	0
+explain partitions delete t1,t2 from t1, t2 where t1.a=5 and t2.a=5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
 flush status;
 delete t1,t2 from t1, t2 where t1.a=5 and t2.a=5;
 show status like 'Handler_read_rnd_next';
@@ -2771,6 +2799,13 @@ PARTITION p1 VALUES LESS THAN (400),
 PARTITION p2 VALUES LESS THAN (600),
 PARTITION p3 VALUES LESS THAN (800),
 PARTITION p4 VALUES LESS THAN (1001));
+CREATE TABLE `t3` (
+`a` int(11) default NULL,
+`b` int(11) default NULL
+);
+explain partitions insert into t2 select a,1 from t1 where a < 200;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	NULL	ALL	NULL	NULL	NULL	NULL	1010	Using where
 insert into t2 select a,1 from t1 where a < 200;
 insert into t2 select a,2 from t1 where a >= 200 and a < 400;
 insert into t2 select a,3 from t1 where a >= 400 and a < 600;
@@ -2779,47 +2814,96 @@ insert into t2 select a,5 from t1 where
 explain partitions select * from t2;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	
+explain partitions insert into t3 select * from t2;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	
+explain extended   insert into t3 select * from t2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1010	100.00	
 explain partitions select * from t2 where a < 801 and a > 200;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	800	Using where
+explain partitions insert into t3 select * from t2 where a < 801 and a > 200;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	800	Using where
 explain partitions select * from t2 where a < 801 and a > 800;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	200	Using where
+explain partitions insert into t3 select * from t2 where a < 801 and a > 800;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p4	ALL	NULL	NULL	NULL	NULL	200	Using where
 explain partitions select * from t2 where a > 600;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
+explain partitions insert into t3 select * from t2 where a > 600;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where a > 600 and b = 1;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
+explain partitions insert into t3 select * from t2 where a > 600 and b = 1;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where a > 600 and b = 4;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
+explain partitions insert into t3 select * from t2 where a > 600 and b = 4;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where a > 600 and b = 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
+explain partitions insert into t3 select * from t2 where a > 600 and b = 5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 explain partitions select * from t2 where b = 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+explain partitions insert into t3 select * from t2 where b = 5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
+DROP TABLE t3;
+explain extended update t2 set b = 100 where b = 6;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1010	100.00	Using where
+explain partitions update t2 set b = 100 where b = 6;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	NULL	NULL	NULL	NULL	1010	Using where
 flush status;
 update t2 set b = 100 where b = 6;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	1015
+explain partitions update t2 set a = 1002 where a = 1001;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No matching rows after partition pruning
 flush status;
 update t2 set a = 1002 where a = 1001;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	0
+explain partitions update t2 set b = 6 where a = 600;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3	ALL	NULL	NULL	NULL	NULL	200	Using where
 flush status;
 update t2 set b = 6 where a = 600;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	201
+explain partitions update t2 set b = 6 where a > 600 and a < 800;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3	ALL	NULL	NULL	NULL	NULL	200	Using where
 flush status;
 update t2 set b = 6 where a > 600 and a < 800;
 show status like 'Handler_read_rnd_next';
 Variable_name	Value
 Handler_read_rnd_next	201
+explain extended delete from t2 where a > 600;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	400	100.00	Using where
+explain partitions delete from t2 where a > 600;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p3,p4	ALL	NULL	NULL	NULL	NULL	400	Using where
 flush status;
 delete from t2 where a > 600;
 show status like 'Handler_read_rnd_next';
@@ -2931,6 +3015,12 @@ Note	1003	select `test`.`t2`.`a` AS `a`,
 explain partitions select * from t2 where b > 0 and b < 5;
 id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where
+explain extended update t2 set a = 111 where b = 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	b	b	5	NULL	5	100.00	Using where; Using temporary
+explain partitions update t2 set a = 111 where b = 10;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	range	b	b	5	NULL	5	Using where; Using temporary
 flush status;
 update t2 set a = 111 where b = 10;
 show status like 'Handler_read_rnd_next';
@@ -2939,6 +3029,9 @@ Handler_read_rnd_next	0
 show status like 'Handler_read_key';
 Variable_name	Value
 Handler_read_key	5
+explain partitions update t2 set a = 111 where b in (5,6);
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	910	Using where; Using temporary
 flush status;
 update t2 set a = 111 where b in (5,6);
 show status like 'Handler_read_rnd_next';
@@ -2947,6 +3040,9 @@ Handler_read_rnd_next	915
 show status like 'Handler_read_key';
 Variable_name	Value
 Handler_read_key	0
+explain partitions update t2 set a = 222 where b = 7;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	range	b	b	5	NULL	102	Using where; Using temporary
 flush status;
 update t2 set a = 222 where b = 7;
 show status like 'Handler_read_rnd_next';
@@ -2955,6 +3051,12 @@ Handler_read_rnd_next	0
 show status like 'Handler_read_key';
 Variable_name	Value
 Handler_read_key	5
+explain extended delete from t2 where b = 7;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	range	b	b	5	NULL	139	100.00	Using where
+explain partitions delete from t2 where b = 7;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	range	b	b	5	NULL	139	Using where
 flush status;
 delete from t2 where b = 7;
 show status like 'Handler_read_rnd_next';
@@ -2963,6 +3065,9 @@ Handler_read_rnd_next	0
 show status like 'Handler_read_key';
 Variable_name	Value
 Handler_read_key	5
+explain partitions delete from t2 where b > 5;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	810	Using where
 flush status;
 delete from t2 where b > 5;
 show status like 'Handler_read_rnd_next';
@@ -2977,6 +3082,9 @@ Handler_read_prev	0
 show status like 'Handler_read_next';
 Variable_name	Value
 Handler_read_next	0
+explain partitions delete from t2 where b < 5 or b > 3;
+id	select_type	table	partitions	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	p0,p1,p2,p3,p4	ALL	b	NULL	NULL	NULL	510	Using where
 flush status;
 delete from t2 where b < 5 or b > 3;
 show status like 'Handler_read_rnd_next';

=== modified file 'mysql-test/t/explain.test'
--- a/mysql-test/t/explain.test	2011-05-10 13:37:37 +0000
+++ b/mysql-test/t/explain.test	2011-07-02 21:01:41 +0000
@@ -373,4 +373,23 @@ EXECUTE s;
 DEALLOCATE PREPARE s;
 DROP TABLE t1;
 
+--echo #
+--echo # WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
+--echo # 
+--echo # Coverage tests after code refactoring
+--echo #
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2),(3);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (3),(4),(5);
+
+# LIMIT <offset> is for SELECT, not for EXPLAIN OUTPUT:
+--echo # EXPLAIN must return 3 rows:
+EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2,2;
+
+DROP TABLE t1, t2;
+
+--echo # End WL#4897
+
 --echo End of 6.0 tests.

=== added file 'mysql-test/t/grant_explain_non_select.test'
--- a/mysql-test/t/grant_explain_non_select.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/grant_explain_non_select.test	2011-07-02 21:01:41 +0000
@@ -0,0 +1,258 @@
+#
+# Privilege-specific tests for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
+#
+
+# Grant tests not performed with embedded server
+-- source include/not_embedded.inc
+
+# Save the initial number of concurrent sessions
+--source include/count_sessions.inc
+
+CREATE DATABASE privtest_db;
+
+CREATE TABLE privtest_db.t1 (a INT);
+CREATE TABLE privtest_db.t2 (a INT);
+INSERT INTO privtest_db.t2 VALUES (1), (2), (3);
+
+GRANT USAGE ON *.* TO 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost';
+
+connect(con1,localhost,privtest,,);
+connection con1;
+
+USE privtest_db;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN INSERT INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+        INSERT INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN INSERT INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+        INSERT INTO t1 SELECT * FROM t2;
+
+connection default;
+GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN INSERT INTO t1 VALUES (10);
+        INSERT INTO t1 VALUES (10);
+
+EXPLAIN INSERT INTO t1 SELECT * FROM t2;
+        INSERT INTO t1 SELECT * FROM t2;
+
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+        REPLACE INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+        REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+        REPLACE INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+        REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+REVOKE INSERT ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 VALUES (10);
+--error ER_TABLEACCESS_DENIED_ERROR
+        REPLACE INTO t1 VALUES (10);
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+--error ER_TABLEACCESS_DENIED_ERROR
+        REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+GRANT INSERT, DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN REPLACE INTO t1 VALUES (10);
+        REPLACE INTO t1 VALUES (10);
+
+EXPLAIN REPLACE INTO t1 SELECT * FROM t2;
+        REPLACE INTO t1 SELECT * FROM t2;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1 SET a = a + 1;
+--error ER_TABLEACCESS_DENIED_ERROR
+        UPDATE t1 SET a = a + 1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+        UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1 SET a = a + 1;
+--error ER_COLUMNACCESS_DENIED_ERROR
+        UPDATE t1 SET a = a + 1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+--error ER_COLUMNACCESS_DENIED_ERROR
+        UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE UPDATE ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1 SET a = a + 1;
+--error ER_TABLEACCESS_DENIED_ERROR
+        UPDATE t1 SET a = a + 1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+        UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+GRANT UPDATE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN UPDATE t1 SET a = a + 1;
+        UPDATE t1 SET a = a + 1;
+
+EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+        UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+--error ER_TABLEACCESS_DENIED_ERROR
+        DELETE FROM t1 WHERE a = 10;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+        DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+connection default;
+GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_COLUMNACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+--error ER_COLUMNACCESS_DENIED_ERROR
+        DELETE FROM t1 WHERE a = 10;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+        DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+--error ER_TABLEACCESS_DENIED_ERROR
+        DELETE FROM t1 WHERE a = 10;
+
+--error ER_TABLEACCESS_DENIED_ERROR
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+--error ER_TABLEACCESS_DENIED_ERROR
+        DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+GRANT DELETE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost';
+connection con1;
+
+EXPLAIN DELETE FROM t1 WHERE a = 10;
+        DELETE FROM t1 WHERE a = 10;
+
+EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+        DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a;
+
+# Views
+
+connection default;
+REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost';
+CREATE VIEW privtest_db.v1 (a) AS SELECT a FROM privtest_db.t1;
+GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.v1 TO 'privtest'@'localhost';
+connection con1;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN SELECT * FROM v1;
+        SELECT * FROM v1;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN INSERT INTO v1 VALUES (10);
+        INSERT INTO v1 VALUES (10);
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN INSERT INTO v1 SELECT * FROM t2;
+        INSERT INTO v1 SELECT * FROM t2;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN REPLACE  INTO v1 VALUES (10);
+        REPLACE  INTO v1 VALUES (10);
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN REPLACE INTO v1 SELECT * FROM t2;
+        REPLACE INTO v1 SELECT * FROM t2;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN UPDATE v1 SET a = a + 1;
+        UPDATE v1 SET a = a + 1;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
+        UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN DELETE FROM v1 WHERE a = 10;
+        DELETE FROM v1 WHERE a = 10;
+
+--error ER_VIEW_NO_EXPLAIN
+EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
+        DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a;
+
+connection default;
+disconnect con1;
+
+DROP USER 'privtest'@localhost;
+USE test;
+DROP DATABASE privtest_db;
+
+# Wait till we reached the initial number of concurrent sessions
+--source include/wait_until_count_sessions.inc 

=== added file 'mysql-test/t/innodb_explain_non_select_all.test'
--- a/mysql-test/t/innodb_explain_non_select_all.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_explain_non_select_all.test	2011-07-02 21:01:41 +0000
@@ -0,0 +1,22 @@
+# 
+# Run explain_non_select.inc on InnoDB with all of the so-called 6.0 features.
+#
+
+--source include/have_innodb.inc
+
+--source include/have_semijoin.inc
+--source include/have_materialization.inc
+--source include/have_firstmatch.inc
+--source include/have_loosescan.inc
+--source include/have_index_condition_pushdown.inc
+--source include/have_mrr.inc
+
+set optimizer_switch='semijoin=on,materialization=on,firstmatch=on,loosescan=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=off';
+
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = InnoDB;
+--let $innodb = 1
+--source include/explain_non_select.inc
+set default_storage_engine= @save_storage_engine;
+
+set optimizer_switch=default;

=== added file 'mysql-test/t/innodb_explain_non_select_none.test'
--- a/mysql-test/t/innodb_explain_non_select_none.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_explain_non_select_none.test	2011-07-02 21:01:41 +0000
@@ -0,0 +1,32 @@
+# 
+# Run explain_non_select.inc on InnoDB without any of the socalled 6.0 features.
+#
+
+--source include/have_innodb.inc
+
+--disable_query_log
+if (`select locate('semijoin', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='semijoin=off';
+}
+if (`select locate('materialization', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='materialization=off';
+}
+if (`select locate('index_condition_pushdown', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='index_condition_pushdown=off';
+}
+if (`select locate('mrr', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='mrr=off';
+}
+--enable_query_log
+
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = InnoDB;
+--let $innodb = 1
+--source include/explain_non_select.inc
+set default_storage_engine= @save_storage_engine;
+
+set optimizer_switch=default;

=== added file 'mysql-test/t/myisam_explain_non_select_all.test'
--- a/mysql-test/t/myisam_explain_non_select_all.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/myisam_explain_non_select_all.test	2011-07-02 21:01:41 +0000
@@ -0,0 +1,19 @@
+# 
+# Run explain_non_select.inc on MyISAM with all of the so-called 6.0 features.
+#
+
+--source include/have_semijoin.inc
+--source include/have_materialization.inc
+--source include/have_firstmatch.inc
+--source include/have_loosescan.inc
+--source include/have_index_condition_pushdown.inc
+--source include/have_mrr.inc
+
+set optimizer_switch='semijoin=on,materialization=on,firstmatch=on,loosescan=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=off';
+
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = MyISAM;
+--source include/explain_non_select.inc
+set default_storage_engine= @save_storage_engine;
+
+set optimizer_switch=default;

=== added file 'mysql-test/t/myisam_explain_non_select_none.test'
--- a/mysql-test/t/myisam_explain_non_select_none.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/myisam_explain_non_select_none.test	2011-07-02 21:01:41 +0000
@@ -0,0 +1,29 @@
+# 
+# Run explain_non_select.inc on MyISAM without any of the socalled 6.0 features.
+#
+
+--disable_query_log
+if (`select locate('semijoin', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='semijoin=off';
+}
+if (`select locate('materialization', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='materialization=off';
+}
+if (`select locate('index_condition_pushdown', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='index_condition_pushdown=off';
+}
+if (`select locate('mrr', @@optimizer_switch) > 0`) 
+{
+  set optimizer_switch='mrr=off';
+}
+--enable_query_log
+
+set @save_storage_engine= @@session.default_storage_engine;
+set session default_storage_engine = MyISAM;
+--source include/explain_non_select.inc
+set default_storage_engine= @save_storage_engine;
+
+set optimizer_switch=default;

=== modified file 'mysql-test/t/partition_pruning.test'
--- a/mysql-test/t/partition_pruning.test	2010-09-13 13:56:56 +0000
+++ b/mysql-test/t/partition_pruning.test	2011-07-02 21:01:41 +0000
@@ -936,37 +936,49 @@ create table t1 (a int) partition by lis
 );
 insert into t1 values (1),(1),(2),(2),(3),(4),(3),(4);
 
-# This won't do any table access
+--echo # This won't do any table access
+--let $q = update t1 set a=100 where a=5
+--eval explain extended $q
+--eval explain partitions $q
 flush status;
-update t1 set a=100 where a=5;
+--eval $q
 show status like 'Handler_read_rnd_next';
 
-# ... as compared to this, which will scan both partitions
+--echo # ... as compared to this, which will scan both partitions
+--let $q = update t1 set a=100 where a+1=5+1
+--eval explain partitions $q
 flush status;
-update t1 set a=100 where a+1=5+1;
+--eval $q
 show status like 'Handler_read_rnd_next';
 
-# Same as above for DELETE:
+--echo # Same as above for DELETE:
+--let $q = delete from t1 where a=5
+--eval explain extended $q
+--eval explain partitions $q
 flush status;
-delete from t1 where a=5;
+--eval $q
 show status like 'Handler_read_rnd_next';
 
+--let $q = delete from t1 where a+1=5+1
+--eval explain partitions $q
 flush status;
-delete from t1 where a+1=5+1;
+--eval $q
 show status like 'Handler_read_rnd_next';
 
-# Same as above multi-table UPDATE/DELETE
+--echo # Same as above multi-table UPDATE/DELETE
 create table t2 like t1;
 insert into t2 select * from t2;
 
+--let $q = update t1,t2 set t1.a=1000, t2.a=1000 where t1.a=5 and t2.a=5
+--eval explain partitions $q
 flush status;
-update t1,t2 set t1.a=1000, t2.a=1000 where t1.a=5 and t2.a=5;
+--eval $q
 show status like 'Handler_read_rnd_next';
-# ^ This shows 3 accesses, these are caused by const table reads. 
-# They should vanish when partition pruning results are used.
 
+--let $q = delete t1,t2 from t1, t2 where t1.a=5 and t2.a=5
+--eval explain partitions $q
 flush status;
-delete t1,t2 from t1, t2 where t1.a=5 and t2.a=5;
+--eval $q
 show status like 'Handler_read_rnd_next';
 drop table t1,t2;
 
@@ -999,35 +1011,72 @@ PARTITION p2 VALUES LESS THAN (600),
 PARTITION p3 VALUES LESS THAN (800),
 PARTITION p4 VALUES LESS THAN (1001));
 
+CREATE TABLE `t3` (
+  `a` int(11) default NULL,
+  `b` int(11) default NULL
+);
+
+explain partitions insert into t2 select a,1 from t1 where a < 200;
 insert into t2 select a,1 from t1 where a < 200;
 insert into t2 select a,2 from t1 where a >= 200 and a < 400;
 insert into t2 select a,3 from t1 where a >= 400 and a < 600;
 insert into t2 select a,4 from t1 where a >= 600 and a < 800;
 insert into t2 select a,5 from t1 where a >= 800 and a < 1001;
 
-explain partitions select * from t2;
-explain partitions select * from t2 where a < 801 and a > 200;
-explain partitions select * from t2 where a < 801 and a > 800;
-explain partitions select * from t2 where a > 600;
-explain partitions select * from t2 where a > 600 and b = 1;
-explain partitions select * from t2 where a > 600 and b = 4;
-explain partitions select * from t2 where a > 600 and b = 5;
-explain partitions select * from t2 where b = 5;
-
-flush status;
-update t2 set b = 100 where b = 6;
-show status like 'Handler_read_rnd_next';
-flush status;
-update t2 set a = 1002 where a = 1001;
-show status like 'Handler_read_rnd_next';
-flush status;
-update t2 set b = 6 where a = 600;
-show status like 'Handler_read_rnd_next';
-flush status;
-update t2 set b = 6 where a > 600 and a < 800;
-show status like 'Handler_read_rnd_next';
+--let $q =  select * from t2
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--eval explain extended   insert into t3 $q
+--let $q =  select * from t2 where a < 801 and a > 200
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--let $q =  select * from t2 where a < 801 and a > 800
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--let $q =  select * from t2 where a > 600
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--let $q =  select * from t2 where a > 600 and b = 1
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--let $q =  select * from t2 where a > 600 and b = 4
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--let $q =  select * from t2 where a > 600 and b = 5
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+--let $q =  select * from t2 where b = 5
+--eval explain partitions $q
+--eval explain partitions insert into t3 $q
+
+DROP TABLE t3;
+
+--let $q = update t2 set b = 100 where b = 6
+--eval explain extended $q
+--eval explain partitions $q
+flush status;
+--eval $q
+show status like 'Handler_read_rnd_next';
+--let $q = update t2 set a = 1002 where a = 1001
+--eval explain partitions $q
+flush status;
+--eval $q
+show status like 'Handler_read_rnd_next';
+--let $q = update t2 set b = 6 where a = 600
+--eval explain partitions $q
+flush status;
+--eval $q
+show status like 'Handler_read_rnd_next';
+--let $q = update t2 set b = 6 where a > 600 and a < 800
+--eval explain partitions $q
+flush status;
+--eval $q
+show status like 'Handler_read_rnd_next';
+--let $q = delete from t2 where a > 600
+--eval explain extended $q
+--eval explain partitions $q
 flush status;
-delete from t2 where a > 600;
+--eval $q
 show status like 'Handler_read_rnd_next';
 
 drop table t2;
@@ -1086,30 +1135,44 @@ explain partitions select * from t2 wher
 explain extended select * from t2 where b > 0 and b < 5;
 explain partitions select * from t2 where b > 0 and b < 5;
 
+--let $q = update t2 set a = 111 where b = 10
+--eval explain extended $q
+--eval explain partitions $q
 flush status;
-update t2 set a = 111 where b = 10;
+--eval $q
 show status like 'Handler_read_rnd_next';
 show status like 'Handler_read_key';
+--let $q = update t2 set a = 111 where b in (5,6)
+--eval explain partitions $q
 flush status;
-update t2 set a = 111 where b in (5,6);
+--eval $q
 show status like 'Handler_read_rnd_next';
 show status like 'Handler_read_key';
+--let $q = update t2 set a = 222 where b = 7
+--eval explain partitions $q
 flush status;
-update t2 set a = 222 where b = 7;
+--eval $q
 show status like 'Handler_read_rnd_next';
 show status like 'Handler_read_key';
+--let $q = delete from t2 where b = 7
+--eval explain extended $q
+--eval explain partitions $q
 flush status;
-delete from t2 where b = 7;
+--eval $q
 show status like 'Handler_read_rnd_next';
 show status like 'Handler_read_key';
+--let $q = delete from t2 where b > 5
+--eval explain partitions $q
 flush status;
-delete from t2 where b > 5;
+--eval $q
 show status like 'Handler_read_rnd_next';
 show status like 'Handler_read_key';
 show status like 'Handler_read_prev';
 show status like 'Handler_read_next';
+--let $q = delete from t2 where b < 5 or b > 3
+--eval explain partitions $q
 flush status;
-delete from t2 where b < 5 or b > 3;
+--eval $q
 show status like 'Handler_read_rnd_next';
 show status like 'Handler_read_key';
 show status like 'Handler_read_prev';

=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt	2011-04-15 09:04:21 +0000
+++ b/sql/CMakeLists.txt	2011-07-02 21:01:41 +0000
@@ -73,6 +73,7 @@ SET(SQL_SHARED_SOURCES
   mf_iocache.cc
   my_decimal.cc
   net_serv.cc
+  opt_explain.cc
   opt_range.cc
   opt_sum.cc 
   parse_file.cc

=== added file 'sql/opt_explain.cc'
--- a/sql/opt_explain.cc	1970-01-01 00:00:00 +0000
+++ b/sql/opt_explain.cc	2011-07-02 21:01:41 +0000
@@ -0,0 +1,1540 @@
+/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+/** @file "EXPLAIN <command>" implementation */ 
+
+#include "opt_explain.h"
+#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);
+
+/**
+  A base for all Explain_* classes
+
+  Explain_* classes collect and output EXPLAIN data.
+
+  This class hierarchy is a successor of the old select_describe() function of 5.5.
+*/
+
+class Explain
+{
+private:
+  List<Item> items; ///< item list to feed select_result::send_data()
+  Item_null *nil; ///< pre-allocated NULL item to fill empty columns in EXPLAIN
+
+protected:
+  /**
+    Helper class to keep string data in MEM_ROOT before passing to Item_string
+
+    Since Item_string constructors doesn't copy input string parameter data 
+    in the most cases, those input strings must have the same lifetime as
+    Item_string objects, i.e. lifetime of MEM_ROOT.
+    This class allocates input parameters for Item_string objects in MEM_ROOT.
+  */
+  struct mem_root_str
+  {
+    MEM_ROOT *const mem_root;
+    const char *str;
+    size_t length;
+    
+    mem_root_str(THD *thd) : mem_root(thd->mem_root) { cleanup(); }
+    void cleanup()
+    {
+      str= NULL;
+      length= 0;
+    }
+    bool is_empty() const { return str == NULL; }
+
+    bool set(const char *str_arg)
+    {
+      return set(str_arg, strlen(str_arg));
+    }
+    bool set(const String &s)
+    {
+      return set(s.ptr(), s.length());
+    }
+    /**
+      Make a copy of the string in MEM_ROOT
+      
+      @param str_arg    string to copy
+      @param length_arg input string length
+
+      @return false if success, true if error
+    */
+    bool set(const char *str_arg, size_t length_arg)
+    {
+      if (!(str= static_cast<char *>(memdup_root(mem_root,str_arg,length_arg))))
+        return true; /* purecov: inspected */
+      length= length_arg;
+      return false;
+    }
+    /**
+      Make a copy of string constant
+
+      Variant of set() usable when the str_arg argument lives longer
+      than the mem_root_str instance.
+    */
+    void set_const(const char *str_arg)
+    {
+      str= str_arg;
+      length= strlen(str_arg);
+    }
+  };
+
+  /*
+    Next "col_*" fields are intended to be filling by "explain_*()" functions.
+    Then the make_list() function links these Items into "items" list.
+
+    NOTE: NULL value or mem_root_str.is_empty()==true means that Item_null object
+          will be pushed into "items" list instead.
+  */
+  Item_uint   *col_id; ///< "id" column: seq. number of SELECT withing the query
+  mem_root_str col_select_type; ///< "select_type" column
+  mem_root_str col_table_name; ///< "table" to which the row of output refers
+  mem_root_str col_partitions; ///< "partitions" column
+  mem_root_str col_join_type; ///< "type" column, see join_type_str array
+  mem_root_str col_possible_keys; ///< "possible_keys": comma-separated list
+  mem_root_str col_key; ///< "key" column: index that is actually decided to use
+  mem_root_str col_key_len; ///< "key_length" column: length of the "key" above
+  mem_root_str col_ref; ///< "ref":columns/constants which are compared to "key"
+  Item_int    *col_rows; ///< "rows": estimated number of examined table rows
+  Item_float  *col_filtered; ///< "filtered": % of rows filtered by condition
+  mem_root_str col_extra; ///< "extra" column: additional information
+
+  THD *const thd; ///< cached THD pointer
+  const CHARSET_INFO *const cs; ///< cached pointer to system_charset_info
+  JOIN *const join; ///< top-level JOIN (if any) provided by caller
+
+  select_result *const external_result; ///< stream (if any) provided by caller
+
+protected:
+  explicit Explain(THD *thd_arg, JOIN *join_arg= NULL)
+  : nil(NULL),
+    col_select_type(thd_arg),
+    col_table_name(thd_arg),
+    col_partitions(thd_arg),
+    col_join_type(thd_arg),
+    col_possible_keys(thd_arg),
+    col_key(thd_arg),
+    col_key_len(thd_arg),
+    col_ref(thd_arg),
+    col_extra(thd_arg),
+    thd(thd_arg),
+    cs(system_charset_info),
+    join(join_arg),
+    external_result(join ? join->result : NULL)
+  {
+    init_columns();
+  }
+  virtual ~Explain() {}
+
+public:
+  bool send();
+
+private:
+  void init_columns();
+  bool make_list();
+  bool push(Item *item) { return items.push_back(item ? item : nil); }
+  bool push(const mem_root_str &s)
+  {
+    if (s.is_empty())
+      return items.push_back(nil);
+    Item_string *item= new Item_string(s.str, s.length, cs);
+    return item == NULL || items.push_back(item);
+  }
+
+protected:
+  bool describe(uint8 mask) { return thd->lex->describe & mask; }
+
+  SELECT_LEX *select_lex() const
+  {
+    return join ? join->select_lex : &thd->lex->select_lex;
+  }
+
+  /**
+    Prepare the self-allocated result object
+
+    For queries with top-level JOIN the caller provides pre-allocated
+    select_send object. Then that JOIN object prepares the select_send
+    object calling result->prepare() in JOIN::prepare(),
+    result->initalize_tables() in JOIN::optimize() and result->prepare2()
+    in JOIN::exec().
+    However without the presence of the top-level JOIN we have to
+    prepare/initialize select_send object manually.
+  */
+  bool prepare(select_result *result)
+  {
+    DBUG_ASSERT(join == NULL);
+    List<Item> dummy;
+    return result->prepare(dummy, select_lex()->master_unit()) ||
+           result->prepare2();
+  }
+
+  virtual bool send_to(select_result *to);
+
+  /*
+    Rest of the functions are overloadable functions, those calculate and fill
+    "col_*" fields with Items for further sending as EXPLAIN columns.
+
+    "explain_*" functions return false on success and true on error (usually OOM).
+  */
+  virtual bool explain_id();
+  virtual bool explain_select_type();
+  virtual bool explain_table_name() { return false; }
+  virtual bool explain_partitions() { return false; }
+  virtual bool explain_join_type() { return false; }
+  virtual bool explain_possible_keys() { return false; }
+  /** fill col_key and and col_key_len fields together */
+  virtual bool explain_key_and_len() { return false; }
+  virtual bool explain_ref() { return false; }
+  /** fill col_rows and col_filtered fields together */
+  virtual bool explain_rows_and_filtered() { return false; }
+  virtual bool explain_extra();
+};
+
+
+/**
+  Explain_no_table class outputs a trivial EXPLAIN row with "extra" column
+
+  This class is intended for simple cases to produce EXPLAIN output
+  with "No tables used", "No matching records" etc.
+  Optionally it can output number of estimated rows in the "row"
+  column.
+
+  @note This class also produces EXPLAIN rows for inner units (if any).
+*/
+
+class Explain_no_table: public Explain
+{
+private:
+  const char *message; ///< cached "message" argument
+  const ha_rows rows; ///< HA_POS_ERROR or cached "rows" argument
+
+public:
+  Explain_no_table(THD *thd_arg, JOIN *join_arg, const char *message_arg)
+  : Explain(thd_arg, join_arg), message(message_arg), rows(HA_POS_ERROR)
+  {}
+
+  Explain_no_table(THD *thd_arg, const char *message_arg,
+                   ha_rows rows_arg= HA_POS_ERROR)
+  : Explain(thd_arg), message(message_arg), rows(rows_arg)
+  {}
+
+protected:
+  virtual bool explain_rows_and_filtered();
+  virtual bool explain_extra();
+};
+
+
+/**
+  Explain_union class outputs EXPLAIN row for UNION
+*/
+
+class Explain_union : public Explain
+{
+public:
+  Explain_union(THD *thd_arg, JOIN *join_arg) : Explain(thd_arg, join_arg)
+  {
+    /* it's a UNION: */
+    DBUG_ASSERT(join_arg->select_lex == join_arg->unit->fake_select_lex);
+  }
+
+protected:
+  virtual bool explain_id();
+  virtual bool explain_table_name();
+  virtual bool explain_join_type();
+  virtual bool explain_extra();
+};
+
+
+
+/**
+  Common base class for Explain_join and Explain_table
+*/
+
+class Explain_table_base : public Explain {
+protected:
+  const TABLE *table;
+  key_map usable_keys;
+
+  Explain_table_base(THD *const thd_arg, JOIN *const join_arg)
+  : Explain(thd_arg, join_arg), table(NULL)
+  {}
+
+  Explain_table_base(THD *const thd_arg, TABLE *const table_arg)
+  : Explain(thd_arg), table(table_arg)
+  {}
+
+  virtual bool explain_partitions();
+  virtual bool explain_possible_keys();
+
+  bool explain_key_and_len_quick(const SQL_SELECT *select);
+  bool explain_key_and_len_index(int key);
+  bool explain_key_and_len_index(int key, uint key_length);
+  void explain_extra_common(const SQL_SELECT *select,
+                            const JOIN_TAB *tab,
+                            int quick_type,
+                            uint keyno,
+                            String *str_extra);
+  void explain_tmptable_and_filesort(bool need_tmp_table_arg,
+                                     bool need_sort_arg,
+                                     String *str_extra);
+};
+
+
+/**
+  Explain_join class produces EXPLAIN output for JOINs
+*/
+
+class Explain_join : public Explain_table_base
+{
+private:
+  bool need_tmp_table; ///< add "Using temporary" to "extra" if true
+  bool need_order; ///< add "Using filesort"" to "extra" if true
+  const bool distinct; ///< add "Distinct" string to "extra" column if true
+
+  uint tabnum; ///< current tab number in join->join_tab[]
+  JOIN_TAB *tab; ///< current JOIN_TAB
+  int quick_type; ///< current quick type, see anon. enum at QUICK_SELECT_I
+  table_map used_tables; ///< accumulate used tables bitmap
+  uint last_sjm_table; ///< last materialized semi-joined table
+
+public:
+  Explain_join(THD *thd_arg, JOIN *join_arg,
+               bool need_tmp_table_arg, bool need_order_arg,
+               bool distinct_arg)
+  : Explain_table_base(thd_arg, join_arg), need_tmp_table(need_tmp_table_arg),
+    need_order(need_order_arg), distinct(distinct_arg),
+    tabnum(0), used_tables(0), last_sjm_table(MAX_TABLES)
+  {
+    /* it is not UNION: */
+    DBUG_ASSERT(join_arg->select_lex != join_arg->unit->fake_select_lex);
+  }
+
+protected:
+  virtual bool send_to(select_result *to);
+  virtual bool explain_table_name();
+  virtual bool explain_join_type();
+  virtual bool explain_key_and_len();
+  virtual bool explain_ref();
+  virtual bool explain_rows_and_filtered();
+  virtual bool explain_extra();
+};
+
+
+/**
+  Explain_table class produce EXPLAIN output for queries without top-level JOIN
+
+  This class is a simplified version of the Explain_join class. It works in the
+  context of queries which implementation lacks top-level JOIN object (EXPLAIN
+  single-table UPDATE and DELETE).
+*/
+
+class Explain_table: public Explain_table_base
+{
+private:
+  const SQL_SELECT *const select; ///< cached "select" argument
+  const uint       key;        ///< cached "key" number argument
+  const ha_rows    limit;      ///< HA_POS_ERROR or cached "limit" argument
+  const bool       need_tmp_table; ///< cached need_tmp_table argument
+  const bool       need_sort;  ///< cached need_sort argument
+
+public:
+  Explain_table(THD *const thd_arg, TABLE *const table_arg,
+                const SQL_SELECT *select_arg,
+                uint key_arg, ha_rows limit_arg,
+                bool need_tmp_table_arg, bool need_sort_arg)
+  : Explain_table_base(thd_arg, table_arg), select(select_arg), key(key_arg),
+    limit(limit_arg),
+    need_tmp_table(need_tmp_table_arg), need_sort(need_sort_arg)
+  {
+    usable_keys= table->keys_in_use_for_query;
+  }
+
+private:
+  virtual bool explain_table_name();
+  virtual bool explain_join_type();
+  virtual bool explain_key_and_len();
+  virtual bool explain_rows_and_filtered();
+  virtual bool explain_extra();
+};
+
+
+static join_type calc_join_type(int quick_type)
+{
+  if ((quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE) ||
+      (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT) ||
+      (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION))
+    return JT_INDEX_MERGE;
+  else
+    return JT_RANGE;
+}
+
+
+/* Explain class functions ****************************************************/
+
+
+/**
+  Explain class main function
+
+  This function:
+    a) allocates a select_send object (if no one pre-allocated available),
+    b) calculates and sends whole EXPLAIN data.
+
+  @return false if success, true if error
+*/
+
+bool Explain::send()
+{
+  DBUG_ENTER("Explain::send");
+  /* Don't log this into the slow query log */
+  thd->server_status&= ~(SERVER_QUERY_NO_INDEX_USED |
+                         SERVER_QUERY_NO_GOOD_INDEX_USED);
+
+  select_result *result;
+  if (external_result == NULL)
+  {
+    /* Create select_result object if the caller doesn't provide one: */
+    if (!(result= new select_send))
+      DBUG_RETURN(true); /* purecov: inspected */
+    if (thd->send_explain_fields(result) || prepare(result))
+    {
+      delete result;
+      DBUG_RETURN(true); /* purecov: inspected */
+    }
+  }
+  else
+  {
+    result= external_result;
+    external_result->reset_offset_limit_cnt();
+  }
+
+  if (nil == NULL && !(nil= new Item_null))
+    DBUG_RETURN(true); /* purecov: inspected */
+  bool ret= send_to(result);
+
+  if (ret && join)
+    join->error= 1; /* purecov: inspected */
+
+  for (SELECT_LEX_UNIT *unit= select_lex()->first_inner_unit();
+       unit && !ret;
+       unit= unit->next_unit())
+    ret= mysql_explain_union(thd, unit, result);
+
+  if (external_result == NULL)
+  {
+    if (ret)
+      result->abort_result_set(); /* purecov: inspected */
+    else
+      result->send_eof();
+    delete result;
+  }
+  DBUG_RETURN(ret);
+}
+
+
+/**
+  Reset all "col_*" fields
+*/
+
+void Explain::init_columns()
+{
+  col_id= NULL;
+  col_select_type.cleanup();
+  col_table_name.cleanup();
+  col_partitions.cleanup();
+  col_join_type.cleanup();
+  col_possible_keys.cleanup();
+  col_key.cleanup();
+  col_key_len.cleanup();
+  col_ref.cleanup();
+  col_rows= NULL;
+  col_filtered= NULL;
+  col_extra.cleanup();
+}
+
+
+/**
+  Calculate EXPLAIN column values and link them into "items" list
+
+  @return false if success, true if error
+*/
+
+bool Explain::make_list()
+{
+  if (explain_id() ||
+      explain_select_type() ||
+      explain_table_name() ||
+      explain_partitions() ||
+      explain_join_type() ||
+      explain_possible_keys() ||
+      explain_key_and_len() ||
+      explain_ref() ||
+      explain_rows_and_filtered() ||
+      explain_extra())
+    return true; /* purecov: inspected */
+
+  /*
+    NOTE: the number/types of items pushed into item_list must be in sync with
+    EXPLAIN column types as they're "defined" in THD::send_explain_fields()
+  */
+  return push(col_id) ||
+         push(col_select_type) ||
+         push(col_table_name) ||
+         (describe(DESCRIBE_PARTITIONS) && push(col_partitions)) ||
+         push(col_join_type) ||
+         push(col_possible_keys) ||
+         push(col_key) ||
+         push(col_key_len) ||
+         push(col_ref) ||
+         push(col_rows) ||
+         (describe(DESCRIBE_EXTENDED) && push(col_filtered)) ||
+         push(col_extra);
+}
+
+
+/**
+  Make "items" list and send it to select_result output stream
+
+  @note An overloaded Explain_join::send_to() function sends
+        one item list per each JOIN::join_tab[] element.
+
+  @return false if success, true if error
+*/
+
+bool Explain::send_to(select_result *to)
+{
+  const bool ret= make_list() || to->send_data(items);
+  items.empty();
+  init_columns();
+  return ret;
+}
+
+
+bool Explain::explain_id()
+{
+  col_id= new Item_uint(select_lex()->select_number);
+  return col_id == NULL;
+}
+
+
+bool Explain::explain_select_type()
+{
+  if (select_lex()->type)
+    col_select_type.set(select_lex()->type);
+  else if (select_lex()->first_inner_unit() || select_lex()->next_select())
+    col_select_type.set_const("PRIMARY");
+  else
+    col_select_type.set_const("SIMPLE");
+  return col_select_type.is_empty();
+}
+
+
+bool Explain::explain_extra()
+{
+  col_extra.set_const("");
+  return false;
+}
+
+
+/* Explain_no_table class functions *******************************************/
+
+
+bool Explain_no_table::explain_rows_and_filtered()
+{
+  if (rows == HA_POS_ERROR)
+    return false;
+  col_rows= new Item_int(rows, MY_INT64_NUM_DECIMAL_DIGITS);
+  return col_rows == NULL;
+}
+
+
+bool Explain_no_table::explain_extra()
+{
+  return col_extra.set(message);
+}
+
+
+/* Explain_union class functions **********************************************/
+
+
+bool Explain_union::explain_id()
+{
+  return false;
+}
+
+
+bool Explain_union::explain_table_name()
+{
+  SELECT_LEX *last_select= join->unit->first_select()->last_select();
+  // # characters needed to print select_number of last select
+  int last_length= (int)log10((double)last_select->select_number)+1;
+
+  SELECT_LEX *sl= join->unit->first_select();
+  uint len= 6, lastop= 0;
+  char table_name_buffer[NAME_LEN];
+  memcpy(table_name_buffer, STRING_WITH_LEN("<union"));
+  /*
+    - len + lastop: current position in table_name_buffer
+    - 6 + last_length: the number of characters needed to print
+      '...,'<last_select->select_number>'>\0'
+  */
+  for (;
+       sl && len + lastop + 6 + last_length < NAME_CHAR_LEN;
+       sl= sl->next_select())
+  {
+    len+= lastop;
+    lastop= my_snprintf(table_name_buffer + len, NAME_CHAR_LEN - len,
+                        "%u,", sl->select_number);
+  }
+  if (sl || len + lastop >= NAME_CHAR_LEN)
+  {
+    memcpy(table_name_buffer + len, STRING_WITH_LEN("...,"));
+    len+= 4;
+    lastop= my_snprintf(table_name_buffer + len, NAME_CHAR_LEN - len,
+                        "%u,", last_select->select_number);
+  }
+  len+= lastop;
+  table_name_buffer[len - 1]= '>';  // change ',' to '>'
+
+  return col_table_name.set(table_name_buffer, len);
+}
+
+
+bool Explain_union::explain_join_type()
+{
+  col_join_type.set_const(join_type_str[JT_ALL]);
+  return false;
+}
+
+
+bool Explain_union::explain_extra()
+{
+  /*
+    here we assume that the query will return at least two rows, so we
+    show "filesort" in EXPLAIN. Of course, sometimes we'll be wrong
+    and no filesort will be actually done, but executing all selects in
+    the UNION to provide precise EXPLAIN information will hardly be
+    appreciated :)
+  */
+  if (join->unit->global_parameters->order_list.first)
+  {
+    col_extra.set_const("Using filesort");
+    return false;
+  }
+  return Explain::explain_extra();
+}
+
+
+/* Explain_table_base class functions *****************************************/
+
+
+bool Explain_table_base::explain_partitions()
+{
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+  if (!table->derived_select_number && table->part_info)
+  {
+    String s;
+    make_used_partitions_str(table->part_info, &s);
+    return col_partitions.set(s);
+  }
+#endif
+  return false;
+}
+
+
+bool Explain_table_base::explain_possible_keys()
+{
+  if (usable_keys.is_clear_all())
+    return false;
+
+  StringBuffer<512> str_possible_keys(cs);
+
+  for (uint j= 0 ; j < table->s->keys ; j++)
+  {
+    if (usable_keys.is_set(j))
+    {
+      if (str_possible_keys.length())
+        str_possible_keys.append(',');
+      str_possible_keys.append(table->key_info[j].name,
+                               strlen(table->key_info[j].name), cs);
+    }
+  }
+  if (str_possible_keys.length())
+    return col_possible_keys.set(str_possible_keys);
+  return false;
+}
+
+
+bool Explain_table_base::explain_key_and_len_quick(const SQL_SELECT *select)
+{
+  DBUG_ASSERT(select && select->quick);
+
+  StringBuffer<512> str_key(cs);
+  StringBuffer<512> str_key_len(cs);
+
+  select->quick->add_keys_and_lengths(&str_key, &str_key_len);
+  return col_key.set(str_key) || col_key_len.set(str_key_len);
+}
+
+
+bool Explain_table_base::explain_key_and_len_index(int key)
+{
+  DBUG_ASSERT(key != MAX_KEY);
+  return explain_key_and_len_index(key, table->key_info[key].key_length);
+}
+
+
+bool Explain_table_base::explain_key_and_len_index(int key, uint key_length)
+{
+  DBUG_ASSERT(key != MAX_KEY);
+
+  const KEY *key_info= table->key_info + key;
+  char buff_key_len[24];
+  const int length= longlong2str(key_length, buff_key_len, 10) - buff_key_len;
+  return col_key.set(key_info->name) || col_key_len.set(buff_key_len, length);
+}
+
+
+void Explain_table_base::explain_extra_common(const SQL_SELECT *select,
+                                              const JOIN_TAB *tab,
+                                              int quick_type,
+                                              uint keyno,
+                                              String *str_extra)
+{
+  if ((keyno != MAX_KEY && keyno == table->file->pushed_idx_cond_keyno &&
+       table->file->pushed_idx_cond) || (tab && tab->cache_idx_cond))
+    str_extra->append(STRING_WITH_LEN("; Using index condition"));
+
+  switch (quick_type) {
+  case QUICK_SELECT_I::QS_TYPE_ROR_UNION:
+  case QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT:
+  case QUICK_SELECT_I::QS_TYPE_INDEX_MERGE:
+    str_extra->append(STRING_WITH_LEN("; Using "));
+    select->quick->add_info_string(str_extra);
+    break;
+  default: ;
+  }
+
+  if (select)
+  {
+    if (tab && tab->use_quick == QS_DYNAMIC_RANGE)
+    {
+      /* 4 bits per 1 hex digit + terminating '\0' */
+      char buf[MAX_KEY / 4 + 1];
+      str_extra->append(STRING_WITH_LEN("; Range checked for each "
+                                        "record (index map: 0x"));
+      str_extra->append(tab->keys.print(buf));
+      str_extra->append(')');
+    }
+    else if (select->cond)
+    {
+      const Item *pushed_cond= table->file->pushed_cond;
+
+      if (thd->optimizer_switch_flag(OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) &&
+          pushed_cond)
+      {
+        str_extra->append(STRING_WITH_LEN("; Using where with pushed condition"));
+        if (describe(DESCRIBE_EXTENDED))
+        {
+          str_extra->append(STRING_WITH_LEN(": "));
+          ((Item *)pushed_cond)->print(str_extra, QT_ORDINARY);
+        }
+      }
+      else
+        str_extra->append(STRING_WITH_LEN("; Using where"));
+    }
+  }
+  if (table->reginfo.not_exists_optimize)
+    str_extra->append(STRING_WITH_LEN("; Not exists"));
+
+  if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE &&
+      !(((QUICK_RANGE_SELECT*)(select->quick))->mrr_flags &
+       (HA_MRR_USE_DEFAULT_IMPL | HA_MRR_SORTED)))
+  {
+    /*
+      During normal execution of a query, multi_range_read_init() is
+      called to initialize MRR. If HA_MRR_SORTED is set at this point,
+      multi_range_read_init() for any native MRR implementation will
+      revert to default MRR because they cannot produce sorted output
+      currently.
+      Calling multi_range_read_init() can potentially be costly, so it
+      is not done when executing an EXPLAIN. We therefore make the
+      assumption that HA_MRR_SORTED means no MRR. If some MRR native
+      implementation will support sorted output in the future, a
+      function "bool mrr_supports_sorted()" should be added in the
+      handler.
+    */
+    str_extra->append(STRING_WITH_LEN("; Using MRR"));
+  }
+}
+
+void Explain_table_base::explain_tmptable_and_filesort(bool need_tmp_table_arg,
+                                                       bool need_sort_arg,
+                                                       String *str_extra)
+{
+  if (need_tmp_table_arg)
+    str_extra->append(STRING_WITH_LEN("; Using temporary"));
+  if (need_sort_arg)
+    str_extra->append(STRING_WITH_LEN("; Using filesort"));
+}
+
+
+/* Explain_join class functions ***********************************************/
+
+
+bool Explain_join::send_to(select_result *to)
+{
+  for (; tabnum < join->tables; tabnum++)
+  {
+    tab= join->join_tab + tabnum;
+    table= tab->table;
+    usable_keys= tab->keys;
+    quick_type= -1;
+
+    if (tab->type == JT_ALL && tab->select && tab->select->quick)
+    {
+      quick_type= tab->select->quick->get_type();
+      tab->type= calc_join_type(quick_type);
+    }
+
+    if (Explain_table_base::send_to(external_result))
+      return true; /* purecov: inspected */
+
+    used_tables|= table->map;
+  }
+  return false;
+}
+
+
+bool Explain_join::explain_table_name()
+{
+  if (table->derived_select_number)
+  {
+    /* Derived table name generation */
+    char table_name_buffer[NAME_LEN];
+    const size_t len= my_snprintf(table_name_buffer,
+                                  sizeof(table_name_buffer) - 1,
+                                  "<derived%u>", table->derived_select_number);
+    return col_table_name.set(table_name_buffer, len);
+  }
+  else
+    return col_table_name.set(table->pos_in_table_list->alias);
+}
+
+
+bool Explain_join::explain_join_type()
+{
+  col_join_type.set_const(join_type_str[tab->type]);
+  return false;
+}
+
+
+bool Explain_join::explain_key_and_len()
+{
+  if (tab->ref.key_parts)
+    return explain_key_and_len_index(tab->ref.key, tab->ref.key_length);
+  else if (tab->type == JT_NEXT)
+    return explain_key_and_len_index(tab->index);
+  else if (tab->select && tab->select->quick)
+    return explain_key_and_len_quick(tab->select);
+  else
+  {
+    const TABLE_LIST *table_list= table->pos_in_table_list;
+    if (table_list->schema_table &&
+        table_list->schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE)
+    {
+      StringBuffer<512> str_key(cs);
+      const char *f_name;
+      int f_idx;
+      if (table_list->has_db_lookup_value)
+      {
+        f_idx= table_list->schema_table->idx_field1;
+        f_name= table_list->schema_table->fields_info[f_idx].field_name;
+        str_key.append(f_name, strlen(f_name), cs);
+      }
+      if (table_list->has_table_lookup_value)
+      {
+        if (table_list->has_db_lookup_value)
+          str_key.append(',');
+        f_idx= table_list->schema_table->idx_field2;
+        f_name= table_list->schema_table->fields_info[f_idx].field_name;
+        str_key.append(f_name, strlen(f_name), cs);
+      }
+      if (str_key.length())
+        return col_key.set(str_key);
+    }
+  }
+  return false;
+}
+
+
+bool Explain_join::explain_ref()
+{
+  if (tab->ref.key_parts)
+  {
+    StringBuffer<512> str_ref(cs);
+    for (const store_key *const *ref= tab->ref.key_copy; *ref; ref++)
+    {
+      if (str_ref.length())
+        str_ref.append(',');
+      str_ref.append((*ref)->name(), strlen((*ref)->name()), cs);
+    }
+    return col_ref.set(str_ref);
+  }
+  return false;
+}
+
+
+bool Explain_join::explain_rows_and_filtered()
+{
+  if (table->pos_in_table_list->schema_table)
+    return false;
+
+  double examined_rows;
+  if (tab->select && tab->select->quick)
+    examined_rows= rows2double(tab->select->quick->records);
+  else if (tab->type == JT_NEXT || tab->type == JT_ALL)
+  {
+    if (tab->limit)
+      examined_rows= rows2double(tab->limit);
+    else
+    {
+      table->file->info(HA_STATUS_VARIABLE);
+      examined_rows= rows2double(table->file->stats.records);
+    }
+  }
+  else
+    examined_rows= join->best_positions[tabnum].records_read;
+
+  col_rows= new Item_int((longlong) (ulonglong) examined_rows,
+                         MY_INT64_NUM_DECIMAL_DIGITS);
+  if (col_rows == NULL)
+    return true; /* purecov: inspected */
+
+  /* Add "filtered" field */
+  if (describe(DESCRIBE_EXTENDED))
+  {
+    float f= 0.0;
+    if (examined_rows)
+      f= 100.0 * join->best_positions[tabnum].records_read / examined_rows;
+    col_filtered= new Item_float(f, 2);
+    return col_filtered == NULL;
+  }
+  return false;
+}
+
+
+bool Explain_join::explain_extra()
+{
+  StringBuffer<512> str_extra(cs);
+
+  if (tab->info)
+    col_extra.set(tab->info);
+  else if (tab->packed_info & TAB_INFO_HAVE_VALUE)
+  {
+    if (tab->packed_info & TAB_INFO_USING_INDEX)
+      str_extra.append(STRING_WITH_LEN("; Using index"));
+    if (tab->packed_info & TAB_INFO_USING_WHERE)
+      str_extra.append(STRING_WITH_LEN("; Using where"));
+    if (tab->packed_info & TAB_INFO_FULL_SCAN_ON_NULL)
+      str_extra.append(STRING_WITH_LEN("; Full scan on NULL key"));
+    /* Skip initial "; "*/
+    const char *str= str_extra.ptr();
+    uint32 len= str_extra.length();
+    if (len)
+    {
+      str += 2;
+      len -= 2;
+    }
+    col_extra.set(str, len);
+  }
+  else
+  {
+    const SQL_SELECT *select= tab->select;
+    uint keyno= MAX_KEY;
+    if (tab->ref.key_parts)
+      keyno= tab->ref.key;
+    else if (select && select->quick)
+      keyno = select->quick->index;
+
+    explain_extra_common(select, tab, quick_type, keyno, &str_extra);
+
+    const TABLE_LIST *table_list= table->pos_in_table_list;
+    if (table_list->schema_table &&
+        table_list->schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE)
+    {
+      if (!table_list->table_open_method)
+        str_extra.append(STRING_WITH_LEN("; Skip_open_table"));
+      else if (table_list->table_open_method == OPEN_FRM_ONLY)
+        str_extra.append(STRING_WITH_LEN("; Open_frm_only"));
+      else
+        str_extra.append(STRING_WITH_LEN("; Open_full_table"));
+      if (table_list->has_db_lookup_value &&
+          table_list->has_table_lookup_value)
+        str_extra.append(STRING_WITH_LEN("; Scanned 0 databases"));
+      else if (table_list->has_db_lookup_value ||
+               table_list->has_table_lookup_value)
+        str_extra.append(STRING_WITH_LEN("; Scanned 1 database"));
+      else
+        str_extra.append(STRING_WITH_LEN("; Scanned all databases"));
+    }
+    if (((tab->type == JT_NEXT || tab->type == JT_CONST) &&
+         table->covering_keys.is_set(tab->index)) ||
+        (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT &&
+         !((QUICK_ROR_INTERSECT_SELECT*) select->quick)->need_to_fetch_row) ||
+        table->key_read)
+    {
+      if (quick_type == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX)
+      {
+        QUICK_GROUP_MIN_MAX_SELECT *qgs=
+          (QUICK_GROUP_MIN_MAX_SELECT *) select->quick;
+        str_extra.append(STRING_WITH_LEN("; Using index for group-by"));
+        qgs->append_loose_scan_type(&str_extra);
+      }
+      else
+        str_extra.append(STRING_WITH_LEN("; Using index"));
+    }
+
+    explain_tmptable_and_filesort(need_tmp_table, need_order, &str_extra);
+    need_tmp_table= need_order= false;
+
+    if (distinct && test_all_bits(used_tables,thd->used_tables))
+      str_extra.append(STRING_WITH_LEN("; Distinct"));
+
+    if (tab->loosescan_match_tab)
+      str_extra.append(STRING_WITH_LEN("; LooseScan"));
+
+    if (tab->flush_weedout_table)
+      str_extra.append(STRING_WITH_LEN("; Start temporary"));
+    if (tab->check_weed_out_table)
+      str_extra.append(STRING_WITH_LEN("; End temporary"));
+    else if (tab->do_firstmatch)
+    {
+      if (tab->do_firstmatch == join->join_tab - 1)
+        str_extra.append(STRING_WITH_LEN("; FirstMatch"));
+      else
+      {
+        str_extra.append(STRING_WITH_LEN("; FirstMatch("));
+        TABLE *prev_table= tab->do_firstmatch->table;
+        if (prev_table->derived_select_number)
+        {
+          char namebuf[NAME_LEN];
+          /* Derived table name generation */
+          int len= my_snprintf(namebuf, sizeof(namebuf)-1,
+                               "<derived%u>",
+                               prev_table->derived_select_number);
+          str_extra.append(namebuf, len);
+        }
+        else
+          str_extra.append(prev_table->pos_in_table_list->alias);
+        str_extra.append(STRING_WITH_LEN(")"));
+      }
+    }
+    uint sj_strategy= join->best_positions[tabnum].sj_strategy;
+    if (sj_is_materialize_strategy(sj_strategy))
+    {
+      if (join->best_positions[tabnum].n_sj_tables == 1)
+        str_extra.append(STRING_WITH_LEN("; Materialize"));
+      else
+      {
+        last_sjm_table= tabnum + join->best_positions[tabnum].n_sj_tables - 1;
+        str_extra.append(STRING_WITH_LEN("; Start materialize"));
+      }
+      if (sj_strategy == SJ_OPT_MATERIALIZE_SCAN)
+          str_extra.append(STRING_WITH_LEN("; Scan"));
+    }
+    else if (last_sjm_table == tabnum)
+    {
+      str_extra.append(STRING_WITH_LEN("; End materialize"));
+    }
+
+    if (tab->has_guarded_conds())
+      str_extra.append(STRING_WITH_LEN("; Full scan on NULL key"));
+
+    if (tabnum > 0 && tab[-1].next_select == sub_select_cache)
+    {
+      str_extra.append(STRING_WITH_LEN("; Using join buffer ("));
+      if ((tab->use_join_cache & JOIN_CACHE::ALG_BNL))
+        str_extra.append(STRING_WITH_LEN("BNL"));
+      else if ((tab->use_join_cache & JOIN_CACHE::ALG_BKA))
+        str_extra.append(STRING_WITH_LEN("BKA"));
+      else if ((tab->use_join_cache & JOIN_CACHE::ALG_BKA_UNIQUE))
+        str_extra.append(STRING_WITH_LEN("BKA_UNIQUE"));
+      else
+        DBUG_ASSERT(0); /* purecov: inspected */
+      if (tab->use_join_cache & JOIN_CACHE::NON_INCREMENTAL_BUFFER)
+        str_extra.append(STRING_WITH_LEN(", regular buffers)"));
+      else
+        str_extra.append(STRING_WITH_LEN(", incremental buffers)"));
+    }
+
+    /* Skip initial "; "*/
+    const char *str= str_extra.ptr();
+    uint32 len= str_extra.length();
+    if (len)
+    {
+      str += 2;
+      len -= 2;
+    }
+    col_extra.set(str, len);
+  }
+  return col_extra.is_empty();
+}
+
+
+/* Explain_table class functions **********************************************/
+
+
+bool Explain_table::explain_table_name()
+{
+  return col_table_name.set(table->alias);
+}
+
+
+bool Explain_table::explain_join_type()
+{
+  join_type jt;
+  if (select && select->quick)
+    jt= calc_join_type(select->quick->get_type());
+  else
+    jt= JT_ALL;
+
+  col_join_type.set_const(join_type_str[jt]);
+  return false;
+}
+
+
+bool Explain_table::explain_key_and_len()
+{
+  if (key != MAX_KEY)
+    return explain_key_and_len_index(key);
+  if (select && select->quick)
+    return explain_key_and_len_quick(select);
+  return false;
+}
+
+
+bool Explain_table::explain_rows_and_filtered()
+{
+  double examined_rows;
+  if (select && select->quick)
+    examined_rows= rows2double(select->quick->records);
+  else if (!select && !need_sort && limit != HA_POS_ERROR)
+    examined_rows= rows2double(limit);
+  else
+  {
+    table->file->info(HA_STATUS_VARIABLE);
+    examined_rows= rows2double(table->file->stats.records);
+  }
+  col_rows= new Item_int((longlong) (ulonglong) examined_rows,
+                         MY_INT64_NUM_DECIMAL_DIGITS);
+  if (col_rows == NULL)
+    return true; /* purecov: inspected */
+
+  if (describe(DESCRIBE_EXTENDED))
+  {
+    col_filtered= new Item_float(100.0, 2);
+    if (col_filtered == NULL)
+      return true; /* purecov: inspected */
+  }
+  return false;
+}
+
+
+bool Explain_table::explain_extra()
+{
+  StringBuffer<512> str_extra(cs);
+  const uint keyno= (select && select->quick) ? select->quick->index : key;
+  const int quick_type= (select && select->quick) ? select->quick->get_type() 
+                                                  : -1;
+  explain_extra_common(select, NULL, quick_type, keyno, &str_extra);
+  explain_tmptable_and_filesort(need_tmp_table, need_sort, &str_extra);
+
+  /* Skip initial "; "*/
+  const char *str= str_extra.ptr();
+  uint32 len= str_extra.length();
+  if (len)
+  {
+    str += 2;
+    len -= 2;
+  }
+  return col_extra.set(str, len);
+}
+
+
+/**
+  EXPLAIN functionality for insert_select, multi_update and multi_delete
+
+  This class objects substitute insert_select, multi_update and multi_delete
+  data interceptor objects to implement EXPLAIN for INSERT, REPLACE and
+  multi-table UPDATE and DELETE queries.
+  explain_send class object initializes tables like insert_select, multi_update
+  or multi_delete data interceptor do, but it suppress table data modification
+  by the underlying interceptor object.
+  Thus, we can use explain_send object in the context of EXPLAIN INSERT/
+  REPLACE/UPDATE/DELETE query like we use select_send in the context of
+  EXPLAIN SELECT command:
+    1) in presence of lex->describe flag we pass explain_send object to the
+       mysql_select() function,
+    2) it call prepare(), prepare2() and initialize_tables() functions to
+       mark modified tables etc.
+
+*/
+
+class explain_send : public select_send {
+protected:
+  /*
+    As far as we use explain_send object in a place of select_send, explain_send
+    have to pass multiple invocation of its prepare(), prepare2() and
+    initialize_tables() functions, since JOIN::exec() of subqueries runs
+    these functions of select_send multiple times by design.
+    insert_select, multi_update and multi_delete class functions are not intended
+    for multiple invocations, so "prepared", "prepared2" and "initialized" flags
+    guard data interceptor object from function re-invocation.
+  */
+  bool prepared;    ///< prepare() is done
+  bool prepared2;   ///< prepare2() is done
+  bool initialized; ///< initialize_tables() is done
+  
+  /**
+    Pointer to underlying insert_select, multi_update or multi_delete object
+  */
+  select_result_interceptor *interceptor;
+
+public:
+  explain_send(select_result_interceptor *interceptor_arg)
+  : prepared(false), prepared2(false), initialized(false),
+    interceptor(interceptor_arg)
+  {}
+
+protected:
+  virtual int prepare(List<Item> &list, SELECT_LEX_UNIT *u)
+  {
+    if (prepared)
+      return false;
+    prepared= true;
+    return select_send::prepare(list, u) || interceptor->prepare(list, u);
+  }
+
+  virtual int prepare2(void)
+  {
+    if (prepared2)
+      return false;
+    prepared2= true;
+    return select_send::prepare2() || interceptor->prepare2();
+  }
+
+  virtual bool initialize_tables(JOIN *join)
+  {
+    if (initialized)
+      return false;
+    initialized= true;
+    return select_send::initialize_tables(join) ||
+           interceptor->initialize_tables(join);
+  }
+
+  virtual void cleanup()
+  {
+    select_send::cleanup();
+    interceptor->cleanup();
+  }
+};
+
+
+/******************************************************************************
+  External function implementations
+******************************************************************************/
+
+
+/**
+  Send a message as an "extra" column value
+
+  This function forms the 1st row of the QEP output with a simple text message.
+  This is useful to explain such trivial cases as "No tables used" etc.
+
+  @note Also this function explains the rest of QEP (subqueries or joined
+        tables if any).
+
+  @param thd      current THD
+  @param join     JOIN
+  @param message  text message for the "extra" column.
+
+  @return false if success, true if error
+*/
+
+bool explain_no_table(THD *thd, JOIN *join, const char *message)
+{
+  DBUG_ENTER("explain_no_table");
+  const bool ret= Explain_no_table(thd, join, message).send();
+  DBUG_RETURN(ret);
+}
+
+
+/**
+  Send a message as an "extra" column value
+
+  This function forms the 1st row of the QEP output with a simple text message.
+  This is useful to explain such trivial cases as "No tables used" etc.
+
+  @note Also this function explains the rest of QEP (subqueries if any).
+
+  @param thd      current THD
+  @param message  text message for the "extra" column.
+  @param rows     HA_POS_ERROR or a value for the "rows" column.
+
+  @return false if success, true if error
+*/
+
+bool explain_no_table(THD *thd, const char *message, ha_rows rows)
+{
+  DBUG_ENTER("explain_no_table");
+  const bool ret= Explain_no_table(thd, message, rows).send();
+  DBUG_RETURN(ret);
+
+}
+
+
+/**
+  EXPLAIN handling for single-table UPDATE and DELETE queries
+
+  Send to the client a QEP data set for single-table EXPLAIN UPDATE/DELETE
+  queries. As far as single-table UPDATE/DELETE are implemented without
+  the regular JOIN tree, we can't reuse mysql_explain_union() directly,
+  thus we deal with this single table in a special way and then call
+  mysql_explain_union() for subqueries (if any).
+
+  @param thd            current THD
+  @param table          TABLE object to update/delete rows in the UPDATE/DELETE
+                        query.
+  @param select         SQL_SELECT object that represents quick access functions
+                        and WHERE clause.
+  @param key            MAX_KEY or and index number of the key that was chosen
+                        to access table data.
+  @param limit          HA_POS_ERROR or LIMIT value.
+  @param need_tmp_table true if it requires temporary table -- "Using temporary"
+                        string in the "extra" column.
+  @param need_sort      true if it requires filesort() -- "Using filesort"
+                        string in the "extra" column.
+
+  @return false if success, true if error
+*/
+
+bool explain_single_table_modification(THD *thd,
+                                       TABLE *table,
+                                       const SQL_SELECT *select,
+                                       uint key,
+                                       ha_rows limit,
+                                       bool need_tmp_table,
+                                       bool need_sort)
+{
+  DBUG_ENTER("explain_single_table_modification");
+  const bool ret= Explain_table(thd, table, select, key, limit,
+                                need_tmp_table, need_sort).send();
+  DBUG_RETURN(ret);
+}
+
+
+/**
+  EXPLAIN handling for EXPLAIN SELECT queries
+
+  Send QEP to the client.
+
+  @param thd             current THD
+  @param join            JOIN
+  @param need_tmp_table  true if it requires a temporary table --
+                         "Using temporary" string in the "extra" column.
+  @param need_order      true if it requires filesort() -- "Using filesort"
+                         string in the "extra" column.
+  @param distinct        true if there is the DISTINCT clause (not optimized
+                         out) -- "Distinct" string in the "extra" column.
+
+  @return false if success, true if error
+*/
+
+bool explain_query_specification(THD *thd, JOIN *join, bool need_tmp_table,
+                                 bool need_order, bool distinct)
+{
+  DBUG_ENTER("explain_query_specification");
+  DBUG_PRINT("info", ("Select %p, type %s",
+		      join->select_lex, join->select_lex->type));
+  bool ret;
+  if (join->select_lex == join->unit->fake_select_lex)
+    ret= Explain_union(thd, join).send();
+  else
+    ret= Explain_join(thd, join, need_tmp_table, need_order, distinct).send();
+  DBUG_RETURN(ret);
+}
+
+
+/**
+  EXPLAIN handling for INSERT, REPLACE and multi-table UPDATE/DELETE queries
+
+  Send to the client a QEP data set for data-modifying commands those have a
+  regular JOIN tree (INSERT...SELECT, REPLACE...SELECT and multi-table
+  UPDATE and DELETE queries) like mysql_select() does for SELECT queries in
+  the "describe" mode.
+
+  @note @see explain_single_table_modification() for single-table
+        UPDATE/DELETE EXPLAIN handling.
+
+  @note Unlike the mysql_select function, explain_multi_table_modification
+        calls abort_result_set() itself in the case of failure (OOM etc.)
+        since explain_multi_table_modification() uses internally created
+        select_result stream.
+
+  @param thd     current THD
+  @param result  pointer to select_insert, multi_delete or multi_update object:
+                 the function uses it to call result->prepare(),
+                 result->prepare2() and result->initialize_tables() only but
+                 not to modify table data or to send a result to client.
+  @return false if success, true if error
+*/
+
+bool explain_multi_table_modification(THD *thd,
+                                      select_result_interceptor *result)
+{
+  DBUG_ENTER("explain_multi_table_modification");
+  explain_send explain(result);
+  bool res= explain_query_expression(thd, &explain);
+  DBUG_RETURN(res);
+}
+
+
+/**
+  EXPLAIN handling for SELECT and table-modifying queries that have JOIN
+
+  Send to the client a QEP data set for SELECT or data-modifying commands
+  those have a regular JOIN tree (INSERT...SELECT, REPLACE...SELECT and
+  multi-table UPDATE and DELETE queries) like mysql_select() does for SELECT
+  queries in the "describe" mode.
+
+  @note @see explain_single_table_modification() for single-table
+        UPDATE/DELETE EXPLAIN handling.
+
+  @note explain_query_expression() calls abort_result_set() itself in the
+        case of failure (OOM etc.) since explain_multi_table_modification()
+        uses internally created select_result stream.
+
+  @param thd     current THD
+  @param result  pointer to select_result, select_insert, multi_delete or
+                 multi_update object: the function uses it to call
+                 result->prepare(), result->prepare2() and
+                 result->initialize_tables() only but not to modify table data
+                 or to send a result to client.
+  @return false if success, true if error
+*/
+
+bool explain_query_expression(THD *thd, select_result *result)
+{
+  DBUG_ENTER("explain_query_expression");
+  const bool res= thd->send_explain_fields(result) ||
+                  mysql_explain_union(thd, &thd->lex->unit, result) ||
+                  thd->is_error();
+  /*
+    The code which prints the extended description is not robust
+    against malformed queries, so skip it if we have an error.
+  */
+  if (!res && (thd->lex->describe & DESCRIBE_EXTENDED) &&
+      thd->lex->sql_command == SQLCOM_SELECT) // TODO: implement for INSERT/etc
+  {
+    StringBuffer<1024> str;
+    /*
+      The warnings system requires input in utf8, @see mysqld_show_warnings().
+    */
+    thd->lex->unit.print(&str, QT_TO_SYSTEM_CHARSET);
+    str.append('\0');
+    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+                 ER_YES, str.ptr());
+  }
+  if (res)
+    result->abort_result_set();
+  else
+    result->send_eof();
+  DBUG_RETURN(res);
+}
+
+
+/**
+  Explain UNION or subqueries of the unit
+
+  If the unit is a UNION, explain it as a UNION. Otherwise explain nested
+  subselects.
+
+  @param thd            thread object
+  @param unit           unit object
+  @param result         result stream to send QEP dataset
+
+  @return false if success, true if error
+*/
+bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
+{
+  DBUG_ENTER("mysql_explain_union");
+  bool res= 0;
+  SELECT_LEX *first= unit->first_select();
+
+  for (SELECT_LEX *sl= first;
+       sl;
+       sl= sl->next_select())
+  {
+    // drop UNCACHEABLE_EXPLAIN, because it is for internal usage only
+    uint8 uncacheable= (sl->uncacheable & ~UNCACHEABLE_EXPLAIN);
+    sl->type= (((&thd->lex->select_lex)==sl)?
+	       (sl->first_inner_unit() || sl->next_select() ? 
+		"PRIMARY" : "SIMPLE"):
+	       ((sl == first)?
+		((sl->linkage == DERIVED_TABLE_TYPE) ?
+		 "DERIVED":
+		 ((uncacheable & UNCACHEABLE_DEPENDENT) ?
+		  "DEPENDENT SUBQUERY":
+		  (uncacheable?"UNCACHEABLE SUBQUERY":
+		   "SUBQUERY"))):
+		((uncacheable & UNCACHEABLE_DEPENDENT) ?
+		 "DEPENDENT UNION":
+		 uncacheable?"UNCACHEABLE UNION":
+		 "UNION")));
+    sl->options|= SELECT_DESCRIBE;
+  }
+  if (unit->is_union())
+  {
+    unit->fake_select_lex->select_number= UINT_MAX; // jost for initialization
+    unit->fake_select_lex->type= "UNION RESULT";
+    unit->fake_select_lex->options|= SELECT_DESCRIBE;
+    if (!(res= unit->prepare(thd, result, SELECT_NO_UNLOCK | SELECT_DESCRIBE)))
+      res= unit->exec();
+  }
+  else
+  {
+    thd->lex->current_select= first;
+    unit->set_limit(unit->global_parameters);
+    res= mysql_select(thd,
+                      first->table_list.first,
+                      first->with_wild, first->item_list,
+                      first->where,
+                      first->order_list.elements +
+                      first->group_list.elements,
+                      first->order_list.first,
+                      first->group_list.first,
+                      first->having,
+                      thd->lex->proc_list.first,
+                      first->options | thd->variables.option_bits | SELECT_DESCRIBE,
+                      result, unit, first);
+  }
+  DBUG_RETURN(res || thd->is_error());
+}
+
+

=== added file 'sql/opt_explain.h'
--- a/sql/opt_explain.h	1970-01-01 00:00:00 +0000
+++ b/sql/opt_explain.h	2011-07-02 21:01:41 +0000
@@ -0,0 +1,73 @@
+/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+
+#ifndef OPT_EXPLAIN_INCLUDED
+#define OPT_EXPLAIN_INCLUDED
+
+/** @file "EXPLAIN <command>" 
+
+Single table UPDATE/DELETE commands are explained by the 
+explain_single_table_modification() function.
+
+A query expression (complete SELECT query possibly including
+subqueries and unions), INSERT...SELECT and multitable UPDATE/DELETE
+commands are explained like this:
+
+(1) explain_query_expression()
+
+Is the entry point. Forwards the job to mysql_explain_union().
+
+(2) mysql_explain_union()
+
+Is for a SELECT_LEX_UNIT, prepares, optimizes, executes one JOIN for
+each "top-level" SELECT_LEXs of the unit (like: all SELECTs of a
+UNION; but not subqueries), and one JOIN for the fake SELECT_LEX of
+UNION); each JOIN execution (JOIN::exec()) calls explain_query_specification()
+
+(3) explain_query_specification()
+
+Is for a single SELECT_LEX (fake or not). It needs a prepared and
+optimized JOIN, for which it builds the EXPLAIN rows. But it also
+launches the EXPLAIN process for "inner units" (==subqueries of this
+SELECT_LEX), by calling mysql_explain_union() for each of them. 
+*/
+
+class JOIN;
+class select_result;
+class select_result_interceptor;
+class SQL_SELECT;
+class TABLE;
+class THD;
+
+#include "my_base.h"
+
+bool explain_no_table(THD *thd, JOIN *join, const char *message);
+bool explain_no_table(THD *thd, const char *message,
+                      ha_rows rows= HA_POS_ERROR);
+bool explain_single_table_modification(THD *thd,
+                                       TABLE *table,
+                                       const SQL_SELECT *select,
+                                       uint key,
+                                       ha_rows limit,
+                                       bool need_tmp_table,
+                                       bool need_sort);
+bool explain_query_specification(THD *thd, JOIN *join, bool need_tmp_table,
+                                 bool need_order, bool distinct);
+bool explain_multi_table_modification(THD *thd,
+                                      select_result_interceptor *result);
+bool explain_query_expression(THD *thd, select_result *result);
+
+#endif /* OPT_EXPLAIN_INCLUDED */

=== modified file 'sql/opt_range.h'
--- a/sql/opt_range.h	2011-04-01 14:04:52 +0000
+++ b/sql/opt_range.h	2011-07-02 21:01:41 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -435,8 +435,6 @@ protected:
   friend uint quick_range_seq_next(range_seq_t rseq, KEY_MULTI_RANGE *range);
   friend range_seq_t quick_range_seq_init(void *init_param,
                                           uint n_ranges, uint flags);
-  friend void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
-                              bool distinct,const char *message);
   friend class QUICK_SELECT_DESC;
   friend class QUICK_INDEX_MERGE_SELECT;
   friend class QUICK_ROR_INTERSECT_SELECT;

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2011-06-21 07:57:31 +0000
+++ b/sql/sql_class.h	2011-07-02 21:01:41 +0000
@@ -3374,6 +3374,14 @@ public:
   */
   virtual void cleanup();
   void set_thd(THD *thd_arg) { thd= thd_arg; }
+
+  /**
+    If we execute EXPLAIN SELECT ... LIMIT (or any other EXPLAIN query)
+    we have to ignore offset value sending EXPLAIN output rows since
+    offset value belongs to the underlying query, not to the whole EXPLAIN.
+  */
+  void reset_offset_limit_cnt() { unit->offset_limit_cnt= 0; }
+
 #ifdef EMBEDDED_LIBRARY
   virtual void begin_dataset() {}
 #else
@@ -4081,6 +4089,11 @@ public:
 */
 #define CF_WRITE_RPL_INFO_COMMAND (1U << 12)
 
+/**
+  Identifies statements that can be explained with EXPLAIN.
+*/
+#define CF_CAN_BE_EXPLAINED       (1U << 13)
+
 /* Bits in server_command_flags */
 
 /**

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2011-05-26 15:20:09 +0000
+++ b/sql/sql_delete.cc	2011-07-02 21:01:41 +0000
@@ -35,6 +35,7 @@
 #include "sp_head.h"
 #include "sql_trigger.h"
 #include "transaction.h"
+#include "opt_explain.h"
 #include "records.h"                            // init_read_record,
                                                 // end_read_record
 
@@ -60,6 +61,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *
   ha_rows	deleted= 0;
   bool          reverse= FALSE;
   bool          skip_record;
+  bool          need_sort= FALSE;
+  bool          err= true;
   ORDER *order= (ORDER *) ((order_list && order_list->elements) ?
                            order_list->first : NULL);
   uint usable_index= MAX_KEY;
@@ -144,6 +147,13 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     /* Update the table->file->stats.records number */
     table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
     ha_rows const maybe_deleted= table->file->stats.records;
+
+    if (thd->lex->describe)
+    {
+      err= explain_no_table(thd, "Deleting all rows", maybe_deleted);
+      goto exit_without_my_ok;
+    }
+
     DBUG_PRINT("debug", ("Trying to use delete_all_rows()"));
     if (!(error=table->file->ha_delete_all_rows()))
     {
@@ -169,14 +179,28 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     Item::cond_result result;
     conds= remove_eq_conds(thd, conds, &result);
     if (result == Item::COND_FALSE)             // Impossible where
+    {
       limit= 0;
+
+      if (thd->lex->describe)
+      {
+        err= explain_no_table(thd, "Impossible WHERE");
+        goto exit_without_my_ok;
+      }
+    }
   }
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   if (prune_partitions(thd, table, conds))
   {
+    /* No matching records */
+    if (thd->lex->describe)
+    {
+      err= explain_no_table(thd, "No matching rows after partition pruning");
+      goto exit_without_my_ok;
+    }
+
     free_underlaid_joins(thd, select_lex);
-    // No matching record
     my_ok(thd, 0);
     DBUG_RETURN(0);
   }
@@ -219,23 +243,33 @@ bool mysql_delete(THD *thd, TABLE_LIST *
       DBUG_RETURN(TRUE);
     }
   }
+
+  if (order)
+  {
+    table->update_const_key_parts(conds);
+    order= simple_remove_const(order, conds);
+
+    usable_index= get_index_for_order(order, table, select, limit,
+                                      &need_sort, &reverse);
+  }
+
+  if (thd->lex->describe)
+  {
+    err= explain_single_table_modification(thd, table, select, usable_index,
+                                           limit, false, need_sort);
+    goto exit_without_my_ok;
+  }
+
   if (options & OPTION_QUICK)
     (void) table->file->extra(HA_EXTRA_QUICK);
 
-  if (order)
+  if (need_sort)
   {
     uint         length= 0;
     SORT_FIELD  *sortorder;
     ha_rows examined_rows;
     ha_rows found_rows;
     
-    table->update_const_key_parts(conds);
-    order= simple_remove_const(order, conds);
-
-    bool need_sort;
-    usable_index= get_index_for_order(order, table, select, limit,
-                                      &need_sort, &reverse);
-    if (need_sort)
     {
       DBUG_ASSERT(usable_index == MAX_KEY);
       table->sort.io_cache= (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
@@ -361,6 +395,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     (void) table->file->extra(HA_EXTRA_NORMAL);
 
 cleanup:
+  DBUG_ASSERT(!thd->lex->describe);
   /*
     Invalidate the table in the query cache if something changed. This must
     be before binlog writing and ha_autocommit_...
@@ -413,6 +448,11 @@ cleanup:
     DBUG_PRINT("info",("%ld records deleted",(long) deleted));
   }
   DBUG_RETURN(thd->is_error() || thd->killed);
+
+exit_without_my_ok:
+  delete select;
+  free_underlaid_joins(thd, select_lex);
+  DBUG_RETURN((err || thd->is_error() || thd->killed) ? 1 : 0);
 }
 
 

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2011-06-24 09:29:07 +0000
+++ b/sql/sql_insert.cc	2011-07-02 21:01:41 +0000
@@ -76,6 +76,7 @@
 #include "transaction.h"
 #include "sql_audit.h"
 #include "debug_sync.h"
+#include "opt_explain.h"
 
 #ifndef EMBEDDED_LIBRARY
 static bool delayed_get_table(THD *thd, MDL_request *grl_protection_request,
@@ -454,11 +455,12 @@ void upgrade_lock_type(THD *thd, thr_loc
         the statement indirectly via a stored function or trigger:
         if it is used, that will lead to a deadlock between the
         client connection and the delayed thread.
+      - we're running the EXPLAIN INSERT command
     */
     if (specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE) ||
         thd->variables.max_insert_delayed_threads == 0 ||
         thd->locked_tables_mode > LTM_LOCK_TABLES ||
-        thd->lex->uses_stored_routines())
+        thd->lex->uses_stored_routines() || thd->lex->describe)
     {
       *lock_type= TL_WRITE;
       return;
@@ -499,6 +501,7 @@ void upgrade_lock_type(THD *thd, thr_loc
         thread may be old and use the before-the-change value.
       */
       *lock_type= TL_WRITE;
+      return;
     }
   }
 }
@@ -658,6 +661,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
 		  bool ignore)
 {
   int error, res;
+  bool err= true;
   bool transactional_table, joins_freed= FALSE;
   bool changed;
   bool was_insert_delayed= (table_list->lock_ty