1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Added test cases for preceding test

This includes all test changes from
"Changing all cost calculation to be given in milliseconds"
and forwards.

Some of the things that caused changes in the result files:

- As part of fixing tests, I added 'echo' to some comments to be able to
  easier find out where things where wrong.
- MATERIALIZED has now a higher cost compared to X than before. Because
  of this some MATERIALIZED types have changed to DEPENDEND SUBQUERY.
  - Some test cases that required MATERIALIZED to repeat a bug was
    changed by adding more rows to force MATERIALIZED to happen.
- 'Filtered' in SHOW EXPLAIN has in many case changed from 100.00 to
  something smaller. This is because now filtered also takes into
  account the smallest possible ref access and filters, even if they
  where not used. Another reason for 'Filtered' being smaller is that
  we now also take into account implicit filtering done for subqueries
  using FIRSTMATCH.
  (main.subselect_no_exists_to_in)
  This is caluculated in best_access_path() and stored in records_out.
- Table orders has changed because more accurate costs.
- 'index' and 'ALL' for small tables has changed to use 'range' or
   'ref' because of optimizer_scan_setup_cost.
- index can be changed to 'range' as 'range' optimizer assumes we don't
  have to read the blocks from disk that range optimizer has already read.
  This can be confusing in the case where there is no obvious where clause
  but instead there is a hidden 'key_column > NULL' added by the optimizer.
  (main.subselect_no_exists_to_in)
- Scan on primary clustered key does not report 'Using Index' anymore
  (It's a table scan, not an index scan).
- For derived tables, the number of rows is now 100 instead of 2,
  which can be seen in EXPLAIN.
- More tests have "Using index for group by" as the cost of this
  optimization is now more correct (lower).
- A primary key could be preferred for a normal key, even if it would
  access more rows, as it's faster to do 1 lokoup and 3 'index_next' on a
  clustered primary key than one lookup trough a secondary.
  (main.stat_tables_innodb)

Notes:

- There was a 4.7% more calls to best_extension_by_limited_search() in
  the main.greedy_optimizer test.  However examining the test results
  it looked that the plans where slightly better (eq_ref where more
  chained together) so I assume this is ok.
- I have verified a few test cases where there was notable/unexpected
  changes in the plan and in all cases the new optimizer plans where
  faster.  (main.greedy_optimizer and some others)
This commit is contained in:
Monty
2022-10-04 16:16:06 +03:00
committed by Sergei Petrunia
parent eb68023c8e
commit 727491b72a
290 changed files with 10927 additions and 8874 deletions

View File

@ -13,6 +13,11 @@
drop table if exists t1,t2,t3,t4; drop table if exists t1,t2,t3,t4;
--enable_warnings --enable_warnings
# We have to use Aria instead of MyISAM as MyISAM has a very high row
# access cost which causes some tests to use use join_cache instead of eq_ref
set @@default_storage_engine="aria";
CREATE TABLE t1 ( CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
@ -1429,7 +1434,7 @@ set tmp_memory_table_size=default;
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10; select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
# #
# A big order by that should trigger a merge in filesort # A big order by that should traigger a merge in filesort
# #
select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2; select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2;
@ -1446,9 +1451,9 @@ select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr orde
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
# --echo #
# Some test with ORDER BY and limit --echo # Some test with ORDER BY and limit
# --echo #
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
@ -1501,7 +1506,7 @@ create table t4 (
companyname char(30) NOT NULL default '', companyname char(30) NOT NULL default '',
PRIMARY KEY (companynr), PRIMARY KEY (companynr),
UNIQUE KEY companyname(companyname) UNIQUE KEY companyname(companyname)
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; ) ENGINE=aria MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
--disable_query_log --disable_query_log
INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1'); INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1');
@ -1555,8 +1560,9 @@ explain select companynr,companyname from t2 left join t4 using (companynr) wher
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
delete from t2 where fld1=999999; delete from t2 where fld1=999999;
# --echo #
# Test left join optimization --echo # Test left join optimization
--echo #
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;

View File

@ -1,6 +1,7 @@
# This file is a collection of regression and coverage tests # This file is a collection of regression and coverage tests
# for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE. # for WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE.
-- source include/have_sequence.inc
-- disable_query_log -- disable_query_log
-- disable_result_log -- disable_result_log
# SET GLOBAL innodb_stats_persistent=0; # SET GLOBAL innodb_stats_persistent=0;
@ -78,10 +79,13 @@ CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2), (3); INSERT INTO t1 VALUES (1), (2), (3);
CREATE TABLE t2 (b INT); CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1), (2), (3), (1000); INSERT INTO t2 VALUES (1), (2), (3), (1000);
--let $query = UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) CREATE TABLE t3 like t2;
--let $select = SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) insert into t3 select * from t2;
insert into t3 select seq from seq_1001_to_2000;
--let $query = UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3)
--let $select = SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3)
--source include/explain_utils.inc --source include/explain_utils.inc
DROP TABLE t1, t2; DROP TABLE t1, t2, t3;
--echo #8 --echo #8
CREATE TABLE t1 (a INT); CREATE TABLE t1 (a INT);

View File

@ -486,7 +486,7 @@ CREATE TABLE t1 (
); );
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
insert into t1 select seq,seq from seq_100_to_110;
EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
SET SESSION optimizer_switch='index_condition_pushdown=off'; SET SESSION optimizer_switch='index_condition_pushdown=off';
@ -723,7 +723,6 @@ DROP TABLE t1;
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b)); CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill'); INSERT INTO t1 VALUES (1,4,'Ill');
insert into t1 select seq+100,5,seq from seq_1_to_100;
CREATE TABLE t2 (a varchar(1024), KEY (a(512))); CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES INSERT INTO t2 VALUES
@ -856,6 +855,8 @@ ANALYZE TABLE t1,t2;
SET @save_optimize_switch=@@optimizer_switch; SET @save_optimize_switch=@@optimizer_switch;
SET optimizer_switch='materialization=on'; SET optimizer_switch='materialization=on';
set @save_optimizer_where_cost=@@optimizer_where_cost;
set @@optimizer_where_cost=1;
EXPLAIN EXPLAIN
SELECT COUNT(*) FROM t1 AS t, t2 SELECT COUNT(*) FROM t1 AS t, t2
@ -873,6 +874,7 @@ WHERE c = g
OR a = 0 AND h < 'z' ); OR a = 0 AND h < 'z' );
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
set @@optimizer_where_cost=@save_optimizer_where_cost;
DROP TABLE t1,t2; DROP TABLE t1,t2;

View File

@ -1183,14 +1183,14 @@ set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
set global innodb_autoextend_increment=8; set global innodb_autoextend_increment=8;
set global innodb_autoextend_increment=@my_innodb_autoextend_increment; set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
# --echo #
# Bug #37830: ORDER BY ASC/DESC - no difference --echo # Bug #37830: ORDER BY ASC/DESC - no difference
# --echo #
CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b)) CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
ENGINE=InnoDB; ENGINE=InnoDB;
INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1); INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1), (100,2,2);
INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1; INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
-- disable_query_log -- disable_query_log

View File

@ -8,7 +8,7 @@
--connect con1,localhost,root --connect con1,localhost,root
SET DEBUG_SYNC="handler_ha_index_next_end SIGNAL idx_scan_in_progress WAIT_FOR finish_scan"; SET DEBUG_SYNC="handler_rnd_next_end SIGNAL idx_scan_in_progress WAIT_FOR finish_scan";
send_eval SELECT * FROM $percona_nonflushing_analyze_table; send_eval SELECT * FROM $percona_nonflushing_analyze_table;

View File

@ -2,13 +2,18 @@
--source include/have_debug_sync.inc --source include/have_debug_sync.inc
--source include/have_sequence.inc --source include/have_sequence.inc
--source include/count_sessions.inc --source include/count_sessions.inc
--source include/have_sequence.inc
--source include/no_valgrind_without_big.inc
--echo # --echo #
--echo # MDEV-22761 KILL QUERY during rowid_filter, crashes --echo # MDEV-22761 KILL QUERY during rowid_filter, crashes
--echo # --echo #
create table t1(a int);
insert into t1 select seq from seq_1_to_1000;
create table t2(a int); create table t2(a int);
insert into t2 select * from seq_0_to_99; insert into t2 select seq from seq_1_to_100;
# 10K rows # 10K rows
CREATE TABLE t3 ( CREATE TABLE t3 (
@ -18,22 +23,16 @@ CREATE TABLE t3 (
KEY (key1), KEY (key1),
KEY (key2) KEY (key2)
); );
insert into t3 select seq,seq, 'filler-data-filler-data' from seq_1_to_2000;
select engine from information_schema.tables select engine from information_schema.tables
where table_schema=database() and table_name='t3'; where table_schema=database() and table_name='t3';
insert into t3
select
A.seq,
B.seq,
'filler-data-filler-data'
from seq_0_to_99 A, seq_0_to_99 B;
analyze table t2,t3; analyze table t2,t3;
explain explain
select * from t2, t3 select * from t2, t3
where where
t3.key1=t2.a and t3.key2 in (2,3); t3.key1=t2.a and t3.key2 in (2,3,4,5,6,7,8,9,10);
let $target_id= `select connection_id()`; let $target_id= `select connection_id()`;
@ -41,7 +40,7 @@ set debug_sync='handler_rowid_filter_check SIGNAL at_rowid_filter_check WAIT_FOR
send send
select * from t2, t3 select * from t2, t3
where where
t3.key1=t2.a and t3.key2 in (2,3); t3.key1=t2.a and t3.key2 in (2,3,4,5,6,7,8,9,10);
connect (con1, localhost, root,,); connect (con1, localhost, root,,);
set debug_sync='now WAIT_FOR at_rowid_filter_check'; set debug_sync='now WAIT_FOR at_rowid_filter_check';
@ -55,5 +54,5 @@ disconnect con1;
reap; reap;
set debug_sync='RESET'; set debug_sync='RESET';
drop table t2,t3; drop table t1,t2,t3;
--source include/wait_until_count_sessions.inc --source include/wait_until_count_sessions.inc

View File

@ -771,12 +771,12 @@ ANALYZE
"r_other_time_ms": "REPLACED", "r_other_time_ms": "REPLACED",
"filtered": 100, "filtered": 100,
"r_filtered": 0, "r_filtered": 0,
"attached_condition": "<in_optimizer>(t2.b,<exists>(subquery#2))" "attached_condition": "<in_optimizer>(t2.b,t2.b in (subquery#2))"
}, },
"buffer_type": "flat", "buffer_type": "flat",
"buffer_size": "65", "buffer_size": "65",
"join_type": "BNL", "join_type": "BNL",
"attached_condition": "<in_optimizer>(t2.b,<exists>(subquery#2))", "attached_condition": "<in_optimizer>(t2.b,t2.b in (subquery#2))",
"r_filtered": null, "r_filtered": null,
"r_unpack_time_ms": "REPLACED" "r_unpack_time_ms": "REPLACED"
} }
@ -786,21 +786,20 @@ ANALYZE
{ {
"query_block": { "query_block": {
"select_id": 2, "select_id": 2,
"r_loops": 2, "r_loops": 1,
"r_total_time_ms": "REPLACED", "r_total_time_ms": "REPLACED",
"nested_loop": [ "nested_loop": [
{ {
"table": { "table": {
"table_name": "t1", "table_name": "t1",
"access_type": "ALL", "access_type": "ALL",
"r_loops": 2, "r_loops": 1,
"rows": 2, "rows": 2,
"r_rows": 2, "r_rows": 2,
"r_table_time_ms": "REPLACED", "r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED", "r_other_time_ms": "REPLACED",
"filtered": 100, "filtered": 100,
"r_filtered": 0, "r_filtered": 100
"attached_condition": "4 = t1.a"
} }
} }
] ]
@ -809,6 +808,8 @@ ANALYZE
] ]
} }
} }
SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
a b
drop table t1,t2; drop table t1,t2;
# #
# MDEV-8864: Server crash #2 in Item_field::print on ANALYZE FORMAT=JSON # MDEV-8864: Server crash #2 in Item_field::print on ANALYZE FORMAT=JSON

View File

@ -190,6 +190,7 @@ INSERT INTO t2 VALUES (3),(4);
--source include/analyze-format.inc --source include/analyze-format.inc
ANALYZE FORMAT=JSON SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 ); ANALYZE FORMAT=JSON SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
SELECT STRAIGHT_JOIN * FROM t1, t2 WHERE b IN ( SELECT a FROM t1 );
drop table t1,t2; drop table t1,t2;

View File

@ -377,13 +377,11 @@ a b
EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM t1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 0.00 100.00 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 3.00 100.00 0.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 3.00 100.00 100.00
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# I/R/U/D/S on the inner view # I/R/U/D/S on the inner view
# Expectation: Can run everything # Expectation: Can run everything
@ -492,13 +490,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# I/R/U/D/S on the outer view # I/R/U/D/S on the outer view
# Expectation: Can run everything # Expectation: Can run everything
@ -599,13 +595,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 12 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 12.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#======================================================================== #========================================================================
# Test: Grant INSERT on the table # Test: Grant INSERT on the table
@ -1592,13 +1586,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# I/R/U/D/S on the outer view # I/R/U/D/S on the outer view
# Expectation: Can run everything: SELECT access to the column `a` # Expectation: Can run everything: SELECT access to the column `a`
@ -1709,13 +1701,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#======================================================================== #========================================================================
# Test: Grant SELECT, INSERT, UPDATE, DELETE on the table # Test: Grant SELECT, INSERT, UPDATE, DELETE on the table
@ -1941,13 +1931,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 4.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# I/R/U/D/S on the outer view # I/R/U/D/S on the outer view
# Expectation: Can run everything # Expectation: Can run everything
@ -2049,13 +2037,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 8.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
######################################################################### #########################################################################
# Inner view permission tests # Inner view permission tests
@ -2698,13 +2684,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 14 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 14 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 14 14.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 14 14.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# I/R/U/D/S on the outer view # I/R/U/D/S on the outer view
# Expectation: Can run everything # Expectation: Can run everything
@ -2805,13 +2789,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 18 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 18 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 18 18.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#======================================================================== #========================================================================
# Test: Grant INSERT on the inner view # Test: Grant INSERT on the inner view
@ -3988,13 +3970,11 @@ a b
EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 35 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 35 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v1 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 35 35.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# I/R/U/D/S on the outer view # I/R/U/D/S on the outer view
# Expectation: Can run everything # Expectation: Can run everything
@ -4095,13 +4075,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
######################################################################### #########################################################################
# Outer view permission tests # Outer view permission tests
@ -4615,13 +4593,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 39 39.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
#======================================================================== #========================================================================
# Test: Grant INSERT on the outer view # Test: Grant INSERT on the outer view
@ -5222,13 +5198,11 @@ a b
EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); EXPLAIN SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 44 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 44 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3
ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 ); ANALYZE SELECT * FROM v2 WHERE a IN ( SELECT a FROM t2 );
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 44 44.00 100.00 0.00 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 NULL 100.00 NULL 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 NULL 100.00 NULL
disconnect con1; disconnect con1;
connection default; connection default;
DROP USER 'privtest'@localhost; DROP USER 'privtest'@localhost;

View File

@ -6,6 +6,7 @@ select * from information_schema.session_status where variable_name= 'COMPRESSIO
VARIABLE_NAME VARIABLE_VALUE VARIABLE_NAME VARIABLE_VALUE
COMPRESSION ON COMPRESSION ON
drop table if exists t1,t2,t3,t4; drop table if exists t1,t2,t3,t4;
set @@default_storage_engine="aria";
CREATE TABLE t1 ( CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
@ -606,6 +607,9 @@ explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort 1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index
#
# Some test with ORDER BY and limit
#
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort 1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort
@ -1295,7 +1299,7 @@ companynr tinyint(2) unsigned zerofill NOT NULL default '00',
companyname char(30) NOT NULL default '', companyname char(30) NOT NULL default '',
PRIMARY KEY (companynr), PRIMARY KEY (companynr),
UNIQUE KEY companyname(companyname) UNIQUE KEY companyname(companyname)
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; ) ENGINE=aria MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
companynr companyname companynr companyname
00 Unknown 00 Unknown
@ -1385,6 +1389,9 @@ explain select companynr,companyname from t4 left join t2 using (companynr) wher
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
delete from t2 where fld1=999999; delete from t2 where fld1=999999;
#
# Test left join optimization
#
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
@ -1399,15 +1406,15 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -1423,11 +1430,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra

View File

@ -7,11 +7,11 @@ insert into t1 values(20,2,2,2,2),(21,3,4,5,6);
explain select sum(e) as "table_scan" from t1; explain select sum(e) as "table_scan" from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 12 1 SIMPLE t1 ALL NULL NULL NULL NULL 12
Last_query_cost 5.500000 Last_query_cost 0.012556
explain select sum(a) as "index scan" from t1; explain select sum(a) as "index scan" from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 12 Using index 1 SIMPLE t1 index NULL PRIMARY 4 NULL 12 Using index
Last_query_cost 3.202929 Last_query_cost 0.007441
# #
# Range scans should be used if we don't examine all rows in the table # Range scans should be used if we don't examine all rows in the table
# #
@ -21,71 +21,71 @@ id select_type table type possible_keys key key_len ref rows Extra
Last_query_cost 0.000000 Last_query_cost 0.000000
explain select count(*) from t1 where a > 0; explain select count(*) from t1 where a > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 12 Using where; Using index 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 12 Using where; Using index
Last_query_cost 3.202929 Last_query_cost 0.002795
explain select count(*) from t1 where a > 1; explain select count(*) from t1 where a > 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 12 Using where; Using index 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 12 Using where; Using index
Last_query_cost 3.202929 Last_query_cost 0.002795
explain select count(*) from t1 where a > 2; explain select count(*) from t1 where a > 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 11 Using where; Using index 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 11 Using where; Using index
Last_query_cost 2.997685 Last_query_cost 0.002665
# #
# Shorter indexes are prefered over longer indexs # Shorter indexes are prefered over longer indexs
# #
explain select sum(a+b) from t1; explain select sum(a+b) from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL ba 9 NULL 12 Using index 1 SIMPLE t1 index NULL ba 9 NULL 12 Using index
Last_query_cost 3.204394 Last_query_cost 0.007441
explain select count(*) from t1 where b between 5 and 10; explain select count(*) from t1 where b between 5 and 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range ba,bda ba 5 NULL 6 Using where; Using index 1 SIMPLE t1 range ba,bda ba 5 NULL 6 Using where; Using index
Last_query_cost 1.872197 Last_query_cost 0.002015
explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6; explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index 1 SIMPLE t1 range ba,bda,cba,cb cba 10 NULL 2 Using where; Using index
Last_query_cost 0.970781 Last_query_cost 0.001494
# Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd' # Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd'
explain select count(*) from t1 where b > 6; explain select count(*) from t1 where b > 6;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range ba,bda ba 5 NULL 5 Using where; Using index 1 SIMPLE t1 range ba,bda ba 5 NULL 5 Using where; Using index
Last_query_cost 1.646831 Last_query_cost 0.001885
explain select count(*) from t1 where d > 6; explain select count(*) from t1 where d > 6;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range d d 5 NULL 5 Using where; Using index 1 SIMPLE t1 range d d 5 NULL 5 Using where; Using index
Last_query_cost 1.646343 Last_query_cost 0.001885
# #
# Check covering index usage # Check covering index usage
# #
explain select a,b,c from t1 where a=b; explain select a,b,c from t1 where a=b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL cba 14 NULL 12 Using where; Using index 1 SIMPLE t1 index NULL cba 14 NULL 12 Using where; Using index
Last_query_cost 3.205859 Last_query_cost 0.007441
# #
# Prefer ref keys over ranges # Prefer ref keys over ranges
# #
explain select count(*) from t1 where b=2; explain select count(*) from t1 where b=2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref ba,bda ba 5 const 2 Using index 1 SIMPLE t1 ref ba,bda ba 5 const 2 Using index
Last_query_cost 0.950732 Last_query_cost 0.001059
explain select count(*) from t1 where b=2 and c=2; explain select count(*) from t1 where b=2 and c=2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref ba,bda,cba,cb cb 10 const,const 2 Using index 1 SIMPLE t1 ref ba,bda,cba,cb cba 10 const,const 2 Using index
Last_query_cost 0.950781 Last_query_cost 0.001059
explain select count(*) from t1 where b=3 and c between 3 and 4; explain select count(*) from t1 where b=3 and c between 3 and 4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index 1 SIMPLE t1 range ba,bda,cba,cb cba 10 NULL 2 Using where; Using index
Last_query_cost 0.970781 Last_query_cost 0.001494
# #
# Prefer eq keys over ref keys # Prefer eq keys over ref keys
# #
explain select a,b,e from t1 where a=10 or a=11; explain select a,b,e from t1 where a=10 or a=11;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition
Last_query_cost 2.520488 Last_query_cost 0.003126
explain select a,b,e from t1 where d=10 or d=11; explain select a,b,e from t1 where d=10 or d=11;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range d d 5 NULL 2 Using index condition 1 SIMPLE t1 range d d 5 NULL 2 Using index condition
Last_query_cost 2.520537 Last_query_cost 0.003126
drop table t1; drop table t1;

View File

@ -150,16 +150,14 @@ explain
with t as (select a from t1 where a<5) with t as (select a from t1 where a<5)
select * from t2 where c in (select a from t); select * from t2 where c in (select a from t);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
3 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where
explain explain
select * from t2 select * from t2
where c in (select a from (select a from t1 where a<5) as t); where c in (select a from (select a from t1 where a<5) as t);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 Using where; FirstMatch(t2); Using join buffer (flat, BNL join)
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 8 Using where
# materialized t is used in a subquery # materialized t is used in a subquery
with t as (select count(*) as c from t1 where b >= 'c' group by a) with t as (select count(*) as c from t1 where b >= 'c' group by a)
select * from t2 where c in (select c from t); select * from t2 where c in (select c from t);
@ -2300,14 +2298,14 @@ WHERE col1 IN ( SELECT col FROM t );
SELECT * FROM tt; SELECT * FROM tt;
col2 col2
2018-10-01 2018-10-01
2018-10-01
2017-10-01 2017-10-01
2018-10-01
SELECT t4.col1 SELECT t4.col1
FROM tt, t4 FROM tt, t4
WHERE t4.col2 = tt.col2 AND t4.col1 IN ( SELECT col FROM t ); WHERE t4.col2 = tt.col2 AND t4.col1 IN ( SELECT col FROM t );
col1 col1
8
4 4
8
DROP TABLE t,tt; DROP TABLE t,tt;
CALL SP1(); CALL SP1();
col1 col1

View File

@ -692,10 +692,10 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived3> ref key0 key0 5 c.h_id 2 100.00 1 PRIMARY <derived3> ref key0 key0 5 c.h_id 2 100.00
1 PRIMARY <derived3> ref key0 key0 5 c.w_id 2 100.00 1 PRIMARY <derived3> ref key0 key0 5 c.w_id 2 100.00
3 DERIVED folks ALL NULL NULL NULL NULL 12 100.00 Using where 3 DERIVED folks ALL NULL NULL NULL NULL 12 100.00 Using where
4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 4 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where
4 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join) 4 RECURSIVE UNION <derived2> ref key0 key0 5 test.p.id 2 100.00
5 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 5 RECURSIVE UNION p ALL NULL NULL NULL NULL 12 100.00 Using where
5 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (flat, BNL join) 5 RECURSIVE UNION <derived2> ref key0 key0 5 test.p.id 2 100.00
NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL NULL NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL NULL
2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where 2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 100.00 Using where
Warnings: Warnings:
@ -3854,8 +3854,8 @@ 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 t1 ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY <derived3> ref key0 key0 23 test.t1.a1 1 FirstMatch(t1) 1 PRIMARY <derived3> ref key0 key0 23 test.t1.a1 1 FirstMatch(t1)
3 DERIVED t2 const PRIMARY PRIMARY 22 const 1 Using index 3 DERIVED t2 const PRIMARY PRIMARY 22 const 1 Using index
4 RECURSIVE UNION <derived3> ALL NULL NULL NULL NULL 2 Using where 4 RECURSIVE UNION tt2 ALL b1 NULL NULL NULL 14 Using where
4 RECURSIVE UNION tt2 ref b1 b1 23 cte.a2 2 4 RECURSIVE UNION <derived3> ref key0 key0 23 test.tt2.b1 1
NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL
analyze format=json select fv analyze format=json select fv
from (select t1.a1, f1(t1.a2) fv from t1) dt from (select t1.a1, f1(t1.a2) fv from t1) dt
@ -3946,30 +3946,31 @@ ANALYZE
"nested_loop": [ "nested_loop": [
{ {
"table": { "table": {
"table_name": "<derived3>", "table_name": "tt2",
"access_type": "ALL", "access_type": "ALL",
"possible_keys": ["b1"],
"r_loops": 1, "r_loops": 1,
"rows": 2, "rows": 14,
"r_rows": 1, "r_rows": 14,
"r_table_time_ms": "REPLACED", "r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED", "r_other_time_ms": "REPLACED",
"filtered": 100, "filtered": 100,
"r_filtered": 100, "r_filtered": 100,
"attached_condition": "cte.a2 is not null" "attached_condition": "tt2.b1 is not null"
} }
}, },
{ {
"table": { "table": {
"table_name": "tt2", "table_name": "<derived3>",
"access_type": "ref", "access_type": "ref",
"possible_keys": ["b1"], "possible_keys": ["key0"],
"key": "b1", "key": "key0",
"key_length": "23", "key_length": "23",
"used_key_parts": ["b1"], "used_key_parts": ["a2"],
"ref": ["cte.a2"], "ref": ["test.tt2.b1"],
"r_loops": 1, "r_loops": 14,
"rows": 2, "rows": 1,
"r_rows": 1, "r_rows": 0.071428571,
"r_table_time_ms": "REPLACED", "r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED", "r_other_time_ms": "REPLACED",
"filtered": 100, "filtered": 100,
@ -4032,8 +4033,8 @@ FROM cte JOIN t3 ON t3.tm BETWEEN cte.st AND cte.fn)
SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR); SELECT t1.* FROM t1 JOIN cte2 USING (YEAR) JOIN cte3 USING (YEAR);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY <derived5> ref key0 key0 5 const 0 0.00 1 PRIMARY <derived5> ref key0 key0 5 const 0 100.00
1 PRIMARY <derived4> ref key0 key0 5 const 0 0.00 1 PRIMARY <derived4> ref key0 key0 5 const 0 100.00
2 DERIVED t1 system NULL NULL NULL NULL 1 100.00 2 DERIVED t1 system NULL NULL NULL NULL 1 100.00
3 RECURSIVE UNION t1 system NULL NULL NULL NULL 1 100.00 3 RECURSIVE UNION t1 system NULL NULL NULL NULL 1 100.00
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where 3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where
@ -4467,9 +4468,9 @@ NULL UNION RESULT <union4,5> ALL NULL NULL NULL NULL NULL
3 DERIVED v ALL NULL NULL NULL NULL 12 Using where 3 DERIVED v ALL NULL NULL NULL NULL 12 Using where
3 DERIVED h ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 3 DERIVED h ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
3 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join) 3 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join)
2 RECURSIVE UNION h ALL NULL NULL NULL NULL 12 2 RECURSIVE UNION h ALL NULL NULL NULL NULL 12 Using where
2 RECURSIVE UNION <derived4> ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 2 RECURSIVE UNION <derived4> ref key0 key0 5 test.h.id 2
2 RECURSIVE UNION w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join) 2 RECURSIVE UNION w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
NULL UNION RESULT <union3,2> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union3,2> ALL NULL NULL NULL NULL NULL
prepare stmt from "with recursive prepare stmt from "with recursive
ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, ancestor_couples(h_id, h_name, h_dob, h_father, h_mother,

View File

@ -1569,7 +1569,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 23 NULL 1 Using where; Using index 1 SIMPLE t1 range a a 23 NULL 1 Using where; Using index
EXPLAIN SELECT * FROM t1 WHERE a LIKE 'c%'; EXPLAIN SELECT * FROM t1 WHERE a LIKE 'c%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index 1 SIMPLE t1 range a a 23 NULL 31 Using where; Using index
SELECT * FROM t1 WHERE a LIKE 'c%'; SELECT * FROM t1 WHERE a LIKE 'c%';
a a
ca ca
@ -1585,7 +1585,7 @@ ch
ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ucs2 COLLATE ucs2_croatian_ci; ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ucs2 COLLATE ucs2_croatian_ci;
EXPLAIN SELECT * FROM t1 WHERE a LIKE 'd%'; EXPLAIN SELECT * FROM t1 WHERE a LIKE 'd%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index 1 SIMPLE t1 range a a 23 NULL 31 Using where; Using index
SELECT hex(concat('d',_ucs2 0x017E,'%')); SELECT hex(concat('d',_ucs2 0x017E,'%'));
hex(concat('d',_ucs2 0x017E,'%')) hex(concat('d',_ucs2 0x017E,'%'))
0064017E0025 0064017E0025

View File

@ -92,6 +92,9 @@ select * from t1;
a b a b
1 apple 1 apple
drop table t1; drop table t1;
#
# IGNORE option
#
create table t11 (a int NOT NULL, b int, primary key (a)); create table t11 (a int NOT NULL, b int, primary key (a));
create table t12 (a int NOT NULL, b int, primary key (a)); create table t12 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a)); create table t2 (a int NOT NULL, b int, primary key (a));
@ -125,6 +128,11 @@ a b
33 10 33 10
0 11 0 11
2 12 2 12
explain delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t12 ALL PRIMARY NULL NULL NULL 3
1 PRIMARY t11 eq_ref PRIMARY PRIMARY 4 test.t12.a 1 Using where
2 DEPENDENT SUBQUERY t2 ALL PRIMARY NULL NULL NULL 3 Using where
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
Warnings: Warnings:
Warning 1242 Subquery returns more than 1 row Warning 1242 Subquery returns more than 1 row

View File

@ -106,9 +106,9 @@ delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a;
select * from t1; select * from t1;
drop table t1; drop table t1;
# --echo #
# IGNORE option --echo # IGNORE option
# --echo #
create table t11 (a int NOT NULL, b int, primary key (a)); create table t11 (a int NOT NULL, b int, primary key (a));
create table t12 (a int NOT NULL, b int, primary key (a)); create table t12 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a)); create table t2 (a int NOT NULL, b int, primary key (a));
@ -122,6 +122,7 @@ select * from t2;
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
select * from t11; select * from t11;
select * from t12; select * from t12;
explain delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a); delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
select * from t11; select * from t11;
select * from t12; select * from t12;

View File

@ -17,7 +17,7 @@ a
b b
EXPLAIN DELETE b FROM t1 AS a JOIN t1 AS b; EXPLAIN DELETE b FROM t1 AS a JOIN t1 AS b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE a index NULL PRIMARY 255 NULL 3 Using index 1 SIMPLE a ALL NULL NULL NULL NULL 3
1 SIMPLE b ALL NULL NULL NULL NULL 3 1 SIMPLE b ALL NULL NULL NULL NULL 3
DELETE b FROM t1 AS a JOIN t1 AS b; DELETE b FROM t1 AS a JOIN t1 AS b;
SELECT * FROM t1; SELECT * FROM t1;

View File

@ -237,7 +237,7 @@ count(*)
explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 THEMAX.E2 1 Using where
2 DERIVED A ALL NULL NULL NULL NULL 2 Using where 2 DERIVED A ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where
drop table t1; drop table t1;
@ -1346,7 +1346,7 @@ DROP TABLE t1;
# Test of "Derived tables and union can now create distinct keys" # Test of "Derived tables and union can now create distinct keys"
# #
create table t1 (a int); create table t1 (a int);
insert into t1 values (100),(100); insert into t1 values (100),(100),(100),(100),(100),(100),(100),(100),(100),(100);
create table duplicates_tbl (a int); create table duplicates_tbl (a int);
insert into duplicates_tbl select seq/100 from seq_1_to_10000; insert into duplicates_tbl select seq/100 from seq_1_to_10000;
explain explain
@ -1360,7 +1360,7 @@ where T.a=5
) as 'A' ) as 'A'
from t1; from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 10
2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 10000 Using where 2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 10000 Using where
3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000 3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000
select select
@ -1375,6 +1375,14 @@ from t1;
A A
1 1
1 1
1
1
1
1
1
1
1
1
explain explain
select select
t1.a = all ( SELECT COUNT(*) t1.a = all ( SELECT COUNT(*)
@ -1386,7 +1394,7 @@ where T.a=5
) as 'A' ) as 'A'
from t1; from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 10
2 DEPENDENT SUBQUERY <derived3> ALL NULL NULL NULL NULL 10000 Using where 2 DEPENDENT SUBQUERY <derived3> ALL NULL NULL NULL NULL 10000 Using where
3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000 3 DERIVED duplicates_tbl ALL NULL NULL NULL NULL 10000
select select
@ -1401,6 +1409,14 @@ from t1;
A A
1 1
1 1
1
1
1
1
1
1
1
1
drop table t1, duplicates_tbl; drop table t1, duplicates_tbl;
# #
# End of 11.0 tests # End of 11.0 tests

View File

@ -1156,7 +1156,7 @@ DROP TABLE t1;
--echo # --echo #
create table t1 (a int); create table t1 (a int);
insert into t1 values (100),(100); insert into t1 values (100),(100),(100),(100),(100),(100),(100),(100),(100),(100);
create table duplicates_tbl (a int); create table duplicates_tbl (a int);
insert into duplicates_tbl select seq/100 from seq_1_to_10000; insert into duplicates_tbl select seq/100 from seq_1_to_10000;

View File

@ -8174,7 +8174,7 @@ EXPLAIN
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"attached_condition": "t2.b = 2", "attached_condition": "t2.b = 2",
"first_match": "t1" "first_match": "t1"
} }
@ -8272,7 +8272,7 @@ EXPLAIN
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"attached_condition": "t2.b = 2", "attached_condition": "t2.b = 2",
"first_match": "t1" "first_match": "t1"
} }
@ -8799,8 +8799,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery2>", "table_name": "<subquery2>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -8869,8 +8869,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery2>", "table_name": "<subquery2>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -8969,8 +8969,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -9036,8 +9036,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -9098,8 +9098,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -9160,8 +9160,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -9224,8 +9224,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -9286,8 +9286,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -9348,8 +9348,8 @@ EXPLAIN
"table": { "table": {
"table_name": "<subquery3>", "table_name": "<subquery3>",
"access_type": "system", "access_type": "system",
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -17526,7 +17526,7 @@ on t1.a=t.a
where t1.b < 3; where t1.b < 3;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 range idx_b idx_b 5 NULL 4 100.00 Using index condition; Using where 1 PRIMARY t1 range idx_b idx_b 5 NULL 4 100.00 Using index condition; Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 2 100.00 1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 2 50.00
2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00 2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`s` AS `s`,`t`.`m` AS `m` from `test`.`t1` join (/* select#2 */ select `test`.`t2`.`a` AS `a`,sum(`test`.`t2`.`b`) AS `s`,min(`test`.`t2`.`c`) AS `m` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` where `t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` < 3 Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`s` AS `s`,`t`.`m` AS `m` from `test`.`t1` join (/* select#2 */ select `test`.`t2`.`a` AS `a`,sum(`test`.`t2`.`b`) AS `s`,min(`test`.`t2`.`c`) AS `m` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` where `t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` < 3
@ -17564,7 +17564,7 @@ EXPLAIN
"used_key_parts": ["a"], "used_key_parts": ["a"],
"ref": ["test.t1.a"], "ref": ["test.t1.a"],
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"materialized": { "materialized": {
"lateral": 1, "lateral": 1,
"query_block": { "query_block": {
@ -17647,7 +17647,7 @@ on t1.a=t.a
where t1.b <= 5; where t1.b <= 5;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL idx_b NULL NULL NULL 12 83.33 Using where 1 PRIMARY t1 ALL idx_b NULL NULL NULL 12 83.33 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 2 100.00 1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 2 50.00
2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00 2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`s` AS `s`,`t`.`m` AS `m` from `test`.`t1` join (/* select#2 */ select `test`.`t2`.`a` AS `a`,sum(`test`.`t2`.`b`) AS `s`,min(`test`.`t2`.`b`) AS `m` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` where `t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <= 5 Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`s` AS `s`,`t`.`m` AS `m` from `test`.`t1` join (/* select#2 */ select `test`.`t2`.`a` AS `a`,sum(`test`.`t2`.`b`) AS `s`,min(`test`.`t2`.`b`) AS `m` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` where `t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <= 5
@ -17681,7 +17681,7 @@ EXPLAIN
"used_key_parts": ["a"], "used_key_parts": ["a"],
"ref": ["test.t1.a"], "ref": ["test.t1.a"],
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"materialized": { "materialized": {
"lateral": 1, "lateral": 1,
"query_block": { "query_block": {
@ -17762,7 +17762,7 @@ from t1 left join
on t1.a=t.a; on t1.a=t.a;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00
1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 2 100.00 Using where 1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 2 50.00 Using where
2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00 2 LATERAL DERIVED t2 ref idx_a idx_a 5 test.t1.a 1 100.00
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t1` left join (/* select#2 */ select `test`.`t2`.`a` AS `a`,max(`test`.`t2`.`b`) AS `max`,min(`test`.`t2`.`b`) AS `min` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` on(`t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` is not null) where 1 Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t1` left join (/* select#2 */ select `test`.`t2`.`a` AS `a`,max(`test`.`t2`.`b`) AS `max`,min(`test`.`t2`.`b`) AS `min` from `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` group by `test`.`t2`.`a`) `t` on(`t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` is not null) where 1
@ -17794,7 +17794,7 @@ EXPLAIN
"used_key_parts": ["a"], "used_key_parts": ["a"],
"ref": ["test.t1.a"], "ref": ["test.t1.a"],
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"attached_condition": "trigcond(trigcond(t1.a is not null))", "attached_condition": "trigcond(trigcond(t1.a is not null))",
"materialized": { "materialized": {
"lateral": 1, "lateral": 1,
@ -17953,10 +17953,10 @@ on t3.a=t.a and t3.c=t.c
where t3.b <= 15; where t3.b <= 15;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL idx_b NULL NULL NULL 12 83.33 Using where 1 PRIMARY t3 ALL idx_b NULL NULL NULL 12 83.33 Using where
1 PRIMARY <derived2> ref key0 key0 133 test.t3.a,test.t3.c 4 100.00 1 PRIMARY <derived2> ref key0 key0 133 test.t3.a,test.t3.c 2 50.00
2 DERIVED t4 ALL idx NULL NULL NULL 40 100.00 Using temporary; Using filesort 2 LATERAL DERIVED t4 ref idx idx 133 test.t3.a,test.t3.c 1 100.00
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` group by `test`.`t4`.`a`,`test`.`t4`.`c`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15 Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a` and `test`.`t4`.`c` = `test`.`t3`.`c` group by `test`.`t4`.`a`,`test`.`t4`.`c`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15
explain format=json select t3.a,t3.c,t.max,t.min explain format=json select t3.a,t3.c,t.max,t.min
from t3 join from t3 join
(select a, c, max(b) max, min(b) min from t4 group by a,c) t (select a, c, max(b) max, min(b) min from t4 group by a,c) t
@ -17986,21 +17986,24 @@ EXPLAIN
"key_length": "133", "key_length": "133",
"used_key_parts": ["a", "c"], "used_key_parts": ["a", "c"],
"ref": ["test.t3.a", "test.t3.c"], "ref": ["test.t3.a", "test.t3.c"],
"rows": 4, "rows": 2,
"filtered": 100, "filtered": 50,
"materialized": { "materialized": {
"lateral": 1,
"query_block": { "query_block": {
"select_id": 2, "select_id": 2,
"filesort": { "outer_ref_condition": "t3.a is not null and t3.c is not null",
"sort_key": "t4.a, t4.c",
"temporary_table": {
"nested_loop": [ "nested_loop": [
{ {
"table": { "table": {
"table_name": "t4", "table_name": "t4",
"access_type": "ALL", "access_type": "ref",
"possible_keys": ["idx"], "possible_keys": ["idx"],
"rows": 40, "key": "idx",
"key_length": "133",
"used_key_parts": ["a", "c"],
"ref": ["test.t3.a", "test.t3.c"],
"rows": 1,
"filtered": 100 "filtered": 100
} }
} }
@ -18009,8 +18012,6 @@ EXPLAIN
} }
} }
} }
}
}
] ]
} }
} }
@ -18126,10 +18127,10 @@ on t3.a=t.a and t3.c=t.c
where t3.b <= 15; where t3.b <= 15;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL idx_b NULL NULL NULL 12 83.33 Using where 1 PRIMARY t3 ALL idx_b NULL NULL NULL 12 83.33 Using where
1 PRIMARY <derived2> ref key0 key0 133 test.t3.a,test.t3.c 4 100.00 1 PRIMARY <derived2> ref key0 key0 133 test.t3.a,test.t3.c 2 50.00
2 DERIVED t4 ALL idx NULL NULL NULL 40 100.00 Using temporary; Using filesort 2 LATERAL DERIVED t4 ref idx idx 133 test.t3.a,test.t3.c 1 100.00
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` group by `test`.`t4`.`c`,`test`.`t4`.`a`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15 Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`c` AS `c`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t3` join (/* select#2 */ select `test`.`t4`.`a` AS `a`,`test`.`t4`.`c` AS `c`,max(`test`.`t4`.`b`) AS `max`,min(`test`.`t4`.`b`) AS `min` from `test`.`t4` where `test`.`t4`.`a` = `test`.`t3`.`a` and `test`.`t4`.`c` = `test`.`t3`.`c` group by `test`.`t4`.`c`,`test`.`t4`.`a`) `t` where `t`.`a` = `test`.`t3`.`a` and `t`.`c` = `test`.`t3`.`c` and `test`.`t3`.`b` <= 15
explain format=json select t3.a,t3.c,t.max,t.min explain format=json select t3.a,t3.c,t.max,t.min
from t3 join from t3 join
(select a, c, max(b) max, min(b) min from t4 group by c,a) t (select a, c, max(b) max, min(b) min from t4 group by c,a) t
@ -18159,21 +18160,24 @@ EXPLAIN
"key_length": "133", "key_length": "133",
"used_key_parts": ["a", "c"], "used_key_parts": ["a", "c"],
"ref": ["test.t3.a", "test.t3.c"], "ref": ["test.t3.a", "test.t3.c"],
"rows": 4, "rows": 2,
"filtered": 100, "filtered": 50,
"materialized": { "materialized": {
"lateral": 1,
"query_block": { "query_block": {
"select_id": 2, "select_id": 2,
"filesort": { "outer_ref_condition": "t3.a is not null and t3.c is not null",
"sort_key": "t4.c, t4.a",
"temporary_table": {
"nested_loop": [ "nested_loop": [
{ {
"table": { "table": {
"table_name": "t4", "table_name": "t4",
"access_type": "ALL", "access_type": "ref",
"possible_keys": ["idx"], "possible_keys": ["idx"],
"rows": 40, "key": "idx",
"key_length": "133",
"used_key_parts": ["a", "c"],
"ref": ["test.t3.a", "test.t3.c"],
"rows": 1,
"filtered": 100 "filtered": 100
} }
} }
@ -18182,8 +18186,6 @@ EXPLAIN
} }
} }
} }
}
}
] ]
} }
} }
@ -19022,7 +19024,7 @@ a c
explain extended SELECT * FROM t4 WHERE c IN ( SELECT c FROM v1 ) and a < 2; explain extended SELECT * FROM t4 WHERE c IN ( SELECT c FROM v1 ) and a < 2;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t4 range a a 5 NULL 1 100.00 Using index condition; Using where 1 PRIMARY t4 range a a 5 NULL 1 100.00 Using index condition; Using where
1 PRIMARY <derived3> ref key0 key0 128 test.t4.c 2 100.00 FirstMatch(t4) 1 PRIMARY <derived3> ref key0 key0 128 test.t4.c 2 50.00 FirstMatch(t4)
3 LATERAL DERIVED t3 ref c c 128 test.t4.c 2 100.00 3 LATERAL DERIVED t3 ref c c 128 test.t4.c 2 100.00
3 LATERAL DERIVED <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00 3 LATERAL DERIVED <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00
4 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 100.00 4 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 100.00
@ -19059,7 +19061,7 @@ EXPLAIN
"used_key_parts": ["c"], "used_key_parts": ["c"],
"ref": ["test.t4.c"], "ref": ["test.t4.c"],
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"first_match": "t4", "first_match": "t4",
"materialized": { "materialized": {
"lateral": 1, "lateral": 1,
@ -19413,7 +19415,7 @@ GROUP BY t1.b,t2.c) dt
WHERE t3.d = dt.b; WHERE t3.d = dt.b;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where 1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where
1 PRIMARY <derived2> ref key0 key0 5 test.t3.d 2 100.00 1 PRIMARY <derived2> ref key0 key0 5 test.t3.d 2 50.00
2 LATERAL DERIVED t1 ref idx_b idx_b 5 test.t3.d 1 100.00 Using index; Using temporary; Using filesort 2 LATERAL DERIVED t1 ref idx_b idx_b 5 test.t3.d 1 100.00 Using index; Using temporary; Using filesort
2 LATERAL DERIVED t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) 2 LATERAL DERIVED t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
Warnings: Warnings:
@ -19503,7 +19505,7 @@ id a
explain extended select id, a from t1 where id in (select id from v1); explain extended select id, a from t1 where id in (select id from v1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00
1 PRIMARY <derived3> ref key0 key0 4 test.t1.id 2 100.00 FirstMatch(t1) 1 PRIMARY <derived3> ref key0 key0 4 test.t1.id 2 50.00 FirstMatch(t1)
3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort 3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort
3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where 3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where
Warnings: Warnings:
@ -19541,7 +19543,7 @@ on (t1.id = t2.ro_id AND t2.flag = 1)
group by t1.id) dt); group by t1.id) dt);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00
1 PRIMARY <derived3> ref key1 key1 4 test.t1.id 2 100.00 FirstMatch(t1) 1 PRIMARY <derived3> ref key1 key1 4 test.t1.id 2 50.00 FirstMatch(t1)
3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort 3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort
3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where 3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where
Warnings: Warnings:
@ -19724,6 +19726,7 @@ insert into t1 values
(17,1),(17,3010),(17,3013),(17,3053),(21,2446),(21,2467),(21,2); (17,1),(17,3010),(17,3013),(17,3053),(21,2446),(21,2467),(21,2);
create table t2 (a int) engine=myisam; create table t2 (a int) engine=myisam;
insert into t2 values (1),(2),(3),(1000),(2000),(3000); insert into t2 values (1),(2),(3),(1000),(2000),(3000);
insert into t2 select 5000 from seq_5000_to_6000;
create table t3 (id int) engine=myisam; create table t3 (id int) engine=myisam;
insert into t3 values (1),(2); insert into t3 values (1),(2);
analyze table t1,t2,t3; analyze table t1,t2,t3;
@ -19747,8 +19750,8 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 test.t3.id 1 1 PRIMARY t1 ref a a 5 test.t3.id 1
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY <derived2> ref key0 key0 5 test.t3.id 2 1 PRIMARY <derived2> ref key0 key0 5 test.t3.id 2
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1007
2 DERIVED cp2 index NULL a 5 NULL 7 Using index 2 DERIVED cp2 range NULL a 5 NULL 7 Using index for group-by
explain format=json select * from t1, (select a from t1 cp2 group by a) dt, t3 explain format=json select * from t1, (select a from t1 cp2 group by a) dt, t3
where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2); where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2);
EXPLAIN EXPLAIN
@ -19798,7 +19801,7 @@ EXPLAIN
"table": { "table": {
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
"rows": 6, "rows": 1007,
"filtered": 100 "filtered": 100
} }
} }
@ -19825,13 +19828,13 @@ EXPLAIN
{ {
"table": { "table": {
"table_name": "cp2", "table_name": "cp2",
"access_type": "index", "access_type": "range",
"key": "a", "key": "a",
"key_length": "5", "key_length": "5",
"used_key_parts": ["a"], "used_key_parts": ["a"],
"rows": 7, "rows": 7,
"filtered": 100, "filtered": 100,
"using_index": true "using_index_for_group_by": true
} }
} }
] ]
@ -19855,7 +19858,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref a a 5 test.t3.id 1 1 PRIMARY t1 ref a a 5 test.t3.id 1
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY <derived2> ref key0 key0 5 test.t3.id 2 1 PRIMARY <derived2> ref key0 key0 5 test.t3.id 2
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1007
2 LATERAL DERIVED cp2 ref a a 5 test.t1.a 1 Using where; Using index 2 LATERAL DERIVED cp2 ref a a 5 test.t1.a 1 Using where; Using index
explain format=json select * from t1, (select a from t1 cp2 group by a) dt, t3 explain format=json select * from t1, (select a from t1 cp2 group by a) dt, t3
where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2); where dt.a = t1.a and t1.a = t3.id and t1.a in (select a from t2);
@ -19906,7 +19909,7 @@ EXPLAIN
"table": { "table": {
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
"rows": 6, "rows": 1007,
"filtered": 100 "filtered": 100
} }
} }
@ -19968,7 +19971,7 @@ id a a id
deallocate prepare stmt; deallocate prepare stmt;
drop table t1,t2,t3; drop table t1,t2,t3;
# #
# MDEV-MDEV-27132: Splittable derived with equality in WHERE # MDEV-27132: Splittable derived with equality in WHERE
# #
CREATE TABLE t1 ( CREATE TABLE t1 (
id int PRIMARY KEY id int PRIMARY KEY
@ -20009,6 +20012,7 @@ INSERT INTO t2(deleted, t1_id, email, reporting_person)
SELECT deleted, t1_id+80000, email, reporting_person FROM t2; SELECT deleted, t1_id+80000, email, reporting_person FROM t2;
INSERT INTO t2(deleted, t1_id, email, reporting_person) INSERT INTO t2(deleted, t1_id, email, reporting_person)
SELECT deleted, t1_id+160000, email, reporting_person FROM t2; SELECT deleted, t1_id+160000, email, reporting_person FROM t2;
insert into t2 (id,t1_id) select -seq,-seq from seq_1_to_1000;
CREATE TABLE t3 ( CREATE TABLE t3 (
id int PRIMARY KEY, id int PRIMARY KEY,
deleted int, deleted int,
@ -20059,10 +20063,10 @@ JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx
ON tx.t1_id = t1.id ON tx.t1_id = t1.id
WHERE t1.id BETWEEN 200 AND 100000; WHERE t1.id BETWEEN 200 AND 100000;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 index t1_id t1_id 15 NULL 47 Using where; Using index 1 PRIMARY t3 range t1_id t1_id 5 NULL 47 Using where; Using index
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.t1_id 1 Using index 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.t1_id 1 Using index
1 PRIMARY <derived2> ref key0 key0 5 test.t3.t1_id 2 1 PRIMARY <derived2> ref key0 key0 5 test.t3.t1_id 2
2 LATERAL DERIVED t2 ref t1_id t1_id 5 test.t1.id 3 Using index condition; Using where 2 LATERAL DERIVED t2 ref t1_id t1_id 5 test.t1.id 1 Using index condition; Using where
EXPLAIN FORMAT=JSON SELECT t1.id EXPLAIN FORMAT=JSON SELECT t1.id
FROM t1 FROM t1
JOIN t3 JOIN t3
@ -20078,11 +20082,11 @@ EXPLAIN
{ {
"table": { "table": {
"table_name": "t3", "table_name": "t3",
"access_type": "index", "access_type": "range",
"possible_keys": ["t1_id"], "possible_keys": ["t1_id"],
"key": "t1_id", "key": "t1_id",
"key_length": "15", "key_length": "5",
"used_key_parts": ["t1_id", "YEAR", "quarter"], "used_key_parts": ["t1_id"],
"rows": 47, "rows": 47,
"filtered": 100, "filtered": 100,
"attached_condition": "t3.t1_id between 200 and 100000 and t3.t1_id is not null", "attached_condition": "t3.t1_id between 200 and 100000 and t3.t1_id is not null",
@ -20113,7 +20117,7 @@ EXPLAIN
"used_key_parts": ["t1_id"], "used_key_parts": ["t1_id"],
"ref": ["test.t3.t1_id"], "ref": ["test.t3.t1_id"],
"rows": 2, "rows": 2,
"filtered": 100, "filtered": 50,
"materialized": { "materialized": {
"lateral": 1, "lateral": 1,
"query_block": { "query_block": {
@ -20128,8 +20132,8 @@ EXPLAIN
"key_length": "5", "key_length": "5",
"used_key_parts": ["t1_id"], "used_key_parts": ["t1_id"],
"ref": ["test.t1.id"], "ref": ["test.t1.id"],
"rows": 3, "rows": 1,
"filtered": 59.09090805, "filtered": 34.55045319,
"index_condition": "t2.t1_id between 200 and 100000 and t2.t1_id = t3.t1_id", "index_condition": "t2.t1_id between 200 and 100000 and t2.t1_id = t3.t1_id",
"attached_condition": "t2.reporting_person = 1" "attached_condition": "t2.reporting_person = 1"
} }
@ -20151,6 +20155,18 @@ JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx
ON tx.t1_id = t1.id ON tx.t1_id = t1.id
WHERE t1.id BETWEEN 200 AND 100000; WHERE t1.id BETWEEN 200 AND 100000;
id id
EXPLAIN SELECT t1.id
FROM t1
JOIN t3
ON t3.t1_id = t1.id
JOIN (SELECT t1_id FROM t2 WHERE reporting_person = 1 GROUP BY t1_id) tx
ON tx.t1_id = t1.id
WHERE t1.id BETWEEN 200 AND 100000;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 range t1_id t1_id 5 NULL 47 Using where; Using index
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.t1_id 1 Using index
1 PRIMARY <derived2> ref key0 key0 5 test.t3.t1_id 10
2 DERIVED t2 ALL t1_id NULL NULL NULL 2408 Using where; Using temporary; Using filesort
set optimizer_switch='split_materialized=default'; set optimizer_switch='split_materialized=default';
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
# #
@ -20273,7 +20289,7 @@ ON from_agg_items.charge_id = charges.id AND
from_agg_items.ledger_id = charges.from_ledger_id from_agg_items.ledger_id = charges.from_ledger_id
WHERE charges.to_ledger_id = 2; WHERE charges.to_ledger_id = 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY charges ALL PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger NULL NULL NULL 20 Using where 1 PRIMARY charges ref PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger fk_charge_to_ledger 8 const 8
1 PRIMARY <derived2> ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 2 1 PRIMARY <derived2> ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 2
2 LATERAL DERIVED transaction_items ref fk_items_transaction,fk_items_charge fk_items_charge 9 test.charges.id 2 2 LATERAL DERIVED transaction_items ref fk_items_transaction,fk_items_charge fk_items_charge 9 test.charges.id 2
2 LATERAL DERIVED transactions eq_ref PRIMARY,fk_transactions_ledger PRIMARY 8 test.transaction_items.transaction_id 1 Using where 2 LATERAL DERIVED transactions eq_ref PRIMARY,fk_transactions_ledger PRIMARY 8 test.transaction_items.transaction_id 1 Using where
@ -20303,15 +20319,18 @@ EXPLAIN
{ {
"table": { "table": {
"table_name": "charges", "table_name": "charges",
"access_type": "ALL", "access_type": "ref",
"possible_keys": [ "possible_keys": [
"PRIMARY", "PRIMARY",
"fk_charge_from_ledger", "fk_charge_from_ledger",
"fk_charge_to_ledger" "fk_charge_to_ledger"
], ],
"rows": 20, "key": "fk_charge_to_ledger",
"filtered": 40, "key_length": "8",
"attached_condition": "charges.to_ledger_id = 2" "used_key_parts": ["to_ledger_id"],
"ref": ["const"],
"rows": 8,
"filtered": 100
} }
}, },
{ {
@ -20412,10 +20431,10 @@ ON from_agg_items.charge_id = charges.id AND
from_agg_items.ledger_id = charges.from_ledger_id from_agg_items.ledger_id = charges.from_ledger_id
WHERE charges.to_ledger_id = 2; WHERE charges.to_ledger_id = 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY charges ALL PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger NULL NULL NULL 20 Using where 1 PRIMARY charges ref PRIMARY,fk_charge_from_ledger,fk_charge_to_ledger fk_charge_to_ledger 8 const 8
1 PRIMARY <derived2> ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 4 1 PRIMARY <derived2> ref key0 key0 17 test.charges.from_ledger_id,test.charges.id 4
2 DERIVED transactions ALL PRIMARY NULL NULL NULL 40 Using temporary; Using filesort 2 DERIVED transaction_items ALL fk_items_transaction NULL NULL NULL 40 Using temporary; Using filesort
2 DERIVED transaction_items ref fk_items_transaction fk_items_transaction 8 test.transactions.id 1 2 DERIVED transactions eq_ref PRIMARY PRIMARY 8 test.transaction_items.transaction_id 1
INSERT INTO charges (id, from_ledger_id, to_ledger_id, amount) VALUES INSERT INTO charges (id, from_ledger_id, to_ledger_id, amount) VALUES
(101, 4, 2, 100), (102, 7, 2, 200); (101, 4, 2, 100), (102, 7, 2, 200);
set optimizer_switch='split_materialized=on'; set optimizer_switch='split_materialized=on';
@ -20467,7 +20486,7 @@ ON from_agg_items.charge_id = charges.id AND
from_agg_items.ledger_id = charges.from_ledger_id from_agg_items.ledger_id = charges.from_ledger_id
WHERE charges.to_ledger_id = 2; WHERE charges.to_ledger_id = 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY charges ALL fk_charge_to_ledger NULL NULL NULL 20 Using where 1 PRIMARY charges ref fk_charge_to_ledger fk_charge_to_ledger 8 const 10
1 PRIMARY <derived2> ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 2 1 PRIMARY <derived2> ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 2
2 LATERAL DERIVED transaction_items ref fk_items_transaction,fk_items_charge fk_items_charge 9 test.charges.id 2 2 LATERAL DERIVED transaction_items ref fk_items_transaction,fk_items_charge fk_items_charge 9 test.charges.id 2
2 LATERAL DERIVED transactions eq_ref PRIMARY,fk_transactions_ledger PRIMARY 8 test.transaction_items.transaction_id 1 Using where 2 LATERAL DERIVED transactions eq_ref PRIMARY,fk_transactions_ledger PRIMARY 8 test.transaction_items.transaction_id 1 Using where
@ -20497,11 +20516,14 @@ EXPLAIN
{ {
"table": { "table": {
"table_name": "charges", "table_name": "charges",
"access_type": "ALL", "access_type": "ref",
"possible_keys": ["fk_charge_to_ledger"], "possible_keys": ["fk_charge_to_ledger"],
"rows": 20, "key": "fk_charge_to_ledger",
"filtered": 50, "key_length": "8",
"attached_condition": "charges.to_ledger_id = 2" "used_key_parts": ["to_ledger_id"],
"ref": ["const"],
"rows": 10,
"filtered": 100
} }
}, },
{ {
@ -20604,10 +20626,10 @@ ON from_agg_items.charge_id = charges.id AND
from_agg_items.ledger_id = charges.from_ledger_id from_agg_items.ledger_id = charges.from_ledger_id
WHERE charges.to_ledger_id = 2; WHERE charges.to_ledger_id = 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY charges ALL fk_charge_to_ledger NULL NULL NULL 20 Using where 1 PRIMARY charges ref fk_charge_to_ledger fk_charge_to_ledger 8 const 10
1 PRIMARY <derived2> ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 4 1 PRIMARY <derived2> ref key0 key0 18 test.charges.from_ledger_id,test.charges.id 4
2 DERIVED transactions ALL PRIMARY NULL NULL NULL 40 Using temporary; Using filesort 2 DERIVED transaction_items ALL fk_items_transaction NULL NULL NULL 40 Using temporary; Using filesort
2 DERIVED transaction_items ref fk_items_transaction fk_items_transaction 8 test.transactions.id 1 2 DERIVED transactions eq_ref PRIMARY PRIMARY 8 test.transaction_items.transaction_id 1
set optimizer_switch='split_materialized=default'; set optimizer_switch='split_materialized=default';
DROP TABLE transaction_items; DROP TABLE transaction_items;
DROP TABLE transactions; DROP TABLE transactions;

View File

@ -3602,6 +3602,7 @@ insert into t1 values
create table t2 (a int) engine=myisam; create table t2 (a int) engine=myisam;
insert into t2 values (1),(2),(3),(1000),(2000),(3000); insert into t2 values (1),(2),(3),(1000),(2000),(3000);
insert into t2 select 5000 from seq_5000_to_6000;
create table t3 (id int) engine=myisam; create table t3 (id int) engine=myisam;
insert into t3 values (1),(2); insert into t3 values (1),(2);
@ -3630,7 +3631,7 @@ deallocate prepare stmt;
drop table t1,t2,t3; drop table t1,t2,t3;
--echo # --echo #
--echo # MDEV-MDEV-27132: Splittable derived with equality in WHERE --echo # MDEV-27132: Splittable derived with equality in WHERE
--echo # --echo #
CREATE TABLE t1 ( CREATE TABLE t1 (
@ -3677,6 +3678,9 @@ INSERT INTO t2(deleted, t1_id, email, reporting_person)
INSERT INTO t2(deleted, t1_id, email, reporting_person) INSERT INTO t2(deleted, t1_id, email, reporting_person)
SELECT deleted, t1_id+160000, email, reporting_person FROM t2; SELECT deleted, t1_id+160000, email, reporting_person FROM t2;
insert into t2 (id,t1_id) select -seq,-seq from seq_1_to_1000;
CREATE TABLE t3 ( CREATE TABLE t3 (
id int PRIMARY KEY, id int PRIMARY KEY,
deleted int, deleted int,
@ -3724,6 +3728,7 @@ eval EXPLAIN FORMAT=JSON $q;
set optimizer_switch='split_materialized=off'; set optimizer_switch='split_materialized=off';
eval $q; eval $q;
eval EXPLAIN $q;
set optimizer_switch='split_materialized=default'; set optimizer_switch='split_materialized=default';

View File

@ -111,7 +111,7 @@ count(*)
explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 2 Using where 1 PRIMARY A ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where
3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where
drop table t1; drop table t1;
create table t1 (a int); create table t1 (a int);

View File

@ -21,7 +21,7 @@ WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort 1 PRIMARY t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort
1 PRIMARY <derived2> ref key0 key0 8 test.t1.n1,test.t1.n2 2 1 PRIMARY <derived2> ref key0 key0 8 test.t1.n1,test.t1.n2 2
2 DERIVED t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort 2 LATERAL DERIVED t1 ref c1,n1_c1_n2 n1_c1_n2 4 test.t1.n1 1 Using where; Using index
SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t
WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1; WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1;
n1 n1
@ -128,8 +128,8 @@ left join
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null) (v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
on t1.f1=t.f1; on t1.f1=t.f1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t const f2 NULL NULL NULL 1 Impossible ON condition 1 PRIMARY t const f2 NULL NULL NULL 0 Impossible ON condition
1 PRIMARY <derived2> const key1 NULL NULL NULL 1 Impossible ON condition 1 PRIMARY <derived2> const key1 NULL NULL NULL 0 Impossible ON condition
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 DERIVED t2 ALL PRIMARY NULL NULL NULL 3 Using temporary; Using filesort 2 DERIVED t2 ALL PRIMARY NULL NULL NULL 3 Using temporary; Using filesort
set statement optimizer_switch='split_materialized=off' for explain select t.f2 set statement optimizer_switch='split_materialized=off' for explain select t.f2
@ -138,8 +138,8 @@ left join
(v1 join t1 as t on v1.f1=t.f1 and t.f2 = null) (v1 join t1 as t on v1.f1=t.f1 and t.f2 = null)
on t1.f1=t.f1; on t1.f1=t.f1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t const f2 NULL NULL NULL 1 Impossible ON condition 1 PRIMARY t const f2 NULL NULL NULL 0 Impossible ON condition
1 PRIMARY <derived3> const key1 NULL NULL NULL 1 Impossible ON condition 1 PRIMARY <derived3> const key1 NULL NULL NULL 0 Impossible ON condition
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY t1 ALL NULL NULL NULL NULL 3
3 DERIVED t2 index NULL PRIMARY 4 NULL 3 3 DERIVED t2 index NULL PRIMARY 4 NULL 3
drop view v1; drop view v1;
@ -157,26 +157,26 @@ set statement optimizer_switch='split_materialized=off' for EXPLAIN
SELECT * SELECT *
FROM FROM
t1 JOIN t1 JOIN
(SELECT t1.a, t1.b FROM t1, t2 WHERE t1.b = t2.c GROUP BY t1.a, t1.b) as dt (SELECT t1_inner.a, t1_inner.b FROM t1 as t1_inner, t2 as t2_inner WHERE t1_inner.b = t2_inner.c GROUP BY t1_inner.a, t1_inner.b) as dt
WHERE WHERE
t1.a = dt.a; t1.a = dt.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index 1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index
1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2
3 DERIVED t1 index NULL a_2 10 NULL 6 Using where; Using index 3 DERIVED t1_inner index NULL a_2 10 NULL 6 Using where; Using index
3 DERIVED t2 ref c c 5 test.t1.b 1 Using index 3 DERIVED t2_inner ref c c 5 test.t1_inner.b 1 Using index
set statement optimizer_switch='split_materialized=on' for EXPLAIN set statement optimizer_switch='split_materialized=on' for EXPLAIN
SELECT * SELECT *
FROM FROM
t1 JOIN t1 JOIN
(SELECT t1.a, t1.b FROM t1, t2 WHERE t1.b = t2.c GROUP BY t1.a, t1.b) as dt (SELECT t1_inner.a, t1_inner.b FROM t1 as t1_inner, t2 as t2_inner WHERE t1_inner.b = t2_inner.c GROUP BY t1_inner.a, t1_inner.b) as dt
WHERE WHERE
t1.a = dt.a; t1.a = dt.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index 1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index
1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2
3 DERIVED t1 index a,a_2 a_2 10 NULL 6 Using where; Using index; Using temporary; Using filesort 3 DERIVED t1_inner index a,a_2 a_2 10 NULL 6 Using where; Using index
3 DERIVED t2 ref c c 5 test.t1.b 1 Using index 3 DERIVED t2_inner ref c c 5 test.t1_inner.b 1 Using index
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
# Bug mdev-25714: usage non-splitting covering index is cheaper than # Bug mdev-25714: usage non-splitting covering index is cheaper than
@ -210,7 +210,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 1
1 PRIMARY t1 ref idx idx 4 test.t2.id 1 1 PRIMARY t1 ref idx idx 4 test.t2.id 1
1 PRIMARY <derived2> ref key0 key0 9 test.t2.id,test.t1.id 2 1 PRIMARY <derived2> ref key0 key0 9 test.t2.id,test.t1.id 2
2 LATERAL DERIVED t3 ref idx1,idx2 idx2 4 test.t1.itemid 1 Using index condition; Using where 2 DERIVED t3 ref idx1,idx2 idx1 4 const 5 Using where; Using index
select t1.id, t1.itemid, dt.id, t2.id select t1.id, t1.itemid, dt.id, t2.id
from t1, from t1,
(select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt, (select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt,

View File

@ -1216,11 +1216,11 @@ SELECT * FROM t3
WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b); WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
2 DEPENDENT SUBQUERY <derived3> ref key1 key1 5 func 2 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY <derived3> ref key0 key0 5 test.t2.a 2 100.00 Using where
3 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort 3 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where <expr_cache><`test`.`t3`.`a`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(/* select#2 */ select `v1`.`a` from `test`.`v1` join `test`.`t2` where `test`.`t2`.`a` = `v1`.`b` and <cache>(`test`.`t3`.`a`) = `v1`.`a`))) Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where <expr_cache><`test`.`t3`.`a`>(<in_optimizer>(`test`.`t3`.`a`,<exists>(/* select#2 */ select `v1`.`a` from `test`.`v1` join `test`.`t2` where `v1`.`b` = `test`.`t2`.`a` and <cache>(`test`.`t3`.`a`) = `v1`.`a`)))
SELECT * FROM t3 SELECT * FROM t3
WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b); WHERE t3.a IN (SELECT v1.a FROM v1, t2 WHERE t2.a = v1.b);
a a
@ -1248,9 +1248,9 @@ SELECT t.f1 AS f
FROM (SELECT DISTINCT t1.* FROM t1,t2 WHERE t2.f2 = t1.f2) t,t3,t4 FROM (SELECT DISTINCT t1.* FROM t1,t2 WHERE t2.f2 = t1.f2) t,t3,t4
WHERE t4.f2 = t3.f2 AND t4.f2 = t.f1 ORDER BY f; WHERE t4.f2 = t3.f2 AND t4.f2 = t.f1 ORDER BY f;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where; Using filesort 1 PRIMARY t4 index f2 f2 9 NULL 2 Using where; Using index; Using temporary; Using filesort
1 PRIMARY t4 ref f2 f2 4 t.f1 1 Using index 1 PRIMARY t3 ref f2 f2 4 test.t4.f2 2 Using index
1 PRIMARY t3 ref f2 f2 4 t.f1 2 Using index 1 PRIMARY <derived2> ref key0 key0 4 test.t4.f2 2
2 DERIVED t2 system NULL NULL NULL NULL 1 Using temporary 2 DERIVED t2 system NULL NULL NULL NULL 1 Using temporary
2 DERIVED t1 ref f2 f2 4 const 2 Using where 2 DERIVED t1 ref f2 f2 4 const 2 Using where
SELECT t.f1 AS f SELECT t.f1 AS f
@ -1917,7 +1917,7 @@ WHERE t2.c = v1.c AND t2.c = v1.b AND v1.b = t3.c);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 1 PRIMARY t2 system NULL NULL NULL NULL 1
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where 1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 3 Using where; Start temporary; End temporary 1 PRIMARY <derived3> ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t3)
3 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where 3 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where
SELECT * FROM t3 SELECT * FROM t3
WHERE t3.b IN (SELECT v1.b FROM v1, t2 WHERE t3.b IN (SELECT v1.b FROM v1, t2
@ -2370,7 +2370,7 @@ GROUP BY TABLE_SCHEMA) AS UNIQUES
ON ( COLUMNS.TABLE_SCHEMA = UNIQUES.TABLE_SCHEMA); ON ( COLUMNS.TABLE_SCHEMA = UNIQUES.TABLE_SCHEMA);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY COLUMNS ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases 1 PRIMARY COLUMNS ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 1 PRIMARY <derived2> ref key0 key0 194 information_schema.COLUMNS.TABLE_SCHEMA 10
2 DERIVED STATISTICS ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort 2 DERIVED STATISTICS ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort
SELECT COUNT(*) > 0 SELECT COUNT(*) > 0
FROM INFORMATION_SCHEMA.COLUMNS FROM INFORMATION_SCHEMA.COLUMNS
@ -2463,8 +2463,6 @@ SELECT * FROM t1;
a a
1 1
1 1
1
1
drop table t1,t2; drop table t1,t2;
set optimizer_switch=@save968720_optimizer_switch; set optimizer_switch=@save968720_optimizer_switch;
# #
@ -3081,7 +3079,7 @@ SELECT * FROM t1 LEFT JOIN v2 ON t1.id=v2.order_pk;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index
1 PRIMARY <derived2> ref key0 key0 5 test.t1.id 2 100.00 1 PRIMARY <derived2> ref key0 key0 5 test.t1.id 2 100.00
2 DERIVED t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index; Using filesort 2 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00 Using where; Using index
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v2`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v2` on(`v2`.`order_pk` = `test`.`t1`.`id`) where 1 Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v2`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v2` on(`v2`.`order_pk` = `test`.`t1`.`id`) where 1
SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk; SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk;
@ -3095,7 +3093,7 @@ SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index
1 PRIMARY <derived2> ref key0 key0 5 test.t1.id 2 100.00 1 PRIMARY <derived2> ref key0 key0 5 test.t1.id 2 100.00
2 DERIVED t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index; Using filesort 2 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00 Using where; Using index
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v3`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v3` on(`v3`.`order_pk` = `test`.`t1`.`id`) where 1 Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v3`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v3` on(`v3`.`order_pk` = `test`.`t1`.`id`) where 1
DROP VIEW v1,v2,v3; DROP VIEW v1,v2,v3;

View File

@ -146,7 +146,7 @@ CREATE TABLE t1 (p int NOT NULL, a int NOT NULL, PRIMARY KEY (p,a desc));
insert into t1 select 2,seq from seq_0_to_1000; insert into t1 select 2,seq from seq_0_to_1000;
EXPLAIN select MIN(a) from t1 where p = 2 group by p; EXPLAIN select MIN(a) from t1 where p = 2 group by p;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 8 NULL 1001 Using where; Using index 1 SIMPLE t1 ref PRIMARY PRIMARY 4 const 1000 Using index
select json_detailed(json_extract(trace, '$**.potential_group_range_indexes')) select json_detailed(json_extract(trace, '$**.potential_group_range_indexes'))
from information_schema.optimizer_trace; from information_schema.optimizer_trace;
json_detailed(json_extract(trace, '$**.potential_group_range_indexes')) json_detailed(json_extract(trace, '$**.potential_group_range_indexes'))

View File

@ -173,9 +173,9 @@ INSERT INTO t2 values (1),(2),(3);
INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2'); INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2');
explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where; Using temporary 1 SIMPLE t2 index a a 4 NULL 5 Using index; Using temporary
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 Using where
1 SIMPLE t3 ref a a 5 test.t1.b 2 Using index 1 SIMPLE t3 ref a a 5 test.t1.b 2 Using index
1 SIMPLE t2 ref a a 4 test.t1.a 2 Using index; Distinct
SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
a a
1 1
@ -522,8 +522,8 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2 EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2
WHERE t1_1.a = t1_2.a; WHERE t1_1.a = t1_2.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1_1 ALL PRIMARY NULL NULL NULL 3 Using temporary 1 SIMPLE t1_2 index PRIMARY PRIMARY 4 NULL 3 Using index; Using temporary
1 SIMPLE t1_2 eq_ref PRIMARY PRIMARY 4 test.t1_1.a 1 Using index; Distinct 1 SIMPLE t1_1 eq_ref PRIMARY PRIMARY 4 test.t1_2.a 1
EXPLAIN SELECT a FROM t1 GROUP BY a; EXPLAIN SELECT a FROM t1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 4 NULL 3 Using index 1 SIMPLE t1 index NULL PRIMARY 4 NULL 3 Using index
@ -538,10 +538,10 @@ PRIMARY KEY (a,b));
INSERT INTO t2 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4); INSERT INTO t2 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
EXPLAIN SELECT DISTINCT a FROM t2; EXPLAIN SELECT DISTINCT a FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index 1 SIMPLE t2 range NULL PRIMARY 4 NULL 3 Using index for group-by
EXPLAIN SELECT DISTINCT a,a FROM t2; EXPLAIN SELECT DISTINCT a,a FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index 1 SIMPLE t2 range NULL PRIMARY 4 NULL 3 Using index for group-by
EXPLAIN SELECT DISTINCT b,a FROM t2; EXPLAIN SELECT DISTINCT b,a FROM t2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index 1 SIMPLE t2 index NULL PRIMARY 8 NULL 3 Using index

View File

@ -333,9 +333,7 @@ WHERE t1.f1 GROUP BY t1.f1));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index 2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'test'
PREPARE stmt FROM PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1 'EXPLAIN SELECT 1 FROM t1
WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a
@ -345,16 +343,12 @@ EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index 2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'test'
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index 2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'test'
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
PREPARE stmt FROM PREPARE stmt FROM
'EXPLAIN SELECT 1 FROM t1 'EXPLAIN SELECT 1 FROM t1
@ -365,9 +359,7 @@ EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
2 SUBQUERY a system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1
2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index 2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: 'test'
INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5'); INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5');
EXECUTE stmt; EXECUTE stmt;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra

View File

@ -15,6 +15,6 @@ explain
SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0; SELECT * FROM (SELECT id FROM t1 GROUP BY id) dt WHERE 1=0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DERIVED t1 index NULL id 53 NULL 1 Using index 2 DERIVED t1 range NULL id 53 NULL 1 Using index for group-by
SET GLOBAL slow_query_log = @sql_tmp; SET GLOBAL slow_query_log = @sql_tmp;
drop table t1; drop table t1;

View File

@ -713,12 +713,11 @@ EXPLAIN
create table t2 like t1; create table t2 like t1;
insert into t2 select * from t1; insert into t2 select * from t1;
explain format=json explain format=json
select * from t1,t2 where t1.a in ( select a from t0); select * from t1,t2 where t1.a in ( select seq+0 from seq_1_to_100);
EXPLAIN EXPLAIN
{ {
"query_block": { "query_block": {
"select_id": 1, "select_id": 1,
"const_condition": "1",
"nested_loop": [ "nested_loop": [
{ {
"table": { "table": {
@ -734,11 +733,12 @@ EXPLAIN
"access_type": "eq_ref", "access_type": "eq_ref",
"possible_keys": ["distinct_key"], "possible_keys": ["distinct_key"],
"key": "distinct_key", "key": "distinct_key",
"key_length": "4", "key_length": "8",
"used_key_parts": ["a"], "used_key_parts": ["seq+0"],
"ref": ["func"], "ref": ["func"],
"rows": 1, "rows": 1,
"filtered": 100, "filtered": 100,
"attached_condition": "t1.a = seq_1_to_100.seq + 0",
"materialized": { "materialized": {
"unique": 1, "unique": 1,
"query_block": { "query_block": {
@ -746,10 +746,14 @@ EXPLAIN
"nested_loop": [ "nested_loop": [
{ {
"table": { "table": {
"table_name": "t0", "table_name": "seq_1_to_100",
"access_type": "ALL", "access_type": "index",
"rows": 10, "key": "PRIMARY",
"filtered": 100 "key_length": "8",
"used_key_parts": ["seq"],
"rows": 100,
"filtered": 100,
"using_index": true
} }
} }
] ]
@ -766,7 +770,7 @@ EXPLAIN
"filtered": 100 "filtered": 100
}, },
"buffer_type": "flat", "buffer_type": "flat",
"buffer_size": "1Kb", "buffer_size": "19Kb",
"join_type": "BNL" "join_type": "BNL"
} }
} }
@ -847,7 +851,7 @@ EXPLAIN
"table_name": "t1", "table_name": "t1",
"access_type": "ALL", "access_type": "ALL",
"rows": 10, "rows": 10,
"filtered": 100 "filtered": 10
}, },
"buffer_type": "flat", "buffer_type": "flat",
"buffer_size": "206", "buffer_size": "206",
@ -1225,12 +1229,18 @@ analyze table t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status Table is already up to date test.t1 analyze status Table is already up to date
select count(*) from t1;
count(*)
128
explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using where; Using index for group-by 1 SIMPLE t1 range NULL idx_t1_2 147 NULL 17 Using where; Using index for group-by
explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL idx_t1_1 163 NULL 65 Using where; Using index for group-by 1 SIMPLE t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index
explain select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 1 Using where; Using index for group-by
explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');
EXPLAIN EXPLAIN
{ {
@ -1241,7 +1251,7 @@ EXPLAIN
"table": { "table": {
"table_name": "t1", "table_name": "t1",
"access_type": "range", "access_type": "range",
"key": "idx_t1_1", "key": "idx_t1_2",
"key_length": "147", "key_length": "147",
"used_key_parts": ["a1", "a2", "b"], "used_key_parts": ["a1", "a2", "b"],
"rows": 17, "rows": 17,
@ -1262,13 +1272,36 @@ EXPLAIN
{ {
"table": { "table": {
"table_name": "t1", "table_name": "t1",
"access_type": "range", "access_type": "index",
"key": "idx_t1_1", "key": "idx_t1_1",
"key_length": "163", "key_length": "163",
"used_key_parts": ["a1", "a2", "b", "c"], "used_key_parts": ["a1", "a2", "b", "c"],
"rows": 65, "rows": 128,
"filtered": 100, "filtered": 0.198364258,
"attached_condition": "t1.b = 'a' and t1.c = 'i121' and t1.a2 >= 'b'", "attached_condition": "t1.b = 'a' and t1.c = 'i121' and t1.a2 >= 'b'",
"using_index": true
}
}
]
}
}
explain format=json select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a');
EXPLAIN
{
"query_block": {
"select_id": 1,
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "range",
"possible_keys": ["idx_t1_0", "idx_t1_1", "idx_t1_2"],
"key": "idx_t1_1",
"key_length": "147",
"used_key_parts": ["a1", "a2", "b"],
"rows": 1,
"filtered": 100,
"attached_condition": "t1.b = 'a' and t1.a1 >= '' and t1.a2 >= 'b'",
"using_index_for_group_by": true "using_index_for_group_by": true
} }
} }
@ -1470,7 +1503,7 @@ insert into t2 values (1),(2);
explain explain
select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0; select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY NULL NULL NULL 1 Impossible ON condition 1 SIMPLE t2 const PRIMARY NULL NULL NULL 0 Impossible ON condition
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 1 SIMPLE t1 ALL NULL NULL NULL NULL 2
explain format=json explain format=json
select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0; select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0;
@ -1485,8 +1518,8 @@ EXPLAIN
"table_name": "t2", "table_name": "t2",
"access_type": "const", "access_type": "const",
"possible_keys": ["PRIMARY"], "possible_keys": ["PRIMARY"],
"rows": 1, "rows": 0,
"filtered": 100, "filtered": 0,
"impossible_on_condition": true "impossible_on_condition": true
} }
}, },
@ -1520,9 +1553,9 @@ ANALYZE
"access_type": "const", "access_type": "const",
"possible_keys": ["PRIMARY"], "possible_keys": ["PRIMARY"],
"r_loops": 0, "r_loops": 0,
"rows": 1, "rows": 0,
"r_rows": null, "r_rows": null,
"filtered": 100, "filtered": 0,
"r_filtered": null, "r_filtered": null,
"impossible_on_condition": true "impossible_on_condition": true
} }
@ -1832,7 +1865,8 @@ ANALYZE
"buffer_size": "400", "buffer_size": "400",
"join_type": "BKA", "join_type": "BKA",
"mrr_type": "Rowid-ordered scan", "mrr_type": "Rowid-ordered scan",
"r_filtered": 100 "r_filtered": 100,
"r_unpack_time_ms": "REPLACED"
} }
} }
] ]
@ -2004,7 +2038,7 @@ EXPLAIN
"table_name": "t3", "table_name": "t3",
"access_type": "ALL", "access_type": "ALL",
"rows": 2, "rows": 2,
"filtered": 100 "filtered": 25
}, },
"buffer_type": "incremental", "buffer_type": "incremental",
"buffer_size": "109", "buffer_size": "109",

View File

@ -2,6 +2,7 @@
# EXPLAIN FORMAT=JSON tests. These are tests developed for MariaDB. # EXPLAIN FORMAT=JSON tests. These are tests developed for MariaDB.
# #
--source include/default_optimizer_switch.inc --source include/default_optimizer_switch.inc
--source include/have_sequence.inc
--disable_warnings --disable_warnings
drop table if exists t0,t1,t2; drop table if exists t0,t1,t2;
@ -117,7 +118,7 @@ select * from t1 where a in (select max(a) from t1 group by b);
create table t2 like t1; create table t2 like t1;
insert into t2 select * from t1; insert into t2 select * from t1;
explain format=json explain format=json
select * from t1,t2 where t1.a in ( select a from t0); select * from t1,t2 where t1.a in ( select seq+0 from seq_1_to_100);
--echo # --echo #
--echo # First-Match --echo # First-Match
@ -271,13 +272,17 @@ create index idx_t1_0 on t1 (a1);
create index idx_t1_1 on t1 (a1,a2,b,c); create index idx_t1_1 on t1 (a1,a2,b,c);
create index idx_t1_2 on t1 (a1,a2,b); create index idx_t1_2 on t1 (a1,a2,b);
analyze table t1; analyze table t1;
select count(*) from t1;
explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');
explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');
explain select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a');
explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a'); explain format=json select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');
explain format=json select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121'); explain format=json select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');
explain format=json select count(distinct a1,a2,b) from t1 where a1 >= "" and (a2 >= 'b') and (b = 'a');
drop table t1; drop table t1;
--echo # --echo #

View File

@ -54,8 +54,7 @@ EXPLAIN
], ],
"rows": 1, "rows": 1,
"filtered": 100, "filtered": 100,
"attached_condition": "tbl_alias2.c = tbl_alias1.column_name_2", "attached_condition": "tbl_alias2.c = tbl_alias1.column_name_2"
"using_index": true
} }
} }
] ]

View File

@ -834,6 +834,14 @@ fetch first 2 rows with ties;
first_name last_name first_name last_name
Alice Fowler Alice Fowler
Bob Trasc Bob Trasc
explain select first_name, last_name
from t1
where first_name != 'John'
group by first_name, last_name
order by first_name
fetch first 2 rows with ties;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range t1_name t1_name 206 NULL 3 Using where; Using index for group-by
select first_name, last_name select first_name, last_name
from t1 from t1
where first_name != 'John' where first_name != 'John'
@ -843,7 +851,6 @@ fetch first 2 rows with ties;
first_name last_name first_name last_name
Alice Fowler Alice Fowler
Bob Trasc Bob Trasc
Silvia Ganush
# #
# Test CTE support. # Test CTE support.
# #

View File

@ -621,7 +621,12 @@ where first_name != 'John'
order by first_name order by first_name
fetch first 2 rows with ties; fetch first 2 rows with ties;
explain select first_name, last_name
from t1
where first_name != 'John'
group by first_name, last_name
order by first_name
fetch first 2 rows with ties;
select first_name, last_name select first_name, last_name
from t1 from t1

View File

@ -594,6 +594,9 @@ CREATE TABLE t2 (a int, b2 char(10), FULLTEXT KEY b2 (b2));
INSERT INTO t2 VALUES (1,'Scargill'); INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int); CREATE TABLE t3 (a int, b int);
INSERT INTO t3 VALUES (1,1), (2,1); INSERT INTO t3 VALUES (1,1), (2,1);
SELECT * FROM t2 where MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE);
a b2
1 Scargill
# t2 should use full text index # t2 should use full text index
EXPLAIN EXPLAIN
SELECT count(*) FROM t1 WHERE SELECT count(*) FROM t1 WHERE
@ -603,8 +606,8 @@ WHERE t3.a=t1.a AND MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE)
); );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
2 MATERIALIZED t2 fulltext b2 b2 0 1 Using where 2 DEPENDENT SUBQUERY t2 fulltext b2 b2 0 1 Using where
2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using where 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
# should return 0 # should return 0
SELECT count(*) FROM t1 WHERE SELECT count(*) FROM t1 WHERE
not exists( not exists(

View File

@ -547,6 +547,8 @@ INSERT INTO t2 VALUES (1,'Scargill');
CREATE TABLE t3 (a int, b int); CREATE TABLE t3 (a int, b int);
INSERT INTO t3 VALUES (1,1), (2,1); INSERT INTO t3 VALUES (1,1), (2,1);
SELECT * FROM t2 where MATCH(b2) AGAINST('scargill' IN BOOLEAN MODE);
--echo # t2 should use full text index --echo # t2 should use full text index
EXPLAIN EXPLAIN
SELECT count(*) FROM t1 WHERE SELECT count(*) FROM t1 WHERE

View File

@ -36,7 +36,6 @@ SELECT IF(a=7,'match',IF(a=4,'match', 'no-match')), MATCH (message) AGAINST ('st
# for fulltext searches too # for fulltext searches too
# #
alter table t1 add key m (message); alter table t1 add key m (message);
show create table t1;
explain SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message; explain SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message;
SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message desc; SELECT message FROM t1 WHERE MATCH (message) AGAINST ('steve') ORDER BY message desc;

View File

@ -607,7 +607,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain explain
select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK'); select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 Using where; Using index 1 SIMPLE t1 range PRIMARY PRIMARY 3 NULL 14 Using where; Using index
explain explain
select max(a3) from t1 where a2 < 2 and a3 < 'SEA'; select max(a3) from t1 where a2 < 2 and a3 < 'SEA';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -652,7 +652,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain explain
select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME'; select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k2 4 NULL 7 Using where; Using index 1 SIMPLE t2 range k2 k2 4 NULL 6 Using where; Using index
1 SIMPLE t1 index NULL PRIMARY 3 NULL 15 Using index; Using join buffer (flat, BNL join) 1 SIMPLE t1 index NULL PRIMARY 3 NULL 15 Using index; Using join buffer (flat, BNL join)
drop table t1, t2; drop table t1, t2;
create table t1 (a char(10)); create table t1 (a char(10));
@ -1336,7 +1336,7 @@ INSERT INTO t2 ( a, b, c ) VALUES
( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 ), ( 2, NULL, 2 ), ( 2, 3, 4 ), ( 2, 4, 4 ); ( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 ), ( 2, NULL, 2 ), ( 2, 3, 4 ), ( 2, 4, 4 );
EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1; EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL a NULL NULL NULL 6 Using where 1 SIMPLE t2 ref a a 5 const 3
SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1; SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
MIN(b) MIN(c) MIN(b) MIN(c)
3 2 3 2
@ -1856,7 +1856,7 @@ NULL
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10; SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 20.00 Using where; FirstMatch
1 PRIMARY t1 range a a 4 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join) 1 PRIMARY t1 range a a 4 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = 1 and `test`.`t2`.`b` = 2 and `test`.`t1`.`a` < 10 Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = 1 and `test`.`t2`.`b` = 2 and `test`.`t1`.`a` < 10

View File

@ -246,12 +246,12 @@ INSERT INTO t1(a, b, c) VALUES
('', 'a', 1), ('', 'a', 1), ('', 'a', 2), ('', 'a', 2), ('', 'a', 3), ('', 'a', 1), ('', 'a', 1), ('', 'a', 2), ('', 'a', 2), ('', 'a', 3),
('', 'a', 3), ('', 'a', 4), ('', 'a', 4), ('', 'a', 5), ('', 'a', 5); ('', 'a', 3), ('', 'a', 4), ('', 'a', 4), ('', 'a', 5), ('', 'a', 5);
ANALYZE TABLE t1; ANALYZE TABLE t1;
SELECT MIN(c) FROM t1 GROUP BY b;
MIN(c)
0
EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b; EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL b 263 NULL 2 Using index for group-by 1 SIMPLE t1 range NULL b 263 NULL 2 Using index for group-by
SELECT MIN(c) FROM t1 GROUP BY b;
MIN(c)
0
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-17589: Stack-buffer-overflow with indexed varchar (utf8) field # MDEV-17589: Stack-buffer-overflow with indexed varchar (utf8) field

View File

@ -199,8 +199,8 @@ INSERT INTO t1(a, b, c) VALUES
ANALYZE TABLE t1; ANALYZE TABLE t1;
-- enable_result_log -- enable_result_log
SELECT MIN(c) FROM t1 GROUP BY b;
EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b; EXPLAIN SELECT MIN(c) FROM t1 GROUP BY b;
SELECT MIN(c) FROM t1 GROUP BY b;
DROP TABLE t1; DROP TABLE t1;

View File

@ -521,7 +521,7 @@ a
b b
explain select f1 from t1 where f1 in ('a','b'); explain select f1 from t1 where f1 in ('a','b');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index t1f1_idx t1f1_idx 2 NULL 3 Using where; Using index 1 SIMPLE t1 range t1f1_idx t1f1_idx 2 NULL 2 Using where; Using index
select f1 from t1 where f1 in (2,1); select f1 from t1 where f1 in (2,1);
f1 f1
1 1
@ -957,7 +957,7 @@ a
# Conversion to equality is impossible due to different values # Conversion to equality is impossible due to different values
EXPLAIN SELECT * FROM t1 WHERE a IN (1,1,2); EXPLAIN SELECT * FROM t1 WHERE a IN (1,1,2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 3 Using where; Using index 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index
SELECT * FROM t1 WHERE a IN (1,NULL,1); SELECT * FROM t1 WHERE a IN (1,NULL,1);
a a
1 1
@ -1030,7 +1030,7 @@ a b
# No conversion due to different values # No conversion due to different values
EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,'XYZ')); EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,'XYZ'));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index PRIMARY PRIMARY 16 NULL 3 Using where; Using index 1 SIMPLE t2 range PRIMARY PRIMARY 16 NULL 2 Using where; Using index
SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,NULL)); SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,NULL));
a b a b
2 def 2 def
@ -1078,7 +1078,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1 Using index 1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1 Using index
EXECUTE stmt USING 2,3,4; EXECUTE stmt USING 2,3,4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 3 Using where; Using index 1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 3 Using where; Using index
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
# Nested joins # Nested joins
@ -1104,7 +1104,7 @@ AND t3.a IN (1,2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 1 SIMPLE t2 ALL NULL NULL NULL NULL 2
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 4 Using where; Using index; Using join buffer (incremental, BNL join) 1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (incremental, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join)
# Conversion to equalities # Conversion to equalities
EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a) EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a)
@ -1118,7 +1118,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a) EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a)
ON t1.a = t2.a WHERE t1.a IN (1,3); ON t1.a = t2.a WHERE t1.a IN (1,3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
1 SIMPLE t4 ALL NULL NULL NULL NULL 2 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t3 index NULL PRIMARY 4 NULL 4 Using index 1 SIMPLE t3 index NULL PRIMARY 4 NULL 4 Using index
@ -1131,7 +1131,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
EXPLAIN SELECT * FROM v1 WHERE a IN (1,2,3); EXPLAIN SELECT * FROM v1 WHERE a IN (1,2,3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using index condition
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1
# Stored procedures # Stored procedures
CREATE PROCEDURE p1(pa INT, pb INT) CREATE PROCEDURE p1(pa INT, pb INT)
@ -1141,7 +1141,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
CALL p1(2,1); CALL p1(2,1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition
DROP TABLE t1, t2, t3, t4; DROP TABLE t1, t2, t3, t4;
DROP VIEW v1; DROP VIEW v1;
DROP PROCEDURE p1; DROP PROCEDURE p1;

View File

@ -127,7 +127,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 1.650935
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
@ -139,11 +139,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 1.650935
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
@ -151,11 +151,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1330.797643 Last_query_cost 0.602062
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
@ -163,11 +163,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1330.797643 Last_query_cost 0.602062
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
@ -175,11 +175,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1334.341393 Last_query_cost 0.621783
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
@ -187,7 +187,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1334.341393 Last_query_cost 0.621783
set optimizer_prune_level=0; set optimizer_prune_level=0;
select @@optimizer_prune_level; select @@optimizer_prune_level;
@@optimizer_prune_level @@optimizer_prune_level
@ -198,108 +198,108 @@ select @@optimizer_search_depth;
0 0
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2437.438350 Last_query_cost 1.405838
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2437.438350 Last_query_cost 1.405838
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 653.372751 Last_query_cost 0.494824
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 653.372751 Last_query_cost 0.494824
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 662.822751 Last_query_cost 0.453844
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 662.822751 Last_query_cost 0.453844
set optimizer_search_depth=1; set optimizer_search_depth=1;
select @@optimizer_search_depth; select @@optimizer_search_depth;
@@optimizer_search_depth @@optimizer_search_depth
1 1
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 34.291074
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 34.291074
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
@ -307,19 +307,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1762.798851 Last_query_cost 14.789792
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1762.798851 Last_query_cost 14.789792
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
@ -331,7 +331,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1767.523851 Last_query_cost 1.698747
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
@ -343,83 +343,83 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1767.523851 Last_query_cost 1.698747
set optimizer_search_depth=62; set optimizer_search_depth=62;
select @@optimizer_search_depth; select @@optimizer_search_depth;
@@optimizer_search_depth @@optimizer_search_depth
62 62
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2437.438350 Last_query_cost 1.405838
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 Using where
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2437.438350 Last_query_cost 1.405838
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 653.372751 Last_query_cost 0.494824
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 653.372751 Last_query_cost 0.494824
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 662.822751 Last_query_cost 0.453844
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 662.822751 Last_query_cost 0.453844
set optimizer_prune_level=2; set optimizer_prune_level=2;
select @@optimizer_prune_level; select @@optimizer_prune_level;
@@optimizer_prune_level @@optimizer_prune_level
@ -439,7 +439,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 1.650935
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
@ -451,11 +451,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 1.650935
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
@ -463,23 +463,23 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1330.797643 Last_query_cost 0.602062
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1330.797643 Last_query_cost 0.602062
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
@ -487,51 +487,51 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1334.341393 Last_query_cost 0.621783
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1334.341393 Last_query_cost 0.621783
set optimizer_search_depth=1; set optimizer_search_depth=1;
select @@optimizer_search_depth; select @@optimizer_search_depth;
@@optimizer_search_depth @@optimizer_search_depth
1 1
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 34.291074
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t7 index PRIMARY PRIMARY 4 NULL 21 Using index
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 34.291074
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
@ -539,19 +539,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1762.798851 Last_query_cost 14.789792
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 9 Using index
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1762.798851 Last_query_cost 14.789792
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
@ -563,7 +563,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1767.523851 Last_query_cost 1.698747
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where
@ -575,7 +575,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1767.523851 Last_query_cost 1.698747
set optimizer_search_depth=62; set optimizer_search_depth=62;
select @@optimizer_search_depth; select @@optimizer_search_depth;
@@optimizer_search_depth @@optimizer_search_depth
@ -591,7 +591,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 1.650935
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
@ -603,11 +603,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 2445.013350 Last_query_cost 1.650935
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
@ -615,23 +615,23 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1330.797643 Last_query_cost 0.602062
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using index
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using index
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using index
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1330.797643 Last_query_cost 0.602062
explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
@ -639,19 +639,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1334.341393 Last_query_cost 0.621783
explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 6 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.c21 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.c12 1 Using where
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t1.c14 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t1.c16 1 Using where
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join)
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 1334.341393 Last_query_cost 0.621783
drop table t1,t2,t3,t4,t5,t6,t7; drop table t1,t2,t3,t4,t5,t6,t7;
CREATE TABLE t1 (a int, b int, d int, i int); CREATE TABLE t1 (a int, b int, d int, i int);
INSERT INTO t1 VALUES (1,1,1,1); INSERT INTO t1 VALUES (1,1,1,1);
@ -1195,13 +1195,13 @@ COUNT(*)
9000 9000
### NOTE: Handler_reads: 9030, expected: 9045 ### ### NOTE: Handler_reads: 9030, expected: 9045 ###
flush status; flush status;
EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 x,t10000 y EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t10000 y, t10, t10000 x
WHERE x.k=t10.i; WHERE x.k=t10.i;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t10 index IX IX 5 NULL 10 Using where; Using index 1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index
1 SIMPLE t10 range IX IX 5 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index 1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index
1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join) SELECT STRAIGHT_JOIN COUNT(*) FROM t10000 y, t10, t10000 x
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 x,t10000 y
WHERE x.k=t10.i; WHERE x.k=t10.i;
COUNT(*) COUNT(*)
90000 90000
@ -1209,9 +1209,9 @@ flush status;
EXPLAIN SELECT COUNT(*) FROM t10,t10000 x,t10000 y EXPLAIN SELECT COUNT(*) FROM t10,t10000 x,t10000 y
WHERE x.k=t10.i; WHERE x.k=t10.i;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t10 index IX IX 5 NULL 10 Using where; Using index 1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index
1 SIMPLE t10 range IX IX 5 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index 1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index
1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join)
SELECT COUNT(*) FROM t10,t10000 x,t10000 y SELECT COUNT(*) FROM t10,t10000 x,t10000 y
WHERE x.k=t10.i; WHERE x.k=t10.i;
COUNT(*) COUNT(*)
@ -1220,9 +1220,9 @@ flush status;
EXPLAIN SELECT COUNT(*) FROM t10,t10000 y,t10000 x EXPLAIN SELECT COUNT(*) FROM t10,t10000 y,t10000 x
WHERE x.k=t10.i; WHERE x.k=t10.i;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t10 index IX IX 5 NULL 10 Using where; Using index 1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index
1 SIMPLE t10 range IX IX 5 NULL 10 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index 1 SIMPLE x eq_ref PRIMARY PRIMARY 4 test.t10.I 1 Using index
1 SIMPLE y index NULL PRIMARY 4 NULL 10000 Using index; Using join buffer (flat, BNL join)
SELECT COUNT(*) FROM t10,t10000 y,t10000 x SELECT COUNT(*) FROM t10,t10000 y,t10000 x
WHERE x.k=t10.i; WHERE x.k=t10.i;
COUNT(*) COUNT(*)
@ -2913,7 +2913,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 AS x JOIN t1 ON t1.K=x.I JOIN t2 ON t2.K=x.I JOI
DROP TABLE t100, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61; DROP TABLE t100, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60, t61;
show status like "optimizer%"; show status like "optimizer%";
Variable_name Value Variable_name Value
Optimizer_join_prefixes_check_calls 60210 Optimizer_join_prefixes_check_calls 63164
SET OPTIMIZER_SEARCH_DEPTH = DEFAULT; SET OPTIMIZER_SEARCH_DEPTH = DEFAULT;
# #
# Bug found when testing greedy optimizer tests # Bug found when testing greedy optimizer tests

View File

@ -662,7 +662,7 @@ WHERE t100.K=t10.I
## Expect this QEP, cost & #handler_read ## Expect this QEP, cost & #handler_read
# Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before 'cross' ALL(Y) # Expected QEP: 'join EQ_REF(X) on X.K=t10.I' before 'cross' ALL(Y)
let $query= let $query=
SELECT STRAIGHT_JOIN COUNT(*) FROM t10,t10000 x,t10000 y SELECT STRAIGHT_JOIN COUNT(*) FROM t10000 y, t10, t10000 x
WHERE x.k=t10.i; WHERE x.k=t10.i;
--source include/expect_qep.inc --source include/expect_qep.inc

View File

@ -1718,7 +1718,7 @@ NULL
insert into t2 SELECT NULL, NULL from seq_1_to_10; insert into t2 SELECT NULL, NULL from seq_1_to_10;
EXPLAIN SELECT b from t2 GROUP BY a; EXPLAIN SELECT b from t2 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL a 10 NULL 16 Using index 1 SIMPLE t2 range NULL a 5 NULL 9 Using index for group-by
# Expect: Using index for group-by # Expect: Using index for group-by
analyze table t2; analyze table t2;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
@ -2263,11 +2263,11 @@ INSERT INTO t2(col1, col2) VALUES
explain explain
select col1 f1, col2 f2, col1 f3 from t2 group by f1; select col1 f1, col2 f2, col1 f3 from t2 group by f1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL idx 10 NULL 20 Using index 1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by
explain explain
select SQL_BIG_RESULT col1 f1, col2 f2, col1 f3 from t2 group by f1; select SQL_BIG_RESULT col1 f1, col2 f2, col1 f3 from t2 group by f1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL idx 10 NULL 20 Using index; Using filesort 1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by
explain explain
select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2; select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -2275,7 +2275,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain explain
select col1 f1, col1 f2 from t2 group by f1, 1+1; select col1 f1, col1 f2 from t2 group by f1, 1+1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL idx 10 NULL 20 Using index 1 SIMPLE t2 range NULL idx 5 NULL 7 Using index for group-by
explain explain
select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2, f3+0; select col1 f1, col2 f2, col1 f3 from t2 group by f1, f2, f3+0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra

View File

@ -2080,7 +2080,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain extended select a1,a2,min(b),max(b) from t1 explain extended select a1,a2,min(b),max(b) from t1
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2; where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 100.00 Using where; Using index 1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 96.30 Using where; Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2` Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`
explain extended select a1,a2,b,min(c),max(c) from t1 explain extended select a1,a2,b,min(c),max(c) from t1
@ -2100,7 +2100,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL idx_t2_1 163 NULL 548 Using where; Using index 1 SIMPLE t2 index NULL idx_t2_1 163 NULL 548 Using where; Using index
explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b; explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 100.00 Using where; Using index 1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 96.30 Using where; Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1;
@ -2230,7 +2230,7 @@ a
BB BB
EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a; EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref PRIMARY PRIMARY 7 const 4 Using where; Using index 1 SIMPLE t1 range PRIMARY PRIMARY 7 NULL 1 Using where; Using index for group-by
EXPLAIN SELECT a FROM t1 WHERE a='BB' GROUP BY a; EXPLAIN SELECT a FROM t1 WHERE a='BB' GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref PRIMARY PRIMARY 7 const 1 Using where; Using index 1 SIMPLE t1 ref PRIMARY PRIMARY 7 const 1 Using where; Using index
@ -2368,11 +2368,11 @@ CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c));
INSERT INTO t2 SELECT a,b,b FROM t1; INSERT INTO t2 SELECT a,b,b FROM t1;
explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by 1 SIMPLE t1 range a,b a 10 NULL 1 Using where; Using index for group-by
insert into t1 select 1,seq from seq_1_to_100; insert into t1 select 1,seq from seq_1_to_100;
explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by 1 SIMPLE t1 range a,b a 10 NULL 1 Using where; Using index for group-by
analyze table t1; analyze table t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Engine-independent statistics collected
@ -2388,7 +2388,7 @@ MIN(b) a
2 1 2 1
explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index 1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index for group-by
SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
MIN(c) MIN(c)
2 2
@ -2678,7 +2678,7 @@ a b
3 13 3 13
explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a; explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 range a,index a 5 NULL 3 100.00 Using where; Using index for group-by; Using temporary 1 SIMPLE t1 range a,index a 5 NULL 1 100.00 Using where; Using index for group-by; Using temporary
Warnings: Warnings:
Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,max(`test`.`t1`.`b`) + 1 AS `max(b)+1` from `test`.`t1` where `test`.`t1`.`a` = 0 group by `test`.`t1`.`a` Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,max(`test`.`t1`.`b`) + 1 AS `max(b)+1` from `test`.`t1` where `test`.`t1`.`a` = 0 group by `test`.`t1`.`a`
drop table t1; drop table t1;
@ -3579,7 +3579,7 @@ a c COUNT(DISTINCT c, a, b)
EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2 EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range a a 5 NULL 1 Using where; Using index 1 SIMPLE t2 range a a 15 NULL 1 Using where; Using index for group-by
SELECT COUNT(DISTINCT c, a, b) FROM t2 SELECT COUNT(DISTINCT c, a, b) FROM t2
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;
COUNT(DISTINCT c, a, b) COUNT(DISTINCT c, a, b)
@ -3673,7 +3673,7 @@ insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'),
(3, 'A'), (3, 'B'), (3, 'C'), (3, 'D'); (3, 'A'), (3, 'B'), (3, 'C'), (3, 'D');
explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL f1 5 NULL 8 Using index for group-by (scanning) 1 SIMPLE t1 range NULL f1 5 NULL 8 Using index for group-by
SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1;
f1 COUNT(DISTINCT f2) f1 COUNT(DISTINCT f2)
1 3 1 3
@ -4036,10 +4036,10 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
explain select min(a) from t1 where a between "a" and "Cafeeeeeeeeeeeeeeeeeeeeeeeeee"; explain select min(a) from t1 where a between "a" and "Cafeeeeeeeeeeeeeeeeeeeeeeeeee";
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index 1 SIMPLE t1 range a a 13 NULL 2 Using where; Using index
explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb" and "Cafe2"; explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb" and "Cafe2";
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index 1 SIMPLE t1 range a a 13 NULL 2 Using where; Using index
drop table t1; drop table t1;
# #
# MDEV-15433: Optimizer does not use group by optimization with distinct # MDEV-15433: Optimizer does not use group by optimization with distinct
@ -4126,7 +4126,7 @@ CREATE TABLE t1 (p int NOT NULL, a int NOT NULL, PRIMARY KEY (p,a));
insert into t1 select 2,seq from seq_0_to_1000; insert into t1 select 2,seq from seq_0_to_1000;
EXPLAIN select MIN(a) from t1 where p = 2 group by p; EXPLAIN select MIN(a) from t1 where p = 2 group by p;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 10 Using where; Using index for group-by 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using where; Using index for group-by
SELECT MIN(a) from t1 where p = 2 group by p; SELECT MIN(a) from t1 where p = 2 group by p;
MIN(a) MIN(a)
0 0

View File

@ -1392,6 +1392,7 @@ SELECT a, c, COUNT(DISTINCT c, a, b) FROM t2 GROUP BY a, b, c;
EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2 EXPLAIN SELECT COUNT(DISTINCT c, a, b) FROM t2
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;
SELECT COUNT(DISTINCT c, a, b) FROM t2 SELECT COUNT(DISTINCT c, a, b) FROM t2
WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c; WHERE a > 5 AND b BETWEEN 10 AND 20 GROUP BY a, b, c;

View File

@ -73,10 +73,10 @@ insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
alter table t1 drop primary key, add primary key (f2, f1); alter table t1 drop primary key, add primary key (f2, f1);
explain select distinct f1 a, f1 b from t1; explain select distinct f1 a, f1 b from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index; Using temporary 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary
explain select distinct f1, f2 from t1; explain select distinct f1, f2 from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index 1 SIMPLE t1 ALL NULL NULL NULL NULL 4
drop table t1; drop table t1;
create table t1(pk int primary key) engine=innodb; create table t1(pk int primary key) engine=innodb;
create view v1 as select pk from t1 where pk < 20; create view v1 as select pk from t1 where pk < 20;
@ -108,7 +108,7 @@ CREATE TABLE t1 (a CHAR(1), b CHAR(1), PRIMARY KEY (a,b)) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd'); INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd');
EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 2 NULL 2 Using where; Using index 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b';
COUNT(DISTINCT a) COUNT(DISTINCT a)
1 1
@ -118,7 +118,7 @@ ENGINE=InnoDB;
INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd'); INSERT INTO t1 VALUES ('a', 'b'), ('c', 'd');
EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; EXPLAIN SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL a 2 NULL 2 Using where; Using index 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b'; SELECT COUNT(DISTINCT a) FROM t1 WHERE b = 'b';
COUNT(DISTINCT a) COUNT(DISTINCT a)
1 1
@ -162,7 +162,7 @@ ANALYZE TABLE t2;
EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F') EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F')
GROUP BY c1; GROUP BY c1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range k1 k1 5 NULL 31 Using where; Using index 1 SIMPLE t1 range k1 k1 5 NULL 31 Using where
SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F') SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' AND i2 = 17) OR ( c1 = 'F')
GROUP BY c1; GROUP BY c1;
c1 max(i2) c1 max(i2)
@ -171,7 +171,7 @@ F 30
EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR ( c1 = 'F' AND i2 = 17)) EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR ( c1 = 'F' AND i2 = 17))
GROUP BY c1; GROUP BY c1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range k1 k1 5 NULL 31 Using where; Using index 1 SIMPLE t1 range k1 k1 5 NULL 31 Using where
SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR ( c1 = 'F' AND i2 = 17)) SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR ( c1 = 'F' AND i2 = 17))
GROUP BY c1; GROUP BY c1;
c1 max(i2) c1 max(i2)
@ -180,7 +180,7 @@ F 17
EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR c1 = 'F' ) AND ( i2 = 17 ) EXPLAIN SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR c1 = 'F' ) AND ( i2 = 17 )
GROUP BY c1; GROUP BY c1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range k1 k1 5 NULL 2 Using where; Using index for group-by 1 SIMPLE t1 range k1 k1 5 NULL 2 Using where
SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR c1 = 'F' ) AND ( i2 = 17 ) SELECT c1, max(i2) FROM t1 WHERE (c1 = 'C' OR c1 = 'F' ) AND ( i2 = 17 )
GROUP BY c1; GROUP BY c1;
c1 max(i2) c1 max(i2)
@ -190,7 +190,7 @@ EXPLAIN SELECT c1, max(i2) FROM t1
WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 ))) WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 )))
GROUP BY c1; GROUP BY c1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range k1 k1 5 NULL 3 Using where; Using index 1 SIMPLE t1 range k1 k1 5 NULL 3 Using where
SELECT c1, max(i2) FROM t1 SELECT c1, max(i2) FROM t1
WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 ))) WHERE ((c1 = 'C' AND (i2 = 40 OR i2 = 30)) OR ( c1 = 'F' AND (i2 = 40 )))
GROUP BY c1; GROUP BY c1;
@ -200,7 +200,7 @@ EXPLAIN SELECT c1, i1, max(i2) FROM t2
WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ) WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )
GROUP BY c1,i1; GROUP BY c1,i1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range k2 k2 5 NULL 60 Using where; Using index 1 SIMPLE t2 range k2 k2 5 NULL 60 Using where
SELECT c1, i1, max(i2) FROM t2 SELECT c1, i1, max(i2) FROM t2
WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ) WHERE (c1 = 'C' OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )
GROUP BY c1,i1; GROUP BY c1,i1;
@ -211,7 +211,7 @@ EXPLAIN SELECT c1, i1, max(i2) FROM t2
WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )) WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ))
GROUP BY c1,i1; GROUP BY c1,i1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range k2 k2 5 NULL 60 Using where; Using index 1 SIMPLE t2 range k2 k2 5 NULL 60 Using where
SELECT c1, i1, max(i2) FROM t2 SELECT c1, i1, max(i2) FROM t2
WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 )) WHERE (((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35)) AND ( i2 = 17 ))
GROUP BY c1,i1; GROUP BY c1,i1;
@ -222,7 +222,7 @@ EXPLAIN SELECT c1, i1, max(i2) FROM t2
WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 )) WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 ))
GROUP BY c1,i1; GROUP BY c1,i1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k2 9 NULL 180 Using where; Using index 1 SIMPLE t2 index k2 k2 9 NULL 180 Using where
SELECT c1, i1, max(i2) FROM t2 SELECT c1, i1, max(i2) FROM t2
WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 )) WHERE ((c1 = 'C' AND i1 < 40) OR ( c1 = 'F' AND i1 < 35) OR ( i2 = 17 ))
GROUP BY c1,i1; GROUP BY c1,i1;

View File

@ -255,17 +255,15 @@ DROP TABLE t1;
# IGNORED fulltext indexes. # IGNORED fulltext indexes.
# #
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)); CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
INSERT INTO t1 VALUES('Some data', 'for full-text search'); INSERT INTO t1 VALUES('Some data', 'for full-text search'),("hello","hello world"),("mars","here I come");
ANALYZE TABLE t1; SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
Table Op Msg_type Msg_text a b
test.t1 analyze status Engine-independent statistics collected Some data for full-text search
test.t1 analyze Warning Engine-independent statistics are not collected for column 'b' EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
test.t1 analyze status OK
EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections");
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 fulltext a a 0 1 Using where 1 SIMPLE t1 fulltext a a 0 1 Using where
ALTER TABLE t1 ALTER INDEX a IGNORED; ALTER TABLE t1 ALTER INDEX a IGNORED;
EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections"); SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
ERROR HY000: Can't find FULLTEXT index matching the column list ERROR HY000: Can't find FULLTEXT index matching the column list
DROP TABLE t1; DROP TABLE t1;
# #

View File

@ -222,13 +222,11 @@ DROP TABLE t1;
--echo # IGNORED fulltext indexes. --echo # IGNORED fulltext indexes.
--echo # --echo #
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)); CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
INSERT INTO t1 VALUES('Some data', 'for full-text search'); INSERT INTO t1 VALUES('Some data', 'for full-text search'),("hello","hello world"),("mars","here I come");
ANALYZE TABLE t1;
let $query=
EXPLAIN SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("collections");
let $query=SELECT * FROM t1 WHERE MATCH(a, b) AGAINST ("search");
--eval $query --eval $query
--eval EXPLAIN $query
ALTER TABLE t1 ALTER INDEX a IGNORED; ALTER TABLE t1 ALTER INDEX a IGNORED;
--error ER_FT_MATCHING_KEY_NOT_FOUND --error ER_FT_MATCHING_KEY_NOT_FOUND

View File

@ -75,7 +75,7 @@ EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 300000; WHERE Name LIKE 'M%' AND Population > 300000;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge Population,Name Name,Population 35,4 NULL # Using sort_intersect(Name,Population); Using where 1 SIMPLE City range Population,Name Name 35 NULL # Using index condition; Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Name LIKE 'M%' AND Population > 7000000; WHERE Name LIKE 'M%' AND Population > 7000000;
@ -712,7 +712,7 @@ EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%'; WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge Population,Country,Name Name,Country 35,3 NULL # Using sort_intersect(Name,Country); Using where 1 SIMPLE City range Population,Country,Name Name 35 NULL # Using index condition; Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%';

View File

@ -378,7 +378,7 @@ EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%'; WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge Population,Name,Country Name,Population,Country # NULL # Using sort_intersect(Name,Population,Country); Using where 1 SIMPLE City index_merge Population,Name,Country Name,Population # NULL # Using sort_intersect(Name,Population); Using where
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%'; WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%';
ID Name Country Population ID Name Country Population
@ -469,12 +469,12 @@ EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%'; WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where 1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where 1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%'; WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%';
@ -491,7 +491,7 @@ SELECT * FROM City
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
AND Country BETWEEN 'S' AND 'Z' ; AND Country BETWEEN 'S' AND 'Z' ;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where 1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where
SELECT * FROM City USE INDEX () SELECT * FROM City USE INDEX ()
WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%'; WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%';
ID Name Country Population ID Name Country Population
@ -708,7 +708,7 @@ EXPLAIN
SELECT * FROM City WHERE SELECT * FROM City WHERE
Name LIKE 'M%' AND Population > 1500000; Name LIKE 'M%' AND Population > 1500000;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge Population,Name Population,Name 4,35 NULL # Using sort_intersect(Population,Name); Using where 1 SIMPLE City range Population,Name Population 4 NULL # Using index condition; Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%'; WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%';
@ -723,13 +723,13 @@ EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where 1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where
EXPLAIN EXPLAIN
SELECT * FROM City SELECT * FROM City
WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000
AND Country BETWEEN 'S' AND 'Z'; AND Country BETWEEN 'S' AND 'Z';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where 1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where
SELECT * FROM City WHERE SELECT * FROM City WHERE
Name LIKE 'C%' AND Population > 1000000; Name LIKE 'C%' AND Population > 1000000;
ID Name Country Population ID Name Country Population

View File

@ -582,7 +582,7 @@ set @tmp_index_merge_ror_cpk=@@optimizer_switch;
set optimizer_switch='extended_keys=off'; set optimizer_switch='extended_keys=off';
explain select * from t1 where pk1 < 7500 and key1 = 10; explain select * from t1 where pk1 < 7500 and key1 = 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge PRIMARY,key1 key1,PRIMARY 4,4 NULL ROWS Using intersect(key1,PRIMARY); Using where 1 SIMPLE t1 ref PRIMARY,key1 key1 4 const ROWS Using index condition
set optimizer_switch=@tmp_index_merge_ror_cpk; set optimizer_switch=@tmp_index_merge_ror_cpk;
explain select * from t1 where pktail1ok=1 and key1=10; explain select * from t1 where pktail1ok=1 and key1=10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -654,7 +654,7 @@ f1
EXPLAIN SELECT t1.f1 FROM t1 EXPLAIN SELECT t1.f1 FROM t1
WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 Using index 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1
2 SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index 2 SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index
DROP TABLE t1,t2; DROP TABLE t1,t2;
# #
@ -827,13 +827,13 @@ INDEX (b)
INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_100; INSERT INTO t1 SELECT seq, seq, seq from seq_1_to_100;
EXPLAIN SELECT * FROM t1 WHERE a='1' OR b < 5; EXPLAIN SELECT * FROM t1 WHERE a='1' OR b < 5;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge PRIMARY,b b,PRIMARY 5,3074 NULL 5 Using sort_union(b,PRIMARY); Using where 1 SIMPLE t1 ALL PRIMARY,b NULL NULL NULL 100 Using where
SELECT * FROM t1 WHERE a='1' OR b < 5; SELECT * FROM t1 WHERE a='1' OR b < 5;
a b c a b c
1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4 4 4
1 1 1
DROP TABLE t1; DROP TABLE t1;
SET sort_buffer_size= @save_sort_buffer_size; SET sort_buffer_size= @save_sort_buffer_size;
disconnect disable_purge; disconnect disable_purge;

View File

@ -232,7 +232,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index i1_3,i2_3 i321 12 NULL 1024 Using where; Using index 1 SIMPLE t2 index i1_3,i2_3 i321 12 NULL 1024 Using where; Using index
explain select key7 from t2 where key1 <100 or key2 < 100; explain select key7 from t2 where key1 <100 or key2 < 100;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index_merge i1_3,i2_3 i1_3,i2_3 4,4 NULL 186 Using sort_union(i1_3,i2_3); Using where 1 SIMPLE t2 ALL i1_3,i2_3 NULL NULL NULL 1024 Using where
create table t4 ( create table t4 (
key1a int not null, key1a int not null,
key1b int not null, key1b int not null,
@ -405,8 +405,8 @@ from t0 as A straight_join t0 as B
where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1); and (B.key1 = 1 and B.key2 = 1 and B.key3 = 1 and B.key4=1 and B.key5=1 and B.key6=1 and B.key7 = 1 or B.key8=1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE A index_merge i1,i2,i3,i4,i5,i6,i7?,i8 i2,i3,i4,i5,i6,i7?,i8 X NULL # Using union(intersect(i2,i3,i4,i5,i6,i7?),i8); Using where 1 SIMPLE A ALL i1,i2,i3,i4,i5,i6,i7?,i8 NULL NULL NULL # Using where
1 SIMPLE B index_merge i1,i2,i3,i4,i5,i6,i7?,i8 i2,i3,i4,i5,i6,i7?,i8 X NULL # Using union(intersect(i2,i3,i4,i5,i6,i7?),i8); Using where; Using join buffer (flat, BNL join) 1 SIMPLE B ALL i1,i2,i3,i4,i5,i6,i7?,i8 NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5) select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.key5 + B.key5)
from t0 as A straight_join t0 as B from t0 as A straight_join t0 as B
where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1) where (A.key1 = 1 and A.key2 = 1 and A.key3 = 1 and A.key4=1 and A.key5=1 and A.key6=1 and A.key7 = 1 or A.key8=1)
@ -762,13 +762,13 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b st_a,st_b 4,4 NULL 3515 Using intersect(st_a,st_b); Using where; Using index 1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b st_a,st_b 4,4 NULL 3515 Using intersect(st_a,st_b); Using where; Using index
explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1; explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,stb_swt1a_2b,stb_swt1b,st_b st_b 4 const 15094 Using where 1 SIMPLE t1 ALL sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,stb_swt1a_2b,stb_swt1b,st_b NULL NULL NULL 64806 Using where
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1; explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a sta_swt21a 12 const,const,const 971 1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a sta_swt21a 12 const,const,const 971
explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1; explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1b 8 const,const 3885 Using where 1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1a_2b 8 const,const 3879 Using where
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt12a,stb_swt1a_2b 12,12 NULL 58 Using intersect(sta_swt12a,stb_swt1a_2b); Using where 1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt12a,stb_swt1a_2b 12,12 NULL 58 Using intersect(sta_swt12a,stb_swt1a_2b); Using where
@ -783,7 +783,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b) explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b)
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge sta_swt1a,sta_swt2a,st_a,st_b sta_swt1a,sta_swt2a,st_b 8,8,4 NULL 223 Using intersect(sta_swt1a,sta_swt2a,st_b); Using where 1 SIMPLE t1 index_merge sta_swt1a,sta_swt2a,st_a,st_b sta_swt1a,sta_swt2a 8,8 NULL 960 Using intersect(sta_swt1a,sta_swt2a); Using where
explain select * from t1 explain select * from t1
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1; where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -1558,7 +1558,7 @@ This should be intersect:
set optimizer_switch=default; set optimizer_switch=default;
explain select * from t1 where a=10 and b=10; explain select * from t1 where a=10 and b=10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 1 Using intersect(a,b); Using where 1 SIMPLE t1 ref|filter a,b a|b 5|5 const 49 (1%) Using where; Using rowid filter
No intersect when index_merge is disabled: No intersect when index_merge is disabled:
set optimizer_switch='default,index_merge=off,rowid_filter=off'; set optimizer_switch='default,index_merge=off,rowid_filter=off';
explain select * from t1 where a=10 and b=10; explain select * from t1 where a=10 and b=10;

View File

@ -37,6 +37,7 @@ INDEX_STATISTICS TABLE_SCHEMA
KEYWORDS WORD KEYWORDS WORD
KEY_CACHES KEY_CACHE_NAME KEY_CACHES KEY_CACHE_NAME
KEY_COLUMN_USAGE CONSTRAINT_SCHEMA KEY_COLUMN_USAGE CONSTRAINT_SCHEMA
OPTIMIZER_COSTS ENGINE
PARAMETERS SPECIFIC_SCHEMA PARAMETERS SPECIFIC_SCHEMA
PARTITIONS TABLE_SCHEMA PARTITIONS TABLE_SCHEMA
PLUGINS PLUGIN_NAME PLUGINS PLUGIN_NAME
@ -97,6 +98,7 @@ INDEX_STATISTICS TABLE_SCHEMA
KEYWORDS WORD KEYWORDS WORD
KEY_CACHES KEY_CACHE_NAME KEY_CACHES KEY_CACHE_NAME
KEY_COLUMN_USAGE CONSTRAINT_SCHEMA KEY_COLUMN_USAGE CONSTRAINT_SCHEMA
OPTIMIZER_COSTS ENGINE
PARAMETERS SPECIFIC_SCHEMA PARAMETERS SPECIFIC_SCHEMA
PARTITIONS TABLE_SCHEMA PARTITIONS TABLE_SCHEMA
PLUGINS PLUGIN_NAME PLUGINS PLUGIN_NAME

View File

@ -71,6 +71,7 @@ INDEX_STATISTICS
KEYWORDS KEYWORDS
KEY_CACHES KEY_CACHES
KEY_COLUMN_USAGE KEY_COLUMN_USAGE
OPTIMIZER_COSTS
OPTIMIZER_TRACE OPTIMIZER_TRACE
PARAMETERS PARAMETERS
PARTITIONS PARTITIONS
@ -1434,7 +1435,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tables ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort 1 SIMPLE tables ALL NULL NULL NULL NULL NULL Open_frm_only; Scanned all databases; Using filesort
explain select * from (select table_name from information_schema.tables) as a; explain select * from (select table_name from information_schema.tables) as a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 100
2 DERIVED tables ALL NULL NULL NULL NULL NULL Skip_open_table; Scanned all databases 2 DERIVED tables ALL NULL NULL NULL NULL NULL Skip_open_table; Scanned all databases
set optimizer_switch=@tmp_optimizer_switch; set optimizer_switch=@tmp_optimizer_switch;
drop view v1; drop view v1;

View File

@ -5,16 +5,13 @@
select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 const,const 1 Using index -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 const,const 1 Using index
+1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey,i_l_shipdate 4,4 NULL 1 Using intersect(i_l_orderkey,i_l_shipdate); Using where; Using index +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index
flush status; flush status;
select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01';
count(*) count(*)
@@ -17,9 +17,9 @@ @@ -19,7 +19,7 @@
show status like 'handler_read%';
Variable_name Value
Handler_read_first 0 Handler_read_first 0
-Handler_read_key 1 Handler_read_key 1
+Handler_read_key 2
Handler_read_last 0 Handler_read_last 0
-Handler_read_next 1 -Handler_read_next 1
+Handler_read_next 6 +Handler_read_next 6
@ -98,16 +95,13 @@
where l_shipdate='1992-07-01' and l_orderkey=130; where l_shipdate='1992-07-01' and l_orderkey=130;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey,i_l_shipdate 4,4 NULL 1 Using intersect(i_l_orderkey,i_l_shipdate); Using where; Using index +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index
flush status; flush status;
select max(l_linenumber) from lineitem select max(l_linenumber) from lineitem
where l_shipdate='1992-07-01' and l_orderkey=130; where l_shipdate='1992-07-01' and l_orderkey=130;
@@ -143,9 +143,9 @@ @@ -145,7 +145,7 @@
show status like 'handler_read%';
Variable_name Value
Handler_read_first 0 Handler_read_first 0
-Handler_read_key 1 Handler_read_key 1
+Handler_read_key 2
Handler_read_last 0 Handler_read_last 0
-Handler_read_next 0 -Handler_read_next 0
+Handler_read_next 6 +Handler_read_next 6
@ -178,7 +172,7 @@
where l_partkey between 1 and 10 group by l_partkey; where l_partkey between 1 and 10 group by l_partkey;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index for group-by -1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index for group-by
+1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_partkey 5 NULL # Using where; Using index +1 SIMPLE lineitem range i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 NULL # Using where; Using index
flush status; flush status;
select max(l_orderkey) from lineitem select max(l_orderkey) from lineitem
where l_partkey between 1 and 10 group by l_partkey; where l_partkey between 1 and 10 group by l_partkey;
@ -236,17 +230,17 @@
Handler_read_retry 0 Handler_read_retry 0
Handler_read_rnd 0 Handler_read_rnd 0
@@ -314,8 +314,8 @@ @@ -314,8 +314,8 @@
select * from t0, part ignore index (primary) select straight_join * from t0, part ignore index (primary)
where p_partkey=t0.a and p_size=1; where p_partkey=t0.a and p_size=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
-1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where -1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where
-1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1 -1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1
+1 SIMPLE t0 ALL NULL NULL NULL NULL 5 +1 SIMPLE t0 ALL NULL NULL NULL NULL 5
+1 SIMPLE part ref i_p_size i_p_size 5 const 5 Using index condition +1 SIMPLE part ref i_p_size i_p_size 5 const 5 Using index condition
select * from t0, part ignore index (primary) select straight_join * from t0, part ignore index (primary)
where p_partkey=t0.a and p_size=1; where p_partkey=t0.a and p_size=1;
a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment
@@ -494,7 +494,7 @@ @@ -495,7 +495,7 @@
select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a; select * from t1, t3 where t3.col1=t1.a and t3.col2=t1.a and t3.pk1=t1.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where
@ -255,7 +249,7 @@
drop table t1,t2,t3; drop table t1,t2,t3;
# #
# Bug mdev-4340: performance regression with extended_keys=on # Bug mdev-4340: performance regression with extended_keys=on
@@ -725,13 +725,13 @@ @@ -726,13 +726,13 @@
select * from t1 force index(index_date_updated) select * from t1 force index(index_date_updated)
where index_date_updated= 10 and index_id < 800; where index_date_updated= 10 and index_id < 800;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -271,7 +265,7 @@
drop table t0,t1,t2; drop table t0,t1,t2;
# #
# MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff' # MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff'
@@ -766,13 +766,14 @@ @@ -769,11 +769,12 @@
{ {
"table": { "table": {
"table_name": "t1", "table_name": "t1",
@ -285,12 +279,9 @@
+ "used_key_parts": ["f2"], + "used_key_parts": ["f2"],
+ "ref": ["const"], + "ref": ["const"],
"rows": 1, "rows": 1,
- "filtered": 50, "filtered": 100,
+ "filtered": 100,
"index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'",
"attached_condition": "t1.f1 <= '3'" @@ -806,8 +807,8 @@
}
@@ -799,8 +800,8 @@
"access_type": "range", "access_type": "range",
"possible_keys": ["k1"], "possible_keys": ["k1"],
"key": "k1", "key": "k1",
@ -299,5 +290,5 @@
+ "key_length": "3007", + "key_length": "3007",
+ "used_key_parts": ["pk1", "f2"], + "used_key_parts": ["pk1", "f2"],
"rows": 1, "rows": 1,
"filtered": 50, "filtered": 100,
"index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'",

View File

@ -308,15 +308,15 @@ Handler_read_rnd_next 0
# when extended_keys=on # when extended_keys=on
# #
create table t0 (a int); create table t0 (a int);
insert into t0 values (1), (2), (3), (4), (5); insert into t0 select seq from seq_1_to_5;
create index i_p_size on part(p_size); create index i_p_size on part(p_size);
explain explain
select * from t0, part ignore index (primary) select straight_join * from t0, part ignore index (primary)
where p_partkey=t0.a and p_size=1; where p_partkey=t0.a and p_size=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where 1 SIMPLE t0 ALL NULL NULL NULL NULL 5 Using where
1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1 1 SIMPLE part eq_ref i_p_size i_p_size 9 const,dbt3_s001.t0.a 1
select * from t0, part ignore index (primary) select straight_join * from t0, part ignore index (primary)
where p_partkey=t0.a and p_size=1; where p_partkey=t0.a and p_size=1;
a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment a p_partkey p_name p_mfgr p_brand p_type p_size p_container p_retailprice p_comment
2 2 blush rosy metallic lemon navajo Manufacturer#1 Brand#13 LARGE BRUSHED BRASS 1 LG CASE 902 final platelets hang f 2 2 blush rosy metallic lemon navajo Manufacturer#1 Brand#13 LARGE BRUSHED BRASS 1 LG CASE 902 final platelets hang f
@ -381,17 +381,18 @@ INSERT INTO t2 VALUES
(10), (11), (12), (13), (14), (10), (11), (12), (13), (14),
(15), (16), (17), (18), (19), (24); (15), (16), (17), (18), (19), (24);
EXPLAIN EXPLAIN
SELECT a FROM t1 AS t, t2 SELECT a FROM t1 AS t, t2 as t2_out
WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t index a,b b 7 NULL 10 Using index 1 PRIMARY t1 index b b 7 NULL 10 Using index; Start temporary
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index 1 PRIMARY t ref a,b b 3 test.t1.b 2 Using index
1 PRIMARY t1 ref b b 3 test.t.b 2 Using index 1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; End temporary; Using join buffer (flat, BNL join)
1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; FirstMatch(t2) 1 PRIMARY t2_out eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index
SELECT a FROM t1 AS t, t2 SELECT a FROM t1 AS t, t2 as t2_out
WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b);
a a
24 24
Last_query_cost 0.119652
DROP TABLE t1,t2; DROP TABLE t1,t2;
# #
# LP Bug #923236: hash join + extended_keys = on # LP Bug #923236: hash join + extended_keys = on
@ -638,7 +639,7 @@ test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK test.t2 analyze status OK
explain select a from t1 where b is null order by a desc limit 2; explain select a from t1 where b is null order by a desc limit 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range b b 9 NULL 3 Using where; Using filesort 1 SIMPLE t1 index b PRIMARY 8 NULL 2 Using where
select a from t1 where b is null order by a desc limit 2; select a from t1 where b is null order by a desc limit 2;
a a
3 3
@ -774,7 +775,7 @@ EXPLAIN
"key_length": "3070", "key_length": "3070",
"used_key_parts": ["f2", "pk1"], "used_key_parts": ["f2", "pk1"],
"rows": 1, "rows": 1,
"filtered": 50, "filtered": 100,
"index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'",
"attached_condition": "t1.f1 <= '3'" "attached_condition": "t1.f1 <= '3'"
} }
@ -808,7 +809,7 @@ EXPLAIN
"key_length": "3011", "key_length": "3011",
"used_key_parts": ["pk1", "f2", "pk2"], "used_key_parts": ["pk1", "f2", "pk2"],
"rows": 1, "rows": 1,
"filtered": 50, "filtered": 100,
"index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'",
"attached_condition": "t1.f1 <= '3'" "attached_condition": "t1.f1 <= '3'"
} }

View File

@ -4,6 +4,7 @@
--source include/innodb_prefix_index_cluster_optimization.inc --source include/innodb_prefix_index_cluster_optimization.inc
--source include/no_valgrind_without_big.inc --source include/no_valgrind_without_big.inc
--source include/have_sequence.inc
SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB'; SET SESSION DEFAULT_STORAGE_ENGINE='InnoDB';
@ -156,14 +157,14 @@ show status like 'handler_read%';
--echo # --echo #
create table t0 (a int); create table t0 (a int);
insert into t0 values (1), (2), (3), (4), (5); insert into t0 select seq from seq_1_to_5;
create index i_p_size on part(p_size); create index i_p_size on part(p_size);
explain explain
select * from t0, part ignore index (primary) select straight_join * from t0, part ignore index (primary)
where p_partkey=t0.a and p_size=1; where p_partkey=t0.a and p_size=1;
select * from t0, part ignore index (primary) select straight_join * from t0, part ignore index (primary)
where p_partkey=t0.a and p_size=1; where p_partkey=t0.a and p_size=1;
drop table t0; drop table t0;
@ -240,10 +241,11 @@ INSERT INTO t2 VALUES
(15), (16), (17), (18), (19), (24); (15), (16), (17), (18), (19), (24);
EXPLAIN EXPLAIN
SELECT a FROM t1 AS t, t2 SELECT a FROM t1 AS t, t2 as t2_out
WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b);
SELECT a FROM t1 AS t, t2 SELECT a FROM t1 AS t, t2 as t2_out
WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); WHERE t2_out.c = t.a AND t.b IN (SELECT b FROM t1, t2 WHERE b = t.b);
--source include/last_query_cost.inc
DROP TABLE t1,t2; DROP TABLE t1,t2;

View File

@ -414,7 +414,7 @@ WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1 ORDER BY c1
LIMIT 1; LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,k1 PRIMARY 4 NULL 3 Using where; Using filesort 1 SIMPLE t1 range PRIMARY,k1 k1 5 NULL 4 Using where; Using index
DROP TABLE t1; DROP TABLE t1;
# #
# #
@ -437,7 +437,7 @@ WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using where 2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using where
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL # Using join buffer (flat, BNL join)
SELECT * FROM t1 SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
pk i pk i
@ -455,9 +455,10 @@ c1 INT NOT NULL,
PRIMARY KEY (pk) PRIMARY KEY (pk)
); );
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
insert into t1 select seq,seq from seq_100_to_110;
EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 15 Using where
SET SESSION optimizer_switch='index_condition_pushdown=off'; SET SESSION optimizer_switch='index_condition_pushdown=off';
SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1 pk c1
@ -465,6 +466,17 @@ pk c1
2 7 2 7
4 3 4 3
5 1 5 1
100 100
101 101
102 102
103 103
104 104
105 105
106 106
107 107
108 108
109 109
110 110
DROP TABLE t1; DROP TABLE t1;
set optimizer_switch= @save_optimizer_switch; set optimizer_switch= @save_optimizer_switch;
# #
@ -682,7 +694,6 @@ DROP TABLE t1;
# #
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b)); CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill'); INSERT INTO t1 VALUES (1,4,'Ill');
insert into t1 select seq+100,5,seq from seq_1_to_100;
CREATE TABLE t2 (a varchar(1024), KEY (a(512))); CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w'); ('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
@ -816,6 +827,8 @@ test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK test.t2 analyze status OK
SET @save_optimize_switch=@@optimizer_switch; SET @save_optimize_switch=@@optimizer_switch;
SET optimizer_switch='materialization=on'; SET optimizer_switch='materialization=on';
set @save_optimizer_where_cost=@@optimizer_where_cost;
set @@optimizer_where_cost=1;
EXPLAIN EXPLAIN
SELECT COUNT(*) FROM t1 AS t, t2 SELECT COUNT(*) FROM t1 AS t, t2
WHERE c = g WHERE c = g
@ -839,6 +852,7 @@ OR a = 0 AND h < 'z' );
COUNT(*) COUNT(*)
1478 1478
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
set @@optimizer_where_cost=@save_optimizer_where_cost;
DROP TABLE t1,t2; DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables # check "Handler_pushed" status varuiables
CREATE TABLE t1 ( CREATE TABLE t1 (

View File

@ -833,6 +833,7 @@ insert into t1 values (1), (2), (3), (4), (5);
begin; begin;
--echo # Acquire SR metadata lock on t1. --echo # Acquire SR metadata lock on t1.
--sorted_result
select * from t1; select * from t1;
connection con1; connection con1;

View File

@ -346,7 +346,7 @@ invisible a b
9 7 7 9 7 7
explain select * from t1 where invisible =9; explain select * from t1 where invisible =9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL invisible NULL NULL NULL 7 Using where 1 SIMPLE t1 ref invisible invisible 5 const 7
alter table t1 add x int default 3; alter table t1 add x int default 3;
select invisible, a ,b from t1; select invisible, a ,b from t1;
invisible a b invisible a b
@ -368,11 +368,11 @@ drop index invisible on t1;
ERROR 42000: Can't DROP INDEX `invisible`; check that it exists ERROR 42000: Can't DROP INDEX `invisible`; check that it exists
explain select * from t1 where invisible =9; explain select * from t1 where invisible =9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL invisible NULL NULL NULL 7 Using where 1 SIMPLE t1 ref invisible invisible 5 const 7
create index invisible on t1(c); create index invisible on t1(c);
explain select * from t1 where invisible =9; explain select * from t1 where invisible =9;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL invisible_2 NULL NULL NULL 7 Using where 1 SIMPLE t1 ref invisible_2 invisible_2 5 const 7
show indexes in t1; show indexes in t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
t1 1 b 1 b A NULL NULL NULL YES BTREE NO t1 1 b 1 b A NULL NULL NULL YES BTREE NO

View File

@ -65,7 +65,7 @@ id id
NULL 75 NULL 75
explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null; explain select t1.id,t2.id from t2 left join t1 on t1.id>=74 and t1.id<=0 where t2.id=75 and t1.id is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY NULL NULL NULL 1 Impossible ON condition 1 SIMPLE t1 const PRIMARY NULL NULL NULL 0 Impossible ON condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where
explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0; explain select t1.id, t2.id from t1, t2 where t2.id = t1.id and t1.id <0 and t1.id > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -880,10 +880,10 @@ select @a:= A.a + 10*(B.a + 10*C.a), @a, 'filler' from t1 A, t1 B, t1 C;
insert into t3 select * from t2 where a < 800; insert into t3 select * from t2 where a < 800;
explain select * from t2,t3 where t2.a < 200 and t2.b=t3.b; explain select * from t2,t3 where t2.a < 200 and t2.b=t3.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range a,b a 5 NULL 198 Using index condition; Using where 1 SIMPLE t2 ALL a,b NULL NULL NULL 1000 Using where
1 SIMPLE t3 ref b b 5 test.t2.b 1 1 SIMPLE t3 ref b b 5 test.t2.b 1
drop table t1, t2, t3; drop table t1, t2, t3;
create table t1 (a int); create table t1 (a int) engine=myisam;
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, primary key(a)); create table t2 (a int, b int, primary key(a));
insert into t2 select @v:=A.a+10*B.a, @v from t1 A, t1 B; insert into t2 select @v:=A.a+10*B.a, @v from t1 A, t1 B;
@ -892,14 +892,17 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 1 SIMPLE t1 ALL NULL NULL NULL NULL 10
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 3.508545 Last_query_cost 0.011600
select 'The cost of accessing t1 (dont care if it changes' '^'; select 'The cost of accessing t1 (dont care if it changes' '^';
The cost of accessing t1 (dont care if it changes The cost of accessing t1 (dont care if it changes
The cost of accessing t1 (dont care if it changes^ The cost of accessing t1 (dont care if it changes^
select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z; select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z;
Z Z
vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv
set @@optimizer_cache_hit_ratio=0; select @@myisam.optimizer_disk_read_ratio;
@@myisam.optimizer_disk_read_ratio
0.020000
set global myisam.optimizer_disk_read_ratio=0;
explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b; explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
@ -907,11 +910,14 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE B eq_ref PRIMARY PRIMARY 4 test.A.b 1 1 SIMPLE B eq_ref PRIMARY PRIMARY 4 test.A.b 1
show status like 'Last_query_cost'; show status like 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 48.527829 Last_query_cost 0.046590
select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z; select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z;
Z Z
^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error ^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error
set @@optimizer_cache_hit_ratio=default; set global myisam.optimizer_disk_read_ratio=default;
select @@myisam.optimizer_disk_read_ratio;
@@myisam.optimizer_disk_read_ratio
0.020000
drop table t1, t2; drop table t1, t2;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT); CREATE TABLE t1 (a INT PRIMARY KEY, b INT);
CREATE TABLE t2 (c INT PRIMARY KEY, d INT); CREATE TABLE t2 (c INT PRIMARY KEY, d INT);
@ -1278,7 +1284,7 @@ test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK test.t2 analyze status OK
explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL ix2 NULL NULL NULL 2 Using where; Using temporary; Using filesort 1 SIMPLE t2 ref ix2 ix2 5 const 2 Using index condition; Using temporary; Using filesort
1 SIMPLE t1 ref ix1 ix1 5 test.t2.v 1 1 SIMPLE t1 ref ix1 ix1 5 test.t2.v 1
FLUSH STATUS; FLUSH STATUS;
SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1;
@ -1286,14 +1292,14 @@ pk v pk v
SHOW STATUS LIKE 'Handler_read_%'; SHOW STATUS LIKE 'Handler_read_%';
Variable_name Value Variable_name Value
Handler_read_first 0 Handler_read_first 0
Handler_read_key 0 Handler_read_key 1
Handler_read_last 0 Handler_read_last 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
Handler_read_retry 0 Handler_read_retry 0
Handler_read_rnd 0 Handler_read_rnd 0
Handler_read_rnd_deleted 0 Handler_read_rnd_deleted 0
Handler_read_rnd_next 4 Handler_read_rnd_next 1
DROP TABLE t1, t2; DROP TABLE t1, t2;
End of 5.1 tests End of 5.1 tests
# #
@ -1329,9 +1335,9 @@ FROM t4 JOIN
(t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1) (t1 JOIN t3 ON t3.ref_t1=t1.c1 JOIN t2 ON t2.ref_t1=t1.c1)
ON t4.ref_t1=t1.c1; ON t4.ref_t1=t1.c1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join)
EXPLAIN EXPLAIN
SELECT * SELECT *
@ -1340,9 +1346,9 @@ FROM t4 STRAIGHT_JOIN
ON t4.ref_t1=t1.c1; ON t4.ref_t1=t1.c1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 4 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t4.ref_t1 1
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join)
drop table t1,t2,t3,t4; drop table t1,t2,t3,t4;
End of 5.2 tests End of 5.2 tests
# #
@ -1479,8 +1485,8 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE DU system dog_id NULL NULL NULL 1 1 SIMPLE DU system dog_id NULL NULL NULL 1
1 SIMPLE D system PRIMARY NULL NULL NULL 1 1 SIMPLE D system PRIMARY NULL NULL NULL 1
1 SIMPLE DSAR system NULL NULL NULL NULL 1 1 SIMPLE DSAR system NULL NULL NULL NULL 1
1 SIMPLE DT ALL t_id NULL NULL NULL 2 Using where 1 SIMPLE DSA ref PRIMARY PRIMARY 4 const 3 Using where; Using index
1 SIMPLE DSA ref PRIMARY PRIMARY 8 const,test.DT.t_id,func 1 Using index 1 SIMPLE DT ref t_id t_id 2 test.DSA.t_id 2 Using where
SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR
WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND
DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id; DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id;

View File

@ -685,7 +685,7 @@ drop table t1, t2, t3;
# BUG#14940 {Wrong query plan is chosen because of odd results of # BUG#14940 {Wrong query plan is chosen because of odd results of
# prev_record_reads() function } # prev_record_reads() function }
create table t1 (a int); create table t1 (a int) engine=myisam;
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, primary key(a)); create table t2 (a int, b int, primary key(a));
@ -697,11 +697,13 @@ select 'The cost of accessing t1 (dont care if it changes' '^';
select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z; select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z;
set @@optimizer_cache_hit_ratio=0; select @@myisam.optimizer_disk_read_ratio;
set global myisam.optimizer_disk_read_ratio=0;
explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b; explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b;
show status like 'Last_query_cost'; show status like 'Last_query_cost';
select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z; select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z;
set @@optimizer_cache_hit_ratio=default; set global myisam.optimizer_disk_read_ratio=default;
select @@myisam.optimizer_disk_read_ratio;
drop table t1, t2; drop table t1, t2;
# #

View File

@ -894,7 +894,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where
1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) 1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (flat, BNLH join); Using rowid filter
# Part 2, join_cache_level=3, Query 4 # Part 2, join_cache_level=3, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage FROM City,Country,CountryLanguage
@ -1102,7 +1102,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where
1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (incremental, BNLH join) 1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (incremental, BNLH join); Using rowid filter
# Part 2, join_cache_level=4, Query 4 # Part 2, join_cache_level=4, Query 4
SELECT City.Name, Country.Name, CountryLanguage.Language SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage FROM City,Country,CountryLanguage
@ -2162,7 +2162,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where
1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) 1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (flat, BNLH join); Using rowid filter
SELECT City.Name, Country.Name, CountryLanguage.Language SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND WHERE City.Country=Country.Code AND
@ -2266,7 +2266,7 @@ LENGTH(Language) < LENGTH(City.Name) - 2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where 1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where
1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.City.Country 185 Using where; Rowid-ordered scan; Using join buffer (incremental, BNLH join) 1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (incremental, BNLH join); Using rowid filter
SELECT City.Name, Country.Name, CountryLanguage.Language SELECT City.Name, Country.Name, CountryLanguage.Language
FROM City,Country,CountryLanguage FROM City,Country,CountryLanguage
WHERE City.Country=Country.Code AND WHERE City.Country=Country.Code AND
@ -3133,7 +3133,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t8 eq_ref PRIMARY PRIMARY 4 test.t7.artistid 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t8 eq_ref PRIMARY PRIMARY 4 test.t7.artistid 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t3 ref t3_metaid,t3_formatid,t3_metaidformatid t3_metaidformatid 4 test.t9.metaid 1 Using index condition; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t3 ref t3_metaid,t3_formatid,t3_metaidformatid t3_metaidformatid 4 test.t9.metaid 1 Using index condition; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t4 eq_ref PRIMARY,t4_formatclassid,t4_formats_idx PRIMARY 4 test.t3.formatid 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t4 eq_ref PRIMARY,t4_formatclassid,t4_formats_idx PRIMARY 4 test.t3.formatid 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t1 ALL t1_affiliateid,t1_metaid NULL NULL NULL 2 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t1 ref t1_affiliateid,t1_metaid t1_affiliateid 4 const 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t1.uniquekey, t1.xml AS affiliateXml, SELECT t1.uniquekey, t1.xml AS affiliateXml,
t8.name AS artistName, t8.artistid, t8.name AS artistName, t8.artistid,
t11.name AS genreName, t11.genreid, t11.priority AS genrePriority, t11.name AS genreName, t11.genreid, t11.priority AS genrePriority,
@ -3249,7 +3249,7 @@ Warning 1292 Truncated incorrect join_buffer_size value: '32'
set join_cache_level=8; set join_cache_level=8;
EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30; EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL idx NULL NULL NULL 7 Using where 1 SIMPLE t1 range idx idx 5 NULL 3 Using index condition; Using where; Rowid-ordered scan
1 SIMPLE t2 ref idx idx 5 test.t1.a 2 Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan 1 SIMPLE t2 ref idx idx 5 test.t1.a 2 Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30; SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
a b a b a b a b
@ -4398,9 +4398,9 @@ SELECT t2.v FROM t1, t2, t3
WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort 1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where 1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where
1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where
SELECT t2.v FROM t1, t2, t3 SELECT t2.v FROM t1, t2, t3
WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
@ -4415,9 +4415,9 @@ SELECT t2.v FROM t1, t2, t3
WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort 1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where 1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where
1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where
SELECT t2.v FROM t1, t2, t3 SELECT t2.v FROM t1, t2, t3
WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
@ -4433,9 +4433,9 @@ SELECT t2.v FROM t1, t2, t3
WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort 1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort
1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t2.v FROM t1, t2, t3 SELECT t2.v FROM t1, t2, t3
WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
@ -4450,9 +4450,9 @@ SELECT t2.v FROM t1, t2, t3
WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort 1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort
1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 ref idx2 idx2 3 test.t3.v 5 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t3 eq_ref PRIMARY,idx2 PRIMARY 4 test.t2.i 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t2.v FROM t1, t2, t3 SELECT t2.v FROM t1, t2, t3
WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
@ -4468,9 +4468,9 @@ SELECT t2.v FROM t1, t2, t3
WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort 1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort
1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 hash_ALL idx2 #hash#idx2 3 test.t3.v 44 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (incremental, BNLH join)
SELECT t2.v FROM t1, t2, t3 SELECT t2.v FROM t1, t2, t3
WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
@ -4485,9 +4485,9 @@ SELECT t2.v FROM t1, t2, t3
WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using index; Using temporary; Using filesort 1 SIMPLE t1 ALL idx2 NULL NULL NULL 44 Using where; Using temporary; Using filesort
1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE t2 index idx1 idx2 7 NULL 20 Using where; Using index; Using join buffer (flat, BNL join)
1 SIMPLE t1 hash_ALL idx2 #hash#idx2 3 test.t3.v 44 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t3 hash_ALL PRIMARY,idx2 #hash#PRIMARY 4 test.t2.i 20 Using where; Using join buffer (incremental, BNLH join)
SELECT t2.v FROM t1, t2, t3 SELECT t2.v FROM t1, t2, t3
WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100 WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
GROUP BY t2.v ORDER BY t1.pk,t2.v; GROUP BY t2.v ORDER BY t1.pk,t2.v;
@ -5120,7 +5120,7 @@ EXPLAIN
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan; Using join buffer (flat, BNL join)
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
@ -5130,7 +5130,7 @@ EXPLAIN
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Rowid-ordered scan
1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join)
SELECT * FROM t1,t2 SELECT * FROM t1,t2
WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
@ -6035,12 +6035,12 @@ f1 f2
EXPLAIN EXTENDED SELECT * FROM temp EXPLAIN EXTENDED SELECT * FROM temp
WHERE (f1,f2) IN (SELECT t1.i1, t1.v1 FROM (t2 JOIN t1 ON (t1.v1 = t2.v1))); WHERE (f1,f2) IN (SELECT t1.i1, t1.v1 FROM (t2 JOIN t1 ON (t1.v1 = t2.v1)));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1 100.00 1 PRIMARY temp ALL NULL NULL NULL NULL 7 100.00
1 PRIMARY temp hash_ALL NULL #hash#$hj 9 test.t1.i1,test.t1.v1 7 100.00 Using where; Using join buffer (flat, BNLH join) 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00
2 MATERIALIZED t1 ALL NULL NULL NULL NULL 1 100.00 Using where 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 1 100.00 Using where
2 MATERIALIZED t2 hash_index v1 #hash#v1:v1 4:9 test.t1.v1 10 33.33 Using index; Using join buffer (flat, BNLH join) 2 MATERIALIZED t2 hash_index v1 #hash#v1:v1 4:9 test.t1.v1 10 33.33 Using index; Using join buffer (flat, BNLH join)
Warnings: Warnings:
Note 1003 select `test`.`temp`.`f1` AS `f1`,`test`.`temp`.`f2` AS `f2` from `test`.`temp` semi join (`test`.`t2` join `test`.`t1`) where `test`.`temp`.`f1` = `test`.`t1`.`i1` and `test`.`t2`.`v1` = `test`.`t1`.`v1` and `test`.`temp`.`f2` = `test`.`t1`.`v1` Note 1003 select `test`.`temp`.`f1` AS `f1`,`test`.`temp`.`f2` AS `f2` from `test`.`temp` semi join (`test`.`t2` join `test`.`t1`) where `test`.`t2`.`v1` = `test`.`t1`.`v1`
DROP TABLE t1,t2,temp; DROP TABLE t1,t2,temp;
set join_cache_level=@save_join_cache_level; set join_cache_level=@save_join_cache_level;
# #
@ -6210,8 +6210,8 @@ a b c
explain select t1.a, t1.b, t1.c from t1,t2 explain select t1.a, t1.b, t1.c from t1,t2
where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c; where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index PRIMARY PRIMARY 12 NULL 2 Using index 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
1 SIMPLE t1 hash_ALL NULL #hash#$hj 15 test.t2.a,test.t2.b,test.t2.c 2 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 12:12 test.t1.c,test.t1.a,test.t1.b 2 Using index; Using join buffer (flat, BNLH join)
drop table t1,t2; drop table t1,t2;
set join_cache_level=@save_join_cache_level; set join_cache_level=@save_join_cache_level;
# #
@ -6258,7 +6258,7 @@ EXPLAIN
{ {
"table": { "table": {
"table_name": "a", "table_name": "a",
"access_type": "index", "access_type": "range",
"possible_keys": ["PRIMARY"], "possible_keys": ["PRIMARY"],
"key": "PRIMARY", "key": "PRIMARY",
"key_length": "4", "key_length": "4",
@ -6279,7 +6279,7 @@ EXPLAIN
"key_length": "10", "key_length": "10",
"used_key_parts": ["kp1", "kp2"], "used_key_parts": ["kp1", "kp2"],
"rows": 836, "rows": 836,
"filtered": 76, "filtered": 9.090909004,
"index_condition": "b.kp2 <= 10", "index_condition": "b.kp2 <= 10",
"attached_condition": "b.kp2 <= 10 and b.col1 + 1 < 33333" "attached_condition": "b.kp2 <= 10 and b.col1 + 1 < 33333"
}, },

View File

@ -1062,7 +1062,7 @@ t0.b=t1.b AND
(t8.b=t9.b OR t8.c IS NULL) AND (t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1); (t9.a=1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 Using where 1 SIMPLE t0 ref idx_a idx_a 5 const 2 100.00 Using where
1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00
1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where 1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where
@ -1284,8 +1284,8 @@ NULL 2 2
DELETE FROM t3; DELETE FROM t3;
EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const c NULL NULL NULL 1 Impossible ON condition 1 SIMPLE t3 const c NULL NULL NULL 0 Impossible ON condition
1 SIMPLE t2 const b NULL NULL NULL 1 Impossible ON condition 1 SIMPLE t2 const b NULL NULL NULL 0 Impossible ON condition
1 SIMPLE t1 index NULL a 5 NULL 21 Using index 1 SIMPLE t1 index NULL a 5 NULL 21 Using index
SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
a b c a b c

View File

@ -652,7 +652,6 @@ t0.b=t1.b AND
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join)
@ -660,8 +659,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t8 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t8 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings: Warnings:
Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t8`.`b` = `test`.`t9`.`b` or `test`.`t8`.`c` is null) Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t9`.`b` = `test`.`t8`.`b` or `test`.`t8`.`c` is null)
SELECT t9.a,t9.b SELECT t9.a,t9.b
FROM t9; FROM t9;
a b a b
@ -920,7 +920,6 @@ t0.b=t1.b AND
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join)
1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t5 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
@ -928,8 +927,9 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join)
1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
Warnings: Warnings:
Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`a` > 0 and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t8`.`b` = `test`.`t9`.`b` or `test`.`t8`.`c` is null) Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`a` > 0 and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t9`.`b` = `test`.`t8`.`b` or `test`.`t8`.`c` is null)
INSERT INTO t4 VALUES (-3,12,0), (-4,13,0), (-1,11,0), (-3,11,0), (-5,15,0); INSERT INTO t4 VALUES (-3,12,0), (-4,13,0), (-1,11,0), (-3,11,0), (-5,15,0);
INSERT INTO t5 VALUES (-3,11,0), (-2,12,0), (-3,13,0), (-4,12,0); INSERT INTO t5 VALUES (-3,11,0), (-2,12,0), (-3,13,0), (-4,12,0);
CREATE INDEX idx_b ON t4(b); CREATE INDEX idx_b ON t4(b);
@ -1071,7 +1071,7 @@ t0.b=t1.b AND
(t8.b=t9.b OR t8.c IS NULL) AND (t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1); (t9.a=1);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 Using where 1 SIMPLE t0 ref idx_a idx_a 5 const 2 100.00 Using where
1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join)
1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t5 ALL idx_b NULL NULL NULL 7 100.00 Using where; Using join buffer (incremental, BNL join)
@ -1293,8 +1293,8 @@ NULL 2 2
DELETE FROM t3; DELETE FROM t3;
EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const c NULL NULL NULL 1 Impossible ON condition 1 SIMPLE t3 const c NULL NULL NULL 0 Impossible ON condition
1 SIMPLE t2 const b NULL NULL NULL 1 Impossible ON condition 1 SIMPLE t2 const b NULL NULL NULL 0 Impossible ON condition
1 SIMPLE t1 index NULL a 5 NULL 21 Using index 1 SIMPLE t1 index NULL a 5 NULL 21 Using index
SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c; SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
a b c a b c
@ -2086,7 +2086,7 @@ ON t6.b >= 2 AND t5.b=t7.b AND
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t5 ALL NULL NULL NULL NULL 3 1 SIMPLE t5 ALL NULL NULL NULL NULL 3
1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter 1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
1 SIMPLE t6 ALL PRIMARY,b_i NULL NULL NULL 7 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t6 range|filter PRIMARY,b_i PRIMARY|b_i 4|5 NULL 3 (86%) Using where; Rowid-ordered scan; Using join buffer (incremental, BNL join); Using rowid filter
1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5 FROM t5
@ -2120,9 +2120,9 @@ FROM t5 LEFT JOIN
ON (t5.b=t8.b); ON (t5.b=t8.b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t5 ALL NULL NULL NULL NULL 2 1 SIMPLE t5 ALL NULL NULL NULL NULL 2
1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 const PRIMARY PRIMARY 4 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t7 const PRIMARY PRIMARY 4 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t8 ALL b_i NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5 LEFT JOIN FROM t5 LEFT JOIN
(t6 LEFT JOIN t7 ON t7.a=1, t8) (t6 LEFT JOIN t7 ON t7.a=1, t8)
@ -2137,9 +2137,9 @@ FROM t5 LEFT JOIN
ON (t5.b=t8.b); ON (t5.b=t8.b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t5 ALL NULL NULL NULL NULL 2 1 SIMPLE t5 ALL NULL NULL NULL NULL 2
1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t7 ref b_i b_i 5 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t7 ref b_i b_i 5 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t8 ALL b_i NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5 LEFT JOIN FROM t5 LEFT JOIN
(t6 LEFT JOIN t7 ON t7.b=2, t8) (t6 LEFT JOIN t7 ON t7.b=2, t8)
@ -2154,9 +2154,9 @@ FROM t5 LEFT JOIN
ON (t5.b=t8.b); ON (t5.b=t8.b);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t5 ALL NULL NULL NULL NULL 2 1 SIMPLE t5 ALL NULL NULL NULL NULL 2
1 SIMPLE t8 ALL b_i NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t6 ALL NULL NULL NULL NULL 1 Using join buffer (incremental, BNL join)
1 SIMPLE t7 const PRIMARY PRIMARY 4 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t7 const PRIMARY PRIMARY 4 const 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5 LEFT JOIN FROM t5 LEFT JOIN
(t8, t6 LEFT JOIN t7 ON t7.a=1) (t8, t6 LEFT JOIN t7 ON t7.a=1)

View File

@ -1430,7 +1430,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort 1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
@ -1852,7 +1852,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort 1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
@ -2260,7 +2260,7 @@ create table t2 (a int, b int, c int, key(b), key(c));
insert into t2 select insert into t2 select
@a:=A.a + 10*B.a+100*C.a, @a:=A.a + 10*B.a+100*C.a,
IF(@a<900, NULL, @a), IF(@a<900, NULL, @a),
IF(@a<450, NULL, @a) IF(@a<400, NULL, @a)
from t1 A, t1 B, t1 C; from t1 A, t1 B, t1 C;
delete from t1 where a=0; delete from t1 where a=0;
# Check that there are different #rows of NULLs for b and c, both !=10: # Check that there are different #rows of NULLs for b and c, both !=10:
@ -2269,7 +2269,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref b b 5 const 780 Using index condition 1 SIMPLE t2 ref b b 5 const 780 Using index condition
explain select * from t2 force index (c) where c is null; explain select * from t2 force index (c) where c is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref c c 5 const 312 Using index condition 1 SIMPLE t2 ref c c 5 const 282 Using index condition
explain select * from t1 left join t2 on t2.b is null; explain select * from t1 left join t2 on t2.b is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 1 SIMPLE t1 ALL NULL NULL NULL NULL 9
@ -2277,7 +2277,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select * from t1 left join t2 on t2.c is null; explain select * from t1 left join t2 on t2.c is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 1 SIMPLE t1 ALL NULL NULL NULL NULL 9
1 SIMPLE t2 ref c c 5 const 312 Using where 1 SIMPLE t2 ALL c NULL NULL NULL 1000 Using where
drop table t1,t2; drop table t1,t2;
# #
# MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause # MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause

View File

@ -1813,7 +1813,7 @@ create table t2 (a int, b int, c int, key(b), key(c));
insert into t2 select insert into t2 select
@a:=A.a + 10*B.a+100*C.a, @a:=A.a + 10*B.a+100*C.a,
IF(@a<900, NULL, @a), IF(@a<900, NULL, @a),
IF(@a<450, NULL, @a) IF(@a<400, NULL, @a)
from t1 A, t1 B, t1 C; from t1 A, t1 B, t1 C;
delete from t1 where a=0; delete from t1 where a=0;

View File

@ -435,46 +435,48 @@ left join t16 on t15.o1 = t16.p1
where t1.a10 = 1; where t1.a10 = 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where 1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index 1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where; Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where
1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1 1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1
1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 Using index 1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 Using index 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where; Using index 1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where
1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1
1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where 1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where
1 SIMPLE l2 eq_ref PRIMARY PRIMARY 4 test.t11.k4 1 Using where 1 SIMPLE l2 eq_ref PRIMARY PRIMARY 4 test.t11.k4 1 Using where
1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1 1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1
1 SIMPLE t13 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index 1 SIMPLE t13 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index
1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where; Using index 1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where
1 SIMPLE m2 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index 1 SIMPLE m2 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index
1 SIMPLE l3 eq_ref PRIMARY PRIMARY 4 test.m2.m2 1 Using where 1 SIMPLE l3 eq_ref PRIMARY PRIMARY 4 test.m2.m2 1 Using where
1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where 1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where
1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where; Using index 1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where
1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where 1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where
explain select * from v1; explain select * from v1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where 1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where
1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 Using index 1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where; Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.b2 1 Using where
1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1 1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1
1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 Using index 1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 Using index 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1
1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where
1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where; Using index 1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where
1 SIMPLE e2 eq_ref PRIMARY PRIMARY 4 test.t6.f1 1 Using where
1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1
1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t1.a5 1
1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where 1 SIMPLE t12 eq_ref PRIMARY PRIMARY 4 test.t11.k3 1 Using where
1 SIMPLE l2 eq_ref PRIMARY PRIMARY 4 test.t11.k4 1 Using where 1 SIMPLE l2 eq_ref PRIMARY PRIMARY 4 test.t11.k4 1 Using where
1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1 1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1
1 SIMPLE t13 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index 1 SIMPLE t13 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index
1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where; Using index 1 SIMPLE l4 eq_ref PRIMARY PRIMARY 4 test.t13.m2 1 Using where
1 SIMPLE m2 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index 1 SIMPLE m2 ref PRIMARY,m3 m3 8 const,test.t1.a1 1 Using index
1 SIMPLE l3 eq_ref PRIMARY PRIMARY 4 test.m2.m2 1 Using where 1 SIMPLE l3 eq_ref PRIMARY PRIMARY 4 test.m2.m2 1 Using where
1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where 1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where
1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where; Using index 1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where
1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where 1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where
drop view v1; drop view v1;
drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16; drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16;

View File

@ -1437,7 +1437,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort 1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
@ -1859,7 +1859,7 @@ WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 system PRIMARY NULL NULL NULL 1 1 SIMPLE t1 system PRIMARY NULL NULL NULL 1
1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index; Using filesort 1 SIMPLE t2 ref PRIMARY PRIMARY 4 const 1 Using where; Using index
SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1 SELECT * FROM t1 LEFT JOIN t2 ON t2.f1 = t1.f1
WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL WHERE t1.f1 = 4 AND t2.f1 IS NOT NULL AND t2.f2 IS NOT NULL
GROUP BY t2.f1, t2.f2; GROUP BY t2.f1, t2.f2;
@ -2267,7 +2267,7 @@ create table t2 (a int, b int, c int, key(b), key(c));
insert into t2 select insert into t2 select
@a:=A.a + 10*B.a+100*C.a, @a:=A.a + 10*B.a+100*C.a,
IF(@a<900, NULL, @a), IF(@a<900, NULL, @a),
IF(@a<450, NULL, @a) IF(@a<400, NULL, @a)
from t1 A, t1 B, t1 C; from t1 A, t1 B, t1 C;
delete from t1 where a=0; delete from t1 where a=0;
# Check that there are different #rows of NULLs for b and c, both !=10: # Check that there are different #rows of NULLs for b and c, both !=10:
@ -2276,7 +2276,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref b b 5 const 780 Using index condition 1 SIMPLE t2 ref b b 5 const 780 Using index condition
explain select * from t2 force index (c) where c is null; explain select * from t2 force index (c) where c is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref c c 5 const 312 Using index condition 1 SIMPLE t2 ref c c 5 const 282 Using index condition
explain select * from t1 left join t2 on t2.b is null; explain select * from t1 left join t2 on t2.b is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 1 SIMPLE t1 ALL NULL NULL NULL NULL 9
@ -2284,7 +2284,7 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select * from t1 left join t2 on t2.c is null; explain select * from t1 left join t2 on t2.c is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 9 1 SIMPLE t1 ALL NULL NULL NULL NULL 9
1 SIMPLE t2 ref c c 5 const 312 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t2 ALL c NULL NULL NULL 1000 Using where; Using join buffer (flat, BNL join)
drop table t1,t2; drop table t1,t2;
# #
# MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause # MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause
@ -2783,8 +2783,8 @@ id select_type table type possible_keys key key_len ref rows Extra
explain select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5; explain select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 1 SIMPLE t1 ALL NULL NULL NULL NULL 10
1 SIMPLE t3 hash_range a #hash#$hj:a 5:5 test.t1.a 5 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using join buffer (incremental, BNL join) 1 SIMPLE t3 hash_range a #hash#$hj:a 5:5 test.t1.a 5 Using where; Rowid-ordered scan; Using join buffer (incremental, BNLH join)
# #
# .. part 2: make sure condition selectivity can use the condition too. # .. part 2: make sure condition selectivity can use the condition too.
# #

View File

@ -631,19 +631,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort
SHOW STATUS LIKE 'Last_query_cost'; SHOW STATUS LIKE 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 0.014749 Last_query_cost 0.014784
EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a; EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort
SHOW STATUS LIKE 'Last_query_cost'; SHOW STATUS LIKE 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 0.014749 Last_query_cost 0.014784
EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a; EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL a 5 NULL 6 1 SIMPLE t1 index NULL a 5 NULL 6
SHOW STATUS LIKE 'Last_query_cost'; SHOW STATUS LIKE 'Last_query_cost';
Variable_name Value Variable_name Value
Last_query_cost 0.014749 Last_query_cost 0.014784
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-21480: Unique key using ref access though eq_ref access can be used # MDEV-21480: Unique key using ref access though eq_ref access can be used

View File

@ -434,7 +434,7 @@ p i a
3 1 yyyy 3 1 yyyy
4 3 zzzz 4 3 zzzz
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
VARIABLE_NAME VARIABLE_VALUE VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0 KEY_BLOCKS_NOT_FLUSHED 0
@ -482,7 +482,7 @@ p i a
3 1 yyyy 3 1 yyyy
4 3 zzzz 4 3 zzzz
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
VARIABLE_NAME VARIABLE_VALUE VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0 KEY_BLOCKS_NOT_FLUSHED 0
@ -527,7 +527,7 @@ p i a
3 1 yyyy 3 1 yyyy
4 3 zzzz 4 3 zzzz
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
VARIABLE_NAME VARIABLE_VALUE VARIABLE_NAME VARIABLE_VALUE
KEY_BLOCKS_NOT_FLUSHED 0 KEY_BLOCKS_NOT_FLUSHED 0
@ -583,7 +583,7 @@ p i a
3 1 yyyy 3 1 yyyy
4 3 zzzz 4 3 zzzz
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.key_caches where segment_number is null; select * from information_schema.key_caches where segment_number is null;
KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES
default 2 NULL 32768 1024 4 # 0 21 0 26 6 default 2 NULL 32768 1024 4 # 0 21 0 26 6
@ -627,10 +627,14 @@ select * from information_schema.key_caches where segment_number is null;
KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES
default 2 NULL 32768 1024 # # 0 6749 # 3684 103 default 2 NULL 32768 1024 # # 0 6749 # 3684 103
small NULL NULL 1048576 1024 # # 0 0 # 0 0 small NULL NULL 1048576 1024 # # 0 0 # 0 0
analyze table t2;
Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status OK
flush tables; flush tables;
flush status; flush status;
update t1 set a='zzzz' where a='qqqq'; update t1 set a='zzzz' where a='qqqq';
update t2 set i=1 where i=2; set statement optimizer_scan_setup_cost=0 for update t2 set i=1 where i=2;
select * from information_schema.key_caches where segment_number is null; select * from information_schema.key_caches where segment_number is null;
KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES
default 2 NULL 32768 1024 # # 0 3076 18 1552 18 default 2 NULL 32768 1024 # # 0 3076 18 1552 18
@ -699,7 +703,7 @@ update t2 set p=p+3000, i=2 where a='qqqq';
select * from information_schema.key_caches where key_cache_name like "key%" select * from information_schema.key_caches where key_cache_name like "key%"
and segment_number is null; and segment_number is null;
KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES
keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19 keycache1 7 NULL 262143 2048 25 # 0 2082 25 1071 19
set global keycache2.key_buffer_size=1024*1024; set global keycache2.key_buffer_size=1024*1024;
cache index t2 in keycache2; cache index t2 in keycache2;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
@ -712,7 +716,7 @@ keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3
select * from information_schema.key_caches where key_cache_name like "key%" select * from information_schema.key_caches where key_cache_name like "key%"
and segment_number is null; and segment_number is null;
KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES
keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19 keycache1 7 NULL 262143 2048 25 # 0 2082 25 1071 19
keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3 keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3
cache index t2 in keycache1; cache index t2 in keycache1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
@ -753,7 +757,7 @@ select * from information_schema.key_caches where segment_number is null;
KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES
default 2 NULL 32768 1024 # # 0 3172 24 1552 18 default 2 NULL 32768 1024 # # 0 3172 24 1552 18
small NULL NULL 1048576 1024 # # 0 0 0 0 0 small NULL NULL 1048576 1024 # # 0 0 0 0 0
keycache1 7 NULL 262143 2048 # # 0 3277 43 1594 30 keycache1 7 NULL 262143 2048 # # 0 3229 43 1594 30
keycache2 NULL NULL 1048576 1024 # # 0 6 6 3 3 keycache2 NULL NULL 1048576 1024 # # 0 6 6 3 3
set global keycache1.key_cache_block_size=2*1024; set global keycache1.key_cache_block_size=2*1024;
insert into t2 values (7000, 3, 'yyyy'); insert into t2 values (7000, 3, 'yyyy');

View File

@ -299,7 +299,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
select * from t1; select * from t1;
select * from t2; select * from t2;
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
select variable_value into @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; select variable_value into @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
@ -331,8 +331,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
select * from t1; select * from t1;
select * from t2; select * from t2;
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
select variable_value < @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; select variable_value < @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
@ -357,7 +356,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
select * from t1; select * from t1;
select * from t2; select * from t2;
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused'; select * from information_schema.session_status where variable_name like 'key_%' and variable_name != 'Key_blocks_unused';
select variable_value = @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; select variable_value = @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused';
@ -389,7 +388,7 @@ insert into t2 values (1, 1, 'qqqq'), (2, 1, 'pppp'),
select * from t1; select * from t1;
select * from t2; select * from t2;
update t1 set p=3 where p=1; update t1 set p=3 where p=1;
update t2 set i=2 where i=1; set statement optimizer_scan_setup_cost=0 for update t2 set i=2 where i=1;
--replace_column 7 # --replace_column 7 #
select * from information_schema.key_caches where segment_number is null; select * from information_schema.key_caches where segment_number is null;
@ -422,9 +421,10 @@ select * from t2 where p between 1010 and 1020 ;
--replace_column 6 # 7 # 10 # --replace_column 6 # 7 # 10 #
select * from information_schema.key_caches where segment_number is null; select * from information_schema.key_caches where segment_number is null;
analyze table t2;
flush tables; flush status; flush tables; flush status;
update t1 set a='zzzz' where a='qqqq'; update t1 set a='zzzz' where a='qqqq';
update t2 set i=1 where i=2; set statement optimizer_scan_setup_cost=0 for update t2 set i=1 where i=2;
--replace_column 6 # 7 # --replace_column 6 # 7 #
select * from information_schema.key_caches where segment_number is null; select * from information_schema.key_caches where segment_number is null;

View File

@ -211,51 +211,48 @@ explain
select * from t1 select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11); where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1 select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11); where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 11);
c1 c1
bb bb
Warnings: cc
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete dd
explain explain
select * from t1 select * from t1
where c1 IN (select * from t2 where c2 > ' ') where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 11; LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1 select * from t1
where c1 IN (select * from t2 where c2 > ' ') where c1 IN (select * from t2 where c2 > ' ')
LIMIT ROWS EXAMINED 11; LIMIT ROWS EXAMINED 11;
c1 c1
bb bb
Warnings: cc
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete dd
explain explain
select * from t1 select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0) where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 11; LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 2 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * from t1 select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0) where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)
LIMIT ROWS EXAMINED 11; LIMIT ROWS EXAMINED 11;
c1 c1
bb bb
Warnings: cc
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete dd
explain explain
select * from t1i select * from t1i
where c1 IN (select * from t2i where c2 > ' ') where c1 IN (select * from t2i where c2 > ' ')
LIMIT ROWS EXAMINED 6; LIMIT ROWS EXAMINED 6;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1i index PRIMARY PRIMARY 2 NULL 4 Using where; Using index 1 PRIMARY t1i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index
1 PRIMARY t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index 1 PRIMARY t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index
select * from t1i select * from t1i
where c1 IN (select * from t2i where c2 > ' ') where c1 IN (select * from t2i where c2 > ' ')
@ -395,7 +392,7 @@ select * from t1i
where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17; where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1i index NULL PRIMARY 2 NULL 4 Using where; Using index 1 PRIMARY t1i index NULL PRIMARY 2 NULL 4 Using where; Using index
2 MATERIALIZED t2i index PRIMARY PRIMARY 2 NULL 4 Using where; Using index 2 MATERIALIZED t2i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index
select * from t1i select * from t1i
where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17; where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17;
c1 c1
@ -416,24 +413,22 @@ c1
bb bb
cc cc
dd dd
select * from v1 LIMIT ROWS EXAMINED 17; select * from v1 LIMIT ROWS EXAMINED 10;
c1
bb
cc
dd
select * from v1 LIMIT ROWS EXAMINED 8;
c1 c1
bb bb
cc cc
dd dd
Warnings: Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 18 rows, which exceeds LIMIT ROWS EXAMINED (17). The query result may be incomplete Warning 1931 Query execution was interrupted. The query examined at least 9 rows, which exceeds LIMIT ROWS EXAMINED (8). The query result may be incomplete
select * from v1 LIMIT ROWS EXAMINED 16; select * from v1 LIMIT ROWS EXAMINED 3;
c1 c1
bb
cc
Warnings: Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 17 rows, which exceeds LIMIT ROWS EXAMINED (16). The query result may be incomplete Warning 1931 Query execution was interrupted. The query examined at least 4 rows, which exceeds LIMIT ROWS EXAMINED (3). The query result may be incomplete
select * from v1 LIMIT ROWS EXAMINED 11;
c1
bb
Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete
drop view v1; drop view v1;
explain explain
select * select *
@ -441,17 +436,16 @@ from (select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp
LIMIT ROWS EXAMINED 11; LIMIT ROWS EXAMINED 11;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 2 func 1 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where
select * select *
from (select * from t1 from (select * from t1
where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp
LIMIT ROWS EXAMINED 11; LIMIT ROWS EXAMINED 11;
c1 c1
bb bb
Warnings: cc
Warning 1931 Query execution was interrupted. The query examined at least 12 rows, which exceeds LIMIT ROWS EXAMINED (11). The query result may be incomplete dd
========================================================================= =========================================================================
Aggregation Aggregation
========================================================================= =========================================================================

View File

@ -277,9 +277,9 @@ create view v1 as
select * from t1 where c1 IN (select * from t2 where c2 > ' '); select * from t1 where c1 IN (select * from t2 where c2 > ' ');
select * from v1; select * from v1;
select * from v1 LIMIT ROWS EXAMINED 17; select * from v1 LIMIT ROWS EXAMINED 10;
select * from v1 LIMIT ROWS EXAMINED 16; select * from v1 LIMIT ROWS EXAMINED 8;
select * from v1 LIMIT ROWS EXAMINED 11; select * from v1 LIMIT ROWS EXAMINED 3;
drop view v1; drop view v1;

View File

@ -7,7 +7,7 @@ explain select 1 from
(select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top (select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top
join t1 on f1 = f3 where f3 = 'aaaa' order by val; join t1 on f1 = f3 where f3 = 'aaaa' order by val;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1 Using index 1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1
1 PRIMARY <derived2> ref key0 key0 13 const 0 Using where; Using filesort 1 PRIMARY <derived2> ref key0 key0 13 const 0 Using where; Using filesort
2 DERIVED t4 ALL NULL NULL NULL NULL 1 2 DERIVED t4 ALL NULL NULL NULL NULL 1
2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) 2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)

View File

@ -648,6 +648,9 @@ insert into t1 values (1,''), (2,'');
explain select count(*) from t1 where a is null; explain select count(*) from t1 where a is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref idx idx 4 const 2 Using where 1 SIMPLE t1 ref idx idx 4 const 2 Using where
set statement optimizer_scan_setup_cost= 0 for explain select count(*) from t1 where a is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL idx NULL NULL NULL 4 Using where
drop table t1; drop table t1;
create table t1 (c1 int, c2 varchar(4) not null default '', create table t1 (c1 int, c2 varchar(4) not null default '',
key(c2(3))) default charset=utf8; key(c2(3))) default charset=utf8;

View File

@ -595,6 +595,7 @@ explain select count(*) from t1 where a is null;
select count(*) from t1 where a is null; select count(*) from t1 where a is null;
insert into t1 values (1,''), (2,''); insert into t1 values (1,''), (2,'');
explain select count(*) from t1 where a is null; explain select count(*) from t1 where a is null;
set statement optimizer_scan_setup_cost= 0 for explain select count(*) from t1 where a is null;
drop table t1; drop table t1;
# #

View File

@ -256,7 +256,7 @@ FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); 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 id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch 1 PRIMARY t2 ALL NULL NULL NULL NULL 3 33.33 Using where; FirstMatch
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b` < 3 Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b` < 3
@ -332,55 +332,58 @@ CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2), (3); INSERT INTO t1 VALUES (1), (2), (3);
CREATE TABLE t2 (b INT); CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1), (2), (3), (1000); INSERT INTO t2 VALUES (1), (2), (3), (1000);
CREATE TABLE t3 like t2;
insert into t3 select * from t2;
insert into t3 select seq from seq_1001_to_2000;
# #
# query: UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) # query: UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3)
# select: SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) # select: SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3)
# #
Warnings: Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY t1 ALL NULL NULL NULL NULL 3
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 1 PRIMARY t2 ALL NULL NULL NULL NULL 4
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 1004 Using where
FLUSH STATUS; FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); EXPLAIN EXTENDED UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3);
id select_type table type possible_keys key key_len ref rows filtered Extra 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 t1 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00 Using where 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 1004 100.00 Using where
# Status of EXPLAIN EXTENDED query # Status of EXPLAIN EXTENDED query
Variable_name Value Variable_name Value
Handler_read_key 4 Handler_read_key 6
FLUSH STATUS; FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t3 WHERE t3.b < 3);
id select_type table type possible_keys key key_len ref rows filtered Extra 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 t1 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join) 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00 Using where 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 1004 100.00 Using where
Warnings: 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` < 3 Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t3`) join `test`.`t2` where `test`.`t3`.`b` < 3
# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
Variable_name Value Variable_name Value
Handler_read_key 4 Handler_read_key 6
Warnings: Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
# Status of "equivalent" SELECT query execution: # Status of "equivalent" SELECT query execution:
Variable_name Value Variable_name Value
Handler_read_key 7 Handler_read_key 9
Handler_read_rnd_next 14 Handler_read_rnd_next 1014
# Status of testing query execution: # Status of testing query execution:
Variable_name Value Variable_name Value
Handler_read_key 7 Handler_read_key 9
Handler_read_rnd_next 19 Handler_read_rnd_next 1019
Handler_update 2 Handler_update 2
DROP TABLE t1, t2; DROP TABLE t1, t2, t3;
#8 #8
CREATE TABLE t1 (a INT); CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2), (3); INSERT INTO t1 VALUES (1), (2), (3);
@ -790,12 +793,12 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
EXPLAIN DELETE 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 Using where; Using filesort 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where
FLUSH STATUS; FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; 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 id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 100.00 Using where; Using filesort 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
# Status of EXPLAIN EXTENDED query # Status of EXPLAIN EXTENDED query
Variable_name Value Variable_name Value
Handler_read_key 3 Handler_read_key 3
@ -818,11 +821,8 @@ Handler_read_next 3
# Status of testing query execution: # Status of testing query execution:
Variable_name Value Variable_name Value
Handler_delete 3 Handler_delete 3
Handler_read_key 3 Handler_read_key 4
Handler_read_rnd 3 Handler_read_next 3
Handler_read_rnd_next 7
Sort_rows 3
Sort_scan 1
DROP TABLE t1; DROP TABLE t1;
#17 #17
@ -1003,10 +1003,9 @@ FLUSH TABLES;
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT a FROM t2); 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 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 t1 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 100.00
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where 1 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 # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution
Variable_name Value Variable_name Value
Handler_read_key 4 Handler_read_key 4
@ -1014,7 +1013,7 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
# Status of "equivalent" SELECT query execution: # Status of "equivalent" SELECT query execution:
Variable_name Value Variable_name Value
Handler_read_key 7 Handler_read_key 4
Handler_read_rnd_next 9 Handler_read_rnd_next 9
# Status of testing query execution: # Status of testing query execution:
Variable_name Value Variable_name Value
@ -2661,13 +2660,13 @@ Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be
EXPLAIN UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); 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 id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t1 ALL NULL NULL NULL NULL 2
2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 Using where 2 DEPENDENT SUBQUERY t2 ref IDX IDX 5 test.t1.f1 2
FLUSH STATUS; FLUSH STATUS;
FLUSH TABLES; FLUSH TABLES;
EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); 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 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 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where 2 DEPENDENT SUBQUERY t2 ref IDX IDX 5 test.t1.f1 2 100.00
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
# Status of EXPLAIN EXTENDED query # Status of EXPLAIN EXTENDED query
@ -2678,7 +2677,7 @@ FLUSH TABLES;
EXPLAIN EXTENDED SELECT (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1; 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 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 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where 2 DEPENDENT SUBQUERY t2 ref IDX IDX 5 test.t1.f1 2 100.00
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1
Note 1003 /* select#1 */ select <expr_cache><`test`.`t1`.`f1`>((/* select#2 */ 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` Note 1003 /* select#1 */ select <expr_cache><`test`.`t1`.`f1`>((/* select#2 */ 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`
@ -2689,12 +2688,14 @@ Warnings:
Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
# Status of "equivalent" SELECT query execution: # Status of "equivalent" SELECT query execution:
Variable_name Value Variable_name Value
Handler_read_key 9 Handler_read_key 11
Handler_read_rnd_next 9 Handler_read_next 2
Handler_read_rnd_next 3
# Status of testing query execution: # Status of testing query execution:
Variable_name Value Variable_name Value
Handler_read_key 7 Handler_read_key 9
Handler_read_rnd_next 9 Handler_read_next 2
Handler_read_rnd_next 3
Handler_update 2 Handler_update 2
DROP TABLE t1, t2; DROP TABLE t1, t2;

View File

@ -407,7 +407,7 @@ WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240
ORDER BY c1 ORDER BY c1
LIMIT 1; LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,k1 PRIMARY 4 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using filesort 1 SIMPLE t1 range|filter PRIMARY,k1 PRIMARY|k1 4|5 NULL 3 (50%) Using index condition; Using where; Rowid-ordered scan; Using filesort; Using rowid filter
DROP TABLE t1; DROP TABLE t1;
# #
# #
@ -429,8 +429,8 @@ SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index
2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using index condition 2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using index condition
2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join)
SELECT * FROM t1 SELECT * FROM t1
WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10);
pk i pk i
@ -448,9 +448,10 @@ c1 INT NOT NULL,
PRIMARY KEY (pk) PRIMARY KEY (pk)
); );
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
insert into t1 select seq,seq from seq_100_to_110;
EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 Using where 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 16 Using where
SET SESSION optimizer_switch='index_condition_pushdown=off'; SET SESSION optimizer_switch='index_condition_pushdown=off';
SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3); SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1 pk c1
@ -458,6 +459,17 @@ pk c1
2 7 2 7
4 3 4 3
5 1 5 1
100 100
101 101
102 102
103 103
104 104
105 105
106 106
107 107
108 108
109 109
110 110
DROP TABLE t1; DROP TABLE t1;
set optimizer_switch= @save_optimizer_switch; set optimizer_switch= @save_optimizer_switch;
# #
@ -506,7 +518,7 @@ WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan
1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join)
SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1
WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR
(t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6);
@ -675,7 +687,6 @@ DROP TABLE t1;
# #
CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b)); CREATE TABLE t1 (b int NOT NULL, c int, a varchar(1024), PRIMARY KEY (b));
INSERT INTO t1 VALUES (1,4,'Ill'); INSERT INTO t1 VALUES (1,4,'Ill');
insert into t1 select seq+100,5,seq from seq_1_to_100;
CREATE TABLE t2 (a varchar(1024), KEY (a(512))); CREATE TABLE t2 (a varchar(1024), KEY (a(512)));
INSERT INTO t2 VALUES INSERT INTO t2 VALUES
('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w'); ('Ill'), ('eckqzsflbzaffti'), ('w'), ('she'), ('gxbwypqtjzwywwer'), ('w');
@ -685,8 +696,8 @@ EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0) SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c; HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL # Using where; Using filesort 1 SIMPLE t1 system PRIMARY NULL NULL NULL #
1 SIMPLE t2 ref a a 515 test.t1.a # Using where 1 SIMPLE t2 ref a a 515 const # Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0) SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c; HAVING t1.c != 5 ORDER BY t1.c;
b c b c
@ -696,8 +707,8 @@ EXPLAIN
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0) SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c; HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL # Using where; Using filesort 1 SIMPLE t1 system PRIMARY NULL NULL NULL #
1 SIMPLE t2 ref a a 515 test.t1.a # Using where 1 SIMPLE t2 ref a a 515 const # Using where
SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0) SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c; HAVING t1.c != 5 ORDER BY t1.c;
b c b c
@ -809,6 +820,8 @@ test.t2 analyze status Engine-independent statistics collected
test.t2 analyze status Table is already up to date test.t2 analyze status Table is already up to date
SET @save_optimize_switch=@@optimizer_switch; SET @save_optimize_switch=@@optimizer_switch;
SET optimizer_switch='materialization=on'; SET optimizer_switch='materialization=on';
set @save_optimizer_where_cost=@@optimizer_where_cost;
set @@optimizer_where_cost=1;
EXPLAIN EXPLAIN
SELECT COUNT(*) FROM t1 AS t, t2 SELECT COUNT(*) FROM t1 AS t, t2
WHERE c = g WHERE c = g
@ -832,6 +845,7 @@ OR a = 0 AND h < 'z' );
COUNT(*) COUNT(*)
1478 1478
SET optimizer_switch=@save_optimizer_switch; SET optimizer_switch=@save_optimizer_switch;
set @@optimizer_where_cost=@save_optimizer_where_cost;
DROP TABLE t1,t2; DROP TABLE t1,t2;
# check "Handler_pushed" status varuiables # check "Handler_pushed" status varuiables
CREATE TABLE t1 ( CREATE TABLE t1 (

View File

@ -517,7 +517,7 @@ table3.col_varchar_key = table2.col_varchar_nokey AND
table3.pk<>0; table3.pk<>0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE table2 ALL col_varchar_key NULL NULL NULL 40 Using where 1 SIMPLE table2 ALL col_varchar_key NULL NULL NULL 40 Using where
1 SIMPLE table3 ref PRIMARY,col_varchar_key col_varchar_key 3 test.table2.col_varchar_key 5 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE table3 ALL PRIMARY,col_varchar_key NULL NULL NULL 40 Using where; Using join buffer (flat, BNL join)
set join_cache_level= @save_join_cache_level; set join_cache_level= @save_join_cache_level;
set join_buffer_size= @save_join_buffer_size; set join_buffer_size= @save_join_buffer_size;
drop table t1; drop table t1;
@ -572,8 +572,7 @@ Handler_mrr_rowid_refills 0
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int, b int, filler char(200), key(a)); create table t1 (a int, b int, filler char(200), key(a));
insert into t1 insert into t1 select seq, 123, 'filler' from seq_0_to_14999;
select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
explain select sum(b) from t1 where a < 10; explain select sum(b) from t1 where a < 10;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 9 Using index condition; Rowid-ordered scan 1 SIMPLE t1 range a a 5 NULL 9 Using index condition; Rowid-ordered scan

View File

@ -1,6 +1,8 @@
# #
# MRR/MyISAM tests. # MRR/MyISAM tests.
# #
--source include/have_sequence.inc
--disable_warnings --disable_warnings
drop table if exists t0, t1, t2, t3; drop table if exists t0, t1, t2, t3;
@ -278,8 +280,7 @@ show status like 'Handler_mrr%';
create table t0 (a int); create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (a int, b int, filler char(200), key(a)); create table t1 (a int, b int, filler char(200), key(a));
insert into t1 insert into t1 select seq, 123, 'filler' from seq_0_to_14999;
select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
explain select sum(b) from t1 where a < 10; explain select sum(b) from t1 where a < 10;
--echo # This should show one MRR scan and no re-fills: --echo # This should show one MRR scan and no re-fills:

View File

@ -764,6 +764,10 @@ The following specify which files/extra groups are read (specified before remain
key. key.
--optimizer-row-next-find-cost=# --optimizer-row-next-find-cost=#
Cost of finding the next row when scanning the table. Cost of finding the next row when scanning the table.
--optimizer-rowid-compare-cost=#
Cost of comparing two rowid's
--optimizer-rowid-copy-cost=#
Cost of copying a rowid
--optimizer-scan-setup-cost=# --optimizer-scan-setup-cost=#
Extra cost added to TABLE and INDEX scans to get Extra cost added to TABLE and INDEX scans to get
optimizer to prefer index lookups. optimizer to prefer index lookups.
@ -1748,6 +1752,8 @@ optimizer-prune-level 2
optimizer-row-copy-cost 6.0866e-05 optimizer-row-copy-cost 6.0866e-05
optimizer-row-lookup-cost 0.000130839 optimizer-row-lookup-cost 0.000130839
optimizer-row-next-find-cost 4.5916e-05 optimizer-row-next-find-cost 4.5916e-05
optimizer-rowid-compare-cost 2.653e-06
optimizer-rowid-copy-cost 2.653e-06
optimizer-scan-setup-cost 0.01 optimizer-scan-setup-cost 0.01
optimizer-search-depth 62 optimizer-search-depth 62
optimizer-selectivity-sampling-limit 100 optimizer-selectivity-sampling-limit 100

View File

@ -1,5 +1,6 @@
connect pipe_con,localhost,root,,,,,PIPE; connect pipe_con,localhost,root,,,,,PIPE;
drop table if exists t1,t2,t3,t4; drop table if exists t1,t2,t3,t4;
set @@default_storage_engine="aria";
CREATE TABLE t1 ( CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
@ -600,6 +601,9 @@ explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort 1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort
1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index
#
# Some test with ORDER BY and limit
#
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort 1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using filesort
@ -1289,7 +1293,7 @@ companynr tinyint(2) unsigned zerofill NOT NULL default '00',
companyname char(30) NOT NULL default '', companyname char(30) NOT NULL default '',
PRIMARY KEY (companynr), PRIMARY KEY (companynr),
UNIQUE KEY companyname(companyname) UNIQUE KEY companyname(companyname)
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; ) ENGINE=aria MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
companynr companyname companynr companyname
00 Unknown 00 Unknown
@ -1379,6 +1383,9 @@ explain select companynr,companyname from t4 left join t2 using (companynr) wher
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
delete from t2 where fld1=999999; delete from t2 where fld1=999999;
#
# Test left join optimization
#
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
@ -1393,15 +1400,15 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
@ -1417,11 +1424,11 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where 1 SIMPLE t4 range PRIMARY PRIMARY 1 NULL 12 Using index condition
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where 1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra

View File

@ -4,7 +4,7 @@ insert into t1 values (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
(10), (11), (12), (13), (14), (15), (16), (17), (18), (19); (10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
explain select * from t1 where not(not(a)); explain select * from t1 where not(not(a));
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 5 NULL 21 Using where; Using index 1 SIMPLE t1 range a a 5 NULL 20 Using where; Using index
select * from t1 where not(not(a)); select * from t1 where not(not(a));
a a
1 1
@ -55,7 +55,7 @@ a
10 10
explain select * from t1 where not(a = 10); explain select * from t1 where not(a = 10);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 5 NULL 21 Using where; Using index 1 SIMPLE t1 range a a 5 NULL 19 Using where; Using index
select * from t1 where not(a = 10); select * from t1 where not(a = 10);
a a
0 0
@ -500,7 +500,7 @@ NULL NULL
3 1 3 1
explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like "1"), not (a not in (1,2)), not(a != 2) from t1 where not(not(a)) having not(not(a)); explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like "1"), not (a not in (1,2)), not(a != 2) from t1 where not(not(a)) having not(not(a));
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 index a a 5 NULL 5 80.00 Using where; Using index 1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a` <> 0 AS `not(not(a))`,`test`.`t1`.`a` > 2 or `test`.`t1`.`a` <> 0 AS `not(a <= 2 and not(a))`,`test`.`t1`.`a` like '1' AS `not(a not like "1")`,`test`.`t1`.`a` in (1,2) AS `not (a not in (1,2))`,`test`.`t1`.`a` = 2 AS `not(a != 2)` from `test`.`t1` where `test`.`t1`.`a` <> 0 having `test`.`t1`.`a` <> 0 Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a` <> 0 AS `not(not(a))`,`test`.`t1`.`a` > 2 or `test`.`t1`.`a` <> 0 AS `not(a <= 2 and not(a))`,`test`.`t1`.`a` like '1' AS `not(a not like "1")`,`test`.`t1`.`a` in (1,2) AS `not (a not in (1,2))`,`test`.`t1`.`a` = 2 AS `not(a != 2)` from `test`.`t1` where `test`.`t1`.`a` <> 0 having `test`.`t1`.`a` <> 0
drop table t1; drop table t1;

File diff suppressed because it is too large Load Diff

View File

@ -85,23 +85,7 @@ drop table t1,t2,t0;
--echo # group_by min max optimization --echo # group_by min max optimization
--echo # --echo #
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, a INT NOT NULL, KEY(a)); CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, a INT NOT NULL, KEY(a));
--disable_query_log insert into t1 select seq, mod(seq,4)+1 from seq_1_to_65536;
INSERT INTO t1(a) VALUES (1), (2), (3), (4);
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
INSERT INTO t1(a) SELECT a FROM t1;
--enable_query_log
analyze table t1; analyze table t1;
EXPLAIN SELECT DISTINCT a FROM t1; EXPLAIN SELECT DISTINCT a FROM t1;
@ -115,6 +99,7 @@ CREATE TABLE t1 (a INT, b INT, c int, d int, KEY(a,b,c,d));
INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (1,0,1,1), (3,2,3,3), (4,5,4,4); INSERT INTO t1 VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (1,0,1,1), (3,2,3,3), (4,5,4,4);
ANALYZE TABLE t1; ANALYZE TABLE t1;
EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a; EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a;
set statement optimizer_scan_setup_cost=0 for EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a;
select * from information_schema.OPTIMIZER_TRACE; select * from information_schema.OPTIMIZER_TRACE;
DROP TABLE t1; DROP TABLE t1;
@ -138,10 +123,6 @@ drop table t1;
--echo # Late ORDER BY optimization --echo # Late ORDER BY optimization
--echo # --echo #
create table ten(a int);
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table one_k(a int primary key);
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
create table t1 ( create table t1 (
pk int not null, pk int not null,
a int, a int,
@ -153,18 +134,16 @@ create table t1 (
KEY a_b(a,b) KEY a_b(a,b)
); );
insert into t1 insert into t1 select seq, seq,seq,seq, 'filler-dataaa' from seq_0_to_999;
select a, a,a,a, 'filler-dataaa' from test.one_k;
update t1 set a=1 where pk between 0 and 180; update t1 set a=1 where pk between 0 and 180;
update t1 set b=2 where pk between 0 and 20; update t1 set b=2 where pk between 0 and 20;
analyze table t1; analyze table t1;
explain select * from t1 where a=1 and b=2 order by c limit 1;
update t1 set b=2 where pk between 20 and 40;
set optimizer_trace='enabled=on'; set optimizer_trace='enabled=on';
explain select * from t1 where a=1 and b=2 order by c limit 1; explain select * from t1 where a=1 and b=2 order by c limit 1;
update t1 set b=2 where pk between 20 and 40;
explain select * from t1 where a=1 and b=2 order by c limit 1;
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
drop table t1,ten,one_k; drop table t1;
--echo # --echo #
--echo # TABLE ELIMINATION --echo # TABLE ELIMINATION
@ -204,34 +183,23 @@ drop table t0, t1, t2, t3;
--echo # IN subquery to sem-join is traced --echo # IN subquery to sem-join is traced
--echo # --echo #
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1(a int, b int); create table t1(a int, b int);
insert into t1 values (0,0),(1,1),(2,2); insert into t1 select seq,seq from seq_0_to_3;
create table t2 as select * from t1;
create table t11(a int, b int); create table t2 (p int, a int);
insert into t2 select seq,seq from seq_1_to_10;
create table t10 (pk int, a int);
insert into t10 select a,a from t0;
create table t12 like t10;
insert into t12 select * from t10;
analyze table t1,t10;
set optimizer_trace='enabled=on'; set optimizer_trace='enabled=on';
explain extended select * from t1 where a in (select pk from t10); explain extended select * from t1 where a in (select p from t2);
insert into t2 select seq,seq from seq_10_to_100;
explain extended select * from t1 where a in (select p from t2);
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
drop table t0,t1,t11,t10,t12,t2; drop table t1,t2;
--echo # --echo #
--echo # Selectivities for columns and indexes. --echo # Selectivities for columns and indexes.
--echo # --echo #
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 ( create table t1 (
pk int, pk int,
a int, a int,
@ -239,7 +207,7 @@ b int,
key pk(pk), key pk(pk),
key pk_a(pk,a), key pk_a(pk,a),
key pk_a_b(pk,a,b)); key pk_a_b(pk,a,b));
insert into t1 select a,a,a from t0; insert into t1 select seq,seq,seq from seq_0_to_9;
ANALYZE TABLE t1 PERSISTENT FOR COLUMNS (a,b) INDEXES (); ANALYZE TABLE t1 PERSISTENT FOR COLUMNS (a,b) INDEXES ();
set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
@ -251,7 +219,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1;
select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
set @@use_stat_tables= @save_use_stat_tables; set @@use_stat_tables= @save_use_stat_tables;
drop table t0,t1; drop table t1;
set optimizer_trace="enabled=off"; set optimizer_trace="enabled=off";
--echo # --echo #
@ -942,7 +910,6 @@ set @save_histogram_size= @@histogram_size;
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity; set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set optimizer_switch='rowid_filter=on'; set optimizer_switch='rowid_filter=on';
set use_stat_tables='preferably'; set use_stat_tables='preferably';
set optimizer_use_condition_selectivity=4;
set histogram_size=127; set histogram_size=127;
create table t1 (a int, b int, c int, key(a),key(b)); create table t1 (a int, b int, c int, key(a),key(b));
insert into t1 select seq, seq*2, seq/10 from seq_1_to_1000; insert into t1 select seq, seq*2, seq/10 from seq_1_to_1000;
@ -957,8 +924,12 @@ create table t1 (a int, b int, c int, key(a),key(b));
insert into t1 select mod(seq,10), seq, seq from seq_1_to_10000; insert into t1 select mod(seq,10), seq, seq from seq_1_to_10000;
analyze table t1; analyze table t1;
set optimizer_use_condition_selectivity=2;
explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and t1.c<1000;
set optimizer_use_condition_selectivity=4;
--optimizer_trace --optimizer_trace
explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and t1.c<1000; explain format=json select * from three, t1 where t1.a=three.a and t1.b<5000 and t1.c<1000;
drop table three, t1; drop table three, t1;
set @@optimizer_switch= @save_optimizer_switch; set @@optimizer_switch= @save_optimizer_switch;

View File

@ -73,7 +73,7 @@ explain select * from t1 where a=1 or b=1 {
"range_analysis": { "range_analysis": {
"table_scan": { "table_scan": {
"rows": 1000, "rows": 1000,
"cost": 264.7939453 "cost": 0.1729314
}, },
"potential_range_indexes": [ "potential_range_indexes": [
{ {
@ -98,7 +98,9 @@ explain select * from t1 where a=1 or b=1 {
"analyzing_roworder_intersect": { "analyzing_roworder_intersect": {
"cause": "too few roworder scans" "cause": "too few roworder scans"
}, },
"analyzing_sort_intersect": {}, "analyzing_sort_intersect": {
"cutoff_cost": 0.1729314
},
"analyzing_index_merge_union": [ "analyzing_index_merge_union": [
{ {
"indexes_to_merge": [ "indexes_to_merge": [
@ -111,12 +113,12 @@ explain select * from t1 where a=1 or b=1 {
"using_mrr": false, "using_mrr": false,
"index_only": true, "index_only": true,
"rows": 1, "rows": 1,
"cost": 0.745585794, "cost": 0.001388369,
"chosen": true "chosen": true
} }
], ],
"index_to_merge": "a", "index_to_merge": "a",
"cumulated_cost": 0.745585794 "cumulated_cost": 0.001388369
}, },
{ {
"range_scan_alternatives": [ "range_scan_alternatives": [
@ -127,15 +129,15 @@ explain select * from t1 where a=1 or b=1 {
"using_mrr": false, "using_mrr": false,
"index_only": true, "index_only": true,
"rows": 1, "rows": 1,
"cost": 0.745585794, "cost": 0.001388369,
"chosen": true "chosen": true
} }
], ],
"index_to_merge": "b", "index_to_merge": "b",
"cumulated_cost": 1.491171589 "cumulated_cost": 0.002776738
} }
], ],
"cost_of_reading_ranges": 1.491171589, "cost_of_reading_ranges": 0.002776738,
"use_roworder_union": true, "use_roworder_union": true,
"cause": "always cheaper than non roworder retrieval", "cause": "always cheaper than non roworder retrieval",
"analyzing_roworder_scans": [ "analyzing_roworder_scans": [
@ -158,7 +160,7 @@ explain select * from t1 where a=1 or b=1 {
} }
} }
], ],
"index_roworder_union_cost": 2.601171589, "index_roworder_union_cost": 0.005004612,
"members": 2, "members": 2,
"chosen": true "chosen": true
} }
@ -187,7 +189,7 @@ explain select * from t1 where a=1 or b=1 {
] ]
}, },
"rows_for_plan": 2, "rows_for_plan": 2,
"cost_for_plan": 2.601171589, "cost_for_plan": 0.005004612,
"chosen": true "chosen": true
} }
} }
@ -218,17 +220,17 @@ explain select * from t1 where a=1 or b=1 {
{ {
"access_type": "index_merge", "access_type": "index_merge",
"rows": 2, "rows": 2,
"rows_after_scan": 2,
"rows_after_filter": 2, "rows_after_filter": 2,
"cost": 2.601171589, "rows_out": 2,
"cost": 0.005004612,
"chosen": true "chosen": true
} }
], ],
"chosen_access_method": { "chosen_access_method": {
"type": "index_merge", "type": "index_merge",
"records_read": 2, "rows_read": 2,
"records_out": 2, "rows_out": 2,
"cost": 2.601171589, "cost": 0.005004612,
"uses_join_buffering": false "uses_join_buffering": false
} }
} }
@ -239,14 +241,14 @@ explain select * from t1 where a=1 or b=1 {
"plan_prefix": [], "plan_prefix": [],
"table": "t1", "table": "t1",
"rows_for_plan": 2, "rows_for_plan": 2,
"cost_for_plan": 2.601171589 "cost_for_plan": 0.005004612
} }
] ]
}, },
{ {
"best_join_order": ["t1"], "best_join_order": ["t1"],
"rows": 2, "rows": 2,
"cost": 2.601171589 "cost": 0.005004612
}, },
{ {
"substitute_best_equal": { "substitute_best_equal": {
@ -327,7 +329,7 @@ set optimizer_trace='enabled=on';
# 3-way ROR-intersection # 3-way ROR-intersection
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge key1,key2,key3 key1,key2 5,5 NULL 77 Using intersect(key1,key2); Using where 1 SIMPLE t1 ref|filter key1,key2,key3 key1|key2 5|5 const 2243 (3%) Using where; Using rowid filter
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[ [
@ -342,7 +344,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": false, "index_only": false,
"rows": 2243, "rows": 2243,
"cost": 1695.083937, "cost": 2.770260666,
"chosen": true "chosen": true
}, },
{ {
@ -353,7 +355,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": false, "index_only": false,
"rows": 2243, "rows": 2243,
"cost": 1695.083937, "cost": 2.770260666,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
}, },
@ -365,7 +367,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": false, "index_only": false,
"rows": 2243, "rows": 2243,
"cost": 1695.083937, "cost": 2.770260666,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
} }
@ -376,10 +378,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[ [
{ {
"index": "key1", "index": "key1",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 61.88893703, "cumulated_index_scan_cost": 0.240986767,
"disk_sweep_cost": 1682.25, "disk_sweep_cost": 2.564386012,
"cumulative_total_cost": 1744.138937, "cumulative_total_cost": 2.805372779,
"usable": true, "usable": true,
"matching_rows_now": 2243, "matching_rows_now": 2243,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -387,10 +389,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
}, },
{ {
"index": "key2", "index": "key2",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 123.7778741, "cumulated_index_scan_cost": 0.481973534,
"disk_sweep_cost": 57.75, "disk_sweep_cost": 0.088032868,
"cumulative_total_cost": 181.5278741, "cumulative_total_cost": 0.570006402,
"usable": true, "usable": true,
"matching_rows_now": 77.6360508, "matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -398,10 +400,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
}, },
{ {
"index": "key3", "index": "key3",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 185.6668111, "cumulated_index_scan_cost": 0.722960301,
"disk_sweep_cost": 0, "disk_sweep_cost": 0,
"cumulative_total_cost": 185.6668111, "cumulative_total_cost": 0.722960301,
"usable": true, "usable": true,
"matching_rows_now": 2.687185191, "matching_rows_now": 2.687185191,
"intersect_covering_with_this_index": true, "intersect_covering_with_this_index": true,
@ -415,12 +417,32 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index" "cause": "no clustered pk index"
}, },
"rows": 77, "rows": 77,
"cost": 197.0550842, "cost": 0.572490756,
"covering": false, "covering": false,
"chosen": true "chosen": true
}, },
"analyzing_index_merge_union": "analyzing_index_merge_union":
[] []
},
{
"range_scan_alternatives":
[
{
"index": "key2",
"ranges":
[
"(100) <= (key2) <= (100)"
],
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 2243,
"cost": 0.312832109,
"chosen": true
}
]
} }
] ]
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
@ -431,7 +453,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{ {
"type": "index_roworder_intersect", "type": "index_roworder_intersect",
"rows": 77, "rows": 77,
"cost": 197.0550842, "cost": 0.572490756,
"covering": false, "covering": false,
"clustered_pk_scan": false, "clustered_pk_scan": false,
"intersect_of": "intersect_of":
@ -453,7 +475,23 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
] ]
}, },
"rows_for_plan": 77, "rows_for_plan": 77,
"cost_for_plan": 197.0550842, "cost_for_plan": 0.572490756,
"chosen": true
},
{
"range_access_plan":
{
"type": "range_scan",
"index": "key2",
"rows": 2243,
"ranges":
[
"(100) <= (key2) <= (100)"
]
},
"rows_for_plan": 2243,
"cost_for_plan": 0.312832109,
"chosen": true "chosen": true
} }
] ]
@ -487,7 +525,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": true, "index_only": true,
"rows": 2243, "rows": 2243,
"cost": 517.508937, "cost": 0.312832109,
"chosen": true "chosen": true
}, },
{ {
@ -498,13 +536,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": true, "index_only": true,
"rows": 2243, "rows": 2243,
"cost": 517.508937, "cost": 0.312832109,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
} }
], ],
"index_to_merge": "key1", "index_to_merge": "key1",
"cumulated_cost": 517.508937 "cumulated_cost": 0.312832109
}, },
{ {
"range_scan_alternatives": "range_scan_alternatives":
@ -517,7 +555,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": true, "index_only": true,
"rows": 2243, "rows": 2243,
"cost": 517.508937, "cost": 0.312832109,
"chosen": true "chosen": true
}, },
{ {
@ -528,16 +566,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"using_mrr": false, "using_mrr": false,
"index_only": true, "index_only": true,
"rows": 2243, "rows": 2243,
"cost": 517.508937, "cost": 0.312832109,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
} }
], ],
"index_to_merge": "key3", "index_to_merge": "key3",
"cumulated_cost": 1035.017874 "cumulated_cost": 0.625664218
} }
], ],
"cost_of_reading_ranges": 1035.017874, "cost_of_reading_ranges": 0.625664218,
"use_roworder_union": true, "use_roworder_union": true,
"cause": "always cheaper than non roworder retrieval", "cause": "always cheaper than non roworder retrieval",
"analyzing_roworder_scans": "analyzing_roworder_scans":
@ -554,10 +592,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[ [
{ {
"index": "key1", "index": "key1",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 61.88893703, "cumulated_index_scan_cost": 0.240986767,
"disk_sweep_cost": 1682.25, "disk_sweep_cost": 2.564386012,
"cumulative_total_cost": 1744.138937, "cumulative_total_cost": 2.805372779,
"usable": true, "usable": true,
"matching_rows_now": 2243, "matching_rows_now": 2243,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -565,10 +603,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
}, },
{ {
"index": "key2", "index": "key2",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 123.7778741, "cumulated_index_scan_cost": 0.481973534,
"disk_sweep_cost": 57.75, "disk_sweep_cost": 0.088032868,
"cumulative_total_cost": 181.5278741, "cumulative_total_cost": 0.570006402,
"usable": true, "usable": true,
"matching_rows_now": 77.6360508, "matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -581,7 +619,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index" "cause": "no clustered pk index"
}, },
"rows": 77, "rows": 77,
"cost": 197.0550842, "cost": 0.572490756,
"covering": false, "covering": false,
"chosen": true "chosen": true
} }
@ -598,10 +636,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
[ [
{ {
"index": "key3", "index": "key3",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 61.88893703, "cumulated_index_scan_cost": 0.240986767,
"disk_sweep_cost": 1682.25, "disk_sweep_cost": 2.564386012,
"cumulative_total_cost": 1744.138937, "cumulative_total_cost": 2.805372779,
"usable": true, "usable": true,
"matching_rows_now": 2243, "matching_rows_now": 2243,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -609,10 +647,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
}, },
{ {
"index": "key4", "index": "key4",
"index_scan_cost": 61.88893703, "index_scan_cost": 0.240986767,
"cumulated_index_scan_cost": 123.7778741, "cumulated_index_scan_cost": 0.481973534,
"disk_sweep_cost": 57.75, "disk_sweep_cost": 0.088032868,
"cumulative_total_cost": 181.5278741, "cumulative_total_cost": 0.570006402,
"usable": true, "usable": true,
"matching_rows_now": 77.6360508, "matching_rows_now": 77.6360508,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -625,13 +663,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
"cause": "no clustered pk index" "cause": "no clustered pk index"
}, },
"rows": 77, "rows": 77,
"cost": 197.0550842, "cost": 0.572490756,
"covering": false, "covering": false,
"chosen": true "chosen": true
} }
} }
], ],
"index_roworder_union_cost": 333.0257481, "index_roworder_union_cost": 1.135493366,
"members": 2, "members": 2,
"chosen": true "chosen": true
} }
@ -650,7 +688,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{ {
"type": "index_roworder_intersect", "type": "index_roworder_intersect",
"rows": 77, "rows": 77,
"cost": 197.0550842, "cost": 0.572490756,
"covering": false, "covering": false,
"clustered_pk_scan": false, "clustered_pk_scan": false,
"intersect_of": "intersect_of":
@ -674,7 +712,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
{ {
"type": "index_roworder_intersect", "type": "index_roworder_intersect",
"rows": 77, "rows": 77,
"cost": 197.0550842, "cost": 0.572490756,
"covering": false, "covering": false,
"clustered_pk_scan": false, "clustered_pk_scan": false,
"intersect_of": "intersect_of":
@ -698,7 +736,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
] ]
}, },
"rows_for_plan": 154, "rows_for_plan": 154,
"cost_for_plan": 333.0257481, "cost_for_plan": 1.135493366,
"chosen": true "chosen": true
} }
] ]

View File

@ -89,7 +89,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"range_analysis": { "range_analysis": {
"table_scan": { "table_scan": {
"rows": 1000, "rows": 1000,
"cost": 253 "cost": 0.1764192
}, },
"potential_range_indexes": [ "potential_range_indexes": [
{ {
@ -118,8 +118,9 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"using_mrr": false, "using_mrr": false,
"index_only": false, "index_only": false,
"rows": 1000, "rows": 1000,
"cost": 252.02, "cost": 0.19579056,
"chosen": true "chosen": false,
"cause": "cost"
}, },
{ {
"index": "key1", "index": "key1",
@ -128,7 +129,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"using_mrr": false, "using_mrr": false,
"index_only": false, "index_only": false,
"rows": 1, "rows": 1,
"cost": 1.270146475, "cost": 0.00415068,
"chosen": true "chosen": true
} }
], ],
@ -136,10 +137,10 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"intersecting_indexes": [ "intersecting_indexes": [
{ {
"index": "key1", "index": "key1",
"index_scan_cost": 0.525146475, "index_scan_cost": 0.001661605,
"cumulated_index_scan_cost": 0.525146475, "cumulated_index_scan_cost": 0.001661605,
"disk_sweep_cost": 0.752076843, "disk_sweep_cost": 0.00171364,
"cumulative_total_cost": 1.277223319, "cumulative_total_cost": 0.003375245,
"usable": true, "usable": true,
"matching_rows_now": 1, "matching_rows_now": 1,
"intersect_covering_with_this_index": false, "intersect_covering_with_this_index": false,
@ -151,7 +152,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"cause": "cost" "cause": "cost"
}, },
"chosen": false, "chosen": false,
"cause": "cost" "cause": "too few indexes to merge"
}, },
"analyzing_index_merge_union": [] "analyzing_index_merge_union": []
}, },
@ -167,7 +168,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"ranges": ["(1) <= (key1) <= (1)"] "ranges": ["(1) <= (key1) <= (1)"]
}, },
"rows_for_plan": 1, "rows_for_plan": 1,
"cost_for_plan": 1.270146475, "cost_for_plan": 0.00415068,
"chosen": true "chosen": true
} }
} }
@ -177,7 +178,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"rowid_filters": [ "rowid_filters": [
{ {
"key": "key1", "key": "key1",
"build_cost": 0.526146475, "build_cost": 0.000002653,
"rows": 1 "rows": 1
} }
] ]
@ -215,7 +216,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"index": "key1", "index": "key1",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 1, "rows": 1,
"cost": 1.250146475, "cost": 0.00335956,
"chosen": true "chosen": true
}, },
{ {
@ -226,9 +227,9 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
], ],
"chosen_access_method": { "chosen_access_method": {
"type": "ref", "type": "ref",
"records_read": 1, "rows_read": 1,
"records_out": 1, "rows_out": 1,
"cost": 1.250146475, "cost": 0.00335956,
"uses_join_buffering": false "uses_join_buffering": false
} }
} }
@ -239,14 +240,14 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"plan_prefix": [], "plan_prefix": [],
"table": "t1", "table": "t1",
"rows_for_plan": 1, "rows_for_plan": 1,
"cost_for_plan": 1.250146475 "cost_for_plan": 0.00335956
} }
] ]
}, },
{ {
"best_join_order": ["t1"], "best_join_order": ["t1"],
"rows": 1, "rows": 1,
"cost": 1.250146475 "cost": 0.00335956
}, },
{ {
"substitute_best_equal": { "substitute_best_equal": {

View File

@ -80,8 +80,8 @@ select * from db1.t1 {
"table": "t1", "table": "t1",
"table_scan": { "table_scan": {
"rows": 3, "rows": 3,
"read_cost": 0.010373215, "read_cost": 0.010408815,
"read_and_compare_cost": 0.010469215 "read_and_compare_cost": 0.010504815
} }
} }
] ]
@ -103,7 +103,7 @@ select * from db1.t1 {
"rows": 3, "rows": 3,
"rows_after_filter": 3, "rows_after_filter": 3,
"rows_out": 3, "rows_out": 3,
"cost": 0.010469215, "cost": 0.010504815,
"index_only": false, "index_only": false,
"chosen": true "chosen": true
} }
@ -112,7 +112,7 @@ select * from db1.t1 {
"type": "scan", "type": "scan",
"rows_read": 3, "rows_read": 3,
"rows_out": 3, "rows_out": 3,
"cost": 0.010469215, "cost": 0.010504815,
"uses_join_buffering": false "uses_join_buffering": false
} }
} }
@ -123,14 +123,14 @@ select * from db1.t1 {
"plan_prefix": [], "plan_prefix": [],
"table": "t1", "table": "t1",
"rows_for_plan": 3, "rows_for_plan": 3,
"cost_for_plan": 0.010469215 "cost_for_plan": 0.010504815
} }
] ]
}, },
{ {
"best_join_order": ["t1"], "best_join_order": ["t1"],
"rows": 3, "rows": 3,
"cost": 0.010469215 "cost": 0.010504815
}, },
{ {
"attaching_conditions_to_tables": { "attaching_conditions_to_tables": {
@ -219,8 +219,8 @@ select * from db1.v1 {
"table": "t1", "table": "t1",
"table_scan": { "table_scan": {
"rows": 3, "rows": 3,
"read_cost": 0.010373215, "read_cost": 0.010408815,
"read_and_compare_cost": 0.010469215 "read_and_compare_cost": 0.010504815
} }
} }
] ]
@ -242,7 +242,7 @@ select * from db1.v1 {
"rows": 3, "rows": 3,
"rows_after_filter": 3, "rows_after_filter": 3,
"rows_out": 3, "rows_out": 3,
"cost": 0.010469215, "cost": 0.010504815,
"index_only": false, "index_only": false,
"chosen": true "chosen": true
} }
@ -251,7 +251,7 @@ select * from db1.v1 {
"type": "scan", "type": "scan",
"rows_read": 3, "rows_read": 3,
"rows_out": 3, "rows_out": 3,
"cost": 0.010469215, "cost": 0.010504815,
"uses_join_buffering": false "uses_join_buffering": false
} }
} }
@ -262,14 +262,14 @@ select * from db1.v1 {
"plan_prefix": [], "plan_prefix": [],
"table": "t1", "table": "t1",
"rows_for_plan": 3, "rows_for_plan": 3,
"cost_for_plan": 0.010469215 "cost_for_plan": 0.010504815
} }
] ]
}, },
{ {
"best_join_order": ["t1"], "best_join_order": ["t1"],
"rows": 3, "rows": 3,
"cost": 0.010469215 "cost": 0.010504815
}, },
{ {
"attaching_conditions_to_tables": { "attaching_conditions_to_tables": {

View File

@ -53,7 +53,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "a", "index": "a",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 104, "rows": 104,
"cost": 78.54062004, "cost": 0.060906438,
"chosen": true "chosen": true
}, },
{ {
@ -61,7 +61,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "b", "index": "b",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 340, "rows": 340,
"cost": 255.6327963, "cost": 0.14153631,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
}, },
@ -70,25 +70,25 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "c", "index": "c",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 632, "rows": 632,
"cost": 475.2468449, "cost": 0.241743894,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
}, },
{ {
"access_type": "index_merge", "access_type": "index_merge",
"rows": 7, "rows": 7,
"rows_after_scan": 7,
"rows_after_filter": 7, "rows_after_filter": 7,
"cost": 13.79559815, "rows_out": 7,
"cost": 0.045367017,
"chosen": true "chosen": true
} }
], ],
"chosen_access_method": "chosen_access_method":
{ {
"type": "index_merge", "type": "index_merge",
"records_read": 7, "rows_read": 7,
"records_out": 7, "rows_out": 7,
"cost": 13.79559815, "cost": 0.045367017,
"uses_join_buffering": false "uses_join_buffering": false
} }
} }
@ -100,7 +100,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
[], [],
"table": "t1", "table": "t1",
"rows_for_plan": 7, "rows_for_plan": 7,
"cost_for_plan": 13.79559815 "cost_for_plan": 0.045367017
} }
] ]
] ]
@ -148,7 +148,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "a", "index": "a",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 6, "rows": 6,
"cost": 5.002343464, "cost": 0.005306142,
"chosen": true "chosen": true
}, },
{ {
@ -156,7 +156,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "b", "index": "b",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 232, "rows": 232,
"cost": 174.5906139, "cost": 0.104637894,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
}, },
@ -165,7 +165,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"index": "c", "index": "c",
"used_range_estimates": true, "used_range_estimates": true,
"rows": 293, "rows": 293,
"cost": 220.3644392, "cost": 0.125478666,
"chosen": false, "chosen": false,
"cause": "cost" "cause": "cost"
}, },
@ -178,9 +178,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"chosen_access_method": "chosen_access_method":
{ {
"type": "ref", "type": "ref",
"records_read": 6, "rows_read": 6,
"records_out": 0.6, "rows_out": 0.6,
"cost": 5.002343464, "cost": 0.005306142,
"uses_join_buffering": false "uses_join_buffering": false
} }
} }
@ -191,10 +191,11 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
"plan_prefix": "plan_prefix":
[], [],
"table": "t1", "table": "t1",
"rows_for_plan": 6, "rows_for_plan": 0.6,
"cost_for_plan": 5.002343464, "cost_for_plan": 0.005306142,
"selectivity": 0.1, "pushdown_cond_selectivity": 0.1,
"estimated_join_cardinality": 0.6 "filtered": 10,
"rows_out": 0.6
} }
] ]
] ]

View File

@ -530,11 +530,11 @@ a b
4 yq 4 yq
explain extended select * from t3 where a in (1,4); explain extended select * from t3 where a in (1,4);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t3 ALL idx NULL NULL NULL 28 100.00 Using where
1 PRIMARY t3 ref idx idx 5 tvc_0._col_1 3 100.00 1 PRIMARY <derived3> eq_ref distinct_key distinct_key 4 test.t3.a 1 100.00
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from (values (1),(4)) `tvc_0` join `test`.`t3` where `test`.`t3`.`a` = `tvc_0`.`_col_1` Note 1003 /* select#1 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from (values (1),(4)) `tvc_0` join `test`.`t3` where `tvc_0`.`_col_1` = `test`.`t3`.`a`
# use vectors in IN predeicate # use vectors in IN predeicate
set @@in_predicate_conversion_threshold= 4; set @@in_predicate_conversion_threshold= 4;
select * from t1 where (a,b) in ((1,2),(3,4)); select * from t1 where (a,b) in ((1,2),(3,4));

View File

@ -0,0 +1,347 @@
select table_name,engine from information_schema.tables where table_name="optimizer_costs";
table_name engine
OPTIMIZER_COSTS MEMORY
show create table information_schema.optimizer_costs;
Table Create Table
OPTIMIZER_COSTS CREATE TEMPORARY TABLE `OPTIMIZER_COSTS` (
`ENGINE` varchar(192) NOT NULL,
`OPTIMIZER_DISK_READ_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_INDEX_BLOCK_COPY_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_KEY_COMPARE_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_KEY_COPY_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_KEY_LOOKUP_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_KEY_NEXT_FIND_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_DISK_READ_RATIO` decimal(9,6) NOT NULL,
`OPTIMIZER_ROW_COPY_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_ROW_LOOKUP_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_ROW_NEXT_FIND_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_ROWID_COMPARE_COST` decimal(9,6) NOT NULL,
`OPTIMIZER_ROWID_COPY_COST` decimal(9,6) NOT NULL
) ENGINE=MEMORY DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
select * from information_schema.optimizer_costs where engine in
("memory","innodb","aria","default") order by engine;
ENGINE Aria
OPTIMIZER_DISK_READ_COST 10.240000
OPTIMIZER_INDEX_BLOCK_COPY_COST 0.035600
OPTIMIZER_KEY_COMPARE_COST 0.011361
OPTIMIZER_KEY_COPY_COST 0.015685
OPTIMIZER_KEY_LOOKUP_COST 0.435777
OPTIMIZER_KEY_NEXT_FIND_COST 0.082347
OPTIMIZER_DISK_READ_RATIO 0.020000
OPTIMIZER_ROW_COPY_COST 0.060866
OPTIMIZER_ROW_LOOKUP_COST 0.130839
OPTIMIZER_ROW_NEXT_FIND_COST 0.045916
OPTIMIZER_ROWID_COMPARE_COST 0.001000
OPTIMIZER_ROWID_COPY_COST 0.001000
ENGINE default
OPTIMIZER_DISK_READ_COST 10.240000
OPTIMIZER_INDEX_BLOCK_COPY_COST 0.035600
OPTIMIZER_KEY_COMPARE_COST 0.011361
OPTIMIZER_KEY_COPY_COST 0.015685
OPTIMIZER_KEY_LOOKUP_COST 0.435777
OPTIMIZER_KEY_NEXT_FIND_COST 0.082347
OPTIMIZER_DISK_READ_RATIO 0.020000
OPTIMIZER_ROW_COPY_COST 0.060866
OPTIMIZER_ROW_LOOKUP_COST 0.130839
OPTIMIZER_ROW_NEXT_FIND_COST 0.045916
OPTIMIZER_ROWID_COMPARE_COST 0.002653
OPTIMIZER_ROWID_COPY_COST 0.002653
ENGINE InnoDB
OPTIMIZER_DISK_READ_COST 10.240000
OPTIMIZER_INDEX_BLOCK_COPY_COST 0.035600
OPTIMIZER_KEY_COMPARE_COST 0.011361
OPTIMIZER_KEY_COPY_COST 0.015685
OPTIMIZER_KEY_LOOKUP_COST 0.791120
OPTIMIZER_KEY_NEXT_FIND_COST 0.099000
OPTIMIZER_DISK_READ_RATIO 0.020000
OPTIMIZER_ROW_COPY_COST 0.060870
OPTIMIZER_ROW_LOOKUP_COST 0.765970
OPTIMIZER_ROW_NEXT_FIND_COST 0.070130
OPTIMIZER_ROWID_COMPARE_COST 0.002653
OPTIMIZER_ROWID_COPY_COST 0.002653
ENGINE MEMORY
OPTIMIZER_DISK_READ_COST 0.000000
OPTIMIZER_INDEX_BLOCK_COPY_COST 0.000000
OPTIMIZER_KEY_COMPARE_COST 0.011361
OPTIMIZER_KEY_COPY_COST 0.000000
OPTIMIZER_KEY_LOOKUP_COST 0.000000
OPTIMIZER_KEY_NEXT_FIND_COST 0.000000
OPTIMIZER_DISK_READ_RATIO 0.000000
OPTIMIZER_ROW_COPY_COST 0.002334
OPTIMIZER_ROW_LOOKUP_COST 0.000000
OPTIMIZER_ROW_NEXT_FIND_COST 0.000000
OPTIMIZER_ROWID_COMPARE_COST 0.002653
OPTIMIZER_ROWID_COPY_COST 0.002653
show variables like "optimizer%cost";
Variable_name Value
optimizer_disk_read_cost 10.240000
optimizer_index_block_copy_cost 0.035600
optimizer_key_compare_cost 0.011361
optimizer_key_copy_cost 0.015685
optimizer_key_lookup_cost 0.435777
optimizer_key_next_find_cost 0.082347
optimizer_row_copy_cost 0.060866
optimizer_row_lookup_cost 0.130839
optimizer_row_next_find_cost 0.045916
optimizer_rowid_compare_cost 0.002653
optimizer_rowid_copy_cost 0.002653
optimizer_scan_setup_cost 10.000000
optimizer_where_cost 0.032000
show variables like "optimizer_disk_read_ratio";
Variable_name Value
optimizer_disk_read_ratio 0.020000
#
# Test change some 'default' variables
#
SELECT @@optimizer_disk_read_ratio,@@optimizer_index_block_copy_cost;
@@optimizer_disk_read_ratio @@optimizer_index_block_copy_cost
0.020000 0.035600
SET global optimizer_disk_read_ratio=0.8;
SET global optimizer_index_block_copy_cost=0.1;
SELECT @@optimizer_disk_read_ratio,@@optimizer_index_block_copy_cost;
@@optimizer_disk_read_ratio @@optimizer_index_block_copy_cost
0.800000 0.100000
select optimizer_disk_read_ratio,optimizer_index_block_copy_cost from information_schema.optimizer_costs where engine='default';
optimizer_disk_read_ratio optimizer_index_block_copy_cost
0.800000 0.100000
SET global optimizer_disk_read_ratio=default;
SET global optimizer_index_block_copy_cost=default;
SELECT @@optimizer_disk_read_ratio,@@optimizer_index_block_copy_cost;
@@optimizer_disk_read_ratio @@optimizer_index_block_copy_cost
0.020000 0.035600
#
# Test change some 'engine' variables
#
select @@MEMORY.optimizer_row_lookup_cost;
@@MEMORY.optimizer_row_lookup_cost
0.000000
set @tmp=@@MEMORY.optimizer_row_lookup_cost;
set @@global.MEMORY.optimizer_row_lookup_cost=1;
select @@MEMORY.optimizer_row_lookup_cost;
@@MEMORY.optimizer_row_lookup_cost
1.000000
set @@global.MEMORY.optimizer_row_lookup_cost=default;
select @@MEMORY.optimizer_row_lookup_cost;
@@MEMORY.optimizer_row_lookup_cost
0.130839
set @@global.MEMORY.optimizer_row_lookup_cost=@tmp;
select @@MEMORY.optimizer_row_lookup_cost;
@@MEMORY.optimizer_row_lookup_cost
0.000000
#
# Print variables with different syntaxes
#
SHOW VARIABLES like "optimizer_row_lookup_cost";
Variable_name Value
optimizer_row_lookup_cost 0.130839
SELECT @@optimizer_row_lookup_cost;
@@optimizer_row_lookup_cost
0.130839
SELECT @@global.default.optimizer_row_lookup_cost;
@@global.default.optimizer_row_lookup_cost
0.130839
SELECT @@global.default.`optimizer_row_lookup_cost`;
@@global.default.`optimizer_row_lookup_cost`
0.130839
SELECT @@MEMORY.optimizer_row_lookup_cost;
@@MEMORY.optimizer_row_lookup_cost
0.000000
SELECT @@memory.optimizer_row_lookup_cost;
@@memory.optimizer_row_lookup_cost
0.000000
SELECT @@InnoDB.optimizer_row_lookup_cost;
@@InnoDB.optimizer_row_lookup_cost
0.765970
#
# Accessing not existing cost
#
SELECT @@not_existing.optimizer_row_lookup_cost;
@@not_existing.optimizer_row_lookup_cost
0.130839
SELECT @@NOT_existing.optimizer_row_lookup_cost;
@@NOT_existing.optimizer_row_lookup_cost
0.130839
select engine from information_schema.optimizer_costs where engine like '%existing';
engine
#
# Creating a new cost structure
#
SET global new_engine.optimizer_disk_read_cost=100;
select * from information_schema.optimizer_costs where engine like 'new_engine';
ENGINE OPTIMIZER_DISK_READ_COST OPTIMIZER_INDEX_BLOCK_COPY_COST OPTIMIZER_KEY_COMPARE_COST OPTIMIZER_KEY_COPY_COST OPTIMIZER_KEY_LOOKUP_COST OPTIMIZER_KEY_NEXT_FIND_COST OPTIMIZER_DISK_READ_RATIO OPTIMIZER_ROW_COPY_COST OPTIMIZER_ROW_LOOKUP_COST OPTIMIZER_ROW_NEXT_FIND_COST OPTIMIZER_ROWID_COMPARE_COST OPTIMIZER_ROWID_COPY_COST
new_engine 100.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000 -1.000000
select @@new_engine.optimizer_disk_read_cost, @@new_engine.optimizer_row_copy_cost;
@@new_engine.optimizer_disk_read_cost @@new_engine.optimizer_row_copy_cost
100.000000 -1.000000
#
# Errors
#
SELECT @@default.optimizer_disk_read_cost;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'default.optimizer_disk_read_cost' at line 1
set global Aria.optimizer_disk_read_cost=NULL;
ERROR 42000: Incorrect argument type to variable 'optimizer_disk_read_cost'
set @tmp=@@Aria.optimizer_disk_read_cost;
SET global Aria.optimizer_disk_read_cost=-1;
Warnings:
Warning 1292 Truncated incorrect optimizer_disk_read_cost value: '-1'
select @@Aria.optimizer_disk_read_cost;
@@Aria.optimizer_disk_read_cost
0.000000
SET global Aria.optimizer_disk_read_cost=200000;
Warnings:
Warning 1292 Truncated incorrect optimizer_disk_read_cost value: '200000'
select @@Aria.optimizer_disk_read_cost;
@@Aria.optimizer_disk_read_cost
10000.000000
set global Aria.optimizer_disk_read_cost=@tmp;
select @@Aria.optimizer_disk_read_cost;
@@Aria.optimizer_disk_read_cost
10.240000
#
# Test of cost of ref compared to table scan + join_cache
#
create or replace table t1 (p int primary key, a char(10)) engine=myisam;
create or replace table t2 (p int primary key, i int, a char(10), key k2(a)) engine=myisam;
insert into t2 select seq,seq,'a' from seq_1_to_512;
insert into t1 select seq,'a' from seq_1_to_4;
explain select count(*) from t1, t2 where t1.p = t2.i;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 4 Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 512 Using where; Using join buffer (flat, BNL join)
insert into t1 select seq,'a' from seq_5_to_10;
explain select count(*) from t1, t2 where t1.p = t2.i;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 512 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.i 1 Using index
drop table t1,t2;
#
# Test of optimizer_scan_setup_cost
#
create table t1 (p int primary key, a char(10)) engine=myisam;
create table t2 (p int primary key, i int, a char(10), key k1(i), key k2(a)) engine=myisam;
insert into t1 values (2, 'qqqq'), (11, 'yyyy');
insert into t2 values (1, 2, 'qqqq'), (2, 2, 'pppp'),
(3, 2, 'yyyy'), (4, 3, 'zzzz');
set @org_myisam_disk_read_ratio=@@myisam.optimizer_disk_read_ratio;
set @@optimizer_scan_setup_cost=10,@@global.myisam.optimizer_disk_read_ratio=0.2;
flush tables;
explain select sum(t2.p+length(t1.a)) from t1, t2 where t1.p = t2.i;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2
1 SIMPLE t2 ref k1 k1 5 test.t1.p 2
set @@optimizer_scan_setup_cost=0.0, @@global.myisam.optimizer_disk_read_ratio=0.0;
flush tables;
explain select sum(t2.p+length(t1.a)) from t1, t2 where t1.p = t2.i;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2
1 SIMPLE t2 ALL k1 NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join)
set @@optimizer_scan_setup_cost=default,@@global.myisam.optimizer_disk_read_ratio=@org_myisam_disk_read_ratio;
flush tables;
drop table t1,t2;
#
# Test of group by optimization
#
set @@optimizer_scan_setup_cost=0;
CREATE TABLE t1 (id INT NOT NULL, a DATE, KEY(id,a)) engine=myisam;
INSERT INTO t1 values (1,'2001-01-01'),(1,'2001-01-02'),
(1,'2001-01-03'),(1,'2001-01-04'),
(2,'2001-01-01'),(2,'2001-01-02'),
(2,'2001-01-03'),(2,'2001-01-04'),
(3,'2001-01-01'),(3,'2001-01-02'),
(3,'2001-01-03'),(3,'2001-01-04'),
(4,'2001-01-01'),(4,'2001-01-02'),
(4,'2001-01-03'),(4,'2001-01-04');
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL id 8 NULL 16 Using where; Using index
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL id 8 NULL 5 Using where; Using index for group-by
drop table t1;
set @@optimizer_scan_setup_cost=default;
#
# Test of straight join costs
#
create table t1 (l_orderkey int(11) NOT NULL,
l_partkey int(11) DEFAULT NULL,
l_suppkey int(11) DEFAULT NULL,
PRIMARY KEY (l_orderkey)) engine=aria;
insert into t1 select seq,seq,seq from seq_1_to_1000;
explain select straight_join count(*) from seq_1_to_10000,t1 where seq=l_orderkey;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE seq_1_to_10000 index PRIMARY PRIMARY 8 NULL 10000 Using index
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.seq_1_to_10000.seq 1 Using where; Using index
show status like "last_query_cost";
Variable_name Value
Last_query_cost 5.641229
set @org_cost=@@aria.optimizer_key_next_find_cost;
set global aria.optimizer_key_next_find_cost=1000;
flush tables;
explain select count(*) from seq_1_to_10000,t1 where seq=l_orderkey;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE seq_1_to_10000 index PRIMARY PRIMARY 8 NULL 10000 Using index
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.seq_1_to_10000.seq 1 Using where; Using index
show status like "last_query_cost";
Variable_name Value
Last_query_cost 5.641229
set global aria.optimizer_key_next_find_cost=@org_cost;
drop table t1;
#
# Testing distinct group optimization
#
create table t1 (a int, b int, key(a,b));
insert into t1 select seq,seq from seq_1_to_1000;
explain select count(distinct a,b) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL a 10 NULL 1000 Using index for group-by (scanning)
explain select count(distinct a,b) from t1 where a>100;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 10 NULL 901 Using where; Using index for group-by (scanning)
explain select count(distinct a,b) from t1 where a>800;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 206 Using where; Using index
update t1 set a=mod(a,10);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
explain select count(distinct a,b) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL a 10 NULL 1000 Using index for group-by (scanning)
explain select count(distinct a,b) from t1 where a>1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 10 NULL 788 Using where; Using index for group-by (scanning)
explain select count(distinct a,b) from t1 where a>8;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 5 NULL 109 Using where; Using index
update t1 set b=mod(b,2);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
explain select count(distinct a,b) from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range NULL a 10 NULL 11 Using index for group-by
explain select count(distinct a,b) from t1 where a>1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 10 NULL 9 Using where; Using index for group-by
explain select count(distinct a,b) from t1 where a>8;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 10 NULL 1 Using where; Using index for group-by
drop table t1;
#
# cleanup
#
Start_engines: 9 End_engines: 10

View File

@ -0,0 +1,187 @@
#
# Test of optimizer_costs
#
--source include/have_innodb.inc
--source include/have_sequence.inc
select table_name,engine from information_schema.tables where table_name="optimizer_costs";
show create table information_schema.optimizer_costs;
let $start_engines=`select count(*) from information_schema.optimizer_costs`;
--vertical_results
select * from information_schema.optimizer_costs where engine in
("memory","innodb","aria","default") order by engine;
--horizontal_results
show variables like "optimizer%cost";
show variables like "optimizer_disk_read_ratio";
--echo #
--echo # Test change some 'default' variables
--echo #
SELECT @@optimizer_disk_read_ratio,@@optimizer_index_block_copy_cost;
SET global optimizer_disk_read_ratio=0.8;
SET global optimizer_index_block_copy_cost=0.1;
SELECT @@optimizer_disk_read_ratio,@@optimizer_index_block_copy_cost;
select optimizer_disk_read_ratio,optimizer_index_block_copy_cost from information_schema.optimizer_costs where engine='default';
SET global optimizer_disk_read_ratio=default;
SET global optimizer_index_block_copy_cost=default;
SELECT @@optimizer_disk_read_ratio,@@optimizer_index_block_copy_cost;
--echo #
--echo # Test change some 'engine' variables
--echo #
select @@MEMORY.optimizer_row_lookup_cost;
set @tmp=@@MEMORY.optimizer_row_lookup_cost;
set @@global.MEMORY.optimizer_row_lookup_cost=1;
select @@MEMORY.optimizer_row_lookup_cost;
set @@global.MEMORY.optimizer_row_lookup_cost=default;
select @@MEMORY.optimizer_row_lookup_cost;
set @@global.MEMORY.optimizer_row_lookup_cost=@tmp;
select @@MEMORY.optimizer_row_lookup_cost;
--echo #
--echo # Print variables with different syntaxes
--echo #
SHOW VARIABLES like "optimizer_row_lookup_cost";
SELECT @@optimizer_row_lookup_cost;
SELECT @@global.default.optimizer_row_lookup_cost;
SELECT @@global.default.`optimizer_row_lookup_cost`;
SELECT @@MEMORY.optimizer_row_lookup_cost;
SELECT @@memory.optimizer_row_lookup_cost;
SELECT @@InnoDB.optimizer_row_lookup_cost;
--echo #
--echo # Accessing not existing cost
--echo #
SELECT @@not_existing.optimizer_row_lookup_cost;
SELECT @@NOT_existing.optimizer_row_lookup_cost;
select engine from information_schema.optimizer_costs where engine like '%existing';
--echo #
--echo # Creating a new cost structure
--echo #
SET global new_engine.optimizer_disk_read_cost=100;
select * from information_schema.optimizer_costs where engine like 'new_engine';
select @@new_engine.optimizer_disk_read_cost, @@new_engine.optimizer_row_copy_cost;
--echo #
--echo # Errors
--echo #
--error ER_PARSE_ERROR
SELECT @@default.optimizer_disk_read_cost;
--error ER_WRONG_TYPE_FOR_VAR
set global Aria.optimizer_disk_read_cost=NULL;
set @tmp=@@Aria.optimizer_disk_read_cost;
SET global Aria.optimizer_disk_read_cost=-1;
select @@Aria.optimizer_disk_read_cost;
SET global Aria.optimizer_disk_read_cost=200000;
select @@Aria.optimizer_disk_read_cost;
set global Aria.optimizer_disk_read_cost=@tmp;
select @@Aria.optimizer_disk_read_cost;
--echo #
--echo # Test of cost of ref compared to table scan + join_cache
--echo #
create or replace table t1 (p int primary key, a char(10)) engine=myisam;
create or replace table t2 (p int primary key, i int, a char(10), key k2(a)) engine=myisam;
insert into t2 select seq,seq,'a' from seq_1_to_512;
insert into t1 select seq,'a' from seq_1_to_4;
explain select count(*) from t1, t2 where t1.p = t2.i;
insert into t1 select seq,'a' from seq_5_to_10;
explain select count(*) from t1, t2 where t1.p = t2.i;
drop table t1,t2;
--echo #
--echo # Test of optimizer_scan_setup_cost
--echo #
create table t1 (p int primary key, a char(10)) engine=myisam;
create table t2 (p int primary key, i int, a char(10), key k1(i), key k2(a)) engine=myisam;
insert into t1 values (2, 'qqqq'), (11, 'yyyy');
insert into t2 values (1, 2, 'qqqq'), (2, 2, 'pppp'),
(3, 2, 'yyyy'), (4, 3, 'zzzz');
set @org_myisam_disk_read_ratio=@@myisam.optimizer_disk_read_ratio;
set @@optimizer_scan_setup_cost=10,@@global.myisam.optimizer_disk_read_ratio=0.2;
flush tables;
explain select sum(t2.p+length(t1.a)) from t1, t2 where t1.p = t2.i;
set @@optimizer_scan_setup_cost=0.0, @@global.myisam.optimizer_disk_read_ratio=0.0;
flush tables;
explain select sum(t2.p+length(t1.a)) from t1, t2 where t1.p = t2.i;
set @@optimizer_scan_setup_cost=default,@@global.myisam.optimizer_disk_read_ratio=@org_myisam_disk_read_ratio;
flush tables;
drop table t1,t2;
--echo #
--echo # Test of group by optimization
--echo #
set @@optimizer_scan_setup_cost=0;
CREATE TABLE t1 (id INT NOT NULL, a DATE, KEY(id,a)) engine=myisam;
INSERT INTO t1 values (1,'2001-01-01'),(1,'2001-01-02'),
(1,'2001-01-03'),(1,'2001-01-04'),
(2,'2001-01-01'),(2,'2001-01-02'),
(2,'2001-01-03'),(2,'2001-01-04'),
(3,'2001-01-01'),(3,'2001-01-02'),
(3,'2001-01-03'),(3,'2001-01-04'),
(4,'2001-01-01'),(4,'2001-01-02'),
(4,'2001-01-03'),(4,'2001-01-04');
analyze table t1;
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id;
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
insert into t1 values (3,'2001-01-03'),(3,'2001-01-04');
analyze table t1;
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id;
drop table t1;
set @@optimizer_scan_setup_cost=default;
--echo #
--echo # Test of straight join costs
--echo #
create table t1 (l_orderkey int(11) NOT NULL,
l_partkey int(11) DEFAULT NULL,
l_suppkey int(11) DEFAULT NULL,
PRIMARY KEY (l_orderkey)) engine=aria;
insert into t1 select seq,seq,seq from seq_1_to_1000;
explain select straight_join count(*) from seq_1_to_10000,t1 where seq=l_orderkey;
show status like "last_query_cost";
set @org_cost=@@aria.optimizer_key_next_find_cost;
# Set cost for t1 high so that we cannot use it for index scans
set global aria.optimizer_key_next_find_cost=1000;
flush tables;
explain select count(*) from seq_1_to_10000,t1 where seq=l_orderkey;
show status like "last_query_cost";
set global aria.optimizer_key_next_find_cost=@org_cost;
drop table t1;
--echo #
--echo # Testing distinct group optimization
--echo #
create table t1 (a int, b int, key(a,b));
insert into t1 select seq,seq from seq_1_to_1000;
explain select count(distinct a,b) from t1;
explain select count(distinct a,b) from t1 where a>100;
explain select count(distinct a,b) from t1 where a>800;
update t1 set a=mod(a,10);
analyze table t1;
explain select count(distinct a,b) from t1;
explain select count(distinct a,b) from t1 where a>1;
explain select count(distinct a,b) from t1 where a>8;
update t1 set b=mod(b,2);
analyze table t1;
explain select count(distinct a,b) from t1;
explain select count(distinct a,b) from t1 where a>1;
explain select count(distinct a,b) from t1 where a>8;
drop table t1;
--echo #
--echo # cleanup
--echo #
let $end_engines=`select count(*) from information_schema.optimizer_costs`;
--echo Start_engines: $start_engines End_engines: $end_engines

View File

@ -0,0 +1 @@
--optimizer_disk_read_ratio=0.9 --MEMORY.optimizer_disk_read_ratio=0.1 --memory.optimizer_disk_read_ratio=0.3 --memory.optimizer_row_lookup_cost=0.8

View File

@ -0,0 +1,8 @@
select engine,optimizer_disk_read_ratio from information_schema.optimizer_costs where engine in ("memory","aria","default");
engine optimizer_disk_read_ratio
default 0.900000
MEMORY 0.300000
Aria 0.900000
select @@memory.optimizer_row_lookup_cost;
@@memory.optimizer_row_lookup_cost
0.800000

View File

@ -0,0 +1,6 @@
#
# Check default optimizer_cost_arguments
#
select engine,optimizer_disk_read_ratio from information_schema.optimizer_costs where engine in ("memory","aria","default");
select @@memory.optimizer_row_lookup_cost;

View File

@ -1192,7 +1192,10 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k3 5 NULL 111 Using where 1 SIMPLE t2 index k2 k3 5 NULL 111 Using where
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000; EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref k2 k2 5 const 7341 Using where; Using filesort 1 SIMPLE t2 range k2 k2 5 NULL 7341 Using index condition; Using filesort
EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 6000;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL k2 NULL NULL NULL 40960 Using where; Using filesort
EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 10 AND 12 ORDER BY c3 LIMIT 20; EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 10 AND 12 ORDER BY c3 LIMIT 20;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index k2 k3 5 NULL 73 Using where 1 SIMPLE t2 index k2 k3 5 NULL 73 Using where
@ -1577,19 +1580,20 @@ ANALYZE
"r_sort_mode": "sort_key,addon_fields", "r_sort_mode": "sort_key,addon_fields",
"table": { "table": {
"table_name": "t1", "table_name": "t1",
"access_type": "index", "access_type": "ref_or_null",
"possible_keys": ["a_c", "a"], "possible_keys": ["a_c", "a"],
"key": "a_c", "key": "a_c",
"key_length": "10", "key_length": "10",
"used_key_parts": ["a", "c"], "used_key_parts": ["a", "c"],
"ref": ["const", "const"],
"r_loops": 1, "r_loops": 1,
"rows": 2, "rows": 2,
"r_rows": 2, "r_rows": 1,
"r_table_time_ms": "REPLACED", "r_table_time_ms": "REPLACED",
"r_other_time_ms": "REPLACED", "r_other_time_ms": "REPLACED",
"filtered": 50, "filtered": 50,
"r_filtered": 50, "r_filtered": 100,
"attached_condition": "t1.a = 2 and (t1.c = 10 or t1.c is null)", "attached_condition": "t1.c = 10 or t1.c is null",
"using_index": true "using_index": true
} }
} }
@ -1601,26 +1605,11 @@ ANALYZE
EXPLAIN EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a_c,a a_c 10 NULL 2 Using where; Using index; Using filesort 1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort
# Must return 1 row # Must return 1 row
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
col col
1 1
# With more rows "filesort" is removed
INSERT INTO t1 select seq,seq from seq_1_to_2;
EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a_c,a a_c 10 NULL 2 Using where; Using index
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
col
1
# With more rows "range" changes to "ref_or_null"
INSERT INTO t1 select seq,seq from seq_3_to_10;
EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort
# Must use ref-or-null on the a_c index # Must use ref-or-null on the a_c index
EXPLAIN EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC; SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC;
@ -3130,7 +3119,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t3a ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary 1 PRIMARY t3a ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary
1 PRIMARY t3b ref f3_key f3_key 6 test.t3a.f3 1 100.00 Using where; End temporary 1 PRIMARY t3b ref f3_key f3_key 6 test.t3a.f3 1 41.67 Using where; End temporary
Warnings: Warnings:
Note 1003 select concat('foo',`test`.`t2`.`f2`) AS `field` from `test`.`t2` semi join ((`test`.`t3` `t3a` join `test`.`t3` `t3b`)) where `test`.`t3a`.`f3` < 'foo' or `test`.`t3b`.`f3` <> 'foo' order by concat('foo',`test`.`t2`.`f2`) Note 1003 select concat('foo',`test`.`t2`.`f2`) AS `field` from `test`.`t2` semi join ((`test`.`t3` `t3a` join `test`.`t3` `t3b`)) where `test`.`t3a`.`f3` < 'foo' or `test`.`t3b`.`f3` <> 'foo' order by concat('foo',`test`.`t2`.`f2`)
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
@ -3184,7 +3173,7 @@ id select_type table type possible_keys key key_len ref rows Extra
# See above query # See above query
EXPLAIN SELECT id1 FROM t2 WHERE id2=1 AND id3=1 ORDER BY date DESC LIMIT 0,4; EXPLAIN SELECT id1 FROM t2 WHERE id2=1 AND id3=1 ORDER BY date DESC LIMIT 0,4;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range id_23_date,id_234_date id_23_date 2 NULL 8 Using where 1 SIMPLE t2 ref id_23_date,id_234_date id_23_date 2 const,const 8 Using where
drop table t1,t2; drop table t1,t2;
# #
# MDEV-8989: ORDER BY optimizer ignores equality propagation # MDEV-8989: ORDER BY optimizer ignores equality propagation
@ -3565,8 +3554,8 @@ WHERE books.library_id = 8663 AND
books.scheduled_for_removal=0 ) books.scheduled_for_removal=0 )
ORDER BY wings.id; ORDER BY wings.id;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY wings ALL PRIMARY NULL NULL NULL 2 100.00 Using temporary; Using filesort 1 PRIMARY wings ALL PRIMARY NULL NULL NULL 2 100.00 Using filesort
1 PRIMARY books ALL library_idx NULL NULL NULL 2 100.00 Using where; FirstMatch(wings); Using join buffer (flat, BNL join) 1 PRIMARY books ref library_idx library_idx 4 const 2 50.00 Using where; FirstMatch(wings)
Warnings: Warnings:
Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`books`.`wings_id` = `test`.`wings`.`id` order by `test`.`wings`.`id` Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`books`.`wings_id` = `test`.`wings`.`id` order by `test`.`wings`.`id`
set optimizer_switch= @save_optimizer_switch; set optimizer_switch= @save_optimizer_switch;
@ -3700,8 +3689,8 @@ WHERE
t2.key1 = t1.a and t2.key1 IS NOT NULL t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY ORDER BY
t2.key2 ASC t2.key2 ASC
LIMIT 1) LIMIT 1) as "con"
from t1; from t1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 10 1 PRIMARY t1 ALL NULL NULL NULL NULL 10
2 DEPENDENT SUBQUERY t2 ref key1 key1 5 test.t1.a 10 Using index condition; Using where; Using filesort 2 DEPENDENT SUBQUERY t2 ref key1 key1 5 test.t1.a 10 Using index condition; Using where; Using filesort
@ -3712,15 +3701,9 @@ WHERE
t2.key1 = t1.a and t2.key1 IS NOT NULL t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY ORDER BY
t2.key2 ASC t2.key2 ASC
LIMIT 1) LIMIT 1) as "con"
from t1; from t1;
(SELECT concat(id, '-', key1, '-', col1) con
FROM t2
WHERE
t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY
t2.key2 ASC
LIMIT 1)
100-0-123456 100-0-123456
101-1-123456 101-1-123456
102-2-123456 102-2-123456
@ -4463,7 +4446,8 @@ CREATE TABLE t1 (a INT, b int, primary key(a));
CREATE TABLE t2 (a INT, b INT); CREATE TABLE t2 (a INT, b INT);
INSERT INTO t1 (a,b) VALUES (58,1),(96,2),(273,3),(23,4),(231,5),(525,6), INSERT INTO t1 (a,b) VALUES (58,1),(96,2),(273,3),(23,4),(231,5),(525,6),
(2354,7),(321421,3),(535,2),(4535,3); (2354,7),(321421,3),(535,2),(4535,3);
INSERT INTO t2 (a,b) VALUES (58,3),(96,3),(273,3),(1000,1000),(2000,2000); INSERT INTO t2 (a,b) VALUES (58,3),(96,3),(273,3),(1000,1000),(2000,2000),(3000,3000);
INSERT INTO t2 select seq,seq from seq_10_to_100;
# Join order should have the SJM scan table as the first table for both # Join order should have the SJM scan table as the first table for both
# the queries with GROUP BY and ORDER BY clause. # the queries with GROUP BY and ORDER BY clause.
EXPLAIN SELECT t1.a EXPLAIN SELECT t1.a
@ -4471,9 +4455,9 @@ FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3) WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
ORDER BY t1.a DESC; ORDER BY t1.a DESC;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using filesort 1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 10 Using index
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 Using index 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 97 Using where
EXPLAIN FORMAT=JSON SELECT t1.a EXPLAIN FORMAT=JSON SELECT t1.a
FROM t1 FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3) WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
@ -4484,14 +4468,28 @@ EXPLAIN
"select_id": 1, "select_id": 1,
"nested_loop": [ "nested_loop": [
{ {
"read_sorted_file": { "table": {
"filesort": { "table_name": "t1",
"sort_key": "t1.a desc", "access_type": "index",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["a"],
"rows": 10,
"filtered": 100,
"using_index": true
}
},
{
"table": { "table": {
"table_name": "<subquery2>", "table_name": "<subquery2>",
"access_type": "ALL", "access_type": "eq_ref",
"possible_keys": ["distinct_key"], "possible_keys": ["distinct_key"],
"rows": 5, "key": "distinct_key",
"key_length": "4",
"used_key_parts": ["a"],
"ref": ["func"],
"rows": 1,
"filtered": 100, "filtered": 100,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
@ -4502,9 +4500,9 @@ EXPLAIN
"table": { "table": {
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
"rows": 5, "rows": 97,
"filtered": 100, "filtered": 100,
"attached_condition": "t2.b = 3 and t2.a is not null" "attached_condition": "t2.b = 3"
} }
} }
] ]
@ -4512,22 +4510,6 @@ EXPLAIN
} }
} }
} }
}
},
{
"table": {
"table_name": "t1",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["a"],
"ref": ["test.t2.a"],
"rows": 1,
"filtered": 100,
"using_index": true
}
}
] ]
} }
} }
@ -4544,9 +4526,9 @@ FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3) WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
GROUP BY t1.a DESC; GROUP BY t1.a DESC;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using filesort 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 10 Using filesort
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 97 Using where
EXPLAIN FORMAT=JSON SELECT t1.a, group_concat(t1.b) EXPLAIN FORMAT=JSON SELECT t1.a, group_concat(t1.b)
FROM t1 FROM t1
WHERE t1.a IN (SELECT a FROM t2 WHERE b=3) WHERE t1.a IN (SELECT a FROM t2 WHERE b=3)
@ -4561,10 +4543,25 @@ EXPLAIN
"filesort": { "filesort": {
"sort_key": "t1.a desc", "sort_key": "t1.a desc",
"table": { "table": {
"table_name": "<subquery2>", "table_name": "t1",
"access_type": "ALL", "access_type": "ALL",
"possible_keys": ["PRIMARY"],
"rows": 10,
"filtered": 100
}
}
}
},
{
"table": {
"table_name": "<subquery2>",
"access_type": "eq_ref",
"possible_keys": ["distinct_key"], "possible_keys": ["distinct_key"],
"rows": 5, "key": "distinct_key",
"key_length": "4",
"used_key_parts": ["a"],
"ref": ["func"],
"rows": 1,
"filtered": 100, "filtered": 100,
"materialized": { "materialized": {
"unique": 1, "unique": 1,
@ -4575,9 +4572,9 @@ EXPLAIN
"table": { "table": {
"table_name": "t2", "table_name": "t2",
"access_type": "ALL", "access_type": "ALL",
"rows": 5, "rows": 97,
"filtered": 100, "filtered": 100,
"attached_condition": "t2.b = 3 and t2.a is not null" "attached_condition": "t2.b = 3"
} }
} }
] ]
@ -4585,21 +4582,6 @@ EXPLAIN
} }
} }
} }
}
},
{
"table": {
"table_name": "t1",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["a"],
"ref": ["test.t2.a"],
"rows": 1,
"filtered": 100
}
}
] ]
} }
} }

View File

@ -922,17 +922,6 @@ SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
--echo # Must return 1 row --echo # Must return 1 row
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
--echo # With more rows "filesort" is removed
INSERT INTO t1 select seq,seq from seq_1_to_2;
EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
--echo # With more rows "range" changes to "ref_or_null"
INSERT INTO t1 select seq,seq from seq_3_to_10;
EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
# part 2 of the problem : DESC test cases # part 2 of the problem : DESC test cases
--echo # Must use ref-or-null on the a_c index --echo # Must use ref-or-null on the a_c index
--replace_column 1 x 2 x 3 x 6 x 7 x 8 x 9 x 10 x --replace_column 1 x 2 x 3 x 6 x 7 x 8 x 9 x 10 x
@ -2409,7 +2398,7 @@ let $query= select
t2.key1 = t1.a and t2.key1 IS NOT NULL t2.key1 = t1.a and t2.key1 IS NOT NULL
ORDER BY ORDER BY
t2.key2 ASC t2.key2 ASC
LIMIT 1) LIMIT 1) as "con"
from t1; from t1;
--echo # here type should show ref not index --echo # here type should show ref not index
@ -2692,8 +2681,8 @@ CREATE TABLE t2 (a INT, b INT);
INSERT INTO t1 (a,b) VALUES (58,1),(96,2),(273,3),(23,4),(231,5),(525,6), INSERT INTO t1 (a,b) VALUES (58,1),(96,2),(273,3),(23,4),(231,5),(525,6),
(2354,7),(321421,3),(535,2),(4535,3); (2354,7),(321421,3),(535,2),(4535,3);
INSERT INTO t2 (a,b) VALUES (58,3),(96,3),(273,3),(1000,1000),(2000,2000); INSERT INTO t2 (a,b) VALUES (58,3),(96,3),(273,3),(1000,1000),(2000,2000),(3000,3000);
INSERT INTO t2 select seq,seq from seq_10_to_100;
--echo # Join order should have the SJM scan table as the first table for both --echo # Join order should have the SJM scan table as the first table for both
--echo # the queries with GROUP BY and ORDER BY clause. --echo # the queries with GROUP BY and ORDER BY clause.

View File

@ -256,7 +256,7 @@ d1 > '2019-02-06 00:00:00'
dd.d1, dd.d2, dd.id limit 1 dd.d1, dd.d2, dd.id limit 1
); );
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index 1 PRIMARY t1 ALL NULL NULL NULL NULL #
1 PRIMARY t2 eq_ref PRIMARY,id2 id2 8 test.t1.id,func # Using where; Using index 1 PRIMARY t2 eq_ref PRIMARY,id2 id2 8 test.t1.id,func # Using where; Using index
2 DEPENDENT SUBQUERY dd ref id2,for_latest_sort id2 4 test.t1.id # Using where; Using filesort 2 DEPENDENT SUBQUERY dd ref id2,for_latest_sort id2 4 test.t1.id # Using where; Using filesort
drop table t1,t2,t3; drop table t1,t2,t3;

View File

@ -2361,11 +2361,11 @@ b c
EXPLAIN EXPLAIN
SELECT b, c FROM t1 WHERE b = 1 GROUP BY b, c; SELECT b, c FROM t1 WHERE b = 1 GROUP BY b, c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range bc bc 10 NULL 8 Using where; Using index for group-by 1 SIMPLE t1 ref bc bc 5 const 23 Using where; Using index
EXPLAIN EXPLAIN
SELECT b, c FROM t1 WHERE b = 1 or b=2 GROUP BY b, c; SELECT b, c FROM t1 WHERE b = 1 or b=2 GROUP BY b, c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range bc bc 10 NULL 8 Using where; Using index for group-by 1 SIMPLE t1 range bc bc 5 NULL 23 Using where; Using index
DROP TABLE t1; DROP TABLE t1;
# #
# Bug #45807: crash accessing partitioned table and sql_mode # Bug #45807: crash accessing partitioned table and sql_mode

Some files were not shown because too many files have changed in this diff Show More