Commit 582ecb2a authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-3798: EXPLAIN UPDATE/DELETE:

Backport mysql-test/t/myisam_explain_non_select_all.test from mysql-5.6
- the .result file was modified because MariaDB choses different 
  query plans in a number cases. Also, we don't have some of the 
  "incorrect EXPLAIN output" bugs that they still have.

The .test file and includes were taken verbatim with one 
exception: two tests were disabled with --disable parsing:

1. @@sql_safe_updates is not enforced EXPLAINs of multitable 
   updates. In MariaDB, the execution itself will produce 
   ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, but EXPLAIN won't.
2. Their case #71 hits some old bug in MyISAM (See their comments
   in explain_non_select.inc for details).
parent 7e919c52
This diff is collapsed.
# 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 ($json) {
if ($innodb) {
if ($no_rows) {
--replace_regex /"rows": [0-9]+/"rows": "X"/ /"filtered": [0-9.]+/"filtered": "X"/
}
}
--eval EXPLAIN FORMAT=JSON $query;
if ($validation) {
--disable_query_log
--replace_result $MASTER_MYSOCK MASTER_MYSOCK
--exec $MYSQL -S $MASTER_MYSOCK -u root -r test -e "EXPLAIN FORMAT=JSON $query;" > $MYSQLTEST_VARDIR/tmp/explain.json
--replace_regex /[-]*// /FILE.[\/\\:_\.0-9A-Za-z]*/Validation:/
--exec python $MYSQL_TEST_DIR/suite/opt_trace/validate_json.py $MYSQLTEST_VARDIR/tmp/explain.json
--remove_file '$MYSQLTEST_VARDIR/tmp/explain.json'
--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
if ($json) {
if ($innodb) {
if ($no_rows) {
--replace_regex /"rows": [0-9]+/"rows": "X"/ /"filtered": [0-9.]+/"filtered": "X"/
}
}
--eval EXPLAIN FORMAT=JSON $select;
if ($validation) {
--disable_query_log
--replace_result $MASTER_MYSOCK MASTER_MYSOCK
--exec $MYSQL -S $MASTER_MYSOCK -u root -r test -e "EXPLAIN FORMAT=JSON $select;" > $MYSQLTEST_VARDIR/tmp/explain.json
--replace_regex /[-]*// /FILE.[\/\\:_\.0-9A-Za-z]*/Validation:/
--exec python $MYSQL_TEST_DIR/suite/opt_trace/validate_json.py $MYSQLTEST_VARDIR/tmp/explain.json
--remove_file '$MYSQLTEST_VARDIR/tmp/explain.json'
--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
This source diff could not be displayed because it is too large. You can view the blob instead.
#
# 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;
--let $json = 0
--let $validation = 0
--source include/explain_non_select.inc
set default_storage_engine= @save_storage_engine;
set optimizer_switch=default;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment